ConditionRule .java

net.minecraft.world.level.levelgen.material.rule.ConditionRule (record): members: ifTrue, thenRun, compile, codec, CODEC. strings: "then_run", "if_true".

net.minecraft.world.level.levelgen.material.rulerecord29 linescommon1.1 KB

Implements

API Surface (2)

MapCodec<ConditionRule> codec()
RuleEvaluator compile(final MaterialRuleContext context)

Fields & Constants (1)

CODEC

String literals (2)

"if_true"
"then_run"

Code Graph: Dependencies (5)

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

Full Source

ConditionRule.java29 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.material.rule;
2
3
import com.mojang.serialization.MapCodec;
4
import com.mojang.serialization.codecs.RecordCodecBuilder;
5
import net.minecraft.world.level.levelgen.material.MaterialRuleContext;
6
import net.minecraft.world.level.levelgen.material.condition.ConditionEvaluator;
7
import net.minecraft.world.level.levelgen.material.condition.MaterialCondition;
8
9
public record ConditionRule(MaterialCondition ifTrue, MaterialRule thenRun) implements MaterialRule {
10
	public static final MapCodec<ConditionRule> CODEC = RecordCodecBuilder.mapCodec(
11
		i -> i.group(
12
				MaterialCondition.CODEC.fieldOf("if_true").forGetter(ConditionRule::ifTrue), MaterialRule.CODEC.fieldOf("then_run").forGetter(ConditionRule::thenRun)
13
			)
14
			.apply(i, ConditionRule::new)
15
	);
16
17
	@Override
18
	public MapCodec<ConditionRule> codec() {
19
		return CODEC;
20
	}
21
22
	@Override
23
	public RuleEvaluator compile(final MaterialRuleContext context) {
24
		ConditionEvaluator ifTrue = this.ifTrue.compile(context);
25
		RuleEvaluator thenRun = this.thenRun.compile(context);
26
		return (blockX, blockY, blockZ) -> !ifTrue.test() ? null : thenRun.tryApply(blockX, blockY, blockZ);
27
	}
28
}
29

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