-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a0abe7
commit a1f40c6
Showing
6 changed files
with
123 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/dev/ithundxr/railwaystweaks/commands/RailwaysTweaksCommands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package dev.ithundxr.railwaystweaks.commands; | ||
|
||
import com.mojang.brigadier.builder.ArgumentBuilder; | ||
import dev.ithundxr.railwaystweaks.mixin.compat.tconstruct.SimpleChannelAccessor; | ||
import me.pepperbell.simplenetworking.C2SPacket; | ||
import me.pepperbell.simplenetworking.S2CPacket; | ||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; | ||
import net.minecraft.commands.CommandSourceStack; | ||
import net.minecraft.network.chat.Component; | ||
import slimeknights.tconstruct.common.network.TinkerNetwork; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static net.minecraft.commands.Commands.literal; | ||
|
||
public class RailwaysTweaksCommands { | ||
public static void init() { | ||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { | ||
dispatcher.register(literal("railwaystweaks") | ||
.then($dump_hephaestus_packets())); | ||
}); | ||
} | ||
|
||
private static ArgumentBuilder<CommandSourceStack, ?> $dump_hephaestus_packets() { | ||
return literal("dump_hephaestus_packets") | ||
.requires(cs -> cs.hasPermission(2)) | ||
.executes(ctx -> dumpHephaestusPackets(ctx.getSource())); | ||
} | ||
|
||
private static int dumpHephaestusPackets(CommandSourceStack source) { | ||
TinkerNetwork tinkerNetwork = TinkerNetwork.getInstance(); | ||
|
||
Map<Integer, Class<? extends S2CPacket>> idToS2C = new HashMap<>(); | ||
Map<Integer, Class<? extends C2SPacket>> idToC2S = new HashMap<>(); | ||
((SimpleChannelAccessor) tinkerNetwork.network).getS2cIdMap().forEach((packet, id) -> { | ||
idToS2C.put(id, packet); | ||
}); | ||
((SimpleChannelAccessor) tinkerNetwork.network).getC2sIdMap().forEach((packet, id) -> { | ||
idToC2S.put(id, packet); | ||
}); | ||
List<Integer> sortedS2CIds = new ArrayList<>(idToS2C.keySet()); | ||
List<Integer> sortedC2SIds = new ArrayList<>(idToC2S.keySet()); | ||
sortedS2CIds.sort(Integer::compareTo); | ||
sortedC2SIds.sort(Integer::compareTo); | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
sb.append("Hephaestus S2C packets:\n"); | ||
sortedS2CIds.forEach(id -> { | ||
var packet = idToS2C.get(id); | ||
sb.append(id).append(" -> ").append(packet.getName()).append("\n"); | ||
}); | ||
|
||
sb.append("\n"); | ||
sb.append("Hephaestus C2S packets:\n"); | ||
sortedC2SIds.forEach(id -> { | ||
var packet = idToC2S.get(id); | ||
sb.append(id).append(" -> ").append(packet.getName()).append("\n"); | ||
}); | ||
|
||
source.sendSuccess(() -> Component.literal(sb.toString()), true); | ||
|
||
return 0; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/dev/ithundxr/railwaystweaks/mixin/compat/tconstruct/SimpleChannelAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package dev.ithundxr.railwaystweaks.mixin.compat.tconstruct; | ||
|
||
import me.pepperbell.simplenetworking.C2SPacket; | ||
import me.pepperbell.simplenetworking.S2CPacket; | ||
import me.pepperbell.simplenetworking.SimpleChannel; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
import java.util.Map; | ||
|
||
@Mixin(SimpleChannel.class) | ||
public interface SimpleChannelAccessor { | ||
@Accessor | ||
Map<Class<? extends S2CPacket>, Integer> getS2cIdMap(); | ||
|
||
@Accessor | ||
Map<Class<? extends C2SPacket>, Integer> getC2sIdMap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters