SeagrassBlock .java

net.minecraft.world.level.block.SeagrassBlock (class): members: canPlaceLiquid, placeLiquid, mayPlaceOn, isValidBonemealTarget, isBonemealSuccess, SHAPE.

net.minecraft.world.level.blockclass108 linescommonextends VegetationBlock4.0 KB

Implements

API Surface (9)

VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context)
boolean mayPlaceOn(final BlockState state, final BlockGetter level, final BlockPos pos)
BlockState updateShape(final BlockState state, final LevelReader level, final ScheduledTickAccess ticks, final BlockPos pos, final Direction directionToNeighbour, final BlockPos neighbourPos, final BlockState neighbourState, final RandomSource random)
boolean isValidBonemealTarget(final LevelReader level, final BlockPos pos, final BlockState state, final BonemealSource source)
boolean isBonemealSuccess(final Level level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source)
FluidState getFluidState(final BlockState state)
void performBonemeal(final ServerLevel level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source)
boolean canPlaceLiquid(final @Nullable LivingEntity user, final BlockGetter level, final BlockPos pos, final BlockState state, final Fluid type)
boolean placeLiquid(final LevelAccessor level, final BlockPos pos, final BlockState state, final FluidState fluidState)

Fields & Constants (8)

SHAPE
state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState

Full Source

SeagrassBlock.java108 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.core.Direction;
5
import net.minecraft.server.level.ServerLevel;
6
import net.minecraft.tags.BlockTags;
7
import net.minecraft.tags.FluidTags;
8
import net.minecraft.util.RandomSource;
9
import net.minecraft.world.entity.LivingEntity;
10
import net.minecraft.world.item.context.BlockPlaceContext;
11
import net.minecraft.world.level.BlockGetter;
12
import net.minecraft.world.level.Level;
13
import net.minecraft.world.level.LevelAccessor;
14
import net.minecraft.world.level.LevelReader;
15
import net.minecraft.world.level.ScheduledTickAccess;
16
import net.minecraft.world.level.block.state.BlockBehaviour;
17
import net.minecraft.world.level.block.state.BlockState;
18
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
19
import net.minecraft.world.level.material.Fluid;
20
import net.minecraft.world.level.material.FluidState;
21
import net.minecraft.world.level.material.Fluids;
22
import net.minecraft.world.phys.shapes.CollisionContext;
23
import net.minecraft.world.phys.shapes.VoxelShape;
24
import org.jspecify.annotations.Nullable;
25
26
/**
27
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
28
 */
29
public class SeagrassBlock extends VegetationBlock implements BonemealableBlock, LiquidBlockContainer {
30
	private static final VoxelShape SHAPE = Block.column(12.0, 0.0, 12.0);
31
32
	/**
33
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
34
	 */
35
	public SeagrassBlock(final BlockBehaviour.Properties properties) {
36
		super(properties);
37
	}
38
39
	@Override
40
	protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
41
		return SHAPE;
42
	}
43
44
	@Override
45
	protected boolean mayPlaceOn(final BlockState state, final BlockGetter level, final BlockPos pos) {
46
		return state.isFaceSturdy(level, pos, Direction.UP) && !state.is(BlockTags.CANNOT_SUPPORT_SEAGRASS);
47
	}
48
49
	@Override
50
	public @Nullable BlockState getStateForPlacement(final BlockPlaceContext context) {
51
		FluidState fluidState = context.getLevel().getFluidState(context.getClickedPos());
52
		return fluidState.is(FluidTags.WATER) && fluidState.isFull() ? super.getStateForPlacement(context) : null;
53
	}
54
55
	@Override
56
	protected BlockState updateShape(
57
		final BlockState state,
58
		final LevelReader level,
59
		final ScheduledTickAccess ticks,
60
		final BlockPos pos,
61
		final Direction directionToNeighbour,
62
		final BlockPos neighbourPos,
63
		final BlockState neighbourState,
64
		final RandomSource random
65
	) {
66
		BlockState result = super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
67
		if (!result.isAir()) {
68
			ticks.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
69
		}
70
71
		return result;
72
	}
73
74
	@Override
75
	public boolean isValidBonemealTarget(final LevelReader level, final BlockPos pos, final BlockState state, final BonemealSource source) {
76
		return level.getBlockState(pos.above()).is(Blocks.WATER);
77
	}
78
79
	@Override
80
	public boolean isBonemealSuccess(final Level level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source) {
81
		return true;
82
	}
83
84
	@Override
85
	protected FluidState getFluidState(final BlockState state) {
86
		return Fluids.WATER.getSource(false);
87
	}
88
89
	@Override
90
	public void performBonemeal(final ServerLevel level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source) {
91
		BlockState lowerState = Blocks.TALL_SEAGRASS.defaultBlockState();
92
		BlockState upperState = lowerState.setValue(TallSeagrassBlock.HALF, DoubleBlockHalf.UPPER);
93
		BlockPos above = pos.above();
94
		level.setBlock(pos, lowerState, 2);
95
		level.setBlock(above, upperState, 2);
96
	}
97
98
	@Override
99
	public boolean canPlaceLiquid(final @Nullable LivingEntity user, final BlockGetter level, final BlockPos pos, final BlockState state, final Fluid type) {
100
		return false;
101
	}
102
103
	@Override
104
	public boolean placeLiquid(final LevelAccessor level, final BlockPos pos, final BlockState state, final FluidState fluidState) {
105
		return false;
106
	}
107
}
108

Decompiled Minecraft 26.3 source of SeagrassBlock (net/minecraft/world/level/block/SeagrassBlock.java) with Mojang official mappings, stored verbatim on the site.