Search in sources :

Example 6 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project BetterStorage by copygirl.

the class StackUtils method getEnchantments.

// Enchantment functions
/** Returns the enchantments on the item stack. */
public static Map<Integer, StackEnchantment> getEnchantments(ItemStack stack) {
    Map<Integer, StackEnchantment> enchantments = new HashMap<Integer, StackEnchantment>();
    NBTTagList list = ((stack.getItem() == Items.enchanted_book) ? Items.enchanted_book.func_92110_g(stack) : stack.getEnchantmentTagList());
    if (list != null)
        for (int i = 0; i < list.tagCount(); i++) {
            StackEnchantment ench = new StackEnchantment(stack, list.getCompoundTagAt(i));
            enchantments.put(ench.ench.effectId, ench);
        }
    return enchantments;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) HashMap(java.util.HashMap)

Example 7 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project BetterStorage by copygirl.

the class CratePileData method fromCompound.

public static CratePileData fromCompound(CratePileCollection collection, int crateId, NBTTagCompound compound) {
    int numCrates = compound.getShort("numCrates");
    CratePileData pileData = new CratePileData(collection, crateId, numCrates);
    NBTTagList stacks = compound.getTagList("stacks", NBT.TAG_COMPOUND);
    for (int j = 0; j < stacks.tagCount(); j++) {
        NBTTagCompound stackCompound = stacks.getCompoundTagAt(j);
        Item item = Item.getItemById(stackCompound.getShort("id"));
        int count = stackCompound.getInteger("Count");
        int damage = stackCompound.getShort("Damage");
        ItemStack stack = new ItemStack(item, count, damage);
        if (stackCompound.hasKey("tag"))
            stack.stackTagCompound = stackCompound.getCompoundTag("tag");
        if (stack.getItem() != null)
            pileData.getContents().set(new ItemIdentifier(stack), stack.stackSize);
    }
    if (compound.hasKey("map"))
        pileData.map = CratePileMap.fromCompound(compound.getCompoundTag("map"));
    return pileData;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) Item(net.minecraft.item.Item) ItemIdentifier(net.mcft.copy.betterstorage.misc.ItemIdentifier) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 8 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project BluePower by Qmunity.

the class InventoryItem method readFromNBT.

protected void readFromNBT() {
    reading = true;
    NBTTagList itemList = (NBTTagList) ((NBTTagCompound) item.stackTagCompound.getTag("Inventory")).getTag("Items");
    for (int i = 0; i < itemList.tagCount(); i++) {
        NBTTagCompound slotEntry = itemList.getCompoundTagAt(i);
        int j = slotEntry.getByte("Slot") & 0xff;
        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 9 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project BluePower by Qmunity.

the class WorldConverter method convertTile.

private boolean convertTile(NBTTagCompound tag) {
    NBTTagList parts = tag.getTagList("parts", new NBTTagCompound().getId());
    int count = parts.tagCount();
    FMPPart fmppart = new FMPPart(true);
    for (int i = 0; i < count; i++) {
        NBTTagCompound part = parts.getCompoundTagAt(i);
        String id = part.getString("id");
        for (IPartConverter c : converters) {
            if (c.matches(id)) {
                IPart p = c.convert(part);
                if (p == null)
                    continue;
                fmppart.addPart(p);
                parts.removeTag(i);
                i--;
                break;
            }
        }
        count = parts.tagCount();
    }
    if (fmppart.getParts().size() > 0) {
        NBTTagCompound part = new NBTTagCompound();
        fmppart.save(part);
        part.setString("id", fmppart.getType());
        parts.appendTag(part);
        return true;
    }
    return false;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IPart(uk.co.qmunity.lib.part.IPart) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) FMPPart(uk.co.qmunity.lib.part.compat.fmp.FMPPart)

Example 10 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project BluePower by Qmunity.

the class WorldConverter method convertRegion.

private void convertRegion(File file) {
    RegionFile reg = new RegionFile(file);
    for (int x = 0; x < 32; x++) {
        for (int z = 0; z < 32; z++) {
            NBTTagCompound chunk = getChunk(reg, x, z);
            if (chunk == null)
                continue;
            NBTTagList tileEntities = chunk.getTagList("TileEntities", new NBTTagCompound().getId());
            boolean changed = false;
            for (int i = 0; i < tileEntities.tagCount(); i++) {
                NBTTagCompound te = tileEntities.getCompoundTagAt(i);
                if (te.getString("id").equals("savedMultipart"))
                    changed |= convertTile(te);
            }
            if (changed)
                saveChunk(reg, x, z, chunk);
        }
    }
    try {
        reg.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) RegionFile(net.minecraft.world.chunk.storage.RegionFile) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOException(java.io.IOException)

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