Time .java

net.minecraft.client.renderer.item.properties.numeric.Time (class): members: TimeSource, wobbler, randomSource, calculate, source, MAP_CODEC, type.

net.minecraft.client.renderer.item.properties.numericclass69 linesclientextends NeedleDirectionHelper2.2 KB

Implements

API Surface (3)

float calculate(final ItemStack itemStack, final ClientLevel level, final int seed, final ItemOwner owner)
MapCodec<Time> type()
String getSerializedName()

Fields & Constants (4)

MAP_CODEC
source
randomSource
wobbler

String literals (8)

"wobble"
"source"
"RANDOM"
"random"
"DAYTIME"
"daytime"
"MOON_PHASE"
"moon_phase"

Full Source

Time.java69 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.RandomSource;
10
import net.minecraft.util.StringRepresentable;
11
import net.minecraft.world.entity.ItemOwner;
12
import net.minecraft.world.item.ItemStack;
13
14
@Environment(EnvType.CLIENT)
15
public class Time extends NeedleDirectionHelper implements RangeSelectItemModelProperty {
16
	public static final MapCodec<Time> MAP_CODEC = RecordCodecBuilder.mapCodec(
17
		i -> i.group(
18
				Codec.BOOL.optionalFieldOf("wobble", true).forGetter(NeedleDirectionHelper::wobble), Time.TimeSource.CODEC.fieldOf("source").forGetter(o -> o.source)
19
			)
20
			.apply(i, Time::new)
21
	);
22
	private final Time.TimeSource source;
23
	private final RandomSource randomSource = RandomSource.create();
24
	private final NeedleDirectionHelper.Wobbler wobbler;
25
26
	public Time(final boolean wooble, final Time.TimeSource source) {
27
		super(wooble);
28
		this.source = source;
29
		this.wobbler = this.newWobbler(0.9F);
30
	}
31
32
	@Override
33
	protected float calculate(final ItemStack itemStack, final ClientLevel level, final int seed, final ItemOwner owner) {
34
		float targetRotation = this.source.get(level, itemStack, owner, this.randomSource);
35
		long gameTime = level.getGameTime();
36
		if (this.wobbler.shouldUpdate(gameTime)) {
37
			this.wobbler.update(gameTime, targetRotation);
38
		}
39
40
		return this.wobbler.rotation();
41
	}
42
43
	@Override
44
	public MapCodec<Time> type() {
45
		return MAP_CODEC;
46
	}
47
48
	@Environment(EnvType.CLIENT)
49
	public enum TimeSource implements StringRepresentable {
50
		RANDOM("RANDOM", 0, "random"),
51
		DAYTIME("DAYTIME", 1, "daytime"),
52
		MOON_PHASE("MOON_PHASE", 2, "moon_phase");
53
54
		public static final Codec<Time.TimeSource> CODEC = StringRepresentable.fromEnum(Time.TimeSource::values);
55
		private final String name;
56
57
		TimeSource(final String name) {
58
			this.name = name;
59
		}
60
61
		@Override
62
		public String getSerializedName() {
63
			return this.name;
64
		}
65
66
		public abstract float get(final ClientLevel level, final ItemStack itemStack, final ItemOwner owner, final RandomSource random);
67
	}
68
}
69

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