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

The following are Jave code examples for showing how to use appendTag() of the net.minecraft.nbt.NBTTagList class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: DecompiledMinecraft   File: TileEntityFurnace.java   View Source Code Vote up 6 votes
public void writeToNBT(NBTTagCompound compound)
{
    super.writeToNBT(compound);
    compound.setShort("BurnTime", (short)this.furnaceBurnTime);
    compound.setShort("CookTime", (short)this.cookTime);
    compound.setShort("CookTimeTotal", (short)this.totalCookTime);
    NBTTagList nbttaglist = new NBTTagList();

    for (int i = 0; i < this.furnaceItemStacks.length; ++i)
    {
        if (this.furnaceItemStacks[i] != null)
        {
            NBTTagCompound nbttagcompound = new NBTTagCompound();
            nbttagcompound.setByte("Slot", (byte)i);
            this.furnaceItemStacks[i].writeToNBT(nbttagcompound);
            nbttaglist.appendTag(nbttagcompound);
        }
    }

    compound.setTag("Items", nbttaglist);

    if (this.hasCustomName())
    {
        compound.setString("CustomName", this.furnaceCustomName);
    }
}
 
Example 2
Project: BaseClient   File: ScoreboardSaveData.java   View Source Code Vote up 6 votes
protected NBTTagList objectivesToNbt()
{
    NBTTagList nbttaglist = new NBTTagList();

    for (ScoreObjective scoreobjective : this.theScoreboard.getScoreObjectives())
    {
        if (scoreobjective.getCriteria() != null)
        {
            NBTTagCompound nbttagcompound = new NBTTagCompound();
            nbttagcompound.setString("Name", scoreobjective.getName());
            nbttagcompound.setString("CriteriaName", scoreobjective.getCriteria().getName());
            nbttagcompound.setString("DisplayName", scoreobjective.getDisplayName());
            nbttagcompound.setString("RenderType", scoreobjective.getRenderType().func_178796_a());
            nbttaglist.appendTag(nbttagcompound);
        }
    }

    return nbttaglist;
}
 
Example 3
Project: CustomWorldGen   File: ItemStack.java   View Source Code Vote up 6 votes
public void addAttributeModifier(String attributeName, AttributeModifier modifier, EntityEquipmentSlot equipmentSlot)
{
    if (this.stackTagCompound == null)
    {
        this.stackTagCompound = new NBTTagCompound();
    }

    if (!this.stackTagCompound.hasKey("AttributeModifiers", 9))
    {
        this.stackTagCompound.setTag("AttributeModifiers", new NBTTagList());
    }

    NBTTagList nbttaglist = this.stackTagCompound.getTagList("AttributeModifiers", 10);
    NBTTagCompound nbttagcompound = SharedMonsterAttributes.writeAttributeModifierToNBT(modifier);
    nbttagcompound.setString("AttributeName", attributeName);

    if (equipmentSlot != null)
    {
        nbttagcompound.setString("Slot", equipmentSlot.getName());
    }

    nbttaglist.appendTag(nbttagcompound);
}
 
Example 4
Project: MagicWinds   File: TileEntityTrinketMaker.java   View Source Code Vote up 6 votes
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    super.writeToNBT(compound);

    NBTTagList list = new NBTTagList();
    for(int i = 0; i<this.getSizeInventory(); i++){
        if(this.getStackInSlot(i) != null){
            NBTTagCompound stackTag = new NBTTagCompound();
            stackTag.setByte("Slot", (byte) i);
            getStackInSlot(i).writeToNBT(stackTag);
            list.appendTag(stackTag);
        }
    }
    compound.setTag("Items", list);

    if(hasCustomName()){
        compound.setString("customName", getCustomName());
    }
    return compound;
}
 
Example 5
Project: CustomWorldGen   File: EnchantmentHelper.java   View Source Code Vote up 5 votes
/**
 * Set the enchantments for the specified stack.
 */
