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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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: pnc-repressurized   File: DateEventHandler.java   Source Code and License 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 6
Project: pnc-repressurized   File: InventoryPneumaticInventoryItem.java   Source Code and License 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 7
Project: pnc-repressurized   File: ContainerRemote.java   Source Code and License 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 8
Project: Never-Enough-Currency   File: InventoryItem.java   Source Code and License 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 9
Project: ElementalElaboration   File: TileKTWithInventory.java   Source Code and License 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 10
Project: BaseClient   File: TileEntityHopper.java   Source Code and License 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 11
Project: pnc-repressurized   File: RemoteLayout.java   Source Code and License 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 12
Project: BaseClient   File: InventoryEnderChest.java   Source Code and License 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 13
Project: Backmemed   File: StructureStart.java   Source Code and License 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 14
Project: Backmemed   File: ScoreboardSaveData.java   Source Code and License 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 15
Project: CustomWorldGen   File: ItemEnchantedBook.java   Source Code and License 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 16
Project: StructPro   File: Blueprint.java   Source Code and License 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 17
Project: Firma   File: AnvilTileEntity.java   Source Code and License 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 18
Project: StructPro   File: Tiles.java   Source Code and License 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 19
Project: CustomWorldGen   File: ItemStackHandler.java   Source Code and License 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 20
Project: Backmemed   File: EntityArmorStand.java   Source Code and License 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 21
Project: CustomWorldGen   File: StructureStart.java   Source Code and License 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 22
Project: BaseClient   File: TileEntityDispenser.java   Source Code and License 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 23
Project: BaseClient   File: ItemBanner.java   Source Code and License 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 24
Project: morefurnaces   File: TileEntityIronFurnace.java   Source Code and License 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 25
Project: CustomWorldGen   File: EntityTippedArrow.java   Source Code and License 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 26
Project: BaseClient   File: TileEntityBanner.java   Source Code and License 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 27
Project: BaseClient   File: ItemWritableBook.java   Source Code and License 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 28
Project: BaseClient   File: EntityArmorStand.java   Source Code and License 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 29
Project: Solar   File: PacketHelper.java   Source Code and License 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 30
Project: BaseClient   File: VillageCollection.java   Source Code and License 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 31
Project: Backmemed   File: SharedMonsterAttributes.java   Source Code and License 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 32
Project: Backmemed   File: ItemBanner.java   Source Code and License 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 33
Project: uniquecrops   File: UCUtils.java   Source Code and License 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 34
Project: Solar   File: WorldQuantumData.java   Source Code and License 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 35
Project: pnc-repressurized   File: HeatExchangerLogic.java   Source Code and License 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);
}
 
Example 36
Project: BaseClient   File: Entity.java   Source Code and License 5 votes vote down vote up
/**
 * 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 37
Project: CustomWorldGen   File: StructureMineshaftPieces.java   Source Code and License 5 votes vote down vote up
/**
 * (abstract) Helper method to write subclass data to NBT
 */
protected void writeStructureToNBT(NBTTagCompound tagCompound)
{
    super.writeStructureToNBT(tagCompound);
    NBTTagList nbttaglist = new NBTTagList();

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

    tagCompound.setTag("Entrances", nbttaglist);
}
 
Example 38
Project: BaseClient   File: InventoryPlayer.java   Source Code and License 5 votes vote down vote up
/**
 * Writes the inventory out as a list of compound tags. This is where the slot indices are used (+100 for armor, +80
 * for crafting).
 */
public NBTTagList writeToNBT(NBTTagList p_70442_1_)
{
    for (int i = 0; i < this.mainInventory.length; ++i)
    {
        if (this.mainInventory[i] != null)
        {
            NBTTagCompound nbttagcompound = new NBTTagCompound();
            nbttagcompound.setByte("Slot", (byte)i);
            this.mainInventory[i].writeToNBT(nbttagcompound);
            p_70442_1_.appendTag(nbttagcompound);
        }
    }

    for (int j = 0; j < this.armorInventory.length; ++j)
    {
        if (this.armorInventory[j] != null)
        {
            NBTTagCompound nbttagcompound1 = new NBTTagCompound();
            nbttagcompound1.setByte("Slot", (byte)(j + 100));
            this.armorInventory[j].writeToNBT(nbttagcompound1);
            p_70442_1_.appendTag(nbttagcompound1);
        }
    }

    return p_70442_1_;
}
 
Example 39
Project: pnc-repressurized   File: TileEntityAirCannon.java   Source Code and License 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound tag) {
    super.readFromNBT(tag);
    targetRotationAngle = tag.getFloat("targetRotationAngle");
    targetHeightAngle = tag.getFloat("targetHeightAngle");
    rotationAngle = tag.getFloat("rotationAngle");
    heightAngle = tag.getFloat("heightAngle");
    gpsX = tag.getInteger("gpsX");
    gpsY = tag.getInteger("gpsY");
    gpsZ = tag.getInteger("gpsZ");
    redstoneMode = tag.getByte("redstoneMode");
    coordWithinReach = tag.getBoolean("targetWithinReach");
    inventory = new AirCannonStackHandler();
    inventory.deserializeNBT(tag.getCompoundTag("Items"));

    trackedItemIds = new HashSet<>();
    NBTTagList tagList = tag.getTagList("trackedItems", Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < tagList.tagCount(); i++) {
        NBTTagCompound t = tagList.getCompoundTagAt(i);
        trackedItemIds.add(new UUID(t.getLong("UUIDMost"), t.getLong("UUIDLeast")));
    }

    if (tag.hasKey("inventoryX")) {
        lastInsertingInventory = new BlockPos(tag.getInteger("inventoryX"), tag.getInteger("inventoryY"), tag.getInteger("inventoryZ"));
        lastInsertingInventorySide = EnumFacing.getFront(tag.getByte("inventorySide"));
    } else {
        lastInsertingInventory = null;
        lastInsertingInventorySide = null;
    }
}
 
Example 40
Project: pnc-repressurized   File: TileEntityElevatorBase.java   Source Code and License 5 votes vote down vote up
@Override
public void writeToPacket(NBTTagCompound tag) {
    super.writeToPacket(tag);
    tag.setIntArray("floorHeights", floorHeights);

    NBTTagList floorNameList = new NBTTagList();
    for (int key : floorNames.keySet()) {
        NBTTagCompound floorNameTag = new NBTTagCompound();
        floorNameTag.setInteger("floorHeight", key);
        floorNameTag.setString("floorName", floorNames.get(key));
        floorNameList.appendTag(floorNameTag);
    }
    tag.setTag("floorNames", floorNameList);
}
 
Example 41
Project: BaseClient   File: InventoryPlayer.java   Source Code and License 5 votes vote down vote up
/**
 * Writes the inventory out as a list of compound tags. This is where the slot indices are used (+100 for armor, +80
 * for crafting).
 */
public NBTTagList writeToNBT(NBTTagList p_70442_1_)
{
    for (int i = 0; i < this.mainInventory.length; ++i)
    {
        if (this.mainInventory[i] != null)
        {
            NBTTagCompound nbttagcompound = new NBTTagCompound();
            nbttagcompound.setByte("Slot", (byte)i);
            this.mainInventory[i].writeToNBT(nbttagcompound);
            p_70442_1_.appendTag(nbttagcompound);
        }
    }

    for (int j = 0; j < this.armorInventory.length; ++j)
    {
        if (this.armorInventory[j] != null)
        {
            NBTTagCompound nbttagcompound1 = new NBTTagCompound();
            nbttagcompound1.setByte("Slot", (byte)(j + 100));
            this.armorInventory[j].writeToNBT(nbttagcompound1);
            p_70442_1_.appendTag(nbttagcompound1);
        }
    }

    return p_70442_1_;
}
 
Example 42
Project: pnc-repressurized   File: TileEntityPressureTube.java   Source Code and License 5 votes vote down vote up
@Override
public void readFromPacket(NBTTagCompound tag) {
    super.readFromPacket(tag);
    modules = new TubeModule[6];
    NBTTagList moduleList = tag.getTagList("modules", 10);
    for (int i = 0; i < moduleList.tagCount(); i++) {
        NBTTagCompound moduleTag = moduleList.getCompoundTagAt(i);
        TubeModule module = ModuleRegistrator.getModule(moduleTag.getString("type"));
        module.readFromNBT(moduleTag);
        setModule(module, EnumFacing.getFront(moduleTag.getInteger("side")));
    }
    if (hasWorld() && getWorld().isRemote) {
        rerenderTileEntity();
    }
}
 
