Extract packets

This commit is contained in:
Ryan 2022-07-29 02:38:53 -07:00
parent ffad0b4021
commit c8fe351dd3
2 changed files with 50 additions and 1 deletions

View file

@ -5,6 +5,7 @@ import com.google.gson.JsonElement;
import dev._00a.valence_extractor.extractors.Blocks; import dev._00a.valence_extractor.extractors.Blocks;
import dev._00a.valence_extractor.extractors.Entities; import dev._00a.valence_extractor.extractors.Entities;
import dev._00a.valence_extractor.extractors.EntityData; import dev._00a.valence_extractor.extractors.EntityData;
import dev._00a.valence_extractor.extractors.Packets;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -39,7 +40,7 @@ public class Main implements ModInitializer {
public void onInitialize() { public void onInitialize() {
LOGGER.info("Starting extractors..."); LOGGER.info("Starting extractors...");
var extractors = new Extractor[]{new Blocks(), new Entities(), new EntityData(),}; var extractors = new Extractor[]{new Blocks(), new Entities(), new EntityData(), new Packets()};
Path outputDirectory; Path outputDirectory;
try { try {

View file

@ -0,0 +1,48 @@
package dev._00a.valence_extractor.extractors;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import dev._00a.valence_extractor.Main;
import net.minecraft.network.NetworkSide;
import net.minecraft.network.NetworkState;
import java.util.Locale;
import java.util.TreeSet;
public class Packets implements Main.Extractor {
@Override
public String fileName() {
return "packets.json";
}
@Override
public JsonElement extract() throws Exception {
var packetsJson = new JsonObject();
for (var side : NetworkSide.values()) {
var sideJson = new JsonObject();
for (var state : NetworkState.values()) {
var stateJson = new JsonArray();
var map = state.getPacketIdToPacketMap(side);
for (var id : new TreeSet<>(map.keySet())) {
var packetJson = new JsonObject();
packetJson.addProperty("name", map.get(id.intValue()).getSimpleName());
packetJson.addProperty("id", id);
stateJson.add(packetJson);
}
sideJson.add(state.name().toLowerCase(Locale.ROOT), stateJson);
}
packetsJson.add(side.name().toLowerCase(Locale.ROOT), sideJson);
}
return packetsJson;
}
}