|
| 1 | +package dev.ithundxr.railwaystweaks.commands; |
| 2 | + |
| 3 | +import com.mojang.brigadier.builder.ArgumentBuilder; |
| 4 | +import dev.ithundxr.railwaystweaks.mixin.compat.tconstruct.SimpleChannelAccessor; |
| 5 | +import me.pepperbell.simplenetworking.C2SPacket; |
| 6 | +import me.pepperbell.simplenetworking.S2CPacket; |
| 7 | +import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; |
| 8 | +import net.minecraft.commands.CommandSourceStack; |
| 9 | +import net.minecraft.network.chat.Component; |
| 10 | +import slimeknights.tconstruct.common.network.TinkerNetwork; |
| 11 | + |
| 12 | +import java.util.ArrayList; |
| 13 | +import java.util.HashMap; |
| 14 | +import java.util.List; |
| 15 | +import java.util.Map; |
| 16 | + |
| 17 | +import static net.minecraft.commands.Commands.literal; |
| 18 | + |
| 19 | +public class RailwaysTweaksCommands { |
| 20 | + public static void init() { |
| 21 | + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { |
| 22 | + dispatcher.register(literal("railwaystweaks") |
| 23 | + .then($dump_hephaestus_packets())); |
| 24 | + }); |
| 25 | + } |
| 26 | + |
| 27 | + private static ArgumentBuilder<CommandSourceStack, ?> $dump_hephaestus_packets() { |
| 28 | + return literal("dump_hephaestus_packets") |
| 29 | + .requires(cs -> cs.hasPermission(2)) |
| 30 | + .executes(ctx -> dumpHephaestusPackets(ctx.getSource())); |
| 31 | + } |
| 32 | + |
| 33 | + private static int dumpHephaestusPackets(CommandSourceStack source) { |
| 34 | + TinkerNetwork tinkerNetwork = TinkerNetwork.getInstance(); |
| 35 | + |
| 36 | + Map<Integer, Class<? extends S2CPacket>> idToS2C = new HashMap<>(); |
| 37 | + Map<Integer, Class<? extends C2SPacket>> idToC2S = new HashMap<>(); |
| 38 | + ((SimpleChannelAccessor) tinkerNetwork.network).getS2cIdMap().forEach((packet, id) -> { |
| 39 | + idToS2C.put(id, packet); |
| 40 | + }); |
| 41 | + ((SimpleChannelAccessor) tinkerNetwork.network).getC2sIdMap().forEach((packet, id) -> { |
| 42 | + idToC2S.put(id, packet); |
| 43 | + }); |
| 44 | + List<Integer> sortedS2CIds = new ArrayList<>(idToS2C.keySet()); |
| 45 | + List<Integer> sortedC2SIds = new ArrayList<>(idToC2S.keySet()); |
| 46 | + sortedS2CIds.sort(Integer::compareTo); |
| 47 | + sortedC2SIds.sort(Integer::compareTo); |
| 48 | + |
| 49 | + StringBuilder sb = new StringBuilder(); |
| 50 | + sb.append("Hephaestus S2C packets:\n"); |
| 51 | + sortedS2CIds.forEach(id -> { |
| 52 | + var packet = idToS2C.get(id); |
| 53 | + sb.append(id).append(" -> ").append(packet.getName()).append("\n"); |
| 54 | + }); |
| 55 | + |
| 56 | + sb.append("\n"); |
| 57 | + sb.append("Hephaestus C2S packets:\n"); |
| 58 | + sortedC2SIds.forEach(id -> { |
| 59 | + var packet = idToC2S.get(id); |
| 60 | + sb.append(id).append(" -> ").append(packet.getName()).append("\n"); |
| 61 | + }); |
| 62 | + |
| 63 | + source.sendSuccess(() -> Component.literal(sb.toString()), true); |
| 64 | + |
| 65 | + return 0; |
| 66 | + } |
| 67 | +} |
0 commit comments