diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/lv/enes/mc/eris_alchemy/block/AlchemicalChestBlock.java | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/block/AlchemicalChestBlock.java b/src/main/java/lv/enes/mc/eris_alchemy/block/AlchemicalChestBlock.java index c013df6..9a3b413 100644 --- a/src/main/java/lv/enes/mc/eris_alchemy/block/AlchemicalChestBlock.java +++ b/src/main/java/lv/enes/mc/eris_alchemy/block/AlchemicalChestBlock.java | |||
| @@ -14,6 +14,7 @@ import net.minecraft.world.entity.player.Player; | |||
| 14 | import net.minecraft.world.item.context.BlockPlaceContext; | 14 | import net.minecraft.world.item.context.BlockPlaceContext; |
| 15 | import net.minecraft.world.level.BlockGetter; | 15 | import net.minecraft.world.level.BlockGetter; |
| 16 | import net.minecraft.world.level.Level; | 16 | import net.minecraft.world.level.Level; |
| 17 | import net.minecraft.world.level.LevelAccessor; | ||
| 17 | import net.minecraft.world.level.block.*; | 18 | import net.minecraft.world.level.block.*; |
| 18 | import net.minecraft.world.level.block.entity.BlockEntity; | 19 | import net.minecraft.world.level.block.entity.BlockEntity; |
| 19 | import net.minecraft.world.level.block.entity.BlockEntityTicker; | 20 | import net.minecraft.world.level.block.entity.BlockEntityTicker; |
| @@ -22,15 +23,20 @@ import net.minecraft.world.level.block.entity.ChestBlockEntity; | |||
| 22 | import net.minecraft.world.level.block.state.BlockState; | 23 | import net.minecraft.world.level.block.state.BlockState; |
| 23 | import net.minecraft.world.level.block.state.StateDefinition; | 24 | import net.minecraft.world.level.block.state.StateDefinition; |
| 24 | import net.minecraft.world.level.block.state.properties.BlockStateProperties; | 25 | import net.minecraft.world.level.block.state.properties.BlockStateProperties; |
| 26 | import net.minecraft.world.level.block.state.properties.BooleanProperty; | ||
| 25 | import net.minecraft.world.level.block.state.properties.DirectionProperty; | 27 | import net.minecraft.world.level.block.state.properties.DirectionProperty; |
| 28 | import net.minecraft.world.level.material.FluidState; | ||
| 29 | import net.minecraft.world.level.material.Fluids; | ||
| 26 | import net.minecraft.world.level.pathfinder.PathComputationType; | 30 | import net.minecraft.world.level.pathfinder.PathComputationType; |
| 27 | import net.minecraft.world.phys.BlockHitResult; | 31 | import net.minecraft.world.phys.BlockHitResult; |
| 28 | import net.minecraft.world.phys.shapes.CollisionContext; | 32 | import net.minecraft.world.phys.shapes.CollisionContext; |
| 29 | import net.minecraft.world.phys.shapes.VoxelShape; | 33 | import net.minecraft.world.phys.shapes.VoxelShape; |
| 30 | 34 | ||
| 31 | public class AlchemicalChestBlock extends AbstractChestBlock<AlchemicalChestBlockEntity> { | 35 | public class AlchemicalChestBlock extends AbstractChestBlock<AlchemicalChestBlockEntity> implements SimpleWaterloggedBlock { |
| 32 | public static final Component CONTAINER_TITLE = Component.translatable("container.eris_alchemy.alchemical_chest"); | ||
| 33 | public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; | 36 | public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; |
| 37 | public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; | ||
| 38 | |||
| 39 | public static final Component CONTAINER_TITLE = Component.translatable("container.eris_alchemy.alchemical_chest"); | ||
| 34 | public static final VoxelShape SHAPE = Block.box(1.0, 0.0, 1.0, 15.0, 14.0, 15.0); | 40 | public static final VoxelShape SHAPE = Block.box(1.0, 0.0, 1.0, 15.0, 14.0, 15.0); |
| 35 | 41 | ||
| 36 | public static Container getContainer(Level world, BlockPos pos) { | 42 | public static Container getContainer(Level world, BlockPos pos) { |
| @@ -44,6 +50,7 @@ public class AlchemicalChestBlock extends AbstractChestBlock<AlchemicalChestBloc | |||
| 44 | super(properties, () -> ErisAlchemyBlockEntities.ALCHEMICAL_CHEST); | 50 | super(properties, () -> ErisAlchemyBlockEntities.ALCHEMICAL_CHEST); |
| 45 | registerDefaultState(getStateDefinition().any() | 51 | registerDefaultState(getStateDefinition().any() |
| 46 | .setValue(FACING, Direction.NORTH) | 52 | .setValue(FACING, Direction.NORTH) |
| 53 | .setValue(WATERLOGGED, false) | ||
| 47 | ); | 54 | ); |
| 48 | } | 55 | } |
| 49 | 56 | ||
| @@ -53,15 +60,17 @@ public class AlchemicalChestBlock extends AbstractChestBlock<AlchemicalChestBloc | |||
| 53 | return DoubleBlockCombiner.Combiner::acceptNone; | 60 | return DoubleBlockCombiner.Combiner::acceptNone; |
| 54 | } | 61 | } |
| 55 | 62 | ||
| 63 | @SuppressWarnings("deprecation") | ||
| 56 | @Override | 64 | @Override |
| 57 | protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { | 65 | public int getAnalogOutputSignal(BlockState state, Level world, BlockPos pos) { |
| 58 | builder.add(FACING); | 66 | return AlchemicalChestMenu.getRedstoneSignalFromContainer(getContainer(world, pos)); |
| 59 | } | 67 | } |
| 60 | 68 | ||
| 61 | @SuppressWarnings("deprecation") | 69 | @SuppressWarnings("deprecation") |
| 70 | @Nonnull | ||
| 62 | @Override | 71 | @Override |
| 63 | public int getAnalogOutputSignal(BlockState state, Level world, BlockPos pos) { | 72 | public FluidState getFluidState(BlockState state) { |
| 64 | return AlchemicalChestMenu.getRedstoneSignalFromContainer(getContainer(world, pos)); | 73 | return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); |
| 65 | } | 74 | } |
| 66 | 75 | ||
| 67 | @Override | 76 | @Override |
| @@ -88,7 +97,8 @@ public class AlchemicalChestBlock extends AbstractChestBlock<AlchemicalChestBloc | |||
| 88 | @Override | 97 | @Override |
| 89 | public BlockState getStateForPlacement(BlockPlaceContext ctx) { | 98 | public BlockState getStateForPlacement(BlockPlaceContext ctx) { |
| 90 | return defaultBlockState() | 99 | return defaultBlockState() |
| 91 | .setValue(FACING, ctx.getHorizontalDirection().getOpposite()); | 100 | .setValue(FACING, ctx.getHorizontalDirection().getOpposite()) |
| 101 | .setValue(WATERLOGGED, ctx.getLevel().getFluidState(ctx.getClickedPos()).is(Fluids.WATER)); | ||
| 92 | } | 102 | } |
| 93 | 103 | ||
| 94 | @Override | 104 | @Override |
| @@ -145,6 +155,17 @@ public class AlchemicalChestBlock extends AbstractChestBlock<AlchemicalChestBloc | |||
| 145 | @SuppressWarnings("deprecation") | 155 | @SuppressWarnings("deprecation") |
| 146 | @Nonnull | 156 | @Nonnull |
| 147 | @Override | 157 | @Override |
| 158 | public BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { | ||
| 159 | if (state.getValue(WATERLOGGED)) { | ||
| 160 | world.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); | ||
| 161 | } | ||
| 162 | |||
| 163 | return super.updateShape(state, direction, neighborState, world, pos, neighborPos); | ||
| 164 | } | ||
| 165 | |||
| 166 | @SuppressWarnings("deprecation") | ||
| 167 | @Nonnull | ||
| 168 | @Override | ||
| 148 | public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { | 169 | public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { |
| 149 | if (world.isClientSide) { | 170 | if (world.isClientSide) { |
| 150 | return InteractionResult.SUCCESS; | 171 | return InteractionResult.SUCCESS; |
| @@ -159,4 +180,9 @@ public class AlchemicalChestBlock extends AbstractChestBlock<AlchemicalChestBloc | |||
| 159 | 180 | ||
| 160 | return InteractionResult.CONSUME; | 181 | return InteractionResult.CONSUME; |
| 161 | } | 182 | } |
| 183 | |||
| 184 | @Override | ||
| 185 | protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { | ||
| 186 | builder.add(FACING, WATERLOGGED); | ||
| 187 | } | ||
| 162 | } | 188 | } |