/* * Decompiled with CFR 0.152. * * Could not load the following classes: * org.jspecify.annotations.Nullable */ package net.minecraft.util.debug; import java.util.Objects; import java.util.Optional; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; import net.minecraft.util.Util; import org.jspecify.annotations.Nullable; public class DebugSubscription { public static final int DOES_NOT_EXPIRE = 0; private final @Nullable StreamCodec valueStreamCodec; private final int expireAfterTicks; public DebugSubscription(@Nullable StreamCodec valueStreamCodec, int expireAfterTicks) { this.valueStreamCodec = valueStreamCodec; this.expireAfterTicks = expireAfterTicks; } public DebugSubscription(@Nullable StreamCodec valueStreamCodec) { this(valueStreamCodec, 0); } public Update packUpdate(@Nullable T value) { return new Update(this, Optional.ofNullable(value)); } public Update emptyUpdate() { return new Update(this, Optional.empty()); } public Event packEvent(T value) { return new Event(this, value); } public String toString() { return Util.getRegisteredName(BuiltInRegistries.DEBUG_SUBSCRIPTION, this); } public @Nullable StreamCodec valueStreamCodec() { return this.valueStreamCodec; } public int expireAfterTicks() { return this.expireAfterTicks; } public record Update(DebugSubscription subscription, Optional value) { public static final StreamCodec> STREAM_CODEC = ByteBufCodecs.registry(Registries.DEBUG_SUBSCRIPTION).dispatch(Update::subscription, Update::streamCodec); private static StreamCodec> streamCodec(DebugSubscription subscription) { return ByteBufCodecs.optional(Objects.requireNonNull(subscription.valueStreamCodec)).map(value -> new Update(subscription, value), Update::value); } } public record Event(DebugSubscription subscription, T value) { public static final StreamCodec> STREAM_CODEC = ByteBufCodecs.registry(Registries.DEBUG_SUBSCRIPTION).dispatch(Event::subscription, Event::streamCodec); private static StreamCodec> streamCodec(DebugSubscription subscription) { return Objects.requireNonNull(subscription.valueStreamCodec).map(value -> new Event(subscription, value), Event::value); } } }