Example 43
Project: DankNull   File: InventoryDankNull.java   Source Code and License 5 votes vote down vote up
public void writeToNBT(NBTTagCompound itemTC) {
	NBTTagList nbtTL = new NBTTagList();
	for (int i = 0; i < getSizeInventory(); i++) {
		if (!getStackInSlot(i).isEmpty()) {
			NBTTagCompound nbtTC = new NBTTagCompound();
			nbtTC.setInteger(TAG_SLOT, i);
			nbtTC.setInteger(TAG_COUNT, getStackInSlot(i).getCount() <= DankNullUtils.getDankNullMaxStackSize(this) ? getStackInSlot(i).getCount() : DankNullUtils.getDankNullMaxStackSize(this));
			getStackInSlot(i).writeToNBT(nbtTC);
			nbtTL.appendTag(nbtTC);
		}
	}
	itemTC.setTag(getName(), nbtTL);
}
 
Example 44
Project: Backmemed   File: EnchantmentHelper.java   Source Code and License 5 votes vote down vote up
/**
 * 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 45
Project: pnc-repressurized   File: RemoteLayout.java   Source Code and License 5 votes vote down vote up
public NBTTagCompound toNBT(int guiLeft, int guiTop) {
    NBTTagCompound tag = new NBTTagCompound();

    NBTTagList tagList = new NBTTagList();
    for (ActionWidget actionWidget : actionWidgets) {
        tagList.appendTag(actionWidget.toNBT(guiLeft, guiTop));
    }
    tag.setTag("actionWidgets", tagList);
    return tag;
}
 
Example 46
Project: BaseClient   File: ItemStack.java   Source Code and License 5 votes vote down vote up
public boolean canPlaceOn(Block blockIn)
{
    if (blockIn == this.canPlaceOnCacheBlock)
    {
        return this.canPlaceOnCacheResult;
    }
    else
    {
        this.canPlaceOnCacheBlock = blockIn;

        if (this.hasTagCompound() && this.stackTagCompound.hasKey("CanPlaceOn", 9))
        {
            NBTTagList nbttaglist = this.stackTagCompound.getTagList("CanPlaceOn", 8);

            for (int i = 0; i < nbttaglist.tagCount(); ++i)
            {
                Block block = Block.getBlockFromName(nbttaglist.getStringTagAt(i));

                if (block == blockIn)
                {
                    this.canPlaceOnCacheResult = true;
                    return true;
                }
            }
        }

        this.canPlaceOnCacheResult = false;
        return false;
    }
}
 
Example 47
Project: BaseClient   File: ItemWritableBook.java   Source Code and License 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 48
Project: Backmemed   File: ItemStack.java   Source Code and License 5 votes vote down vote up
public boolean canDestroy(Block blockIn)
{
    if (blockIn == this.canDestroyCacheBlock)
    {
        return this.canDestroyCacheResult;
    }
    else
    {
        this.canDestroyCacheBlock = blockIn;

        if (this.hasTagCompound() && this.stackTagCompound.hasKey("CanDestroy", 9))
        {
            NBTTagList nbttaglist = this.stackTagCompound.getTagList("CanDestroy", 8);

            for (int i = 0; i < nbttaglist.tagCount(); ++i)
            {
                Block block = Block.getBlockFromName(nbttaglist.getStringTagAt(i));

                if (block == blockIn)
                {
                    this.canDestroyCacheResult = true;
                    return true;
                }
            }
        }

        this.canDestroyCacheResult = false;
        return false;
    }
}
 
Example 49
Project: CustomWorldGen   File: TileEntityDispenser.java   Source Code and License 5 votes vote down vote up
public NBTTagCompound writeToNBT(NBTTagCompound compound)
{
    super.writeToNBT(compound);

    if (!this.checkLootAndWrite(compound))
    {
        NBTTagList nbttaglist = new NBTTagList();

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

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

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

    return compound;
}
 
Example 50
Project: CustomWorldGen   File: AnvilChunkLoader.java   Source Code and License 5 votes vote down vote up
@Nullable
public static Entity readChunkEntity(NBTTagCompound compound, World worldIn, Chunk chunkIn)
{
    Entity entity = createEntityFromNBT(compound, worldIn);

    if (entity == null)
    {
        return null;
    }
    else
    {
        chunkIn.addEntity(entity);

        if (compound.hasKey("Passengers", 9))
        {
            NBTTagList nbttaglist = compound.getTagList("Passengers", 10);

            for (int i = 0; i < nbttaglist.tagCount(); ++i)
            {
                Entity entity1 = readChunkEntity(nbttaglist.getCompoundTagAt(i), worldIn, chunkIn);

                if (entity1 != null)
                {
                    entity1.startRiding(entity, true);
                }
            }
        }

        return entity;
    }
}
 
Example 51
Project: CustomWorldGen   File: EntityVillager.java   Source Code and License 5 votes vote down vote up
/**
 * (abstract) Protected helper method to write subclass entity data to NBT.
 */
public void writeEntityToNBT(NBTTagCompound compound)
{
    super.writeEntityToNBT(compound);
    compound.setInteger("Profession", this.getProfession());
    compound.setString("ProfessionName", this.getProfessionForge().getRegistryName().toString());
    compound.setInteger("Riches", this.wealth);
    compound.setInteger("Career", this.careerId);
    compound.setInteger("CareerLevel", this.careerLevel);
    compound.setBoolean("Willing", this.isWillingToMate);

    if (this.buyingList != null)
    {
        compound.setTag("Offers", this.buyingList.getRecipiesAsTags());
    }

    NBTTagList nbttaglist = new NBTTagList();

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

        if (itemstack != null)
        {
            nbttaglist.appendTag(itemstack.writeToNBT(new NBTTagCompound()));
        }
    }

    compound.setTag("Inventory", nbttaglist);
}
 
Example 52
Project: MagicWinds   File: TileEntityTrinketMaker.java   Source Code and License 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound compound) {
    super.readFromNBT(compound);
    NBTTagList list = compound.getTagList("Items", 10);
    for (int i = 0; i < list.tagCount(); ++i) {
        NBTTagCompound stackTag = list.getCompoundTagAt(i);
        int slot = stackTag.getByte("Slot") & 255;
        this.setInventorySlotContents(slot, new ItemStack(compound));
    }

    if (compound.hasKey("CustomName", 8)) {
        this.setCustomName(compound.getString("CustomName"));
    }
}
 
Example 53
Project: Bewitchment   File: BrewUtils.java   Source Code and License 5 votes vote down vote up
public static NBTTagList addBrewData(ItemStack stack) {
	if (!NBTHelper.hasTag(stack, BREW_DATA)) {
		NBTTagList list = new NBTTagList();
		NBTHelper.setNBT(stack, BREW_DATA, list);
		return list;
	}
	return NBTHelper.getNBT(stack, BREW_DATA);
}
 
Example 54
Project: Device-Mod-Apps   File: ApplicationUnofficialAppStore.java   Source Code and License 5 votes vote down vote up
@Override
public void save(NBTTagCompound tagCompound) {
    NBTTagList list = new NBTTagList();
    for (String r : repos) {
        list.appendTag(new NBTTagString(r));
    }
    tagCompound.setTag("repos", list);
}
 
Example 55
Project: Bewitchment   File: Ritual.java   Source Code and License 5 votes vote down vote up
public static NonNullList<ItemStack> getItemsUsedForInput(NBTTagCompound tag) {
	NonNullList<ItemStack> list = NonNullList.create();
	NBTTagList tagList = tag.getTagList("itemsUsed", NBT.TAG_COMPOUND);
	tagList.forEach(nbt -> {
		NBTTagCompound itemTag = (NBTTagCompound) nbt;
		list.add(new ItemStack(itemTag));
	});
	return list;
}
 
Example 56
Project: NemesisSystem   File: NemesisWorldSaveData.java   Source Code and License 5 votes vote down vote up
public static List<NemesisEntry> readNemesesFromNBT(NBTTagCompound c) {
	NBTTagList nbtNemeses = loadNbtList(c);
	ArrayList<NemesisEntry> nemeses = new ArrayList<>();
	for (int i = 0; i < nbtNemeses.tagCount(); i++) {
		NemesisEntry nemesis = new NemesisEntry();
		nemesis.readFromNBT(nbtNemeses.getCompoundTagAt(i));
		nemeses.add(nemesis);
	}
	return nemeses;
}
 
Example 57
Project: connor41-etfuturum2   File: BannerPatternHandler.java   Source Code and License 5 votes vote down vote up
@Override
public void loadCraftingRecipes(ItemStack result) {
	if (result.getItem() != Item.getItemFromBlock(ModBlocks.banner))
		return;

	NBTTagCompound nbt = ItemBanner.getSubTag(result, "BlockEntityTag", false);
	if (nbt != null && nbt.hasKey("Patterns", 9)) {
		NBTTagList patterns = nbt.getTagList("Patterns", 10);
		for (int i = 0; i < patterns.tagCount(); i++) {
			NBTTagCompound patternNBT = patterns.getCompoundTagAt(i);
			EnumBannerPattern pattern = EnumBannerPattern.getPatternByID(patternNBT.getString("Pattern"));
			if (pattern == null)
				continue;

			ItemStack copy = new ItemStack(ModBlocks.banner, 1, result.getItemDamage());
			copy.setTagCompound(null);
			EnumColour colour = patternNBT.hasKey("Color") ? EnumColour.fromDamage(patternNBT.getInteger("Color")) : null;
			if (!pattern.hasValidCrafting())
				continue;
			if (pattern.hasCraftingStack()) {
				if (colour != null)
					arecipes.add(new CachedPatternRecipe(pattern, new String[] { "   ", "xy ", " z " }, Arrays.asList('x', pattern.getCraftingStack(), 'y', colour.getOreName(), 'z', copy)));
				else
					arecipes.add(new CachedPatternRecipe(pattern, new String[] { "   ", "xy ", "   " }, Arrays.asList('x', pattern.getCraftingStack(), 'y', copy)));
			} else {
				String[] layers = pattern.getCraftingLayers();
				String[] layersCopy = new String[] { layers[0], layers[1], layers[2] };
				for (int j = 0; j < 3; j++) {
					String newLayer = layersCopy[j].replaceFirst(" ", "x");
					if (!newLayer.equals(layersCopy[j])) {
						layersCopy[j] = newLayer;
						break;
					}
				}
				arecipes.add(new CachedPatternRecipe(pattern, layersCopy, Arrays.asList('#', colour == null ? "dye" : colour.getOreName(), 'x', copy)));
			}
		}
	}
}
 
Example 58
Project: CustomWorldGen   File: VillageCollection.java   Source Code and License 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 59
Project: Whoosh   File: ItemTransporter.java   Source Code and License 5 votes vote down vote up
private static void createDefaultTag(ItemStack stack) {

        if(!stack.hasTagCompound())
            stack.setTagCompound(new NBTTagCompound());

        NBTTagCompound tag = stack.getTagCompound();
        if(!tag.hasKey("Positions")) {
            NBTTagList list = new NBTTagList();
            tag.setTag("Positions", list);
        }
    }
 
Example 60
Project: BaseClient   File: EntityArmorStand.java   Source Code and License 5 votes vote down vote up
/**
 * (abstract) Protected helper method to read subclass entity data from NBT.
 */
public void readEntityFromNBT(NBTTagCompound tagCompund)
{
    super.readEntityFromNBT(tagCompund);

    if (tagCompund.hasKey("Equipment", 9))
    {
        NBTTagList nbttaglist = tagCompund.getTagList("Equipment", 10);

        for (int i = 0; i < this.contents.length; ++i)
        {
            this.contents[i] = ItemStack.loadItemStackFromNBT(nbttaglist.getCompoundTagAt(i));
        }
    }

    this.setInvisible(tagCompund.getBoolean("Invisible"));
    this.setSmall(tagCompund.getBoolean("Small"));
    this.setShowArms(tagCompund.getBoolean("ShowArms"));
    this.disabledSlots = tagCompund.getInteger("DisabledSlots");
    this.setNoGravity(tagCompund.getBoolean("NoGravity"));
    this.setNoBasePlate(tagCompund.getBoolean("NoBasePlate"));
    this.func_181027_m(tagCompund.getBoolean("Marker"));
    this.field_181028_bj = !this.func_181026_s();
    this.noClip = this.hasNoGravity();
    NBTTagCompound nbttagcompound = tagCompund.getCompoundTag("Pose");
    this.writePoseToNBT(nbttagcompound);
}