| 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.world.entity.LivingEntity;
|
| 8 | import net.minecraft.world.item.ItemStack;
|
| 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.LevelReader;
|
| 13 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 14 | import net.minecraft.world.level.block.state.BlockState;
|
| 15 | import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
|
| 16 | import net.minecraft.world.level.block.state.properties.EnumProperty;
|
| 17 | import net.minecraft.world.level.material.Fluid;
|
| 18 | import net.minecraft.world.level.material.FluidState;
|
| 19 | import net.minecraft.world.level.material.Fluids;
|
| 20 | import net.minecraft.world.phys.shapes.CollisionContext;
|
| 21 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 22 | import org.jspecify.annotations.Nullable;
|
| 23 |
|
| 24 | public class TallSeagrassBlock extends DoublePlantBlock implements LiquidBlockContainer {
|
| 25 | public static final EnumProperty<DoubleBlockHalf> HALF = DoublePlantBlock.HALF;
|
| 26 | private static final VoxelShape SHAPE = Block.column(12.0, 0.0, 16.0);
|
| 27 |
|
| 28 | public TallSeagrassBlock(final BlockBehaviour.Properties properties) {
|
| 29 | super(properties);
|
| 30 | }
|
| 31 |
|
| 32 | @Override
|
| 33 | protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
|
| 34 | return SHAPE;
|
| 35 | }
|
| 36 |
|
| 37 | @Override
|
| 38 | protected boolean mayPlaceOn(final BlockState state, final BlockGetter level, final BlockPos pos) {
|
| 39 | return state.isFaceSturdy(level, pos, Direction.UP) && !state.is(BlockTags.CANNOT_SUPPORT_SEAGRASS);
|
| 40 | }
|
| 41 |
|
| 42 | @Override
|
| 43 | protected ItemStack getCloneItemStack(final LevelReader level, final BlockPos pos, final BlockState state, final boolean includeData) {
|
| 44 | return new ItemStack(Blocks.SEAGRASS);
|
| 45 | }
|
| 46 |
|
| 47 | @Override
|
| 48 | public @Nullable BlockState getStateForPlacement(final BlockPlaceContext context) {
|
| 49 | BlockState state = super.getStateForPlacement(context);
|
| 50 | if (state != null) {
|
| 51 | FluidState fluidState = context.getLevel().getFluidState(context.getClickedPos().above());
|
| 52 | if (fluidState.is(FluidTags.WATER) && fluidState.isFull()) {
|
| 53 | return state;
|
| 54 | }
|
| 55 | }
|
| 56 |
|
| 57 | return null;
|
| 58 | }
|
| 59 |
|
| 60 | @Override
|
| 61 | protected boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos) {
|
| 62 | if (state.getValue(HALF) == DoubleBlockHalf.UPPER) {
|
| 63 | BlockState belowState = level.getBlockState(pos.below());
|
| 64 | return belowState.is(this) && belowState.getValue(HALF) == DoubleBlockHalf.LOWER;
|
| 65 | } else {
|
| 66 | FluidState fluidState = level.getFluidState(pos);
|
| 67 | return super.canSurvive(state, level, pos) && fluidState.is(FluidTags.WATER) && fluidState.isFull();
|
| 68 | }
|
| 69 | }
|
| 70 |
|
| 71 | @Override
|
| 72 | protected FluidState getFluidState(final BlockState state) {
|
| 73 | return Fluids.WATER.getSource(false);
|
| 74 | }
|
| 75 |
|
| 76 | @Override
|
| 77 | public boolean canPlaceLiquid(final @Nullable LivingEntity user, final BlockGetter level, final BlockPos pos, final BlockState state, final Fluid type) {
|
| 78 | return false;
|
| 79 | }
|
| 80 |
|
| 81 | @Override
|
| 82 | public boolean placeLiquid(final LevelAccessor level, final BlockPos pos, final BlockState state, final FluidState fluidState) {
|
| 83 | return false;
|
| 84 | }
|
| 85 | }
|
| 86 |
|