Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamped the check for side invisibility. #51

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 17 additions & 72 deletions src/main/java/net/wurstclient/glass/GlassSlabBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
import net.minecraft.block.Blocks;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.SlabBlock;
import net.minecraft.block.StairsBlock;
import net.minecraft.block.enums.BlockHalf;
import net.minecraft.block.enums.SlabType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.EmptyBlockView;

public final class GlassSlabBlock extends SlabBlock
public class GlassSlabBlock extends SlabBlock
{
public GlassSlabBlock(Settings settings)
{
Expand All @@ -37,79 +35,26 @@ public boolean isSideInvisible(BlockState state, BlockState stateFrom,
if(stateFrom.getBlock() == Blocks.GLASS)
return true;

if(stateFrom.getBlock() == this)
if(isInvisibleToGlassSlab(state, stateFrom, direction))
return true;

if(stateFrom.getBlock() == MoGlassBlocks.GLASS_STAIRS)
if(isInvisibleToGlassStairs(state, stateFrom, direction))
return true;

return super.isSideInvisible(state, stateFrom, direction);
}

private boolean isInvisibleToGlassSlab(BlockState state,
BlockState stateFrom, Direction direction)
{
SlabType type = state.get(SlabBlock.TYPE);
SlabType typeFrom = stateFrom.get(SlabBlock.TYPE);
if(stateFrom.getBlock() == this
&& isInvisible(state, stateFrom, direction))
return true;

switch(direction)
{
case UP:
if(typeFrom != SlabType.TOP && type != SlabType.BOTTOM)
return true;
break;

case DOWN:
if(typeFrom != SlabType.BOTTOM && type != SlabType.TOP)
return true;
break;

case NORTH:
case EAST:
case SOUTH:
case WEST:
if(type == typeFrom || typeFrom == SlabType.DOUBLE)
return true;
break;
}
if(stateFrom.getBlock() == MoGlassBlocks.GLASS_STAIRS
&& isInvisible(state, stateFrom, direction))
return true;

return false;
return super.isSideInvisible(state, stateFrom, direction);
}

private boolean isInvisibleToGlassStairs(BlockState state,
BlockState stateFrom, Direction direction)
protected boolean isInvisible(BlockState state, BlockState stateFrom,
Direction direction)
{
SlabType type = state.get(SlabBlock.TYPE);
BlockHalf halfFrom = stateFrom.get(StairsBlock.HALF);
Direction facingFrom = stateFrom.get(StairsBlock.FACING);

// up
if(direction == Direction.UP)
if(halfFrom == BlockHalf.BOTTOM)
return true;

// down
if(direction == Direction.DOWN)
if(halfFrom == BlockHalf.TOP)
return true;

// other stairs rear
if(facingFrom == direction.getOpposite())
return true;

// sides
if(direction.getHorizontalQuarterTurns() != -1)
{
if(type == SlabType.BOTTOM && halfFrom == BlockHalf.BOTTOM)
return true;

if(type == SlabType.TOP && halfFrom == BlockHalf.TOP)
return true;
}

return false;
VoxelShape stateCullingShape =
state.getOutlineShape(EmptyBlockView.INSTANCE, BlockPos.ORIGIN);
VoxelShape stateFromCullingShape =
stateFrom.getOutlineShape(EmptyBlockView.INSTANCE, BlockPos.ORIGIN);
return VoxelShapes.isSideCovered(stateCullingShape,
stateFromCullingShape, direction);
}

@Override
Expand Down
Loading
Loading