From 2405887e6d0fe90838f3476d8d282dd6f2416b84 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Sun, 3 Nov 2024 21:55:49 -0500 Subject: [PATCH] dump trains cmd --- .../commands/RailwaysTweaksCommands.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/main/java/dev/ithundxr/railwaystweaks/commands/RailwaysTweaksCommands.java b/src/main/java/dev/ithundxr/railwaystweaks/commands/RailwaysTweaksCommands.java index fa1e59c..07ecf0d 100644 --- a/src/main/java/dev/ithundxr/railwaystweaks/commands/RailwaysTweaksCommands.java +++ b/src/main/java/dev/ithundxr/railwaystweaks/commands/RailwaysTweaksCommands.java @@ -1,6 +1,8 @@ package dev.ithundxr.railwaystweaks.commands; import com.mojang.brigadier.builder.ArgumentBuilder; +import com.simibubi.create.Create; +import com.simibubi.create.content.trains.entity.CarriageContraptionEntity; import dev.ithundxr.railwaystweaks.mixin.compat.tconstruct.SimpleChannelAccessor; import me.pepperbell.simplenetworking.C2SPacket; import me.pepperbell.simplenetworking.S2CPacket; @@ -22,6 +24,11 @@ public static void init() { dispatcher.register(literal("railwaystweaks") .then($dump_hephaestus_packets())); }); + + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { + dispatcher.register(literal("railwaystweaks") + .then($dump_trains())); + }); } private static ArgumentBuilder $dump_hephaestus_packets() { @@ -30,6 +37,12 @@ public static void init() { .executes(ctx -> dumpHephaestusPackets(ctx.getSource())); } + private static ArgumentBuilder $dump_trains() { + return literal("dump_create_trains") + .requires(cs -> cs.hasPermission(2)) + .executes(ctx -> dumpCreateTrains(ctx.getSource())); + } + private static int dumpHephaestusPackets(CommandSourceStack source) { TinkerNetwork tinkerNetwork = TinkerNetwork.getInstance(); @@ -64,4 +77,24 @@ private static int dumpHephaestusPackets(CommandSourceStack source) { return 0; } + + private static int dumpCreateTrains(CommandSourceStack source) { + StringBuilder s = new StringBuilder(); + + Create.RAILWAYS.trains.forEach((uuid, train) -> { + s.append("Train Name: ").append(train.name.toString()); + + CarriageContraptionEntity entity = train.carriages.get(0).anyAvailableEntity(); + + if (entity != null) { + s.append(", is at ").append(entity.position()); + } + + s.append("\n"); + }); + + source.sendSuccess(() -> Component.literal(s.toString()), true); + + return 0; + } }