diff --git a/src/main/java/com/simibubi/create/content/decoration/copycat/CopycatPanelBlock.java b/src/main/java/com/simibubi/create/content/decoration/copycat/CopycatPanelBlock.java index 01e875617..d7adde68e 100644 --- a/src/main/java/com/simibubi/create/content/decoration/copycat/CopycatPanelBlock.java +++ b/src/main/java/com/simibubi/create/content/decoration/copycat/CopycatPanelBlock.java @@ -9,6 +9,8 @@ import com.simibubi.create.foundation.placement.IPlacementHelper; import com.simibubi.create.foundation.placement.PlacementHelpers; import com.simibubi.create.foundation.placement.PlacementOffset; +import com.simibubi.create.foundation.utility.worldWrappers.OcclusionTestWorld; + import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -175,12 +177,23 @@ public class CopycatPanelBlock extends WaterloggedCopycatBlock { @Override public boolean hidesNeighborFace(BlockGetter level, BlockPos pos, BlockState state, BlockState neighborState, Direction dir) { + BlockPos otherPos = pos.relative(dir); + BlockState material = getMaterial(level, pos); + BlockState otherMaterial = getMaterial(level, otherPos); + if (state.is(this) == neighborState.is(this)) { - if (CopycatSpecialCases.isBarsMaterial(getMaterial(level, pos)) - && CopycatSpecialCases.isBarsMaterial(getMaterial(level, pos.relative(dir)))) + if (CopycatSpecialCases.isBarsMaterial(material) + && CopycatSpecialCases.isBarsMaterial(otherMaterial)) return state.getValue(FACING) == neighborState.getValue(FACING); - if (getMaterial(level, pos).skipRendering(getMaterial(level, pos.relative(dir)), dir.getOpposite())) + if (material.skipRendering(otherMaterial, dir.getOpposite())) return isOccluded(state, neighborState, dir.getOpposite()); + + OcclusionTestWorld occlusionTestWorld = new OcclusionTestWorld(); + occlusionTestWorld.setBlock(pos, material); + occlusionTestWorld.setBlock(otherPos, otherMaterial); + if (material.isSolidRender(occlusionTestWorld, pos) && otherMaterial.isSolidRender(occlusionTestWorld, otherPos)) + if(!Block.shouldRenderFace(otherMaterial, occlusionTestWorld, pos, dir.getOpposite(), otherPos)) + return isOccluded(state, neighborState, dir.getOpposite()); } return state.getValue(FACING) == dir.getOpposite() diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/OcclusionTestWorld.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/OcclusionTestWorld.java new file mode 100644 index 000000000..23f1ab38d --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/OcclusionTestWorld.java @@ -0,0 +1,59 @@ +package com.simibubi.create.foundation.utility.worldWrappers; + +import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; + +import org.jetbrains.annotations.Nullable; + +import javax.annotation.ParametersAreNonnullByDefault; + +import java.util.HashMap; +import java.util.Map; + +/** + * A simple implementation of BlockGetter for testing occlusion culling. (For example, to test copycats) + */ +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public class OcclusionTestWorld implements BlockGetter { + private final Map blocks = new HashMap<>(); + + public void setBlock(BlockPos pos, BlockState state) { + blocks.put(pos.immutable(), state); + } + + public void clear() { + blocks.clear(); + } + + @Nullable + @Override + public BlockEntity getBlockEntity(BlockPos pos) { + return null; + } + + @Override + public BlockState getBlockState(BlockPos pos) { + return blocks.get(pos); + } + + @Override + public FluidState getFluidState(BlockPos pos) { + return Fluids.EMPTY.defaultFluidState(); + } + + @Override + public int getHeight() { + return 256; + } + + @Override + public int getMinBuildHeight() { + return 0; + } +}