public static void setEnchantments(Map<Enchantment, Integer> enchMap, ItemStack stack)
{
    NBTTagList nbttaglist = new NBTTagList();

    for (Entry<Enchantment, Integer> entry : enchMap.entrySet())
    {
        Enchantment enchantment = (Enchantment)entry.getKey();

        if (enchantment != null)
        {
            int i = ((Integer)entry.getValue()).intValue();
            NBTTagCompound nbttagcompound = new NBTTagCompound();
            nbttagcompound.setShort("id", (short)Enchantment.getEnchantmentID(enchantment));
            nbttagcompound.setShort("lvl", (short)i);
            nbttaglist.appendTag(nbttagcompound);

            if (stack.getItem() == Items.ENCHANTED_BOOK)
            {
                Items.ENCHANTED_BOOK.addEnchantment(stack, new EnchantmentData(enchantment, i));
            }
        }
    }

    if (nbttaglist.hasNoTags())
    {
        if (stack.hasTagCompound())
        {
            stack.getTagCompound().removeTag("ench");
        }
    }
    else if (stack.getItem() != Items.ENCHANTED_BOOK)
    {
        stack.setTagInfo("ench", nbttaglist);
    }
}
 
Example 6
Project: Dynamic-GUIs   File: DynamicTileInventory.java   View Source Code Vote up 5 votes
public static void saveInventory(IItemHandler inventory, NBTTagCompound tag) {
	if (itemHandler != null && itemHandler.getSlots() > 0) {
		NBTTagList list = new NBTTagList();
		
		for (int i = 0; i < itemHandler.getSlots(); i++) {
			ItemStack stack = itemHandler.getStackInSlot(i);
			NBTTagCompound item = new NBTTagCompound();
			stack.writeToNBT(item);
			list.appendTag(item);
		}
		tag.setTag("Items", list);
	}
}
 
Example 7
Project: CustomWorldGen   File: TileEntityBrewingStand.java   View Source Code Vote up 5 votes
public NBTTagCompound writeToNBT(NBTTagCompound compound)
{
    super.writeToNBT(compound);
    compound.setShort("BrewTime", (short)this.brewTime);
    NBTTagList nbttaglist = new NBTTagList();

    for (int i = 0; i < this.brewingItemStacks.length; ++i)
    {
        if (this.brewingItemStacks[i] != null)
        {
            NBTTagCompound nbttagcompound = new NBTTagCompound();
            nbttagcompound.setByte("Slot", (byte)i);
            this.brewingItemStacks[i].writeToNBT(nbttagcompound);
            nbttaglist.appendTag(nbttagcompound);
        }
    }

    compound.setTag("Items", nbttaglist);

    if (this.hasCustomName())
    {
        compound.setString("CustomName", this.customName);
    }

    compound.setByte("Fuel", (byte)this.fuel);
    return compound;
}
 
Example 8
Project: Backmemed   File: StructureOceanMonument.java   View Source Code Vote up 5 votes
public void writeToNBT(NBTTagCompound tagCompound)
{
    super.writeToNBT(tagCompound);
    NBTTagList nbttaglist = new NBTTagList();

    for (ChunkPos chunkpos : this.processed)
    {
        NBTTagCompound nbttagcompound = new NBTTagCompound();
        nbttagcompound.setInteger("X", chunkpos.chunkXPos);
        nbttagcompound.setInteger("Z", chunkpos.chunkZPos);
        nbttaglist.appendTag(nbttagcompound);
    }

    tagCompound.setTag("Processed", nbttaglist);
}
 
Example 9
Project: Wurst-MC-1.12   File: TrollPotionMod.java   View Source Code Vote up 5 votes
@Override
public void onEnable()
{
	// check gamemode
	if(!WMinecraft.getPlayer().capabilities.isCreativeMode)
	{
		ChatUtils.error("Creative mode only.");
		setEnabled(false);
		return;
	}
	
	// generate potion
	ItemStack stack = InventoryUtils.createSplashPotion();
	NBTTagList effects = new NBTTagList();
	for(int i = 1; i <= 23; i++)
	{
		NBTTagCompound effect = new NBTTagCompound();
		effect.setInteger("Amplifier", Integer.MAX_VALUE);
		effect.setInteger("Duration", Integer.MAX_VALUE);
		effect.setInteger("Id", i);
		effects.appendTag(effect);
	}
	stack.setTagInfo("CustomPotionEffects", effects);
	stack.setStackDisplayName("�rSplash Potion of Trolling");
	
	// give potion
	if(InventoryUtils.placeStackInHotbar(stack))
		ChatUtils.message("Potion created.");
	else
		ChatUtils.error("Please clear a slot in your hotbar.");
	
	setEnabled(false);
}
 
