| 1 | package net.minecraft.world.level.block;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.core.Direction;
|
| 5 | import net.minecraft.tags.FluidTags;
|
| 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.Level;
|
| 10 | import net.minecraft.world.level.LevelReader;
|
| 11 | import net.minecraft.world.level.ScheduledTickAccess;
|
| 12 | import net.minecraft.world.level.block.entity.BlockEntity;
|
| 13 | import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
| 14 | import net.minecraft.world.level.block.entity.BlockEntityType;
|
| 15 | import net.minecraft.world.level.block.entity.BlockEntityTypes;
|
| 16 | import net.minecraft.world.level.block.entity.ConduitBlockEntity;
|
| 17 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 18 | import net.minecraft.world.level.block.state.BlockState;
|
| 19 | import net.minecraft.world.level.block.state.StateDefinition;
|
| 20 | import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
| 21 | import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
| 22 | import net.minecraft.world.level.material.FluidState;
|
| 23 | import net.minecraft.world.level.material.Fluids;
|
| 24 | import net.minecraft.world.level.pathfinder.PathComputationType;
|
| 25 | import net.minecraft.world.phys.shapes.CollisionContext;
|
| 26 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 27 | import org.jspecify.annotations.Nullable;
|
| 28 |
|
| 29 | public class ConduitBlock extends BaseEntityBlock implements SimpleWaterloggedBlock {
|
| 30 | public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
|
| 31 | private static final VoxelShape SHAPE = Block.cube(6.0);
|
| 32 |
|
| 33 | public ConduitBlock(final BlockBehaviour.Properties properties) {
|
| 34 | super(properties);
|
| 35 | this.registerDefaultState(this.stateDefinition.any().setValue(WATERLOGGED, true));
|
| 36 | }
|
| 37 |
|
| 38 | @Override
|
| 39 | protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
|
| 40 | builder.add(WATERLOGGED);
|
| 41 | }
|
| 42 |
|
| 43 | @Override
|
| 44 | public BlockEntity newBlockEntity(final BlockPos worldPosition, final BlockState blockState) {
|
| 45 | return new ConduitBlockEntity(worldPosition, blockState);
|
| 46 | }
|
| 47 |
|
| 48 | @Override
|
| 49 | public <T extends BlockEntity> @Nullable BlockEntityTicker<T> getTicker(final Level level, final BlockState blockState, final BlockEntityType<T> type) {
|
| 50 | return createTickerHelper(type, BlockEntityTypes.CONDUIT, level.isClientSide() ? ConduitBlockEntity::clientTick : ConduitBlockEntity::serverTick);
|
| 51 | }
|
| 52 |
|
| 53 | @Override
|
| 54 | protected FluidState getFluidState(final BlockState state) {
|
| 55 | return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
|
| 56 | }
|
| 57 |
|
| 58 | @Override
|
| 59 | protected BlockState updateShape(
|
| 60 | final BlockState state,
|
| 61 | final LevelReader level,
|
| 62 | final ScheduledTickAccess ticks,
|
| 63 | final BlockPos pos,
|
| 64 | final Direction directionToNeighbour,
|
| 65 | final BlockPos neighbourPos,
|
| 66 | final BlockState neighbourState,
|
| 67 | final RandomSource random
|
| 68 | ) {
|
| 69 | if (state.getValue(WATERLOGGED)) {
|
| 70 | ticks.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
|
| 71 | }
|
| 72 |
|
| 73 | return super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
|
| 74 | }
|
| 75 |
|
| 76 | @Override
|
| 77 | protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
|
| 78 | return SHAPE;
|
| 79 | }
|
| 80 |
|
| 81 | @Override
|
| 82 | public @Nullable BlockState getStateForPlacement(final BlockPlaceContext context) {
|
| 83 | FluidState fluidState = context.getLevel().getFluidState(context.getClickedPos());
|
| 84 | return this.defaultBlockState().setValue(WATERLOGGED, fluidState.is(FluidTags.WATER) && fluidState.isFull());
|
| 85 | }
|
| 86 |
|
| 87 | @Override
|
| 88 | protected boolean isPathfindable(final BlockState state, final PathComputationType type) {
|
| 89 | return false;
|
| 90 | }
|
| 91 | }
|
| 92 |
|