DebugSubscription .java

net.minecraft.util.debug.DebugSubscription (class, 72 lines): members: expireAfterTicks, DOES_NOT_EXPIRE, emptyUpdate, packUpdate, packEvent, Event.

net.minecraft.util.debugclass72 linescommon3.0 KB

API Surface (5)

DebugSubscription.Update<T> packUpdate(final @Nullable T value)
DebugSubscription.Update<T> emptyUpdate()
DebugSubscription.Event<T> packEvent(final T value)
String toString()
int expireAfterTicks()

Fields & Constants (4)

DOES_NOT_EXPIRE
valueStreamCodec
expireAfterTicks
RegistryFriendlyByteBuf

Code Graph: Dependencies (6)

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

Full Source

DebugSubscription.java72 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.debug;
2
3
import java.util.Objects;
4
import java.util.Optional;
5
import net.minecraft.core.registries.BuiltInRegistries;
6
import net.minecraft.core.registries.Registries;
7
import net.minecraft.network.RegistryFriendlyByteBuf;
8
import net.minecraft.network.codec.ByteBufCodecs;
9
import net.minecraft.network.codec.StreamCodec;
10
import net.minecraft.util.Util;
11
import org.jspecify.annotations.Nullable;
12
13
public class DebugSubscription<T> {
14
	public static final int DOES_NOT_EXPIRE = 0;
15
	private final @Nullable StreamCodec<? super RegistryFriendlyByteBuf, T> valueStreamCodec;
16
	private final int expireAfterTicks;
17
18
	public DebugSubscription(final @Nullable StreamCodec<? super RegistryFriendlyByteBuf, T> valueStreamCodec, final int expireAfterTicks) {
19
		this.valueStreamCodec = valueStreamCodec;
20
		this.expireAfterTicks = expireAfterTicks;
21
	}
22
23
	public DebugSubscription(final @Nullable StreamCodec<? super RegistryFriendlyByteBuf, T> valueStreamCodec) {
24
		this(valueStreamCodec, 0);
25
	}
26
27
	public DebugSubscription.Update<T> packUpdate(final @Nullable T value) {
28
		return new DebugSubscription.Update<>(this, Optional.ofNullable(value));
29
	}
30
31
	public DebugSubscription.Update<T> emptyUpdate() {
32
		return new DebugSubscription.Update<>(this, Optional.empty());
33
	}
34
35
	public DebugSubscription.Event<T> packEvent(final T value) {
36
		return new DebugSubscription.Event<>(this, value);
37
	}
38
39
	@Override
40
	public String toString() {
41
		return Util.getRegisteredName(BuiltInRegistries.DEBUG_SUBSCRIPTION, this);
42
	}
43
44
	public @Nullable StreamCodec<? super RegistryFriendlyByteBuf, T> valueStreamCodec() {
45
		return this.valueStreamCodec;
46
	}
47
48
	public int expireAfterTicks() {
49
		return this.expireAfterTicks;
50
	}
51
52
	public record Event<T>(DebugSubscription<T> subscription, T value) {
53
		public static final StreamCodec<RegistryFriendlyByteBuf, DebugSubscription.Event<?>> STREAM_CODEC = ByteBufCodecs.registry(Registries.DEBUG_SUBSCRIPTION)
54
			.dispatch(DebugSubscription.Event::subscription, DebugSubscription.Event::streamCodec);
55
56
		private static <T> StreamCodec<? super RegistryFriendlyByteBuf, DebugSubscription.Event<T>> streamCodec(final DebugSubscription<T> subscription) {
57
			return Objects.requireNonNull(subscription.valueStreamCodec)
58
				.map(value -> new DebugSubscription.Event<>(subscription, (T)value), DebugSubscription.Event::value);
59
		}
60
	}
61
62
	public record Update<T>(DebugSubscription<T> subscription, Optional<T> value) {
63
		public static final StreamCodec<RegistryFriendlyByteBuf, DebugSubscription.Update<?>> STREAM_CODEC = ByteBufCodecs.registry(Registries.DEBUG_SUBSCRIPTION)
64
			.dispatch(DebugSubscription.Update::subscription, DebugSubscription.Update::streamCodec);
65
66
		private static <T> StreamCodec<? super RegistryFriendlyByteBuf, DebugSubscription.Update<T>> streamCodec(final DebugSubscription<T> subscription) {
67
			return ByteBufCodecs.optional(Objects.requireNonNull(subscription.valueStreamCodec))
68
				.map(value -> new DebugSubscription.Update<>(subscription, (Optional<T>)value), DebugSubscription.Update::value);
69
		}
70
	}
71
}
72

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