Search in sources :

Example 66 with NBTTagList

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);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ChunkPosition(net.minecraft.world.ChunkPosition) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 67 with NBTTagList

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;
}
Also used : JsonArray(com.google.gson.JsonArray) NBTTagList(net.minecraft.nbt.NBTTagList) JsonElement(com.google.gson.JsonElement) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) JsonObject(com.google.gson.JsonObject) Map(java.util.Map) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray)

Example 68 with NBTTagList

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;
}
Also used : NBTPrimitive(net.minecraft.nbt.NBTBase.NBTPrimitive) JsonPrimitive(com.google.gson.JsonPrimitive) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) JsonObject(com.google.gson.JsonObject) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray) NBTTagList(net.minecraft.nbt.NBTTagList) JsonArray(com.google.gson.JsonArray) NBTBase(net.minecraft.nbt.NBTBase) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 69 with NBTTagList

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);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 70 with NBTTagList

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");
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Aggregations

NBTTagList (net.minecraft.nbt.NBTTagList)451 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)385 ItemStack (net.minecraft.item.ItemStack)69 NBTTagString (net.minecraft.nbt.NBTTagString)42 BlockPos (net.minecraft.util.math.BlockPos)18 HashMap (java.util.HashMap)17 Map (java.util.Map)17 NotNull (org.jetbrains.annotations.NotNull)17 ArrayList (java.util.ArrayList)14 AMVector3 (am2.api.math.AMVector3)9 ChunkPosition (net.minecraft.world.ChunkPosition)9 NBTBase (net.minecraft.nbt.NBTBase)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 Vec3d (net.minecraft.util.math.Vec3d)7 WorldCoordinate (mods.railcraft.api.core.WorldCoordinate)6 Block (net.minecraft.block.Block)6 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)5 Entity (net.minecraft.entity.Entity)5 TileEntity (net.minecraft.tileentity.TileEntity)5 ChunkPos (net.minecraft.util.math.ChunkPos)5