RandomBlockStateMatchTest .java

net.minecraft.world.level.levelgen.structure.templatesystem.RandomBlockStateMatchTest (class): members: probability, blockState, test, getType, CODEC.

net.minecraft.world.level.levelgen.structure.templatesystemclass33 linescommonextends RuleTest1.2 KB

API Surface (2)

boolean test(final BlockState blockState, final BlockPos pos, final RandomSource random)
RuleTestType<?> getType()

Fields & Constants (3)

CODEC
blockState
probability

String literals (2)

"block_state"
"probability"

Code Graph: Dependencies (5)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

RandomBlockStateMatchTest.java33 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.structure.templatesystem;
2
3
import com.mojang.serialization.Codec;
4
import com.mojang.serialization.MapCodec;
5
import com.mojang.serialization.codecs.RecordCodecBuilder;
6
import net.minecraft.core.BlockPos;
7
import net.minecraft.util.RandomSource;
8
import net.minecraft.world.level.block.state.BlockState;
9
10
public class RandomBlockStateMatchTest extends RuleTest {
11
	public static final MapCodec<RandomBlockStateMatchTest> CODEC = RecordCodecBuilder.mapCodec(
12
		i -> i.group(BlockState.CODEC.fieldOf("block_state").forGetter(t -> t.blockState), Codec.FLOAT.fieldOf("probability").forGetter(t -> t.probability))
13
			.apply(i, RandomBlockStateMatchTest::new)
14
	);
15
	private final BlockState blockState;
16
	private final float probability;
17
18
	public RandomBlockStateMatchTest(final BlockState blockState, final float probability) {
19
		this.blockState = blockState;
20
		this.probability = probability;
21
	}
22
23
	@Override
24
	public boolean test(final BlockState blockState, final BlockPos pos, final RandomSource random) {
25
		return blockState == this.blockState && random.nextFloat() < this.probability;
26
	}
27
28
	@Override
29
	protected RuleTestType<?> getType() {
30
		return RuleTestType.RANDOM_BLOCKSTATE_TEST;
31
	}
32
}
33

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