feat: copycat panel block face culling

This commit is contained in:
IThundxr 2024-08-15 15:53:58 -04:00
parent fa4f5243bc
commit e03c191edd
Failed to generate hash of commit
2 changed files with 75 additions and 3 deletions

View file

@ -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()

View file

@ -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<BlockPos, BlockState> 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;
}
}