NeedleDirectionHelper .java

net.minecraft.client.renderer.item.properties.numeric.NeedleDirectionHelper (class): members: standardWobbler, newWobbler, nonWobbler, Wobbler, wobble.

net.minecraft.client.renderer.item.properties.numericclass98 linesclient2.6 KB

API Surface (11)

float get(final ItemStack itemStack, @Nullable ClientLevel clientLevel, final @Nullable ItemOwner owner, final int seed)
boolean wobble()
NeedleDirectionHelper.Wobbler newWobbler(final float factor)
NeedleDirectionHelper.Wobbler standardWobbler(final float factor)
float rotation()
boolean shouldUpdate(final long tick)
void update(final long tick, final float targetRotation)
NeedleDirectionHelper.Wobbler nonWobbler()
float rotation()
boolean shouldUpdate(final long tick)
void update(final long tick, final float targetRotation)

Fields & Constants (1)

wobble

Code Graph: Dependencies (4)

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

Full Source

NeedleDirectionHelper.java98 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.renderer.item.properties.numeric;
2
3
import net.fabricmc.api.EnvType;
4
import net.fabricmc.api.Environment;
5
import net.minecraft.client.multiplayer.ClientLevel;
6
import net.minecraft.util.Mth;
7
import net.minecraft.world.entity.ItemOwner;
8
import net.minecraft.world.item.ItemStack;
9
import org.jspecify.annotations.Nullable;
10
11
@Environment(EnvType.CLIENT)
12
public abstract class NeedleDirectionHelper {
13
	private final boolean wobble;
14
15
	protected NeedleDirectionHelper(final boolean wobble) {
16
		this.wobble = wobble;
17
	}
18
19
	public float get(final ItemStack itemStack, @Nullable ClientLevel clientLevel, final @Nullable ItemOwner owner, final int seed) {
20
		if (owner == null) {
21
			return 0.0F;
22
		}
23
24
		if (clientLevel == null && owner.level() instanceof ClientLevel level) {
25
			clientLevel = level;
26
		}
27
28
		return clientLevel == null ? 0.0F : this.calculate(itemStack, clientLevel, seed, owner);
29
	}
30
31
	protected abstract float calculate(final ItemStack itemStack, final ClientLevel level, final int seed, final ItemOwner owner);
32
33
	protected boolean wobble() {
34
		return this.wobble;
35
	}
36
37
	protected NeedleDirectionHelper.Wobbler newWobbler(final float factor) {
38
		return this.wobble ? standardWobbler(factor) : nonWobbler();
39
	}
40
41
	public static NeedleDirectionHelper.Wobbler standardWobbler(final float factor) {
42
		return new NeedleDirectionHelper.Wobbler() {
43
			private float rotation;
44
			private float deltaRotation;
45
			private long lastUpdateTick;
46
47
			@Override
48
			public float rotation() {
49
				return this.rotation;
50
			}
51
52
			@Override
53
			public boolean shouldUpdate(final long tick) {
54
				return this.lastUpdateTick != tick;
55
			}
56
57
			@Override
58
			public void update(final long tick, final float targetRotation) {
59
				this.lastUpdateTick = tick;
60
				float tempDeltaRotation = Mth.positiveModulo(targetRotation - this.rotation + 0.5F, 1.0F) - 0.5F;
61
				this.deltaRotation += tempDeltaRotation * 0.1F;
62
				this.deltaRotation = this.deltaRotation * factor;
63
				this.rotation = Mth.positiveModulo(this.rotation + this.deltaRotation, 1.0F);
64
			}
65
		};
66
	}
67
68
	public static NeedleDirectionHelper.Wobbler nonWobbler() {
69
		return new NeedleDirectionHelper.Wobbler() {
70
			private float targetValue;
71
72
			@Override
73
			public float rotation() {
74
				return this.targetValue;
75
			}
76
77
			@Override
78
			public boolean shouldUpdate(final long tick) {
79
				return true;
80
			}
81
82
			@Override
83
			public void update(final long tick, final float targetRotation) {
84
				this.targetValue = targetRotation;
85
			}
86
		};
87
	}
88
89
	@Environment(EnvType.CLIENT)
90
	public interface Wobbler {
91
		float rotation();
92
93
		boolean shouldUpdate(long tick);
94
95
		void update(long tick, float targetRotation);
96
	}
97
}
98

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