RandomBlockMatchTest .java

net.minecraft.world.level.levelgen.structure.templatesystem.RandomBlockMatchTest (class, 35 lines): members: probability, block, test, getType, CODEC.

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

API Surface (2)

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

Fields & Constants (3)

CODEC
block
probability

String literals (2)

"block"
"probability"

Code Graph: Dependencies (7)

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

Full Source

RandomBlockMatchTest.java35 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.core.registries.BuiltInRegistries;
8
import net.minecraft.util.RandomSource;
9
import net.minecraft.world.level.block.Block;
10
import net.minecraft.world.level.block.state.BlockState;
11
12
public class RandomBlockMatchTest extends RuleTest {
13
	public static final MapCodec<RandomBlockMatchTest> CODEC = RecordCodecBuilder.mapCodec(
14
		i -> i.group(BuiltInRegistries.BLOCK.byNameCodec().fieldOf("block").forGetter(t -> t.block), Codec.FLOAT.fieldOf("probability").forGetter(t -> t.probability))
15
			.apply(i, RandomBlockMatchTest::new)
16
	);
17
	private final Block block;
18
	private final float probability;
19
20
	public RandomBlockMatchTest(final Block block, final float probability) {
21
		this.block = block;
22
		this.probability = probability;
23
	}
24
25
	@Override
26
	public boolean test(final BlockState blockState, final BlockPos pos, final RandomSource random) {
27
		return blockState.is(this.block) && random.nextFloat() < this.probability;
28
	}
29
30
	@Override
31
	protected RuleTestType<?> getType() {
32
		return RuleTestType.RANDOM_BLOCK_TEST;
33
	}
34
}
35

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