Java Code Examples for net.minecraft.nbt.NBTTagList#appendTag()

The following examples show how to use net.minecraft.nbt.NBTTagList#appendTag() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@Override
public void writeToNBT(NBTTagCompound tag){

    super.writeToNBT(tag);
    // Write the ItemStacks in the inventory to NBT
    tag.setInteger("redstoneMode", redstoneMode);
    tag.setInteger("feedMode", feedMode);
    tag.setString("playerName", playerName);
    tag.setString("playerUUID", playerUUID);
    if(curXpFluid != null) tag.setString("curXpFluid", curXpFluid.getName());
    if(energyRF != null) saveRF(tag);

    tag.setBoolean("connected", isConnectedToPlayer);
    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);
}
 
Example 2
Source Project: Artifacts   File: ComponentNormalDamage.java    License: MIT License 6 votes vote down vote up
@Override
public ItemStack attached(ItemStack i, Random rand, int[] eff) {
	NBTTagCompound inbt = i.stackTagCompound;
	NBTTagCompound nnbt = new NBTTagCompound();
	NBTTagList nnbtl = new NBTTagList();
	int base = i.stackTagCompound.getInteger("material");
	switch(base) {
		case 0:
		case 3:
			base = 0;
			break;
	}
	base += 4;
	AttributeModifier att = new AttributeModifier("generic.attackDamage", base, 0);
	nnbt.setLong("UUIDMost", att.getID().getMostSignificantBits());
	nnbt.setLong("UUIDLeast", att.getID().getLeastSignificantBits());
	nnbt.setString("Name", att.getName());
	nnbt.setDouble("Amount", att.getAmount());
	nnbt.setInteger("Operation", att.getOperation());
	nnbt.setString("AttributeName", att.getName());
	nnbtl.appendTag(nnbt);
	inbt.setTag("AttributeModifiers", nnbtl);
	//i.addEnchantment(Enchantment.sharpness, rand.nextInt(5)+1);
	return i;
}
 
Example 3
Source Project: TFC2   File: EntityCart.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void writeEntityToNBT(NBTTagCompound tagCompound) 
{
	NBTTagList nbttaglist = new NBTTagList();

	for (int i = 0; i < this.cartInv.getSizeInventory(); ++i)
	{
		ItemStack itemstack = this.cartInv.getStackInSlot(i);

		if (itemstack != null)
		{
			NBTTagCompound nbttagcompound1 = new NBTTagCompound();
			nbttagcompound1.setByte("Slot", (byte)i);
			itemstack.writeToNBT(nbttagcompound1);
			nbttaglist.appendTag(nbttagcompound1);
		}
	}

	tagCompound.setTag("Items", nbttaglist);

}
 
Example 4
Source Project: Production-Line   File: TileContainer.java    License: MIT License 6 votes vote down vote up
@Override
@Nonnull
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    NBTTagCompound nbt = super.writeToNBT(compound);

    NBTTagList slotList = new NBTTagList();
    for (int i = 0; i < this.getSizeInventory(); ++i) {
        if (this.tileSlots.get(i) != null) {
            NBTTagCompound tag = new NBTTagCompound();
            tag.setByte("Slot", (byte) i);
            this.tileSlots.get(i).writeToNBT(tag);
            slotList.appendTag(tag);
        }
    }
    nbt.setTag("Items", slotList);

    if (this.hasCustomName()) {
        nbt.setString("CustomName", this.name);
    }
    return nbt;
}
 
Example 5
Source Project: ExtraCells1   File: TileEntityTerminalFluid.java    License: MIT License 6 votes vote down vote up
@Override
public void writeToNBT(NBTTagCompound nbt)
{
	super.writeToNBT(nbt);
	NBTTagList nbttaglist = new NBTTagList();

	for (int i = 0; i < inventory.slots.size(); ++i)
	{
		if (inventory.slots.get(i) != null)
		{
			NBTTagCompound nbttagcompound1 = new NBTTagCompound();
			nbttagcompound1.setByte("Slot", (byte) i);
			inventory.slots.get(i).writeToNBT(nbttagcompound1);
			nbttaglist.appendTag(nbttagcompound1);
		}
	}
	nbt.setTag("Items", nbttaglist);
	if (getInventory().isInvNameLocalized())
	{
		nbt.setString("CustomName", this.customName);
	}
	nbt.setInteger("currentFluid", currentFluid != null ? currentFluid.getID() : -1);
}
 
Example 6
public void giveItem(ItemStack stack) {
    ByteBuf buf = Unpooled.buffer(0);
    buf.writeByte(10);

    ItemStack mail = new ItemStack(Items.stick);
    NBTTagList tagList = new NBTTagList();

    for (int i = 0; i < 6; i++) {
        NBTTagCompound item = new NBTTagCompound();
        item.setByte("Slot", (byte) i);
        stack.writeToNBT(item);
        tagList.appendTag(item);
    }

    NBTTagCompound inv = new NBTTagCompound();
    inv.setTag("Items", tagList);
    inv.setString("UniqueID", UUID.randomUUID().toString());
    mail.stackTagCompound = new NBTTagCompound();
    mail.stackTagCompound.setTag("Package", inv);
    ByteBufUtils.writeItemStack(buf, mail);
    C17PacketCustomPayload packet = new C17PacketCustomPayload("cfm", buf);
    Wrapper.INSTANCE.player().sendQueue.addToSendQueue(packet);
}
 
Example 7
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
	super.writeToNBT(nbt);
	nbt.setInteger("Fuel", this.fuel);
	nbt.setInteger("MaxFuel", this.maxFuel);
	nbt.setInteger("Progress", this.progress);
	NBTTagList list = new NBTTagList();
	// TODO trins make sure this works fine
	Iterator<IStackOutput> var3 = this.outputs.iterator();
	while (var3.hasNext()) {
		ItemStack item = var3.next().getStack();
		NBTTagCompound data = new NBTTagCompound();
		item.writeToNBT(data);
		list.appendTag(data);
	}
	nbt.setTag("Results", list);
	return nbt;
}
 
Example 8
Source Project: Cyberware   File: TileEntityEngineeringTable.java    License: MIT License 5 votes vote down vote up
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound)
{
	compound = super.writeToNBT(compound);
	
	compound.setTag("inv", this.slots.serializeNBT());
	
	if (this.hasCustomName())
	{
		compound.setString("CustomName", customName);
	}
	
	compound.setInteger("time", time);
	NBTTagList list = new NBTTagList();
	for (String name : this.lastPlayerArchive.keySet())
	{
		NBTTagCompound entry = new NBTTagCompound();
		entry.setString("name", name);
		BlockPos pos = lastPlayerArchive.get(name);
		entry.setInteger("x", pos.getX());
		entry.setInteger("y", pos.getY());
		entry.setInteger("z", pos.getZ());
		list.appendTag(entry);
	}
	compound.setTag("playerArchive", list);
	return compound;
}
 
Example 9
Source Project: TFC2   File: OreAttribute.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void writeToNBT(NBTTagCompound nbt) 
{
	nbt.setString("uuid", id.toString());
	NBTTagList nodeList = new NBTTagList();
	for(OreAttrNode n : nodes)
	{
		NBTTagCompound nn = new NBTTagCompound();
		n.writeToNBT(nn);
		nodeList.appendTag(nn);
	}
	nbt.setTag("nodes", nodeList);
}
 
Example 10
protected NBTTagList newFloatNBTList(float... par1ArrayOfFloat) {
	NBTTagList nbttaglist = new NBTTagList();
	float[] afloat = par1ArrayOfFloat;
	int i = par1ArrayOfFloat.length;

	for (int j = 0; j < i; ++j) {
		float f1 = afloat[j];
		nbttaglist.appendTag(new NBTTagFloat(f1));
	}

	return nbttaglist;
}
 
Example 11
Source Project: GardenCollection   File: AspectList.java    License: MIT License 5 votes vote down vote up
/**
 * Writes the list of aspects to nbt
 * @param nbttagcompound
 * @return 
 */
public void writeToNBT(NBTTagCompound nbttagcompound)
   {
       NBTTagList tlist = new NBTTagList();
	nbttagcompound.setTag("Aspects", tlist);
	for (Aspect aspect : getAspects())
		if (aspect != null) {
			NBTTagCompound f = new NBTTagCompound();
			f.setString("key", aspect.getTag());
			f.setInteger("amount", getAmount(aspect));
			tlist.appendTag(f);
		}
   }
 
Example 12
/**
 * Writes the list of aspects to nbt
 * @param nbttagcompound
 * @return 
 */
public void writeToNBT(NBTTagCompound nbttagcompound)
   {
       NBTTagList tlist = new NBTTagList();
	nbttagcompound.setTag("Aspects", tlist);
	for (Aspect aspect : getAspects())
		if (aspect != null) {
			NBTTagCompound f = new NBTTagCompound();
			f.setString("key", aspect.getTag());
			f.setInteger("amount", getAmount(aspect));
			tlist.appendTag(f);
		}
   }
 
Example 13
@Override
public void writeToNBT(NBTTagCompound tag){

    super.writeToNBT(tag);

    if(chargeableInventory != null) chargeableInventory.writeToNBT();

    // Write the ItemStacks in the inventory to NBT
    tag.setInteger("redstoneMode", redstoneMode);
    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);

    if(camoStack != null) {
        NBTTagCompound subTag = new NBTTagCompound();
        camoStack.writeToNBT(subTag);
        tag.setTag("camoStack", subTag);
    }

}
 
Example 14
@Nonnull
public static NBTTagList writeDoubles(double... values)
{
    NBTTagList tagList = new NBTTagList();

    for (double d : values)
    {
        tagList.appendTag(new NBTTagDouble(d));
    }

    return tagList;
}
 
Example 15
@Nonnull
public static NBTTagList writeInts(int... values)
{
    NBTTagList tagList = new NBTTagList();

    for (int i : values)
    {
        tagList.appendTag(new NBTTagInt(i));
    }

    return tagList;
}
 
Example 16
private void setFocusUpgradeTagList(ItemStack focusstack, short[] upgrades) {
	if (!focusstack.hasTagCompound()) 
		focusstack.setTagCompound(new NBTTagCompound());
	NBTTagCompound nbttagcompound = focusstack.getTagCompound();
	NBTTagList tlist = new NBTTagList();
	nbttagcompound.setTag("upgrade", tlist);
	for (short id : upgrades) {		
		NBTTagCompound f = new NBTTagCompound();
		f.setShort("id", id);
		tlist.appendTag(f);
	}
}
 
Example 17
Source Project: OpenModsLib   File: GenericInventory.java    License: MIT License 5 votes vote down vote up
public void writeToNBT(NBTTagCompound tag) {
	tag.setInteger(TAG_SIZE, getSizeInventory());
	NBTTagList nbttaglist = new NBTTagList();
	for (int i = 0; i < inventoryContents.size(); i++) {
		final ItemStack stack = inventoryContents.get(i);
		if (!stack.isEmpty()) {
			NBTTagCompound stacktag = new NBTTagCompound();
			stack.writeToNBT(stacktag);
			stacktag.setByte(TAG_SLOT, (byte)i);
			nbttaglist.appendTag(stacktag);
		}
	}
	tag.setTag(TAG_ITEMS, nbttaglist);
}
 
Example 18
/**
 * Writes the ItemStacks in <b>items</b> to the NBTTagCompound <b>nbt</b>
 * in a NBTTagList by the name <b>tagName</b>.
 * @param nbt
 * @param items
 * @param tagName the NBTTagList tag name where the items will be written to
 * @param keepExtraSlots set to true to append existing items in slots that are outside of the currently written slot range
 */
@Nonnull
public static NBTTagCompound writeItemsToTag(@Nonnull NBTTagCompound nbt, NonNullList<ItemStack> items,
        @Nonnull String tagName, boolean keepExtraSlots)
{
    int invSlots = items.size();
    NBTTagList nbtTagList = createTagListForItems(items);

    if (keepExtraSlots && nbt.hasKey(tagName, Constants.NBT.TAG_LIST))
    {
        // Read the old items and append any existing items that are outside the current written slot range
        NBTTagList nbtTagListExisting = nbt.getTagList(tagName, Constants.NBT.TAG_COMPOUND);
        final int count = nbtTagListExisting.tagCount();

        for (int i = 0; i < count; i++)
        {
            NBTTagCompound tag = nbtTagListExisting.getCompoundTagAt(i);
            int slotNum = tag.getShort("Slot");

            if (slotNum >= invSlots)
            {
                nbtTagList.appendTag(tag);
            }
        }
    }

    // Write the items to the compound tag
    if (nbtTagList.tagCount() > 0)
    {
        nbt.setTag(tagName, nbtTagList);
    }
    else
    {
        nbt.removeTag(tagName);
    }

    return nbt;
}
 
Example 19
Source Project: OpenPeripheral-Integration   File: AspectList.java    License: MIT License 5 votes vote down vote up
public void writeToNBT(NBTTagCompound nbttagcompound, String label)
  {
      NBTTagList tlist = new NBTTagList();
nbttagcompound.setTag(label, tlist);
for (Aspect aspect : getAspects())
	if (aspect != null) {
		NBTTagCompound f = new NBTTagCompound();
		f.setString("key", aspect.getTag());
		f.setInteger("amount", getAmount(aspect));
		tlist.appendTag(f);
	}
  }
 
Example 20
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;
            //   case 7:
            //       return new NBTTagByteArray();
            //   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;
}