Search in sources :

Example 81 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project Minechem by iopleke.

the class JournalItem method getAuthors.

/**
     * Gets a list of authors
     *
     * @param itemStack the journal Stack
     * @return an array of authors can be empty
     */
public String[] getAuthors(ItemStack itemStack) {
    if (itemStack.stackTagCompound != null && itemStack.stackTagCompound.hasKey("authors")) {
        NBTTagList authorsTag = itemStack.stackTagCompound.getTagList("authors", 8);
        String[] authors = new String[authorsTag.tagCount()];
        for (int i = 0; i < authorsTag.tagCount(); i++) {
            authors[i] = authorsTag.getStringTagAt(i);
        }
        return ArrayHelper.removeNulls(authors, String.class);
    }
    return new String[0];
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 82 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project Minechem by iopleke.

the class JournalItem method getKnowledgeKeys.

/**
     * Gets a list of knowledgeKeys
     *
     * @param itemStack the journal Stack
     * @return an array of knowledgeKeys can be empty
     */
public String[] getKnowledgeKeys(ItemStack itemStack) {
    if (itemStack.stackTagCompound != null && itemStack.stackTagCompound.hasKey("research")) {
        NBTTagList authorsTag = itemStack.stackTagCompound.getTagList("research", 8);
        String[] knowledgeKeys = new String[authorsTag.tagCount()];
        for (int i = 0; i < authorsTag.tagCount(); i++) {
            knowledgeKeys[i] = authorsTag.getStringTagAt(i);
        }
        return ArrayHelper.removeNulls(knowledgeKeys, String.class);
    }
    return new String[0];
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 83 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project Minechem by iopleke.

the class BasicInventoryTileEntity method readFromNBT.

/**
     * Read saved values from NBT
     *
     * @param nbttagcompound
     */
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
    super.readFromNBT(nbttagcompound);
    NBTTagList nbttaglist = nbttagcompound.getTagList(inventory.getInventoryName(), Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < inventory.getInventory().length; i++) {
        inventory.setInventorySlotContents(i, ItemStack.loadItemStackFromNBT(nbttaglist.getCompoundTagAt(i)));
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList)

Example 84 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project Minechem by iopleke.

the class BasicInventoryTileEntity method writeToNBT.

/**
     * Save data to NBT
     *
     * @param nbttagcompound
     */
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
    super.writeToNBT(nbttagcompound);
    NBTTagList nbttaglist = new NBTTagList();
    for (ItemStack stack : inventory.getInventory()) {
        if (stack != null) {
            NBTTagCompound nbttagcompound1 = new NBTTagCompound();
            stack.writeToNBT(nbttagcompound1);
            nbttaglist.appendTag(nbttagcompound1);
        } else {
            nbttaglist.appendTag(new NBTTagCompound());
        }
    }
    nbttagcompound.setTag(inventory.getInventoryName(), nbttaglist);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 85 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project MineFactoryReloaded by powercrystals.

the class TileEntityRedNetLogic method readCircuitsOnly.

public void readCircuitsOnly(NBTTagCompound nbttagcompound) {
    NBTTagList circuits = nbttagcompound.getTagList("circuits");
    if (circuits != null) {
        for (int c = 0; c < circuits.tagCount(); c++) {
            initCircuit(c, ((NBTTagCompound) circuits.tagAt(c)).getString("circuit"));
            NBTTagList inputPins = ((NBTTagCompound) circuits.tagAt(c)).getTagList("inputPins");
            if (inputPins != null) {
                for (int i = 0; i < inputPins.tagCount() && i < _pinMappingInputs[c].length; i++) {
                    int pin = ((NBTTagCompound) inputPins.tagAt(i)).getInteger("pin");
                    int buffer = ((NBTTagCompound) inputPins.tagAt(i)).getInteger("buffer");
                    _pinMappingInputs[c][i] = new PinMapping(pin, buffer);
                }
            }
            NBTTagList outputPins = ((NBTTagCompound) circuits.tagAt(c)).getTagList("outputPins");
            if (outputPins != null) {
                for (int i = 0; i < outputPins.tagCount() && i < _pinMappingOutputs[c].length; i++) {
                    int pin = ((NBTTagCompound) outputPins.tagAt(i)).getInteger("pin");
                    int buffer = ((NBTTagCompound) outputPins.tagAt(i)).getInteger("buffer");
                    _pinMappingOutputs[c][i] = new PinMapping(pin, buffer);
                }
            }
            NBTTagCompound circuitState = ((NBTTagCompound) circuits.tagAt(c)).getCompoundTag("state");
            if (circuitState != null) {
                _circuits[c].readFromNBT(circuitState);
            }
        }
    }
}
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