EnchantmentActiveCheck .java

net.minecraft.world.level.storage.loot.predicates.EnchantmentActiveCheck (record, 39 lines): members: active, enchantmentInactiveCheck, test, MAP_CODEC.

net.minecraft.world.level.storage.loot.predicatesrecord39 linescommon1.3 KB

Implements

API Surface (5)

boolean test(final LootContext lootContext)
MapCodec<EnchantmentActiveCheck> codec()
Set<ContextKey<?>> getReferencedContextParams()
LootItemCondition.Builder enchantmentActiveCheck()
LootItemCondition.Builder enchantmentInactiveCheck()

Fields & Constants (1)

MAP_CODEC

String literals (1)

"active"

Code Graph: Dependencies (5)

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

Full Source

EnchantmentActiveCheck.java39 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.storage.loot.predicates;
2
3
import com.mojang.serialization.Codec;
4
import com.mojang.serialization.MapCodec;
5
import com.mojang.serialization.codecs.RecordCodecBuilder;
6
import java.util.Set;
7
import net.minecraft.util.context.ContextKey;
8
import net.minecraft.world.level.storage.loot.LootContext;
9
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
10
11
public record EnchantmentActiveCheck(boolean active) implements LootItemCondition {
12
	public static final MapCodec<EnchantmentActiveCheck> MAP_CODEC = RecordCodecBuilder.mapCodec(
13
		i -> i.group(Codec.BOOL.fieldOf("active").forGetter(EnchantmentActiveCheck::active)).apply(i, EnchantmentActiveCheck::new)
14
	);
15
16
	public boolean test(final LootContext lootContext) {
17
		Boolean value = lootContext.getOptional(LootContextParams.ENCHANTMENT_ACTIVE);
18
		return value != null && value == this.active;
19
	}
20
21
	@Override
22
	public MapCodec<EnchantmentActiveCheck> codec() {
23
		return MAP_CODEC;
24
	}
25
26
	@Override
27
	public Set<ContextKey<?>> getReferencedContextParams() {
28
		return Set.of(LootContextParams.ENCHANTMENT_ACTIVE);
29
	}
30
31
	public static LootItemCondition.Builder enchantmentActiveCheck() {
32
		return () -> new EnchantmentActiveCheck(true);
33
	}
34
35
	public static LootItemCondition.Builder enchantmentInactiveCheck() {
36
		return () -> new EnchantmentActiveCheck(false);
37
	}
38
}
39

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