BuddingAmethystBlock .java

net.minecraft.world.level.block.BuddingAmethystBlock (class): members: canClusterGrowAtState, GROWTH_CHANCE, DIRECTIONS, randomTick. imports: Fluids.

net.minecraft.world.level.blockclass49 linescommonextends AmethystBlock2.1 KB

API Surface (2)

void randomTick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random)
boolean canClusterGrowAtState(final BlockState state)

Fields & Constants (2)

GROWTH_CHANCE
DIRECTIONS

Full Source

BuddingAmethystBlock.java49 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.util.RandomSource;
7
import net.minecraft.world.level.block.state.BlockBehaviour;
8
import net.minecraft.world.level.block.state.BlockState;
9
import net.minecraft.world.level.material.Fluids;
10
11
public class BuddingAmethystBlock extends AmethystBlock {
12
	public static final int GROWTH_CHANCE = 5;
13
	private static final Direction[] DIRECTIONS = Direction.values();
14
15
	public BuddingAmethystBlock(final BlockBehaviour.Properties properties) {
16
		super(properties);
17
	}
18
19
	@Override
20
	protected void randomTick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random) {
21
		if (random.nextInt(5) == 0) {
22
			Direction growDirection = DIRECTIONS[random.nextInt(DIRECTIONS.length)];
23
			BlockPos growPos = pos.relative(growDirection);
24
			BlockState relativeState = level.getBlockState(growPos);
25
			Block nextStage = null;
26
			if (canClusterGrowAtState(relativeState)) {
27
				nextStage = Blocks.SMALL_AMETHYST_BUD;
28
			} else if (relativeState.is(Blocks.SMALL_AMETHYST_BUD) && relativeState.getValue(AmethystClusterBlock.FACING) == growDirection) {
29
				nextStage = Blocks.MEDIUM_AMETHYST_BUD;
30
			} else if (relativeState.is(Blocks.MEDIUM_AMETHYST_BUD) && relativeState.getValue(AmethystClusterBlock.FACING) == growDirection) {
31
				nextStage = Blocks.LARGE_AMETHYST_BUD;
32
			} else if (relativeState.is(Blocks.LARGE_AMETHYST_BUD) && relativeState.getValue(AmethystClusterBlock.FACING) == growDirection) {
33
				nextStage = Blocks.AMETHYST_CLUSTER;
34
			}
35
36
			if (nextStage != null) {
37
				BlockState targetState = nextStage.defaultBlockState()
38
					.setValue(AmethystClusterBlock.FACING, growDirection)
39
					.setValue(AmethystClusterBlock.WATERLOGGED, relativeState.getFluidState().is(Fluids.WATER));
40
				level.setBlockAndUpdate(growPos, targetState);
41
			}
42
		}
43
	}
44
45
	public static boolean canClusterGrowAtState(final BlockState state) {
46
		return state.isAir() || state.is(Blocks.WATER) && state.getFluidState().isFull();
47
	}
48
}
49

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