Skip to content

Commit

Permalink
fix: Check if a block face is invisible before the opaque test
Browse files Browse the repository at this point in the history
Fixes occlusion issues with translucent blocks
  • Loading branch information
jellysquid3 committed Jun 1, 2020
1 parent d028500 commit e730e13
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ public BlockOcclusionCache() {
* @param state The state of the block in the world
* @param view The world view for this render context
* @param pos The position of the block
* @param dir The facing direction of the side to check
* @param facing The facing direction of the side to check
* @return True if the block side facing {@param dir} is not occluded, otherwise false
*/
public boolean shouldDrawSide(BlockState state, BlockView view, BlockPos pos, Direction dir) {
BlockPos adjPos = this.cpos.set(pos).setOffset(dir);
public boolean shouldDrawSide(BlockState state, BlockView view, BlockPos pos, Direction facing) {
BlockPos adjPos = this.cpos.set(pos).setOffset(facing);
BlockState adjState = view.getBlockState(adjPos);

if (!adjState.isOpaque()) {
return true;
if (state.isSideInvisible(adjState, facing)) {
return false;
}

if (state.isSideInvisible(adjState, dir)) {
return false;
if (!adjState.isOpaque()) {
return true;
}

NeighborGroup cache = this.cache;
cache.self = state;
cache.other = adjState;
cache.facing = dir;
cache.facing = facing;

Object2ByteOpenHashMap<NeighborGroup> map = this.map;

Expand All @@ -51,8 +51,8 @@ public boolean shouldDrawSide(BlockState state, BlockView view, BlockPos pos, Di
return cached != 0;
}

VoxelShape selfShape = state.getCullingFace(view, pos, dir);
VoxelShape adjShape = adjState.getCullingFace(view, adjPos, dir.getOpposite());
VoxelShape selfShape = state.getCullingFace(view, pos, facing);
VoxelShape adjShape = adjState.getCullingFace(view, adjPos, facing.getOpposite());

boolean ret = VoxelShapes.matchesAnywhere(selfShape, adjShape, BooleanBiFunction.ONLY_FIRST);

Expand Down

0 comments on commit e730e13

Please sign in to comment.