Example 10
Project: BaseClient   File: SharedMonsterAttributes.java   View Source Code Vote up 5 votes
/**
 * Creates an NBTTagList from a BaseAttributeMap, including all its AttributeInstances
 */
public static NBTTagList writeBaseAttributeMapToNBT(BaseAttributeMap p_111257_0_)
{
    NBTTagList nbttaglist = new NBTTagList();

    for (IAttributeInstance iattributeinstance : p_111257_0_.getAllAttributes())
    {
        nbttaglist.appendTag(writeAttributeInstanceToNBT(iattributeinstance));
    }

    return nbttaglist;
}
 
Example 11
Project: Backmemed   File: Template.java   View Source Code Vote up 5 votes
private NBTTagList writeInts(int... values)
{
    NBTTagList nbttaglist = new NBTTagList();

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

    return nbttaglist;
}
 
Example 12
Project: Bewitchment   File: BrewUtils.java   View Source Code Vote up 5 votes
public static void appendBrews(NBTTagCompound tag, Collection<BrewEffect> effects) {
	NBTTagList list = new NBTTagList();
	tag.setTag(BREW_DATA, list);
	for (BrewEffect effect : effects) {
		NBTTagCompound compound = new NBTTagCompound();
		IBrew brew = effect.getBrew();
		compound.setString(BREW_ID, BrewRegistry.getBrewResource(brew).toString());
		compound.setInteger(BREW_AMPLIFIER, effect.getAmplifier());
		compound.setInteger(BREW_DURATION, effect.getDuration());
		list.appendTag(compound);
	}
}
 
Example 13
Project: ObsidianSuite   File: AnimationParenting.java   View Source Code Vote up 5 votes
public static NBTTagCompound getSaveData(ModelObj model)
{
	NBTTagCompound parentNBT = new NBTTagCompound();
	NBTTagList parentNBTList = new NBTTagList();

	for (PartObj part : model.getPartObjs())
	{
		Set<PartObj> children = part.getChildren();
		List<PartObj> mergeParts = part.getMergedParts();
		if (!children.isEmpty() || !mergeParts.isEmpty())
		{
			NBTTagCompound parentCompound = new NBTTagCompound();
			parentCompound.setString("Parent", part.getName());

			int i = 0;
			for (PartObj child : children)
			{
				String name = child.getName();
				if (child.hasBend())
				{
					name += "*";
				}
				parentCompound.setString("Child" + i, name);
				i++;
			}
			
			for(int j = 0; j < mergeParts.size(); j++)
			{
				PartObj mergedPart = mergeParts.get(j);
				parentCompound.setString("Merged" + j, mergedPart.getName());
			}

			parentNBTList.appendTag(parentCompound);
		}

	}

	parentNBT.setTag("Parenting", parentNBTList);
	return parentNBT;
}
 
Example 14
Project: BaseClient   File: MerchantRecipeList.java   View Source Code Vote up 5 votes
public NBTTagCompound getRecipiesAsTags()
{
    NBTTagCompound nbttagcompound = new NBTTagCompound();
    NBTTagList nbttaglist = new NBTTagList();

    for (int i = 0; i < this.size(); ++i)
    {
        MerchantRecipe merchantrecipe = (MerchantRecipe)this.get(i);
        nbttaglist.appendTag(merchantrecipe.writeToTags());
    }

    nbttagcompound.setTag("Recipes", nbttaglist);
    return nbttagcompound;
}
 
Example 15
Project: BaseClient   File: MobSpawnerBaseLogic.java   View Source Code Vote up 5 votes
public void writeToNBT(NBTTagCompound nbt)
{
    String s = this.getEntityNameToSpawn();

    if (!StringUtils.isNullOrEmpty(s))
    {
        nbt.setString("EntityId", s);
        nbt.setShort("Delay", (short)this.spawnDelay);
        nbt.setShort("MinSpawnDelay", (short)this.minSpawnDelay);
        nbt.setShort("MaxSpawnDelay", (short)this.maxSpawnDelay);
        nbt.setShort("SpawnCount", (short)this.spawnCount);
        nbt.setShort("MaxNearbyEntities", (short)this.maxNearbyEntities);
        nbt.setShort("RequiredPlayerRange", (short)this.activatingRangeFromPlayer);
        nbt.setShort("SpawnRange", (short)this.spawnRange);

        if (this.getRandomEntity() != null)
        {
            nbt.setTag("SpawnData", this.getRandomEntity().nbtData.copy());
        }

        if (this.getRandomEntity() != null || this.minecartToSpawn.size() > 0)
        {
            NBTTagList nbttaglist = new NBTTagList();

            if (this.minecartToSpawn.size() > 0)
            {
                for (MobSpawnerBaseLogic.WeightedRandomMinecart mobspawnerbaselogic$weightedrandomminecart : this.minecartToSpawn)
                {
                    nbttaglist.appendTag(mobspawnerbaselogic$weightedrandomminecart.toNBT());
                }
            }
            else
            {
                nbttaglist.appendTag(this.getRandomEntity().toNBT());
            }

            nbt.setTag("SpawnPotentials", nbttaglist);
        }
    }
}
 
Example 16
Project: Anima-Mundi   File: TileEntityLinkableWorker.java   View Source Code Vote up 5 votes
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound)
{

	NBTTagList list = new NBTTagList();
	for(NodeLink link : links)
	{
		list.appendTag(link.writeToNBT());
	}
	compound.setTag("links", list);
	compound.setTag("items", items.serializeNBT());
	return super.writeToNBT(compound);
}
 
Example 17
Project: Backmemed   File: Entity.java   View Source Code Vote up 5 votes
/**
 * creates a NBT list from the array of doubles passed to this function
 */
protected NBTTagList newDoubleNBTList(double... numbers)
{
    NBTTagList nbttaglist = new NBTTagList();

    for (double d0 : numbers)
    {
        nbttaglist.appendTag(new NBTTagDouble(d0));
    }

    return nbttaglist;
}
 
Example 18
Project: CustomWorldGen   File: EntityPlayer.java   View Source Code Vote up 4 votes
/**
 * (abstract) Protected helper method to write subclass entity data to NBT.
 */
public void writeEntityToNBT(NBTTagCompound compound)
{
    super.writeEntityToNBT(compound);
    compound.setInteger("DataVersion", 512);
    compound.setTag("Inventory", this.inventory.writeToNBT(new NBTTagList()));
    compound.setInteger("SelectedItemSlot", this.inventory.currentItem);
    compound.setBoolean("Sleeping", this.sleeping);
    compound.setShort("SleepTimer", (short)this.sleepTimer);
    compound.setFloat("XpP", this.experience);
    compound.setInteger("XpLevel", this.experienceLevel);
    compound.setInteger("XpTotal", this.experienceTotal);
    compound.setInteger("XpSeed", this.xpSeed);
    compound.setInteger("Score", this.getScore());

    if (this.spawnChunk != null)
    {
        compound.setInteger("SpawnX", this.spawnChunk.getX());
        compound.setInteger("SpawnY", this.spawnChunk.getY());
        compound.setInteger("SpawnZ", this.spawnChunk.getZ());
        compound.setBoolean("SpawnForced", this.spawnForced);
    }

    NBTTagList spawnlist = new NBTTagList();
    for (java.util.Map.Entry<Integer, BlockPos> entry : this.spawnChunkMap.entrySet())
    {
        BlockPos spawn = entry.getValue();
        if (spawn == null) continue;
        Boolean forced = spawnForcedMap.get(entry.getKey());
        if (forced == null) forced = false;
        NBTTagCompound spawndata = new NBTTagCompound();
        spawndata.setInteger("Dim", entry.getKey());
        spawndata.setInteger("SpawnX", spawn.getX());
        spawndata.setInteger("SpawnY", spawn.getY());
        spawndata.setInteger("SpawnZ", spawn.getZ());
        spawndata.setBoolean("SpawnForced", forced);
        spawnlist.appendTag(spawndata);
    }
    compound.setTag("Spawns", spawnlist);

    this.foodStats.writeNBT(compound);
    this.capabilities.writeCapabilitiesToNBT(compound);
    compound.setTag("EnderItems", this.theInventoryEnderChest.saveInventoryToNBT());
}
 
