Skip to content

Instantly share code, notes, and snippets.

@Gerrygames
Created February 17, 2018 23:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Gerrygames/5abbe95d030aa1d4162a334d5843daeb to your computer and use it in GitHub Desktop.
Save Gerrygames/5abbe95d030aa1d4162a334d5843daeb to your computer and use it in GitHub Desktop.
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.util.Map;
public class Main {
public static void main(String args[]) throws IOException {
net.minecraft.data.Main.main(new String[] {"--reports"});
String content = new String(Files.readAllBytes(new File("generated/reports/blocks.json").toPath()));
Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
JsonObject object = gson.fromJson(content, JsonObject.class);
JsonObject viaMappings = new JsonObject();
JsonObject blocks = new JsonObject();
viaMappings.add("blocks", blocks);
for (Map.Entry<String, JsonElement> blocksEntry : object.entrySet()) {
JsonObject block = blocksEntry.getValue().getAsJsonObject();
JsonArray states = block.getAsJsonArray("states");
for (JsonElement state : states) {
StringBuilder value = new StringBuilder(blocksEntry.getKey());
if (state.getAsJsonObject().has("properties")) {
value.append("[");
JsonObject properties = state.getAsJsonObject().getAsJsonObject("properties");
boolean first = true;
for (Map.Entry<String, JsonElement> propertyEntry : properties.entrySet()) {
if (first) first = false;
else value.append(',');
value.append(propertyEntry.getKey()).append('=').append(propertyEntry.getValue().getAsJsonPrimitive().getAsString());
}
value.append("]");
}
blocks.add(state.getAsJsonObject().get("id").getAsString(), new JsonPrimitive(value.toString()));
}
}
content = new String(Files.readAllBytes(new File("generated/reports/items.json").toPath()));
object = gson.fromJson(content, JsonObject.class);
JsonObject items = new JsonObject();
viaMappings.add("items", items);
for (Map.Entry<String, JsonElement> itemsEntry : object.entrySet()) {
items.add(String.valueOf(itemsEntry.getValue().getAsJsonObject().getAsJsonPrimitive("protocol_id").getAsInt()), new JsonPrimitive(itemsEntry.getKey()));
}
try( PrintWriter out = new PrintWriter( "mapping-1.13.json" ) ){
out.print(gson.toJson(viaMappings));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment