| 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.BlockTags;
|
| 6 | import net.minecraft.tags.FluidTags;
|
| 7 | import net.minecraft.util.RandomSource;
|
| 8 | import net.minecraft.world.entity.LivingEntity;
|
| 9 | import net.minecraft.world.item.context.BlockPlaceContext;
|
| 10 | import net.minecraft.world.level.BlockGetter;
|
| 11 | import net.minecraft.world.level.LevelAccessor;
|
| 12 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 13 | import net.minecraft.world.level.block.state.BlockState;
|
| 14 | import net.minecraft.world.level.material.Fluid;
|
| 15 | import net.minecraft.world.level.material.FluidState;
|
| 16 | import net.minecraft.world.level.material.Fluids;
|
| 17 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 18 | import org.jspecify.annotations.Nullable;
|
| 19 |
|
| 20 | /**
|
| 21 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 22 | */
|
| 23 | public class KelpBlock extends GrowingPlantHeadBlock implements LiquidBlockContainer {
|
| 24 | private static final double GROW_PER_TICK_PROBABILITY = 0.14;
|
| 25 | private static final VoxelShape SHAPE = Block.column(16.0, 0.0, 9.0);
|
| 26 |
|
| 27 | /**
|
| 28 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 29 | */
|
| 30 | public KelpBlock(final BlockBehaviour.Properties properties) {
|
| 31 | super(properties, Direction.UP, SHAPE, true, 0.14);
|
| 32 | }
|
| 33 |
|
| 34 | @Override
|
| 35 | protected boolean canGrowInto(final BlockState state) {
|
| 36 | return state.is(Blocks.WATER);
|
| 37 | }
|
| 38 |
|
| 39 | @Override
|
| 40 | protected Block getBodyBlock() {
|
| 41 | return Blocks.KELP_PLANT;
|
| 42 | }
|
| 43 |
|
| 44 | @Override
|
| 45 | protected boolean canAttachTo(final BlockState state) {
|
| 46 | return !state.is(BlockTags.CANNOT_SUPPORT_KELP);
|
| 47 | }
|
| 48 |
|
| 49 | @Override
|
| 50 | public boolean canPlaceLiquid(final @Nullable LivingEntity user, final BlockGetter level, final BlockPos pos, final BlockState state, final Fluid type) {
|
| 51 | return false;
|
| 52 | }
|
| 53 |
|
| 54 | @Override
|
| 55 | public boolean placeLiquid(final LevelAccessor level, final BlockPos pos, final BlockState state, final FluidState fluidState) {
|
| 56 | return false;
|
| 57 | }
|
| 58 |
|
| 59 | @Override
|
| 60 | protected int getBlocksToGrowWhenBonemealed(final RandomSource random) {
|
| 61 | return 1;
|
| 62 | }
|
| 63 |
|
| 64 | @Override
|
| 65 | public @Nullable BlockState getStateForPlacement(final BlockPlaceContext context) {
|
| 66 | FluidState fluidState = context.getLevel().getFluidState(context.getClickedPos());
|
| 67 | return fluidState.is(FluidTags.WATER) && fluidState.isFull() ? super.getStateForPlacement(context) : null;
|
| 68 | }
|
| 69 |
|
| 70 | @Override
|
| 71 | protected FluidState getFluidState(final BlockState state) {
|
| 72 | return Fluids.WATER.getSource(false);
|
| 73 | }
|
| 74 | }
|
| 75 |
|