use of net.minecraft.nbt.NBTTagList in project PneumaticCraft by MineMaarten.
the class TileEntityKeroseneLamp method writeToNBT.
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
NBTTagList lights = new NBTTagList();
for (ChunkPosition pos : managingLights) {
NBTTagCompound t = new NBTTagCompound();
t.setInteger("x", pos.chunkPosX);
t.setInteger("y", pos.chunkPosY);
t.setInteger("z", pos.chunkPosZ);
lights.appendTag(t);
}
tag.setTag("lights", lights);
NBTTagCompound tankTag = new NBTTagCompound();
tank.writeToNBT(tankTag);
tag.setTag("tank", tankTag);
tag.setByte("redstoneMode", (byte) redstoneMode);
tag.setByte("targetRange", (byte) targetRange);
tag.setByte("range", (byte) range);
tag.setByte("sideConnected", (byte) sideConnected.ordinal());
writeInventoryToNBT(tag, inventory);
}
use of net.minecraft.nbt.NBTTagList in project PneumaticCraft by MineMaarten.
the class JsonToNBTConverter method getTag.
private NBTTagCompound getTag(JsonObject object) {
NBTTagCompound nbt = new NBTTagCompound();
for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
JsonObject keyObject = entry.getValue().getAsJsonObject();
int type = keyObject.get("type").getAsInt();
JsonElement element = keyObject.get("value");
switch(type) {
case 1:
nbt.setByte(entry.getKey(), (byte) element.getAsDouble());
break;
case 2:
nbt.setShort(entry.getKey(), (short) element.getAsDouble());
case 3:
nbt.setInteger(entry.getKey(), (int) element.getAsDouble());
break;
case 4:
nbt.setLong(entry.getKey(), (long) element.getAsDouble());
break;
case 5:
nbt.setFloat(entry.getKey(), (float) element.getAsDouble());
break;
case 6:
nbt.setDouble(entry.getKey(), element.getAsDouble());
break;
// break;
case 8:
nbt.setString(entry.getKey(), element.getAsString());
break;
case 9:
JsonArray array = element.getAsJsonArray();
NBTTagList tagList = new NBTTagList();
for (JsonElement e : array) {
tagList.appendTag(getTag(e.getAsJsonObject()));
}
nbt.setTag(entry.getKey(), tagList);
break;
case 10:
nbt.setTag(entry.getKey(), getTag(element.getAsJsonObject()));
break;
case 11:
array = element.getAsJsonArray();
int[] intArray = new int[array.size()];
for (int i = 0; i < array.size(); i++) {
intArray[i] = array.get(i).getAsInt();
}
nbt.setTag(entry.getKey(), new NBTTagIntArray(intArray));
break;
default:
throw new IllegalArgumentException("NBT type no " + type + " is not supported by the Json to NBT converter!");
}
}
return nbt;
}
use of net.minecraft.nbt.NBTTagList 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;
}
use of net.minecraft.nbt.NBTTagList in project PneumaticCraft by MineMaarten.
the class TileEntityPneumaticDoorBase method writeToNBT.
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
tag.setFloat("extension", progress);
tag.setBoolean("opening", opening);
tag.setInteger("orientation", orientation.ordinal());
tag.setInteger("redstoneMode", redstoneMode);
tag.setBoolean("rightGoing", rightGoing);
// Write the ItemStacks in the inventory to NBT
NBTTagList tagList = new NBTTagList();
for (int currentIndex = 0; currentIndex < inventory.length; ++currentIndex) {
if (inventory[currentIndex] != null) {
NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setByte("Slot", (byte) currentIndex);
inventory[currentIndex].writeToNBT(tagCompound);
tagList.appendTag(tagCompound);
}
}
tag.setTag("Items", tagList);
}
use of net.minecraft.nbt.NBTTagList in project PneumaticCraft by MineMaarten.
the class TileEntityPressureChamberInterface method readFromNBT.
// INVENTORY METHODS- && NBT
// ------------------------------------------------------------
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
// Read in the ItemStacks in the inventory from NBT
NBTTagList tagList = tag.getTagList("Items", 10);
inventory = new ItemStack[getSizeInventory()];
for (int i = 0; i < tagList.tagCount(); i++) {
NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
byte slot = tagCompound.getByte("Slot");
if (slot >= 0 && slot < inventory.length) {
inventory[slot] = ItemStack.loadItemStackFromNBT(tagCompound);
}
}
outputProgress = tag.getInteger("outputProgress");
inputProgress = tag.getInteger("inputProgress");
interfaceMode = EnumInterfaceMode.values()[tag.getInteger("interfaceMode")];
filterMode = EnumFilterMode.values()[tag.getInteger("filterMode")];
creativeTabID = tag.getInteger("creativeTabID");
itemNameFilter = tag.getString("itemNameFilter");
redstoneMode = tag.getInteger("redstoneMode");
}
Aggregations