| 1 | package net.minecraft.world.level.block;
|
| 2 |
|
| 3 | import java.util.Map;
|
| 4 | import net.minecraft.core.BlockPos;
|
| 5 | import net.minecraft.core.Direction;
|
| 6 | import net.minecraft.util.RandomSource;
|
| 7 | import net.minecraft.world.item.context.BlockPlaceContext;
|
| 8 | import net.minecraft.world.level.BlockGetter;
|
| 9 | import net.minecraft.world.level.LevelReader;
|
| 10 | import net.minecraft.world.level.ScheduledTickAccess;
|
| 11 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 12 | import net.minecraft.world.level.block.state.BlockState;
|
| 13 | import net.minecraft.world.level.block.state.StateDefinition;
|
| 14 | import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
| 15 | import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
| 16 | import net.minecraft.world.level.material.FluidState;
|
| 17 | import net.minecraft.world.level.material.Fluids;
|
| 18 | import net.minecraft.world.level.pathfinder.PathComputationType;
|
| 19 | import net.minecraft.world.phys.shapes.CollisionContext;
|
| 20 | import net.minecraft.world.phys.shapes.Shapes;
|
| 21 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 22 |
|
| 23 | public class ChainBlock extends RotatedPillarBlock implements SimpleWaterloggedBlock {
|
| 24 | public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
|
| 25 | private static final Map<Direction.Axis, VoxelShape> SHAPES = Shapes.rotateAllAxis(Block.cube(3.0, 3.0, 16.0));
|
| 26 |
|
| 27 | public ChainBlock(final BlockBehaviour.Properties properties) {
|
| 28 | super(properties);
|
| 29 | this.registerDefaultState(this.stateDefinition.any().setValue(WATERLOGGED, false).setValue(AXIS, Direction.Axis.Y));
|
| 30 | }
|
| 31 |
|
| 32 | @Override
|
| 33 | protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
|
| 34 | return SHAPES.get(state.getValue(AXIS));
|
| 35 | }
|
| 36 |
|
| 37 | @Override
|
| 38 | public BlockState getStateForPlacement(final BlockPlaceContext context) {
|
| 39 | FluidState replacedFluidState = context.getLevel().getFluidState(context.getClickedPos());
|
| 40 | boolean isWaterSource = replacedFluidState.is(Fluids.WATER);
|
| 41 | return super.getStateForPlacement(context).setValue(WATERLOGGED, isWaterSource);
|
| 42 | }
|
| 43 |
|
| 44 | @Override
|
| 45 | protected BlockState updateShape(
|
| 46 | final BlockState state,
|
| 47 | final LevelReader level,
|
| 48 | final ScheduledTickAccess ticks,
|
| 49 | final BlockPos pos,
|
| 50 | final Direction directionToNeighbour,
|
| 51 | final BlockPos neighbourPos,
|
| 52 | final BlockState neighbourState,
|
| 53 | final RandomSource random
|
| 54 | ) {
|
| 55 | if (state.getValue(WATERLOGGED)) {
|
| 56 | ticks.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
|
| 57 | }
|
| 58 |
|
| 59 | return super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
|
| 60 | }
|
| 61 |
|
| 62 | @Override
|
| 63 | protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
|
| 64 | builder.add(WATERLOGGED).add(AXIS);
|
| 65 | }
|
| 66 |
|
| 67 | @Override
|
| 68 | protected FluidState getFluidState(final BlockState state) {
|
| 69 | return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
|
| 70 | }
|
| 71 |
|
| 72 | @Override
|
| 73 | protected boolean isPathfindable(final BlockState state, final PathComputationType type) {
|
| 74 | return false;
|
| 75 | }
|
| 76 | }
|
| 77 |
|