diff --git a/common/src/main/java/com/ordana/spelunkery/blocks/ChannelSluiceBlock.java b/common/src/main/java/com/ordana/spelunkery/blocks/ChannelSluiceBlock.java index c80b4f3e..c027055f 100644 --- a/common/src/main/java/com/ordana/spelunkery/blocks/ChannelSluiceBlock.java +++ b/common/src/main/java/com/ordana/spelunkery/blocks/ChannelSluiceBlock.java @@ -84,7 +84,8 @@ public class ChannelSluiceBlock extends ModBaseEntityBlock { public ChannelSluiceBlock(Properties properties) { super(properties); - super.registerDefaultState((this.stateDefinition.any()).setValue(GRATE_NORTH, false).setValue(GRATE_SOUTH, false).setValue(GRATE_EAST, false).setValue(GRATE_WEST, false)); + super.registerDefaultState((this.stateDefinition.any()).setValue(GRATE_NORTH, false) + .setValue(GRATE_SOUTH, false).setValue(GRATE_EAST, false).setValue(GRATE_WEST, false)); } protected void createBlockStateDefinition(StateDefinition.Builder builder) { @@ -92,18 +93,21 @@ protected void createBlockStateDefinition(StateDefinition.Builder playerx.broadcastBreakEvent(hand)); + stack.hurtAndBreak(1, player, (playerx) -> playerx.broadcastBreakEvent(hand)); } player.awardStat(Stats.ITEM_USED.get(stack.getItem())); return InteractionResult.sidedSuccess(level.isClientSide); - } - else if (level.isClientSide) { + } else if (level.isClientSide) { return InteractionResult.SUCCESS; - } - else { + } else { BlockEntity blockEntity = level.getBlockEntity(pos); if (blockEntity instanceof SluiceBlockEntity) { - player.openMenu((SluiceBlockEntity)blockEntity); + player.openMenu((SluiceBlockEntity) blockEntity); } return InteractionResult.CONSUME; } } - @Override public VoxelShape getCollisionShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { if (context instanceof EntityCollisionContext c && c.getEntity() instanceof ItemEntity) { @@ -194,8 +201,7 @@ public VoxelShape getCollisionShape(BlockState state, BlockGetter level, BlockPo if (north && south && east && west) { return SHAPE_TALL_NESW; - } - else if (north) { + } else if (north) { model = SHAPE_TALL_N; if (east) { @@ -258,8 +264,9 @@ else if (west) { public static int getFlow(Level level, BlockState state, BlockPos pos) { int flowCount = 0; for (var direction : Direction.Plane.HORIZONTAL) { - BlockPos neighborPos = pos.relative(direction); - if (!level.getFluidState(neighborPos).is(Fluids.EMPTY) && state.getValue(GRATE_PROPERTY_BY_DIRECTION.get(direction))) { + BlockPos neighborPos = pos.relative(direction).above(); + if (!level.getFluidState(neighborPos).is(Fluids.EMPTY) + && state.getValue(GRATE_PROPERTY_BY_DIRECTION.get(direction))) { flowCount += 1; } } @@ -270,7 +277,7 @@ public void onRemove(BlockState state, Level level, BlockPos pos, BlockState new if (!state.is(newState.getBlock())) { BlockEntity blockEntity = level.getBlockEntity(pos); if (blockEntity instanceof Container) { - Containers.dropContents(level, pos, (Container)blockEntity); + Containers.dropContents(level, pos, (Container) blockEntity); level.updateNeighbourForOutputSignal(pos, this); } @@ -281,7 +288,7 @@ public void onRemove(BlockState state, Level level, BlockPos pos, BlockState new public void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) { BlockEntity blockEntity = level.getBlockEntity(pos); if (blockEntity instanceof SluiceBlockEntity) { - ((SluiceBlockEntity)blockEntity).recheckOpen(); + ((SluiceBlockEntity) blockEntity).recheckOpen(); } super.tick(state, level, pos, random); @@ -296,11 +303,12 @@ public RenderShape getRenderShape(BlockState state) { return RenderShape.MODEL; } - public void setPlacedBy(Level level, BlockPos pos, BlockState state, @org.jetbrains.annotations.Nullable LivingEntity placer, ItemStack stack) { + public void setPlacedBy(Level level, BlockPos pos, BlockState state, + @org.jetbrains.annotations.Nullable LivingEntity placer, ItemStack stack) { if (stack.hasCustomHoverName()) { BlockEntity blockEntity = level.getBlockEntity(pos); if (blockEntity instanceof SluiceBlockEntity) { - ((SluiceBlockEntity)blockEntity).setCustomName(stack.getHoverName()); + ((SluiceBlockEntity) blockEntity).setCustomName(stack.getHoverName()); } } @@ -313,6 +321,7 @@ public boolean hasAnalogOutputSignal(BlockState state) { public int getAnalogOutputSignal(BlockState state, Level level, BlockPos pos) { return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(level.getBlockEntity(pos)); } + public boolean triggerEvent(BlockState state, Level level, BlockPos pos, int id, int param) { super.triggerEvent(state, level, pos, id, param); BlockEntity blockEntity = level.getBlockEntity(pos); @@ -322,14 +331,18 @@ public boolean triggerEvent(BlockState state, Level level, BlockPos pos, int id, @Nullable public MenuProvider getMenuProvider(BlockState state, Level level, BlockPos pos) { BlockEntity blockEntity = level.getBlockEntity(pos); - return blockEntity instanceof MenuProvider ? (MenuProvider)blockEntity : null; + return blockEntity instanceof MenuProvider ? (MenuProvider) blockEntity : null; } @Nullable @Override - public BlockEntityTicker getTicker(Level level, BlockState state, BlockEntityType blockEntityType) { + public BlockEntityTicker getTicker(Level level, BlockState state, + BlockEntityType blockEntityType) { if (!level.isClientSide) { - return createTickerHelper(blockEntityType, (state.is(ModBlocks.WOODEN_SLUICE.get()) ? ModEntities.WOODEN_SLUICE.get() : ModEntities.STONE_SLUICE.get()), SluiceBlockEntity::pushItemsTick); + return createTickerHelper(blockEntityType, + (state.is(ModBlocks.WOODEN_SLUICE.get()) ? ModEntities.WOODEN_SLUICE.get() + : ModEntities.STONE_SLUICE.get()), + SluiceBlockEntity::pushItemsTick); } else { return super.getTicker(level, state, blockEntityType); } @@ -340,20 +353,20 @@ public BlockEntityTicker getTicker(Level level, Block GRATE_EAST = ModBlockProperties.GRATE_EAST; GRATE_SOUTH = ModBlockProperties.GRATE_SOUTH; GRATE_WEST = ModBlockProperties.GRATE_WEST; - GRATE_PROPERTY_BY_DIRECTION = ImmutableMap.copyOf((Map) Util.make(Maps.newEnumMap(Direction.class), (enumMap) -> { - enumMap.put(Direction.NORTH, GRATE_NORTH); - enumMap.put(Direction.EAST, GRATE_EAST); - enumMap.put(Direction.SOUTH, GRATE_SOUTH); - enumMap.put(Direction.WEST, GRATE_WEST); - })); - + GRATE_PROPERTY_BY_DIRECTION = ImmutableMap + .copyOf((Map) Util.make(Maps.newEnumMap(Direction.class), (enumMap) -> { + enumMap.put(Direction.NORTH, GRATE_NORTH); + enumMap.put(Direction.EAST, GRATE_EAST); + enumMap.put(Direction.SOUTH, GRATE_SOUTH); + enumMap.put(Direction.WEST, GRATE_WEST); + })); SHAPE_TALL_NONE = Shapes.or(SHAPE_LEGS, SHAPE_BASE); SHAPE_TALL_N = Shapes.or(SHAPE_LEGS, SHAPE_BASE, Block.box(0.0D, 12.0D, -2.0D, 16.0D, 32.0D, 0.0D)); SHAPE_TALL_E = Shapes.or(SHAPE_LEGS, SHAPE_BASE, Block.box(16.0D, 12.0D, 0.0D, 18.0D, 32.0D, 16.0D)); SHAPE_TALL_S = Shapes.or(SHAPE_LEGS, SHAPE_BASE, Block.box(0.0D, 12.0D, 16.0D, 16.0D, 32.0D, 18.0D)); - SHAPE_TALL_W = Shapes.or(SHAPE_LEGS, SHAPE_BASE, Block.box(-2.0D, 12.0D, 0.0D, 0.0D, 32.0D, 16.0D)); + SHAPE_TALL_W = Shapes.or(SHAPE_LEGS, SHAPE_BASE, Block.box(-2.0D, 12.0D, 0.0D, 0.0D, 32.0D, 16.0D)); SHAPE_TALL_NE = Shapes.or(SHAPE_TALL_N, SHAPE_TALL_E); SHAPE_TALL_SE = Shapes.or(SHAPE_TALL_S, SHAPE_TALL_E);