mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-01-30 23:05:03 +01:00
feat: copycat panel block face culling
This commit is contained in:
parent
fa4f5243bc
commit
e03c191edd
2 changed files with 75 additions and 3 deletions
|
@ -9,6 +9,8 @@ import com.simibubi.create.foundation.placement.IPlacementHelper;
|
||||||
import com.simibubi.create.foundation.placement.PlacementHelpers;
|
import com.simibubi.create.foundation.placement.PlacementHelpers;
|
||||||
import com.simibubi.create.foundation.placement.PlacementOffset;
|
import com.simibubi.create.foundation.placement.PlacementOffset;
|
||||||
|
|
||||||
|
import com.simibubi.create.foundation.utility.worldWrappers.OcclusionTestWorld;
|
||||||
|
|
||||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
|
@ -175,12 +177,23 @@ public class CopycatPanelBlock extends WaterloggedCopycatBlock {
|
||||||
@Override
|
@Override
|
||||||
public boolean hidesNeighborFace(BlockGetter level, BlockPos pos, BlockState state, BlockState neighborState,
|
public boolean hidesNeighborFace(BlockGetter level, BlockPos pos, BlockState state, BlockState neighborState,
|
||||||
Direction dir) {
|
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 (state.is(this) == neighborState.is(this)) {
|
||||||
if (CopycatSpecialCases.isBarsMaterial(getMaterial(level, pos))
|
if (CopycatSpecialCases.isBarsMaterial(material)
|
||||||
&& CopycatSpecialCases.isBarsMaterial(getMaterial(level, pos.relative(dir))))
|
&& CopycatSpecialCases.isBarsMaterial(otherMaterial))
|
||||||
return state.getValue(FACING) == neighborState.getValue(FACING);
|
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());
|
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()
|
return state.getValue(FACING) == dir.getOpposite()
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue