Java Code Examples for net.minecraft.nbt.NBTTagList

The following are top voted examples for showing how to use net.minecraft.nbt.NBTTagList. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: CustomWorldGen   File: TileEntityDispenser.java   View source code 6 votes vote down vote up
public void readFromNBT(NBTTagCompound compound)
{
    super.readFromNBT(compound);

    if (!this.checkLootAndRead(compound))
    {
        NBTTagList nbttaglist = compound.getTagList("Items", 10);
        this.stacks = new ItemStack[this.getSizeInventory()];

        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
            int j = nbttagcompound.getByte("Slot") & 255;

            if (j >= 0 && j < this.stacks.length)
            {
                this.stacks[j] = ItemStack.loadItemStackFromNBT(nbttagcompound);
            }
        }
    }

    if (compound.hasKey("CustomName", 8))
    {
        this.customName = compound.getString("CustomName");
    }
}
 
Example 2
Project: MeeCreeps   File: PortalTileEntity.java   View source code 6 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound compound) {
    super.readFromNBT(compound);
    timeout = compound.getInteger("timeout");
    portalSide = EnumFacing.VALUES[compound.getByte("portalSide")];
    BlockPos pos = BlockPos.fromLong(compound.getLong("pos"));
    int dim = compound.getInteger("dim");
    EnumFacing side = EnumFacing.VALUES[compound.getByte("side")];
    other = new TeleportDestination("", dim, pos, side);
    NBTTagList list = compound.getTagList("bl", Constants.NBT.TAG_COMPOUND);
    blackListed.clear();
    for (int i = 0 ; i < list.tagCount() ; i++) {
        NBTTagCompound tc = list.getCompoundTagAt(i);
        UUID uuid = new UUID(tc.getLong("m"), tc.getLong("l"));
        blackListed.add(uuid);
    }
}
 
Example 3
Project: BaseClient   File: TileEntityBanner.java   View source code 6 votes vote down vote up
/**
 * Removes all the banner related data from a provided instance of ItemStack.
 */
public static void removeBannerData(ItemStack stack)
{
    NBTTagCompound nbttagcompound = stack.getSubCompound("BlockEntityTag", false);

    if (nbttagcompound != null && nbttagcompound.hasKey("Patterns", 9))
    {
        NBTTagList nbttaglist = nbttagcompound.getTagList("Patterns", 10);

        if (nbttaglist.tagCount() > 0)
        {
            nbttaglist.removeTag(nbttaglist.tagCount() - 1);

            if (nbttaglist.hasNoTags())
            {
                stack.getTagCompound().removeTag("BlockEntityTag");

                if (stack.getTagCompound().hasNoTags())
                {
                    stack.setTagCompound((NBTTagCompound)null);
                }
            }
        }
    }
}
 
Example 4
Project: Backmemed   File: PotionUtils.java   View source code 6 votes vote down vote up
public static void addCustomPotionEffectToList(@Nullable NBTTagCompound tag, List<PotionEffect> effectList)
{
    if (tag != null && tag.hasKey("CustomPotionEffects", 9))
    {
        NBTTagList nbttaglist = tag.getTagList("CustomPotionEffects", 10);

        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
            PotionEffect potioneffect = PotionEffect.readCustomPotionEffectFromNBT(nbttagcompound);

            if (potioneffect != null)
            {
                effectList.add(potioneffect);
            }
        }
    }
}
 
Example 5
Project: DecompiledMinecraft   File: EntityMinecartContainer.java   View source code 6 votes vote down vote up
/**
 * (abstract) Protected helper method to read subclass entity data from NBT.
 */
protected void readEntityFromNBT(NBTTagCompound tagCompund)
{
    super.readEntityFromNBT(tagCompund);
    NBTTagList nbttaglist = tagCompund.getTagList("Items", 10);
    this.minecartContainerItems = new ItemStack[this.getSizeInventory()];

    for (int i = 0; i < nbttaglist.tagCount(); ++i)
    {
        NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
        int j = nbttagcompound.getByte("Slot") & 255;

        if (j >= 0 && j < this.minecartContainerItems.length)
        {
            this.minecartContainerItems[j] = ItemStack.loadItemStackFromNBT(nbttagcompound);
        }
    }
}
 
Example 6
Project: pnc-repressurized   File: DateEventHandler.java   View source code 6 votes vote down vote up
public static void spawnFirework(World world, double x, double y, double z) {
    ItemStack rocket = new ItemStack(Items.FIREWORKS);

    ItemStack itemstack1 = getFireworkCharge();

    NBTTagCompound nbttagcompound = new NBTTagCompound();
    NBTTagCompound nbttagcompound1 = new NBTTagCompound();
    NBTTagList nbttaglist = new NBTTagList();

    if (itemstack1 != null && itemstack1.getItem() == Items.FIREWORK_CHARGE && itemstack1.hasTagCompound() && itemstack1.getTagCompound().hasKey("Explosion")) {
        nbttaglist.appendTag(itemstack1.getTagCompound().getCompoundTag("Explosion"));
    }

    nbttagcompound1.setTag("Explosions", nbttaglist);
    nbttagcompound1.setByte("Flight", (byte) 2);
    nbttagcompound.setTag("Fireworks", nbttagcompound1);

    rocket.setTagCompound(nbttagcompound);

    EntityFireworkRocket entity = new EntityFireworkRocket(world, x, y, z, rocket);
    world.spawnEntity(entity);
}
 
Example 7
Project: pnc-repressurized   File: InventoryPneumaticInventoryItem.java   View source code 6 votes vote down vote up
/**
 * Writes a NBT Node with inventory.
 */
public void writeToNBT() {
    NBTTagList itemList = new NBTTagList();
    for (int i = 0; i < getSizeInventory(); i++) {
        if (!getStackInSlot(i).isEmpty()) {
            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");
}
 
Example 8
Project: pnc-repressurized   File: ContainerRemote.java   View source code 6 votes vote down vote up
private static Set<String> getRelevantVariableNames(@Nonnull ItemStack remote) {
    Set<String> variables = new HashSet<>();
    NBTTagCompound tag = remote.getTagCompound();
    if (tag != null) {
        NBTTagList tagList = tag.getTagList("actionWidgets", 10);
        for (int i = 0; i < tagList.tagCount(); i++) {
            NBTTagCompound widgetTag = tagList.getCompoundTagAt(i);
            variables.add(widgetTag.getString("variableName"));
            variables.add(widgetTag.getString("enableVariable"));
            TextVariableParser parser = new TextVariableParser(widgetTag.getString("text"));
            parser.parse();
            variables.addAll(parser.getRelevantVariables());
        }
    }
    return variables;
}
 
Example 9
Project: Never-Enough-Currency   File: InventoryItem.java   View source code 6 votes vote down vote up
/**
 * A custom method to read our inventory from an ItemStack's NBT compound
 */
public void readFromNBT(NBTTagCompound compound) {
	if ("".equals(uniqueID)) {
		// try to read unique ID from NBT
		uniqueID = compound.getString("uniqueID");
		// if it's still "", assign a new one:
		if ("".equals(uniqueID)) {
			uniqueID = UUID.randomUUID().toString();
		}
	}

	NBTTagList items = compound.getTagList("ItemInventory", Constants.NBT.TAG_COMPOUND);

	for (int i = 0; i < items.tagCount(); ++i) {
		NBTTagCompound item = items.getCompoundTagAt(i);
		int slot = item.getInteger("Slot");

		if (slot >= 0 && slot < getSizeInventory()) {
			inventory.set(slot, new ItemStack(item));
		}
	}
}
 
Example 10
Project: ElementalElaboration   File: TileKTWithInventory.java   View source code 6 votes vote down vote up
public  void readFromNBT(NBTTagCompound tagCompound)
{
    super.readFromNBT(tagCompound);
    NBTTagList tagList = tagCompound.getTagList("Items", 10);
    this.inventory = new ItemStack[this.getSizeInventory()];

    for(int i = 0; i < tagList.tagCount(); ++i)
    {
        NBTTagCompound tempTagCompound = tagList.getCompoundTagAt(i);
        byte slot = tempTagCompound.getByte("Slot");

        if(slot >= 0 && slot < this.inventory.length)
        {
            this.setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(tempTagCompound));
        }
    }

    if(tagCompound.hasKey("CustomName", 8))
    {
        this.customName = tagCompound.getString("CustomName");
    }
}
 
Example 11
Project: BaseClient   File: TileEntityHopper.java   View source code 6 votes vote down vote up
public void writeToNBT(NBTTagCompound compound)
{
    super.writeToNBT(compound);
    NBTTagList nbttaglist = new NBTTagList();

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

    compound.setTag("Items", nbttaglist);
    compound.setInteger("TransferCooldown", this.transferCooldown);

    if (this.hasCustomName())
    {
        compound.setString("CustomName", this.customName);
    }
}
 
Example 12
Project: pnc-repressurized   File: RemoteLayout.java   View source code 6 votes vote down vote up
public RemoteLayout(ItemStack remote, int guiLeft, int guiTop) {
    NBTTagCompound tag = remote.getTagCompound();
    if (tag != null) {
        NBTTagList tagList = tag.getTagList("actionWidgets", 10);
        for (int i = 0; i < tagList.tagCount(); i++) {
            NBTTagCompound widgetTag = tagList.getCompoundTagAt(i);
            String id = widgetTag.getString("id");
            Class<? extends ActionWidget> clazz = registeredWidgets.get(id);
            try {
                ActionWidget widget = clazz.newInstance();
                widget.readFromNBT(widgetTag, guiLeft, guiTop);
                actionWidgets.add(widget);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
 
Example 13
Project: BaseClient   File: InventoryEnderChest.java   View source code 6 votes vote down vote up
public NBTTagList saveInventoryToNBT()
{
    NBTTagList nbttaglist = new NBTTagList();

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

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

    return nbttaglist;
}
 
Example 14
Project: Backmemed   File: StructureStart.java   View source code 6 votes vote down vote up
public NBTTagCompound writeStructureComponentsToNBT(int chunkX, int chunkZ)
{
    NBTTagCompound nbttagcompound = new NBTTagCompound();
    nbttagcompound.setString("id", MapGenStructureIO.getStructureStartName(this));
    nbttagcompound.setInteger("ChunkX", chunkX);
    nbttagcompound.setInteger("ChunkZ", chunkZ);
    nbttagcompound.setTag("BB", this.boundingBox.toNBTTagIntArray());
    NBTTagList nbttaglist = new NBTTagList();

    for (StructureComponent structurecomponent : this.components)
    {
        nbttaglist.appendTag(structurecomponent.createStructureBaseNBT());
    }

    nbttagcompound.setTag("Children", nbttaglist);
    this.writeToNBT(nbttagcompound);
    return nbttagcompound;
}
 
Example 15
Project: Backmemed   File: ScoreboardSaveData.java   View source code 6 votes vote down vote up
protected void readScores(NBTTagList nbt)
{
    for (int i = 0; i < nbt.tagCount(); ++i)
    {
        NBTTagCompound nbttagcompound = nbt.getCompoundTagAt(i);
        ScoreObjective scoreobjective = this.theScoreboard.getObjective(nbttagcompound.getString("Objective"));
        String s = nbttagcompound.getString("Name");

        if (s.length() > 40)
        {
            s = s.substring(0, 40);
        }

        Score score = this.theScoreboard.getOrCreateScore(s, scoreobjective);
        score.setScorePoints(nbttagcompound.getInteger("Score"));

        if (nbttagcompound.hasKey("Locked"))
        {
            score.setLocked(nbttagcompound.getBoolean("Locked"));
        }
    }
}
 
Example 16
Project: CustomWorldGen   File: ItemEnchantedBook.java   View source code 6 votes vote down vote up
/**
 * allows items to add custom lines of information to the mouseover description
 */
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced)
{
    super.addInformation(stack, playerIn, tooltip, advanced);
    NBTTagList nbttaglist = this.getEnchantments(stack);

    if (nbttaglist != null)
    {
        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            int j = nbttaglist.getCompoundTagAt(i).getShort("id");
            int k = nbttaglist.getCompoundTagAt(i).getShort("lvl");

            if (Enchantment.getEnchantmentByID(j) != null)
            {
                tooltip.add(Enchantment.getEnchantmentByID(j).getTranslatedName(k));
            }
        }
    }
}
 
Example 17
Project: StructPro   File: Blueprint.java   View source code 6 votes vote down vote up
/**
 * Write to schematic tags
 * @return Control tag
 */
private NBTTagCompound getSchematic() {
    NBTTagCompound tag = new NBTTagCompound();
    tag.setString("Materials", "Alpha");
    tag.setShort("Width", (short) getWidth());
    tag.setShort("Height", (short) getHeight());
    tag.setShort("Length", (short) getLength());
    tag.setByteArray("AddBlocks", new byte[0]);
    byte[] blocksID = new byte[getBlocks().length];
    for (int i = 0; i < getBlocks().length; ++i) {
        blocksID[i] = (byte) getBlock(i);
    }
    tag.setByteArray("Blocks", blocksID);
    tag.setByteArray("AddBlocks", getAddBlocks(getBlocks()));
    tag.setByteArray("Data", getMetas());
    NBTTagList tileEntities = new NBTTagList();
    for (NBTTagCompound tile : getTiles()) {
        if (tile != null) {
            tileEntities.appendTag(tile);
        }
    }
    tag.setTag("TileEntities", tileEntities);
    return tag;
}
 
Example 18
Project: Firma   File: AnvilTileEntity.java   View source code 6 votes vote down vote up
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
    super.writeToNBT(nbt);

    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);
            this.getStackInSlot(i).writeToNBT(stackTag);
            list.appendTag(stackTag);
        }
    }
    nbt.setTag("Items", list);

    if (this.hasCustomName()) {
        nbt.setString("CustomName", this.getCustomName());
    }
    return nbt;
}
 
Example 19
Project: StructPro   File: Tiles.java   View source code 6 votes vote down vote up
/**
 * Load inventory data from NBT tag
 * @param inventory Target inventory
 * @param tag tag to load
 * @param seed Loading seed
 */
private static void load(IInventory inventory, NBTTagCompound tag, long seed) {
    if (tag == null || !Configurator.NATIVE_LOOT) {
        return;
    }
    Random random = new Random(seed);
    NBTTagList items = tag.getTagList("Items", Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < items.tagCount() && i < inventory.getSizeInventory(); ++i) {
        NBTTagCompound stackTag = items.getCompoundTagAt(i);
        String itemName = stackTag.getString("id").replaceAll(".*:", "");
        itemName = itemName.isEmpty() ? String.valueOf(stackTag.getShort("id")) : itemName;
        Pattern iPattern = Pattern.compile(Pattern.quote(itemName), Pattern.CASE_INSENSITIVE);
        UItem item = Utils.select(UItems.items.select(iPattern), random.nextLong());
        byte count = items.getCompoundTagAt(i).getByte("Count");
        int damage = items.getCompoundTagAt(i).getShort("Damage");
        int slot = stackTag.hasKey("Slot", Constants.NBT.TAG_BYTE) ? stackTag.getByte("Slot") : i;
        slot = (slot < 0 || slot >= inventory.getSizeInventory()) ? i : slot;
        if (item != null && count > 0 && UItems.getPossibleMeta(item).contains(damage)) {
            inventory.setInventorySlotContents(slot, new UItemStack(item, count, damage).getItemStack());
        }
    }
}
 
Example 20
Project: CustomWorldGen   File: ItemStackHandler.java   View source code 6 votes vote down vote up
@Override
public NBTTagCompound serializeNBT()
{
    NBTTagList nbtTagList = new NBTTagList();
    for (int i = 0; i < stacks.length; i++)
    {
        if (stacks[i] != null)
        {
            NBTTagCompound itemTag = new NBTTagCompound();
            itemTag.setInteger("Slot", i);
            stacks[i].writeToNBT(itemTag);
            nbtTagList.appendTag(itemTag);
        }
    }
    NBTTagCompound nbt = new NBTTagCompound();
    nbt.setTag("Items", nbtTagList);
    nbt.setInteger("Size", stacks.length);
    return nbt;
}
 
Example 21
Project: Backmemed   File: EntityArmorStand.java   View source code 6 votes vote down vote up
/**
 * Saves the pose to an NBTTagCompound.
 */
private void writePoseToNBT(NBTTagCompound tagCompound)
{
    NBTTagList nbttaglist = tagCompound.getTagList("Head", 5);
    this.setHeadRotation(nbttaglist.hasNoTags() ? DEFAULT_HEAD_ROTATION : new Rotations(nbttaglist));
    NBTTagList nbttaglist1 = tagCompound.getTagList("Body", 5);
    this.setBodyRotation(nbttaglist1.hasNoTags() ? DEFAULT_BODY_ROTATION : new Rotations(nbttaglist1));
    NBTTagList nbttaglist2 = tagCompound.getTagList("LeftArm", 5);
    this.setLeftArmRotation(nbttaglist2.hasNoTags() ? DEFAULT_LEFTARM_ROTATION : new Rotations(nbttaglist2));
    NBTTagList nbttaglist3 = tagCompound.getTagList("RightArm", 5);
    this.setRightArmRotation(nbttaglist3.hasNoTags() ? DEFAULT_RIGHTARM_ROTATION : new Rotations(nbttaglist3));
    NBTTagList nbttaglist4 = tagCompound.getTagList("LeftLeg", 5);
    this.setLeftLegRotation(nbttaglist4.hasNoTags() ? DEFAULT_LEFTLEG_ROTATION : new Rotations(nbttaglist4));
    NBTTagList nbttaglist5 = tagCompound.getTagList("RightLeg", 5);
    this.setRightLegRotation(nbttaglist5.hasNoTags() ? DEFAULT_RIGHTLEG_ROTATION : new Rotations(nbttaglist5));
}
 
Example 22
Project: CustomWorldGen   File: StructureStart.java   View source code 6 votes vote down vote up
public NBTTagCompound writeStructureComponentsToNBT(int chunkX, int chunkZ)
{
    if (MapGenStructureIO.getStructureStartName(this) == null) // This is just a more friendly error instead of the 'Null String' below
    {
        throw new RuntimeException("StructureStart \"" + this.getClass().getName() + "\" missing ID Mapping, Modder see MapGenStructureIO");
    }
    NBTTagCompound nbttagcompound = new NBTTagCompound();
    nbttagcompound.setString("id", MapGenStructureIO.getStructureStartName(this));
    nbttagcompound.setInteger("ChunkX", chunkX);
    nbttagcompound.setInteger("ChunkZ", chunkZ);
    nbttagcompound.setTag("BB", this.boundingBox.toNBTTagIntArray());
    NBTTagList nbttaglist = new NBTTagList();

    for (StructureComponent structurecomponent : this.components)
    {
        nbttaglist.appendTag(structurecomponent.createStructureBaseNBT());
    }

    nbttagcompound.setTag("Children", nbttaglist);
    this.writeToNBT(nbttagcompound);
    return nbttagcompound;
}
 
Example 23
Project: BaseClient   File: TileEntityDispenser.java   View source code 6 votes vote down vote up
public void readFromNBT(NBTTagCompound compound)
{
    super.readFromNBT(compound);
    NBTTagList nbttaglist = compound.getTagList("Items", 10);
    this.stacks = new ItemStack[this.getSizeInventory()];

    for (int i = 0; i < nbttaglist.tagCount(); ++i)
    {
        NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
        int j = nbttagcompound.getByte("Slot") & 255;

        if (j >= 0 && j < this.stacks.length)
        {
            this.stacks[j] = ItemStack.loadItemStackFromNBT(nbttagcompound);
        }
    }

    if (compound.hasKey("CustomName", 8))
    {
        this.customName = compound.getString("CustomName");
    }
}
 
Example 24
Project: BaseClient   File: ItemBanner.java   View source code 6 votes vote down vote up
/**
 * allows items to add custom lines of information to the mouseover description
 */
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced)
{
    NBTTagCompound nbttagcompound = stack.getSubCompound("BlockEntityTag", false);

    if (nbttagcompound != null && nbttagcompound.hasKey("Patterns"))
    {
        NBTTagList nbttaglist = nbttagcompound.getTagList("Patterns", 10);

        for (int i = 0; i < nbttaglist.tagCount() && i < 6; ++i)
        {
            NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
            EnumDyeColor enumdyecolor = EnumDyeColor.byDyeDamage(nbttagcompound1.getInteger("Color"));
            TileEntityBanner.EnumBannerPattern tileentitybanner$enumbannerpattern = TileEntityBanner.EnumBannerPattern.getPatternByID(nbttagcompound1.getString("Pattern"));

            if (tileentitybanner$enumbannerpattern != null)
            {
                tooltip.add(StatCollector.translateToLocal("item.banner." + tileentitybanner$enumbannerpattern.getPatternName() + "." + enumdyecolor.getUnlocalizedName()));
            }
        }
    }
}
 
Example 25
Project: morefurnaces   File: TileEntityIronFurnace.java   View source code 6 votes vote down vote up
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbtTagCompound)
{
    super.writeToNBT(nbtTagCompound);
    nbtTagCompound.setShort("BurnTime", (short) furnaceBurnTime);
    NBTTagList cookList = new NBTTagList();
    for (int i = 0; i < furnaceCookTime.length; i++)
    {
        NBTTagCompound tag = new NBTTagCompound();
        tag.setByte("Id", (byte) i);
        tag.setInteger("Time", furnaceCookTime[i]);
        cookList.appendTag(tag);
    }

    nbtTagCompound.setTag("CookTimes", cookList);

    nbtTagCompound.setByte("facing", facing);
    nbtTagCompound.setBoolean("isActive", isActive);

    NBTTagCompound nbt = itemHandler.serializeNBT();
    nbtTagCompound.setTag("Items", nbt.getTag("Items"));
    nbtTagCompound.setInteger("Size", nbt.getInteger("Size"));

    return nbtTagCompound;
}
 
Example 26
Project: DecompiledMinecraft   File: ItemEnchantedBook.java   View source code 6 votes vote down vote up
/**
 * allows items to add custom lines of information to the mouseover description
 */
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced)
{
    super.addInformation(stack, playerIn, tooltip, advanced);
    NBTTagList nbttaglist = this.getEnchantments(stack);

    if (nbttaglist != null)
    {
        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            int j = nbttaglist.getCompoundTagAt(i).getShort("id");
            int k = nbttaglist.getCompoundTagAt(i).getShort("lvl");

            if (Enchantment.getEnchantmentById(j) != null)
            {
                tooltip.add(Enchantment.getEnchantmentById(j).getTranslatedName(k));
            }
        }
    }
}
 
Example 27
Project: CustomWorldGen   File: EntityTippedArrow.java   View source code 6 votes vote down vote up
/**
 * (abstract) Protected helper method to write subclass entity data to NBT.
 */
public void writeEntityToNBT(NBTTagCompound compound)
{
    super.writeEntityToNBT(compound);

    if (this.potion != PotionTypes.EMPTY && this.potion != null)
    {
        compound.setString("Potion", ((ResourceLocation)PotionType.REGISTRY.getNameForObject(this.potion)).toString());
    }

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

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

        compound.setTag("CustomPotionEffects", nbttaglist);
    }
}
 
Example 28
Project: BaseClient   File: TileEntityBanner.java   View source code 6 votes vote down vote up
/**
 * Removes all the banner related data from a provided instance of ItemStack.
 */
public static void removeBannerData(ItemStack stack)
{
    NBTTagCompound nbttagcompound = stack.getSubCompound("BlockEntityTag", false);

    if (nbttagcompound != null && nbttagcompound.hasKey("Patterns", 9))
    {
        NBTTagList nbttaglist = nbttagcompound.getTagList("Patterns", 10);

        if (nbttaglist.tagCount() > 0)
        {
            nbttaglist.removeTag(nbttaglist.tagCount() - 1);

            if (nbttaglist.hasNoTags())
            {
                stack.getTagCompound().removeTag("BlockEntityTag");

                if (stack.getTagCompound().hasNoTags())
                {
                    stack.setTagCompound((NBTTagCompound)null);
                }
            }
        }
    }
}
 
Example 29
Project: BaseClient   File: ItemWritableBook.java   View source code 5 votes vote down vote up
/**
 * this method returns true if the book's NBT Tag List "pages" is valid
 */
public static boolean isNBTValid(NBTTagCompound nbt)
{
    if (nbt == null)
    {
        return false;
    }
    else if (!nbt.hasKey("pages", 9))
    {
        return false;
    }
    else
    {
        NBTTagList nbttaglist = nbt.getTagList("pages", 8);

        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            String s = nbttaglist.getStringTagAt(i);

            if (s == null)
            {
                return false;
            }

            if (s.length() > 32767)
            {
                return false;
            }
        }

        return true;
    }
}
 
Example 30
Project: DecompiledMinecraft   File: StructureOceanMonument.java   View source code 5 votes vote down vote up
public void readFromNBT(NBTTagCompound tagCompound)
{
    super.readFromNBT(tagCompound);

    if (tagCompound.hasKey("Processed", 9))
    {
        NBTTagList nbttaglist = tagCompound.getTagList("Processed", 10);

        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
            this.field_175791_c.add(new ChunkCoordIntPair(nbttagcompound.getInteger("X"), nbttagcompound.getInteger("Z")));
        }
    }
}
 
Example 31
Project: DecompiledMinecraft   File: StructureMineshaftPieces.java   View source code 5 votes vote down vote up
protected void writeStructureToNBT(NBTTagCompound tagCompound)
{
    NBTTagList nbttaglist = new NBTTagList();

    for (StructureBoundingBox structureboundingbox : this.roomsLinkedToTheRoom)
    {
        nbttaglist.appendTag(structureboundingbox.toNBTTagIntArray());
    }

    tagCompound.setTag("Entrances", nbttaglist);
}
 
Example 32
Project: BaseClient   File: EntityArmorStand.java   View source code 5 votes vote down vote up
/**
 * (abstract) Protected helper method to write subclass entity data to NBT.
 */
public void writeEntityToNBT(NBTTagCompound tagCompound)
{
    super.writeEntityToNBT(tagCompound);
    NBTTagList nbttaglist = new NBTTagList();

    for (int i = 0; i < this.contents.length; ++i)
    {
        NBTTagCompound nbttagcompound = new NBTTagCompound();

        if (this.contents[i] != null)
        {
            this.contents[i].writeToNBT(nbttagcompound);
        }

        nbttaglist.appendTag(nbttagcompound);
    }

    tagCompound.setTag("Equipment", nbttaglist);

    if (this.getAlwaysRenderNameTag() && (this.getCustomNameTag() == null || this.getCustomNameTag().length() == 0))
    {
        tagCompound.setBoolean("CustomNameVisible", this.getAlwaysRenderNameTag());
    }

    tagCompound.setBoolean("Invisible", this.isInvisible());
    tagCompound.setBoolean("Small", this.isSmall());
    tagCompound.setBoolean("ShowArms", this.getShowArms());
    tagCompound.setInteger("DisabledSlots", this.disabledSlots);
    tagCompound.setBoolean("NoGravity", this.hasNoGravity());
    tagCompound.setBoolean("NoBasePlate", this.hasNoBasePlate());

    if (this.func_181026_s())
    {
        tagCompound.setBoolean("Marker", this.func_181026_s());
    }

    tagCompound.setTag("Pose", this.readPoseFromNBT());
}
 
Example 33
Project: Solar   File: PacketHelper.java   View source code 5 votes vote down vote up
public static void syncQuantumToAll() {
	NBTTagCompound compound = new NBTTagCompound();
	NBTTagList tags = new NBTTagList();
	QuantumHandler.getEntanglements().forEach((uuid, stacks) -> {
		NBTTagCompound tag = new NBTTagCompound();
		NBTTagList list = new NBTTagList();
		stacks.forEach(stack -> list.appendTag(stack.writeToNBT(new NBTTagCompound())));
		tag.setTag("list", list);
		tag.setUniqueId("uuid", uuid);
		tags.appendTag(tag);
	});
	compound.setTag("tags", tags);
	PacketHandler.NETWORK.sendToAll(new ServerToClientPacket(PacketHandler.Q_SYNC_ALL, compound));
}
 
Example 34
Project: BaseClient   File: VillageCollection.java   View source code 5 votes vote down vote up
/**
 * reads in data from the NBTTagCompound into this MapDataBase
 */
public void readFromNBT(NBTTagCompound nbt)
{
    this.tickCounter = nbt.getInteger("Tick");
    NBTTagList nbttaglist = nbt.getTagList("Villages", 10);

    for (int i = 0; i < nbttaglist.tagCount(); ++i)
    {
        NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
        Village village = new Village();
        village.readVillageDataFromNBT(nbttagcompound);
        this.villageList.add(village);
    }
}
 
Example 35
Project: DecompiledMinecraft   File: MobSpawnerBaseLogic.java   View source code 5 votes vote down vote up
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 36
Project: Backmemed   File: SharedMonsterAttributes.java   View source code 5 votes vote down vote up
/**
 * Creates an NBTTagList from a BaseAttributeMap, including all its AttributeInstances
 */
public static NBTTagList writeBaseAttributeMapToNBT(AbstractAttributeMap map)
{
    NBTTagList nbttaglist = new NBTTagList();

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

    return nbttaglist;
}
 
Example 37
Project: Backmemed   File: ItemBanner.java   View source code 5 votes vote down vote up
public static ItemStack func_190910_a(EnumDyeColor p_190910_0_, @Nullable NBTTagList p_190910_1_)
{
    ItemStack itemstack = new ItemStack(Items.BANNER, 1, p_190910_0_.getDyeDamage());

    if (p_190910_1_ != null && !p_190910_1_.hasNoTags())
    {
        itemstack.func_190925_c("BlockEntityTag").setTag("Patterns", p_190910_1_.copy());
    }

    return itemstack;
}
 
Example 38
Project: uniquecrops   File: UCUtils.java   View source code 5 votes vote down vote up
public static NBTTagList getServerTaglist(int id) {
	
	MinecraftServer ms = FMLCommonHandler.instance().getMinecraftServerInstance();
	if (ms == null)
		return null;
	EntityPlayer player = (EntityPlayer)ms.getEntityWorld().getEntityByID(id);
	if (player != null) {
		NBTTagCompound tag = player.getEntityData();
		if (tag.hasKey(GrowthSteps.TAG_GROWTHSTAGES)) 
		{
			return tag.getTagList(GrowthSteps.TAG_GROWTHSTAGES, 10);
		}
	}
	return null;
}
 
Example 39
Project: Solar   File: WorldQuantumData.java   View source code 5 votes vote down vote up
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
	NBTTagList list = new NBTTagList();
	getEntanglements().forEach((uuid, itemStacks) -> {
		NBTTagList stackList = new NBTTagList();
		itemStacks.forEach(stack -> stackList.appendTag(stack.writeToNBT(new NBTTagCompound())));
		NBTTagCompound nbt = new NBTTagCompound();
		nbt.setUniqueId("key", uuid);
		nbt.setTag("list", stackList);
		list.appendTag(nbt);
	});
	compound.setTag(QuantumHandler.NBT_TAG, list);
	return compound;
}
 
Example 40
Project: pnc-repressurized   File: HeatExchangerLogic.java   View source code 5 votes vote down vote up
@Override
public void writeToNBT(NBTTagCompound tag) {
    tag.setDouble("temperature", temperature);
    NBTTagList tagList = new NBTTagList();
    for (HeatBehaviour behaviour : behaviours) {
        NBTTagCompound t = new NBTTagCompound();
        t.setString("id", behaviour.getId());
        behaviour.writeToNBT(t);
        tagList.appendTag(t);
    }
    tag.setTag("behaviours", tagList);
}