RepeatedNarrator .java

net.minecraft.realms.RepeatedNarrator (class): members: permitsPerSecond, narrate, Params, params. imports: RateLimiter, GameNarrator, Component, Nullable.

net.minecraft.realmsclass37 linescommon1.2 KB

API Surface (1)

void narrate(final GameNarrator narrator, final Component narration)

Fields & Constants (2)

permitsPerSecond
params

Code Graph: Dependencies (2)

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

Full Source

RepeatedNarrator.java37 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.realms;
2
3
import com.google.common.util.concurrent.RateLimiter;
4
import java.time.Duration;
5
import java.util.concurrent.atomic.AtomicReference;
6
import net.fabricmc.api.EnvType;
7
import net.fabricmc.api.Environment;
8
import net.minecraft.client.GameNarrator;
9
import net.minecraft.network.chat.Component;
10
import org.jspecify.annotations.Nullable;
11
12
@Environment(EnvType.CLIENT)
13
public class RepeatedNarrator {
14
	private final float permitsPerSecond;
15
	private final AtomicReference<RepeatedNarrator.@Nullable Params> params = new AtomicReference<>();
16
17
	public RepeatedNarrator(final Duration repeatDelay) {
18
		this.permitsPerSecond = 1000.0F / (float)repeatDelay.toMillis();
19
	}
20
21
	public void narrate(final GameNarrator narrator, final Component narration) {
22
		RepeatedNarrator.Params params = this.params
23
			.updateAndGet(
24
				existing -> existing != null && narration.equals(existing.narration)
25
					? existing
26
					: new RepeatedNarrator.Params(narration, RateLimiter.create(this.permitsPerSecond))
27
			);
28
		if (params.rateLimiter.tryAcquire(1)) {
29
			narrator.saySystemNow(narration);
30
		}
31
	}
32
33
	@Environment(EnvType.CLIENT)
34
	private record Params(Component narration, RateLimiter rateLimiter) {
35
	}
36
}
37

Decompiled Minecraft 26.3 source of RepeatedNarrator (net/minecraft/realms/RepeatedNarrator.java) with Mojang official mappings, stored verbatim on the site.