Search in sources :

Example 36 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project PneumaticCraft by MineMaarten.

the class HeatExchangerLogic method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound tag) {
    temperature = tag.getDouble("temperature");
    behaviours.clear();
    NBTTagList tagList = tag.getTagList("behaviours", 10);
    for (int i = 0; i < tagList.tagCount(); i++) {
        NBTTagCompound t = tagList.getCompoundTagAt(i);
        HeatBehaviour behaviour = HeatBehaviourManager.getInstance().getBehaviourForId(t.getString("id"));
        if (behaviour != null) {
            behaviour.readFromNBT(t);
            behaviours.add(behaviour);
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) HeatBehaviour(pneumaticCraft.api.tileentity.HeatBehaviour) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 37 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project PneumaticCraft by MineMaarten.

the class ItemPneumaticArmor method getUpgradeStacks.

/**
     * Retrieves the upgrades currently installed on the given armor stack.
     */
public static ItemStack[] getUpgradeStacks(ItemStack iStack) {
    NBTTagCompound tag = NBTUtil.getCompoundTag(iStack, "UpgradeInventory");
    ItemStack[] inventoryStacks = new ItemStack[9];
    if (tag != null) {
        NBTTagList itemList = tag.getTagList("Items", 10);
        if (itemList != null) {
            for (int i = 0; i < itemList.tagCount(); i++) {
                NBTTagCompound slotEntry = itemList.getCompoundTagAt(i);
                int j = slotEntry.getByte("Slot");
                if (j >= 0 && j < 9) {
                    inventoryStacks[j] = ItemStack.loadItemStackFromNBT(slotEntry);
                }
            }
        }
    }
    return inventoryStacks;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 38 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project PneumaticCraft by MineMaarten.

the class InventoryPneumaticInventoryItem method writeToNBT.

/**
     * Writes a NBT Node with inventory.
     * 
     * @param outerTag
     *            The NBT Node to write to.
     * @return The written NBT Node.
     */
public void writeToNBT() {
    NBTTagList itemList = new NBTTagList();
    for (int i = 0; i < getSizeInventory(); i++) {
        if (getStackInSlot(i) != null) {
            NBTTagCompound slotEntry = new NBTTagCompound();
            slotEntry.setByte("Slot", (byte) i);
            getStackInSlot(i).writeToNBT(slotEntry);
            itemList.appendTag(slotEntry);
        }
    }
    // save content in Inventory->Items
    NBTTagCompound inventory = new NBTTagCompound();
    inventory.setTag("Items", itemList);
    NBTUtil.setCompoundTag(armorStack, "UpgradeInventory", inventory);
    NBTUtil.removeTag(armorStack, "Inventory");
// return outerTag;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 39 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project PneumaticCraft by MineMaarten.

the class InventoryPneumaticInventoryItem method readFromNBT.

/**
     * Reads the inventory from a NBT Node.
     * 
     * @param outerTag
     *            The NBT Node to read from.
     */
protected void readFromNBT() {
    reading = true;
    if (NBTUtil.hasTag(armorStack, "Inventory") && armorStack.getTagCompound().getTag("Inventory") instanceof NBTTagCompound) {
        Log.info("Converting 'Inventory' tag to 'UpgradeInventory' in Pneumatic items");
        armorStack.getTagCompound().setTag("UpgradeInventory", armorStack.getTagCompound().getTag("Inventory"));
        armorStack.getTagCompound().removeTag("Inventory");
    }
    NBTTagList itemList = NBTUtil.getCompoundTag(armorStack, "UpgradeInventory").getTagList("Items", 10);
    for (int i = 0; i < itemList.tagCount(); i++) {
        NBTTagCompound slotEntry = itemList.getCompoundTagAt(i);
        int j = slotEntry.getByte("Slot");
        if (j >= 0 && j < getSizeInventory()) {
            setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(slotEntry));
        }
    }
    reading = false;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 40 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project PneumaticCraft by MineMaarten.

the class ItemAmadronTablet method getShoppingCart.

public static Map<AmadronOffer, Integer> getShoppingCart(ItemStack tablet) {
    Map<AmadronOffer, Integer> offers = new HashMap<AmadronOffer, Integer>();
    if (tablet.hasTagCompound() && tablet.getTagCompound().hasKey("shoppingCart")) {
        NBTTagList list = tablet.getTagCompound().getTagList("shoppingCart", 10);
        for (int i = 0; i < list.tagCount(); i++) {
            NBTTagCompound tag = list.getCompoundTagAt(i);
            offers.put(tag.hasKey("inStock") ? AmadronOfferCustom.loadFromNBT(tag) : AmadronOffer.loadFromNBT(tag), tag.getInteger("amount"));
        }
    }
    return offers;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) HashMap(java.util.HashMap) AmadronOffer(pneumaticCraft.common.recipes.AmadronOffer) 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