Skip to content

Commit

Permalink
hephaestus packet debug
Browse files Browse the repository at this point in the history
  • Loading branch information
techno-sam committed Sep 15, 2024
1 parent 8a0abe7 commit a1f40c6
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 5 deletions.
27 changes: 24 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ repositories {
maven("https://maven.tterrag.com/") // Flywheel
maven("https://api.modrinth.com/maven")
maven("https://maven.ithundxr.dev/releases")
maven("https://maven.shedaniel.me/") // Mantle deps
exclusiveMaven("https://maven.ladysnake.org/releases", "dev.onyxstudios.cardinal-components-api") // Cardinal Components
exclusiveMaven("https://maven.wispforest.io", "me.alphamode")
exclusiveMaven("https://maven.terraformersmc.com/releases/", "com.terraformersmc")
}

dependencies {
Expand All @@ -34,13 +38,19 @@ dependencies {
modImplementation("net.fabricmc:fabric-loader:${"fabric_loader_version"()}")
modImplementation("net.fabricmc.fabric-api:fabric-api:${"fabric_api_version"()}")

modImplementation("maven.modrinth:hephaestus:${"minecraft_version"()}-${"hephaestus_version"()}")
modImplementation("slimeknights.mantle:Mantle:${"minecraft_version"()}-${"mantle_version"()}")
for (pl_module in "accessors,attributes,base,brewing,client_events,core,common,config,data,entity,extensions,items,models,model_loader,networking,tags,tool_actions,transfer,fluids,lazy_registration,loot,utility".split(",")) {
modRuntimeOnly("io.github.fabricators_of_create.Porting-Lib:${pl_module}:2.3.4+1.20.1")
}

modImplementation("com.simibubi.create:create-fabric-${"minecraft_version"()}:${"create_version"()}")

modImplementation("com.railwayteam.railways:Steam_Rails-fabric-1.20.1:1.6.4+fabric-mc1.20.1")
modImplementation("dev.ithundxr.createnumismatics:CreateNumismatics-fabric-1.20.1:1.0.6+fabric-mc1.20.1")

modCompileOnly("maven.modrinth:copycats:fabric.1.20.1-1.3.2")

modCompileOnly("maven.modrinth:appleskin:2.5.1+mc1.20")
}

Expand Down Expand Up @@ -86,3 +96,14 @@ operator fun String.invoke(): String {
return rootProject.ext[this] as? String
?: throw IllegalStateException("Property $this is not defined")
}

fun RepositoryHandler.exclusiveMaven(url: String, vararg groups: String) {
exclusiveContent {
forRepository { maven(url) }
filter {
groups.forEach {
includeGroup(it)
}
}
}
}
10 changes: 9 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@ fabric_api_version=0.92.0+1.20.1

# Create
# https://modrinth.com/mod/create-fabric/versions
create_version = 0.5.1-f-build.1335+mc1.20.1
create_version = 0.5.1-f-build.1417+mc1.20.1

# Hephaestus (Fabric Tinker's Construct)
# https://modrinth.com/mod/hephaestus/versions
hephaestus_version = 3.6.4.279

# Mantle
# https://github.com/Alpha-s-Stuff/TinkersConstruct/blob/1.20.1/gradle.properties
mantle_version = 1.9.269
3 changes: 3 additions & 0 deletions src/main/java/dev/ithundxr/railwaystweaks/RailwaysTweaks.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongepowered.asm.mixin.MixinEnvironment;
import dev.ithundxr.railwaystweaks.commands.RailwaysTweaksCommands;

public class RailwaysTweaks implements ModInitializer {
public static final String MODID = "railwaystweaks";
Expand All @@ -14,6 +15,8 @@ public class RailwaysTweaks implements ModInitializer {
public void onInitialize() {
LOGGER.info("Railways Tweaks is loading...");

RailwaysTweaksCommands.init();

if (FabricLoader.getInstance().isDevelopmentEnvironment())
MixinEnvironment.getCurrentEnvironment().audit();
}
Expand Down
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;
}
}
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();
}
3 changes: 2 additions & 1 deletion src/main/resources/railwaystweaks.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"LivingEntityMixin",
"ServerPlayerMixin",
"ServerStatusPacketListenerImplMixin",
"compat.appleskin.SyncHandlerMixin"
"compat.appleskin.SyncHandlerMixin",
"compat.tconstruct.SimpleChannelAccessor"
],
"client": [
"client.HttpTextureMixin",
Expand Down

0 comments on commit a1f40c6

Please sign in to comment.