Count .java

net.minecraft.client.renderer.item.properties.numeric.Count (record): members: normalize, get, MAP_CODEC, type. strings: "normalize". imports: ItemOwner.

net.minecraft.client.renderer.item.properties.numericrecord32 linesclient1.2 KB

Implements

API Surface (2)

float get(final ItemStack itemStack, final @Nullable ClientLevel level, final @Nullable ItemOwner owner, final int seed)
MapCodec<Count> type()

Fields & Constants (1)

MAP_CODEC

String literals (1)

"normalize"

Code Graph: Dependencies (5)

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

Full Source

Count.java32 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.renderer.item.properties.numeric;
2
3
import com.mojang.serialization.Codec;
4
import com.mojang.serialization.MapCodec;
5
import com.mojang.serialization.codecs.RecordCodecBuilder;
6
import net.fabricmc.api.EnvType;
7
import net.fabricmc.api.Environment;
8
import net.minecraft.client.multiplayer.ClientLevel;
9
import net.minecraft.util.Mth;
10
import net.minecraft.world.entity.ItemOwner;
11
import net.minecraft.world.item.ItemStack;
12
import org.jspecify.annotations.Nullable;
13
14
@Environment(EnvType.CLIENT)
15
public record Count(boolean normalize) implements RangeSelectItemModelProperty {
16
	public static final MapCodec<Count> MAP_CODEC = RecordCodecBuilder.mapCodec(
17
		i -> i.group(Codec.BOOL.optionalFieldOf("normalize", true).forGetter(Count::normalize)).apply(i, Count::new)
18
	);
19
20
	@Override
21
	public float get(final ItemStack itemStack, final @Nullable ClientLevel level, final @Nullable ItemOwner owner, final int seed) {
22
		float count = itemStack.getCount();
23
		float maxCount = itemStack.getMaxStackSize();
24
		return this.normalize ? Mth.clamp(count / maxCount, 0.0F, 1.0F) : Mth.clamp(count, 0.0F, maxCount);
25
	}
26
27
	@Override
28
	public MapCodec<Count> type() {
29
		return MAP_CODEC;
30
	}
31
}
32

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