mirror of
https://github.com/italicsjenga/valence.git
synced 2024-12-23 14:31:30 +11:00
Extract packets
This commit is contained in:
parent
ffad0b4021
commit
c8fe351dd3
|
@ -5,6 +5,7 @@ import com.google.gson.JsonElement;
|
|||
import dev._00a.valence_extractor.extractors.Blocks;
|
||||
import dev._00a.valence_extractor.extractors.Entities;
|
||||
import dev._00a.valence_extractor.extractors.EntityData;
|
||||
import dev._00a.valence_extractor.extractors.Packets;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -39,7 +40,7 @@ public class Main implements ModInitializer {
|
|||
public void onInitialize() {
|
||||
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;
|
||||
try {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue