Skip to content

Commit

Permalink
dump trains cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Nov 4, 2024
1 parent 8a39351 commit 2405887
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<CommandSourceStack, ?> $dump_hephaestus_packets() {
Expand All @@ -30,6 +37,12 @@ public static void init() {
.executes(ctx -> dumpHephaestusPackets(ctx.getSource()));
}

private static ArgumentBuilder<CommandSourceStack, ?> $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();

Expand Down Expand Up @@ -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;
}
}

0 comments on commit 2405887

Please sign in to comment.