use of net.minecraft.nbt.NBTBase.NBTPrimitive in project PneumaticCraft by MineMaarten.
the class NBTToJsonConverter method getObject.
private JsonObject getObject(NBTTagCompound tag) {
Set<String> keys = tag.func_150296_c();
JsonObject jsonRoot = new JsonObject();
for (String key : keys) {
JsonObject keyObject = new JsonObject();
jsonRoot.add(key, keyObject);
NBTBase nbt = tag.getTag(key);
keyObject.addProperty("type", nbt.getId());
if (nbt instanceof NBTTagCompound) {
keyObject.add("value", getObject((NBTTagCompound) nbt));
} else if (nbt instanceof NBTPrimitive) {
keyObject.addProperty("value", ((NBTPrimitive) nbt).func_150286_g());
} else if (nbt instanceof NBTTagString) {
keyObject.addProperty("value", ((NBTTagString) nbt).func_150285_a_());
} else if (nbt instanceof NBTTagList) {
JsonArray array = new JsonArray();
NBTTagList tagList = (NBTTagList) nbt;
for (int i = 0; i < tagList.tagCount(); i++) {
array.add(getObject(tagList.getCompoundTagAt(i)));
}
keyObject.add("value", array);
} else if (nbt instanceof NBTTagIntArray) {
JsonArray array = new JsonArray();
NBTTagIntArray intArray = (NBTTagIntArray) nbt;
for (int i : intArray.func_150302_c()) {
array.add(new JsonPrimitive(i));
}
keyObject.add("value", array);
} else {
throw new IllegalArgumentException("NBT to JSON converter doesn't support the nbt tag: " + NBTBase.NBTTypes[nbt.getId()] + ", tag: " + nbt);
}
}
return jsonRoot;
}
Aggregations