NetherWartBlock .java

net.minecraft.world.level.block.NetherWartBlock (class): members: MAX_AGE, AGE, mayPlaceOn, getCloneItemStack, isRandomlyTicking, SHAPES, randomTick.

net.minecraft.world.level.blockclass69 linescommonextends VegetationBlock2.4 KB

API Surface (6)

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)
boolean isRandomlyTicking(final BlockState state)
void randomTick(BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random)
ItemStack getCloneItemStack(final LevelReader level, final BlockPos pos, final BlockState state, final boolean includeData)
void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder)

Fields & Constants (3)

MAX_AGE
AGE
SHAPES

Full Source

NetherWartBlock.java69 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.server.level.ServerLevel;
5
import net.minecraft.tags.BlockTags;
6
import net.minecraft.util.RandomSource;
7
import net.minecraft.world.item.ItemStack;
8
import net.minecraft.world.item.Items;
9
import net.minecraft.world.level.BlockGetter;
10
import net.minecraft.world.level.LevelReader;
11
import net.minecraft.world.level.block.state.BlockBehaviour;
12
import net.minecraft.world.level.block.state.BlockState;
13
import net.minecraft.world.level.block.state.StateDefinition;
14
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
15
import net.minecraft.world.level.block.state.properties.IntegerProperty;
16
import net.minecraft.world.phys.shapes.CollisionContext;
17
import net.minecraft.world.phys.shapes.VoxelShape;
18
19
/**
20
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
21
 */
22
public class NetherWartBlock extends VegetationBlock {
23
	public static final int MAX_AGE = 3;
24
	public static final IntegerProperty AGE = BlockStateProperties.AGE_3;
25
	private static final VoxelShape[] SHAPES = Block.boxes(3, age -> Block.column(16.0, 0.0, 5 + age * 3));
26
27
	/**
28
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
29
	 */
30
	public NetherWartBlock(final BlockBehaviour.Properties properties) {
31
		super(properties);
32
		this.registerDefaultState(this.stateDefinition.any().setValue(AGE, 0));
33
	}
34
35
	@Override
36
	protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
37
		return SHAPES[state.getValue(AGE)];
38
	}
39
40
	@Override
41
	protected boolean mayPlaceOn(final BlockState state, final BlockGetter level, final BlockPos pos) {
42
		return state.is(BlockTags.SUPPORTS_NETHER_WART);
43
	}
44
45
	@Override
46
	protected boolean isRandomlyTicking(final BlockState state) {
47
		return state.getValue(AGE) < 3;
48
	}
49
50
	@Override
51
	protected void randomTick(BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random) {
52
		int age = state.getValue(AGE);
53
		if (age < 3 && random.nextInt(10) == 0) {
54
			state = state.setValue(AGE, age + 1);
55
			level.setBlock(pos, state, 2);
56
		}
57
	}
58
59
	@Override
60
	protected ItemStack getCloneItemStack(final LevelReader level, final BlockPos pos, final BlockState state, final boolean includeData) {
61
		return new ItemStack(Items.NETHER_WART);
62
	}
63
64
	@Override
65
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
66
		builder.add(AGE);
67
	}
68
}
69

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