| 1 | package net.minecraft.util.debug;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.core.BlockPos;
|
| 5 | import net.minecraft.core.Registry;
|
| 6 | import net.minecraft.core.registries.BuiltInRegistries;
|
| 7 | import net.minecraft.network.RegistryFriendlyByteBuf;
|
| 8 | import net.minecraft.network.codec.ByteBufCodecs;
|
| 9 | import net.minecraft.network.codec.StreamCodec;
|
| 10 | import net.minecraft.resources.Identifier;
|
| 11 | import net.minecraft.util.Unit;
|
| 12 | import net.minecraft.world.level.redstone.Orientation;
|
| 13 |
|
| 14 | public class DebugSubscriptions<T> {
|
| 15 | public static final DebugSubscription<?> DEDICATED_SERVER_TICK_TIME = registerSimple("dedicated_server_tick_time");
|
| 16 | public static final DebugSubscription<DebugBeeInfo> BEES = registerWithValue("bees", DebugBeeInfo.STREAM_CODEC);
|
| 17 | public static final DebugSubscription<DebugBrainDump> BRAINS = registerWithValue("brains", DebugBrainDump.STREAM_CODEC);
|
| 18 | public static final DebugSubscription<DebugBreezeInfo> BREEZES = registerWithValue("breezes", DebugBreezeInfo.STREAM_CODEC);
|
| 19 | public static final DebugSubscription<DebugGoalInfo> GOAL_SELECTORS = registerWithValue("goal_selectors", DebugGoalInfo.STREAM_CODEC);
|
| 20 | public static final DebugSubscription<DebugPathInfo> ENTITY_PATHS = registerWithValue("entity_paths", DebugPathInfo.STREAM_CODEC);
|
| 21 | public static final DebugSubscription<DebugEntityBlockIntersection> ENTITY_BLOCK_INTERSECTIONS = registerTemporaryValue(
|
| 22 | "entity_block_intersections", DebugEntityBlockIntersection.STREAM_CODEC, 100
|
| 23 | );
|
| 24 | public static final DebugSubscription<DebugHiveInfo> BEE_HIVES = registerWithValue("bee_hives", DebugHiveInfo.STREAM_CODEC);
|
| 25 | public static final DebugSubscription<DebugPoiInfo> POIS = registerWithValue("pois", DebugPoiInfo.STREAM_CODEC);
|
| 26 | public static final DebugSubscription<Orientation> REDSTONE_WIRE_ORIENTATIONS = registerTemporaryValue(
|
| 27 | "redstone_wire_orientations", Orientation.STREAM_CODEC, 200
|
| 28 | );
|
| 29 | public static final DebugSubscription<Unit> VILLAGE_SECTIONS = registerWithValue("village_sections", Unit.STREAM_CODEC);
|
| 30 | public static final DebugSubscription<List<BlockPos>> RAIDS = registerWithValue("raids", BlockPos.STREAM_CODEC.apply(ByteBufCodecs.list()));
|
| 31 | public static final DebugSubscription<List<DebugStructureInfo>> STRUCTURES = registerWithValue(
|
| 32 | "structures", DebugStructureInfo.STREAM_CODEC.apply(ByteBufCodecs.list())
|
| 33 | );
|
| 34 | public static final DebugSubscription<DebugGameEventListenerInfo> GAME_EVENT_LISTENERS = registerWithValue(
|
| 35 | "game_event_listeners", DebugGameEventListenerInfo.STREAM_CODEC
|
| 36 | );
|
| 37 | public static final DebugSubscription<BlockPos> NEIGHBOR_UPDATES = registerTemporaryValue("neighbor_updates", BlockPos.STREAM_CODEC, 200);
|
| 38 | public static final DebugSubscription<DebugGameEventInfo> GAME_EVENTS = registerTemporaryValue("game_events", DebugGameEventInfo.STREAM_CODEC, 60);
|
| 39 |
|
| 40 | public static DebugSubscription<?> bootstrap(final Registry<DebugSubscription<?>> registry) {
|
| 41 | return DEDICATED_SERVER_TICK_TIME;
|
| 42 | }
|
| 43 |
|
| 44 | private static DebugSubscription<?> registerSimple(final String id) {
|
| 45 | return Registry.register(BuiltInRegistries.DEBUG_SUBSCRIPTION, Identifier.withDefaultNamespace(id), new DebugSubscription(null));
|
| 46 | }
|
| 47 |
|
| 48 | private static <T> DebugSubscription<T> registerWithValue(final String id, final StreamCodec<? super RegistryFriendlyByteBuf, T> valueStreamCodec) {
|
| 49 | return Registry.register(BuiltInRegistries.DEBUG_SUBSCRIPTION, Identifier.withDefaultNamespace(id), new DebugSubscription<>(valueStreamCodec));
|
| 50 | }
|
| 51 |
|
| 52 | private static <T> DebugSubscription<T> registerTemporaryValue(
|
| 53 | final String id, final StreamCodec<? super RegistryFriendlyByteBuf, T> valueStreamCodec, final int expireAfterTicks
|
| 54 | ) {
|
| 55 | return Registry.register(
|
| 56 | BuiltInRegistries.DEBUG_SUBSCRIPTION, Identifier.withDefaultNamespace(id), new DebugSubscription<>(valueStreamCodec, expireAfterTicks)
|
| 57 | );
|
| 58 | }
|
| 59 | }
|
| 60 |
|