ComponentMatches .java

net.minecraft.client.renderer.item.properties.conditional.ComponentMatches (record): members: predicate, seed, get, MAP_CODEC, type. strings: "predicate".

net.minecraft.client.renderer.item.properties.conditionalrecord33 linesclient1.3 KB

Implements

API Surface (2)

boolean get(final ItemStack itemStack, final @Nullable ClientLevel level, final @Nullable LivingEntity owner, final int seed, final ItemDisplayContext displayContext)
MapCodec<ComponentMatches> type()

Fields & Constants (2)

MAP_CODEC
seed

String literals (1)

"predicate"

Full Source

ComponentMatches.java33 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.renderer.item.properties.conditional;
2
3
import com.mojang.serialization.MapCodec;
4
import com.mojang.serialization.codecs.RecordCodecBuilder;
5
import net.fabricmc.api.EnvType;
6
import net.fabricmc.api.Environment;
7
import net.minecraft.client.multiplayer.ClientLevel;
8
import net.minecraft.core.component.predicates.DataComponentPredicate;
9
import net.minecraft.core.component.predicates.DataComponentPredicate.Single;
10
import net.minecraft.world.entity.LivingEntity;
11
import net.minecraft.world.item.ItemDisplayContext;
12
import net.minecraft.world.item.ItemStack;
13
import org.jspecify.annotations.Nullable;
14
15
@Environment(EnvType.CLIENT)
16
public record ComponentMatches(Single<?> predicate) implements ConditionalItemModelProperty {
17
	public static final MapCodec<ComponentMatches> MAP_CODEC = RecordCodecBuilder.mapCodec(
18
		i -> i.group(DataComponentPredicate.singleCodec("predicate").forGetter(ComponentMatches::predicate)).apply(i, ComponentMatches::new)
19
	);
20
21
	@Override
22
	public boolean get(
23
		final ItemStack itemStack, final @Nullable ClientLevel level, final @Nullable LivingEntity owner, final int seed, final ItemDisplayContext displayContext
24
	) {
25
		return this.predicate.predicate().matches(itemStack);
26
	}
27
28
	@Override
29
	public MapCodec<ComponentMatches> type() {
30
		return MAP_CODEC;
31
	}
32
}
33

Decompiled Minecraft 26.3 source of ComponentMatches (net/minecraft/client/renderer/item/properties/conditional/ComponentMatches.java) with Mojang official mappings, stored verbatim on the site.