BambooSaplingBlock .java

net.minecraft.world.level.block.BambooSaplingBlock (class): members: growBamboo, getCloneItemStack, isValidBonemealTarget, isBonemealSuccess, randomTick.

net.minecraft.world.level.blockclass88 linescommonextends Block3.3 KB

Implements

API Surface (9)

VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context)
void randomTick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random)
boolean canSurvive(final BlockState state, final LevelReader 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)
ItemStack getCloneItemStack(final LevelReader level, final BlockPos pos, final BlockState state, final boolean includeData)
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)
void performBonemeal(final ServerLevel level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source)
void growBamboo(final Level level, final BlockPos pos)

Fields & Constants (8)

SHAPE
state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState

Full Source

BambooSaplingBlock.java88 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.util.RandomSource;
8
import net.minecraft.world.item.ItemStack;
9
import net.minecraft.world.item.Items;
10
import net.minecraft.world.level.BlockGetter;
11
import net.minecraft.world.level.Level;
12
import net.minecraft.world.level.LevelReader;
13
import net.minecraft.world.level.ScheduledTickAccess;
14
import net.minecraft.world.level.block.state.BlockBehaviour;
15
import net.minecraft.world.level.block.state.BlockState;
16
import net.minecraft.world.level.block.state.properties.BambooLeaves;
17
import net.minecraft.world.phys.shapes.CollisionContext;
18
import net.minecraft.world.phys.shapes.VoxelShape;
19
20
public class BambooSaplingBlock extends Block implements BonemealableBlock {
21
	private static final VoxelShape SHAPE = Block.column(8.0, 0.0, 12.0);
22
23
	public BambooSaplingBlock(final BlockBehaviour.Properties properties) {
24
		super(properties);
25
	}
26
27
	@Override
28
	protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
29
		return SHAPE.move(state.getOffset(pos));
30
	}
31
32
	@Override
33
	protected void randomTick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random) {
34
		if (random.nextInt(3) == 0 && level.isEmptyBlock(pos.above()) && level.getRawBrightness(pos.above(), 0) >= 9) {
35
			this.growBamboo(level, pos);
36
		}
37
	}
38
39
	@Override
40
	protected boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos) {
41
		return level.getBlockState(pos.below()).is(BlockTags.SUPPORTS_BAMBOO);
42
	}
43
44
	@Override
45
	protected BlockState updateShape(
46
		final BlockState state,
47
		final LevelReader level,
48
		final ScheduledTickAccess ticks,
49
		final BlockPos pos,
50
		final Direction directionToNeighbour,
51
		final BlockPos neighbourPos,
52
		final BlockState neighbourState,
53
		final RandomSource random
54
	) {
55
		if (!state.canSurvive(level, pos)) {
56
			return Blocks.AIR.defaultBlockState();
57
		} else {
58
			return directionToNeighbour == Direction.UP && neighbourState.is(Blocks.BAMBOO)
59
				? Blocks.BAMBOO.defaultBlockState()
60
				: super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
61
		}
62
	}
63
64
	@Override
65
	protected ItemStack getCloneItemStack(final LevelReader level, final BlockPos pos, final BlockState state, final boolean includeData) {
66
		return new ItemStack(Items.BAMBOO);
67
	}
68
69
	@Override
70
	public boolean isValidBonemealTarget(final LevelReader level, final BlockPos pos, final BlockState state, final BonemealSource source) {
71
		return level.getBlockState(pos.above()).isAir() && level.isInsideBuildHeight(pos.above());
72
	}
73
74
	@Override
75
	public boolean isBonemealSuccess(final Level level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source) {
76
		return true;
77
	}
78
79
	@Override
80
	public void performBonemeal(final ServerLevel level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source) {
81
		this.growBamboo(level, pos);
82
	}
83
84
	protected void growBamboo(final Level level, final BlockPos pos) {
85
		level.setBlockAndUpdate(pos.above(), Blocks.BAMBOO.defaultBlockState().setValue(BambooStalkBlock.LEAVES, BambooLeaves.SMALL));
86
	}
87
}
88

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