VegetationBlock .java

net.minecraft.world.level.block.VegetationBlock (class): members: propagatesSkylightDown, mayPlaceOn, isPathfindable, canSurvive, neighbourState, ticks.

net.minecraft.world.level.blockclass55 linescommonextends Block1.8 KB

API Surface (5)

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 canSurvive(final BlockState state, final LevelReader level, final BlockPos pos)
boolean propagatesSkylightDown(final BlockState state)
boolean isPathfindable(final BlockState state, final PathComputationType type)

Fields & Constants (7)

state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState

Full Source

VegetationBlock.java55 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.tags.BlockTags;
6
import net.minecraft.util.RandomSource;
7
import net.minecraft.world.level.BlockGetter;
8
import net.minecraft.world.level.LevelReader;
9
import net.minecraft.world.level.ScheduledTickAccess;
10
import net.minecraft.world.level.block.state.BlockBehaviour;
11
import net.minecraft.world.level.block.state.BlockState;
12
import net.minecraft.world.level.pathfinder.PathComputationType;
13
14
public abstract class VegetationBlock extends Block {
15
	protected VegetationBlock(final BlockBehaviour.Properties properties) {
16
		super(properties);
17
	}
18
19
	protected boolean mayPlaceOn(final BlockState state, final BlockGetter level, final BlockPos pos) {
20
		return state.is(BlockTags.SUPPORTS_VEGETATION);
21
	}
22
23
	@Override
24
	protected BlockState updateShape(
25
		final BlockState state,
26
		final LevelReader level,
27
		final ScheduledTickAccess ticks,
28
		final BlockPos pos,
29
		final Direction directionToNeighbour,
30
		final BlockPos neighbourPos,
31
		final BlockState neighbourState,
32
		final RandomSource random
33
	) {
34
		return !state.canSurvive(level, pos)
35
			? Blocks.AIR.defaultBlockState()
36
			: super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
37
	}
38
39
	@Override
40
	protected boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos) {
41
		BlockPos below = pos.below();
42
		return this.mayPlaceOn(level.getBlockState(below), level, below);
43
	}
44
45
	@Override
46
	protected boolean propagatesSkylightDown(final BlockState state) {
47
		return state.getFluidState().isEmpty();
48
	}
49
50
	@Override
51
	protected boolean isPathfindable(final BlockState state, final PathComputationType type) {
52
		return type == PathComputationType.AIR && !this.hasCollision ? true : super.isPathfindable(state, type);
53
	}
54
}
55

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