UseDuration .java

net.minecraft.client.renderer.item.properties.numeric.UseDuration (record): members: remaining, useDuration, get, MAP_CODEC, type. strings: "remaining".

net.minecraft.client.renderer.item.properties.numericrecord39 linesclient1.4 KB

Implements

API Surface (3)

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

Fields & Constants (1)

MAP_CODEC

String literals (1)

"remaining"

Code Graph: Dependencies (5)

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

Full Source

UseDuration.java39 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.world.entity.ItemOwner;
10
import net.minecraft.world.entity.LivingEntity;
11
import net.minecraft.world.item.ItemStack;
12
import org.jspecify.annotations.Nullable;
13
14
@Environment(EnvType.CLIENT)
15
public record UseDuration(boolean remaining) implements RangeSelectItemModelProperty {
16
	public static final MapCodec<UseDuration> MAP_CODEC = RecordCodecBuilder.mapCodec(
17
		i -> i.group(Codec.BOOL.optionalFieldOf("remaining", false).forGetter(UseDuration::remaining)).apply(i, UseDuration::new)
18
	);
19
20
	@Override
21
	public float get(final ItemStack itemStack, final @Nullable ClientLevel level, final @Nullable ItemOwner owner, final int seed) {
22
		LivingEntity entity = owner == null ? null : owner.asLivingEntity();
23
		if (entity != null && entity.getUseItem() == itemStack) {
24
			return this.remaining ? entity.getUseItemRemainingTicks() : useDuration(itemStack, entity);
25
		} else {
26
			return 0.0F;
27
		}
28
	}
29
30
	@Override
31
	public MapCodec<UseDuration> type() {
32
		return MAP_CODEC;
33
	}
34
35
	public static int useDuration(final ItemStack itemStack, final LivingEntity owner) {
36
		return itemStack.getUseDuration(owner) - owner.getUseItemRemainingTicks();
37
	}
38
}
39

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