|
2 | 2 |
|
3 | 3 | import net.minecraft.core.BlockPos;
|
4 | 4 | import net.minecraft.core.Direction;
|
| 5 | +import net.minecraft.world.InteractionHand; |
| 6 | +import net.minecraft.world.InteractionResult; |
| 7 | +import net.minecraft.world.entity.player.Player; |
5 | 8 | import net.minecraft.world.item.context.BlockPlaceContext;
|
6 | 9 | import net.minecraft.world.level.BlockGetter;
|
| 10 | +import net.minecraft.world.level.Level; |
| 11 | +import net.minecraft.world.level.LevelAccessor; |
7 | 12 | import net.minecraft.world.level.LevelReader;
|
| 13 | +import net.minecraft.world.level.block.AbstractCandleBlock; |
8 | 14 | import net.minecraft.world.level.block.Block;
|
9 | 15 | import net.minecraft.world.level.block.LanternBlock;
|
10 | 16 | import net.minecraft.world.level.block.state.BlockState;
|
11 | 17 | import net.minecraft.world.level.block.state.StateDefinition;
|
| 18 | +import net.minecraft.world.level.material.FluidState; |
| 19 | +import net.minecraft.world.level.material.Fluids; |
| 20 | +import net.minecraft.world.phys.BlockHitResult; |
12 | 21 | import net.minecraft.world.phys.shapes.CollisionContext;
|
13 | 22 | import net.minecraft.world.phys.shapes.Shapes;
|
14 | 23 | import net.minecraft.world.phys.shapes.VoxelShape;
|
15 | 24 | import org.jetbrains.annotations.Nullable;
|
16 | 25 |
|
17 | 26 | import java.util.Optional;
|
18 | 27 |
|
| 28 | +import static net.minecraft.world.level.block.CandleBlock.LIT; |
19 | 29 | import static net.minecraft.world.level.block.CandleBlock.MAX_CANDLES;
|
20 | 30 | import static net.minecraft.world.level.block.CandleBlock.MIN_CANDLES;
|
21 | 31 | import static net.minecraft.world.level.block.state.properties.BlockStateProperties.CANDLES;
|
@@ -54,14 +64,15 @@ public VigilCandleBlock(Properties properties) {
|
54 | 64 | super(properties);
|
55 | 65 | registerDefaultState(defaultBlockState()
|
56 | 66 | .setValue(HANGING, false)
|
| 67 | + .setValue(LIT, false) |
57 | 68 | .setValue(WATERLOGGED, false)
|
58 | 69 | .setValue(CANDLES, MIN_CANDLES));
|
59 | 70 | }
|
60 | 71 |
|
61 | 72 | @Override
|
62 | 73 | protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
63 | 74 | super.createBlockStateDefinition(builder);
|
64 |
| - builder.add(CANDLES); |
| 75 | + builder.add(CANDLES, LIT); |
65 | 76 | }
|
66 | 77 |
|
67 | 78 | public boolean canBeReplaced(BlockState state, BlockPlaceContext context) {
|
@@ -99,4 +110,29 @@ public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) {
|
99 | 110 | }
|
100 | 111 | }
|
101 | 112 |
|
| 113 | + public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { |
| 114 | + if (player.getAbilities().mayBuild && player.getItemInHand(hand).isEmpty() && state.getValue(LIT)) { |
| 115 | + AbstractCandleBlock.extinguish(player, state, level, pos); |
| 116 | + return InteractionResult.sidedSuccess(level.isClientSide); |
| 117 | + } else { |
| 118 | + return InteractionResult.PASS; |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + public boolean placeLiquid(LevelAccessor level, BlockPos pos, BlockState state, FluidState fluid) { |
| 123 | + if (!state.getValue(WATERLOGGED) && fluid.getType() == Fluids.WATER) { |
| 124 | + BlockState waterlogged = state.setValue(WATERLOGGED, true); |
| 125 | + if (state.getValue(LIT)) { |
| 126 | + AbstractCandleBlock.extinguish(null, waterlogged, level, pos); |
| 127 | + } else { |
| 128 | + level.setBlock(pos, waterlogged, 3); |
| 129 | + } |
| 130 | + |
| 131 | + level.scheduleTick(pos, fluid.getType(), fluid.getType().getTickDelay(level)); |
| 132 | + return true; |
| 133 | + } else { |
| 134 | + return false; |
| 135 | + } |
| 136 | + } |
| 137 | + |
102 | 138 | }
|
0 commit comments