Example 19
Project: Backmemed   File: EntityLivingBase.java   View Source Code Vote up 4 votes
/**
 * (abstract) Protected helper method to write subclass entity data to NBT.
 */
public void writeEntityToNBT(NBTTagCompound compound)
{
    compound.setFloat("Health", this.getHealth());
    compound.setShort("HurtTime", (short)this.hurtTime);
    compound.setInteger("HurtByTimestamp", this.revengeTimer);
    compound.setShort("DeathTime", (short)this.deathTime);
    compound.setFloat("AbsorptionAmount", this.getAbsorptionAmount());

    for (EntityEquipmentSlot entityequipmentslot : EntityEquipmentSlot.values())
    {
        ItemStack itemstack = this.getItemStackFromSlot(entityequipmentslot);

        if (!itemstack.func_190926_b())
        {
            this.getAttributeMap().removeAttributeModifiers(itemstack.getAttributeModifiers(entityequipmentslot));
        }
    }

    compound.setTag("Attributes", SharedMonsterAttributes.writeBaseAttributeMapToNBT(this.getAttributeMap()));

    for (EntityEquipmentSlot entityequipmentslot1 : EntityEquipmentSlot.values())
    {
        ItemStack itemstack1 = this.getItemStackFromSlot(entityequipmentslot1);

        if (!itemstack1.func_190926_b())
        {
            this.getAttributeMap().applyAttributeModifiers(itemstack1.getAttributeModifiers(entityequipmentslot1));
        }
    }

    if (!this.activePotionsMap.isEmpty())
    {
        NBTTagList nbttaglist = new NBTTagList();

        for (PotionEffect potioneffect : this.activePotionsMap.values())
        {
            nbttaglist.appendTag(potioneffect.writeCustomPotionEffectToNBT(new NBTTagCompound()));
        }

        compound.setTag("ActiveEffects", nbttaglist);
    }

    compound.setBoolean("FallFlying", this.isElytraFlying());
}
 
Example 20
Project: BetterThanWeagles   File: ModVillagers.java   View Source Code Vote up 4 votes
private static ItemStack createChickenSpawnerKit()
{
	// Build the item tag for the Spawner Changer
	NBTTagCompound spawnerChanger = new NBTTagCompound();
	spawnerChanger.setString("id", "actuallyadditions:item_spawner_changer");
	spawnerChanger.setByte("Count", (byte)1);
	spawnerChanger.setShort("Damage", (short)0);
	spawnerChanger.setByte("Slot", (byte)0);

	NBTTagCompound spawnerTag = new NBTTagCompound();
	spawnerTag.setString("Entity", "minecraft:chicken");
	spawnerChanger.setTag("tag", spawnerTag);

	// Build the item tag for the Mob Spawner
	NBTTagCompound mobSpawner = new NBTTagCompound();
	mobSpawner.setString("id", "minecraft:mob_spawner");
	mobSpawner.setByte("Count", (byte)1);
	mobSpawner.setShort("Damage", (short)0);
	mobSpawner.setByte("Slot", (byte)1);

	// Put the chest items in a list
	NBTTagList inventory = new NBTTagList();
	inventory.appendTag(spawnerChanger);
	inventory.appendTag(mobSpawner);

	// Build the BlockEntityTag
	NBTTagCompound blockEntityTag = new NBTTagCompound();
	blockEntityTag.setString("CustomName", "Chicken Spawner Kit");
	blockEntityTag.setTag("Items", inventory);

	// Build the display tag
	NBTTagCompound displayTag = new NBTTagCompound();
	displayTag.setString("Name", "Chicken Spawner Kit");

	// Create the ItemStack and attach the tags
	ItemStack chest = new ItemStack(Blocks.CHEST);
	chest.setTagInfo("BlockEntityTag", blockEntityTag);
	chest.setTagInfo("display", displayTag);

	return chest;
}