Skip to content

Commit

Permalink
Move blockstate property to MetalLadderBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
voidsong-dragonfly committed Jun 22, 2024
1 parent 12bcdcd commit bb3ee6a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class IEProperties

public static final BooleanProperty MULTIBLOCKSLAVE = BooleanProperty.create("multiblockslave");
public static final BooleanProperty ACTIVE = BooleanProperty.create("active");
public static final BooleanProperty OPEN = BooleanProperty.create("open");
public static final BooleanProperty MIRRORED = BooleanProperty.create("mirrored");

public static final BooleanProperty UP = BooleanProperty.create("up");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,11 +716,11 @@ private void createLadderBlock(Supplier<? extends Block> b, ModelFile model, Mod
{
builder.partialState()
.with(IEProperties.FACING_HORIZONTAL, d)
.with(IEProperties.OPEN, false)
.with(MetalLadderBlock.OPEN, false)
.setModels(new ConfiguredModel(model, 0, getAngle(d, 180), true));
builder.partialState()
.with(IEProperties.FACING_HORIZONTAL, d)
.with(IEProperties.OPEN, true)
.with(MetalLadderBlock.OPEN, true)
.setModels(new ConfiguredModel(modelOpen, 0, getAngle(d, 180), false));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraft.world.level.block.LadderBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext;
Expand All @@ -37,6 +38,8 @@

public class MetalLadderBlock extends LadderBlock implements IHammerBlockInteraction
{
public static final BooleanProperty OPEN = BooleanProperty.create("open");

private static final Map<Direction, VoxelShape> FRAMES = new EnumMap<>(Direction.class);
private static final Map<Direction, VoxelShape> FRAMES_OPEN = new EnumMap<>(Direction.class);

Expand Down Expand Up @@ -94,7 +97,7 @@ public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, Co
else
{
Direction ladderSide = state.getValue(LadderBlock.FACING);
return state.getValue(IEProperties.OPEN) ? Shapes.joinUnoptimized(base, FRAMES_OPEN.get(ladderSide), BooleanOp.OR) : Shapes.joinUnoptimized(base, FRAMES.get(ladderSide), BooleanOp.OR);
return state.getValue(OPEN) ? Shapes.joinUnoptimized(base, FRAMES_OPEN.get(ladderSide), BooleanOp.OR) : Shapes.joinUnoptimized(base, FRAMES.get(ladderSide), BooleanOp.OR);
}
}

Expand All @@ -104,7 +107,7 @@ public BlockState getStateForPlacement(BlockPlaceContext ctx)
{
BlockState baseState = super.getStateForPlacement(ctx);
if(baseState==null) return baseState;
baseState = baseState.setValue(IEProperties.OPEN, false);
baseState = baseState.setValue(OPEN, false);
if(type==CoverType.NONE)
return baseState;
else
Expand All @@ -122,7 +125,7 @@ public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos)

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> state) {
state.add(FACING, WATERLOGGED, IEProperties.OPEN);
state.add(FACING, WATERLOGGED, OPEN);
}

@Override
Expand All @@ -131,7 +134,7 @@ public InteractionResult useHammer(BlockState state, Level world, BlockPos pos,
if (player==null) return InteractionResult.FAIL;
if(type!=CoverType.NONE&&player.isShiftKeyDown())
{
boolean b = world.setBlockAndUpdate(pos, state.setValue(IEProperties.OPEN, !state.getValue(IEProperties.OPEN)));
boolean b = world.setBlockAndUpdate(pos, state.setValue(OPEN, !state.getValue(OPEN)));
if(b)
return InteractionResult.SUCCESS;
else
Expand Down

0 comments on commit bb3ee6a

Please sign in to comment.