java类net.minecraft.nbt.NBTBase的实例源码

TileEntityDispenser.java 文件源码 项目:CustomWorldGen 阅读 19 收藏 0 点赞 0 评论 0
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");
    }
}
PortalTileEntity.java 文件源码 项目:MeeCreeps 阅读 22 收藏 0 点赞 0 评论 0
@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);
    }
}
TileEntityBanner.java 文件源码 项目:BaseClient 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 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);
                }
            }
        }
    }
}
PotionUtils.java 文件源码 项目:Backmemed 阅读 19 收藏 0 点赞 0 评论 0
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);
            }
        }
    }
}
EntityMinecartContainer.java 文件源码 项目:DecompiledMinecraft 阅读 20 收藏 0 点赞 0 评论 0
/**
 * (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);
        }
    }
}
DateEventHandler.java 文件源码 项目:pnc-repressurized 阅读 17 收藏 0 点赞 0 评论 0
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);
}
InventoryPneumaticInventoryItem.java 文件源码 项目:pnc-repressurized 阅读 16 收藏 0 点赞 0 评论 0
/**
 * 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");
}
ContainerRemote.java 文件源码 项目:pnc-repressurized 阅读 17 收藏 0 点赞 0 评论 0
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;
}
InventoryItem.java 文件源码 项目:Never-Enough-Currency 阅读 18 收藏 0 点赞 0 评论 0
/**
 * 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));
        }
    }
}
TileKTWithInventory.java 文件源码 项目:ElementalElaboration 阅读 14 收藏 0 点赞 0 评论 0
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");
    }
}
TileEntityHopper.java 文件源码 项目:BaseClient 阅读 23 收藏 0 点赞 0 评论 0
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);
    }
}
RemoteLayout.java 文件源码 项目:pnc-repressurized 阅读 15 收藏 0 点赞 0 评论 0
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();
            }
        }
    }
}
InventoryEnderChest.java 文件源码 项目:BaseClient 阅读 23 收藏 0 点赞 0 评论 0
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;
}
StructureStart.java 文件源码 项目:Backmemed 阅读 20 收藏 0 点赞 0 评论 0
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;
}
ScoreboardSaveData.java 文件源码 项目:Backmemed 阅读 19 收藏 0 点赞 0 评论 0
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"));
        }
    }
}
ItemEnchantedBook.java 文件源码 项目:CustomWorldGen 阅读 18 收藏 0 点赞 0 评论 0
/**
 * 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));
            }
        }
    }
}
Blueprint.java 文件源码 项目:StructPro 阅读 16 收藏 0 点赞 0 评论 0
/**
 * 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;
}
AnvilTileEntity.java 文件源码 项目:Firma 阅读 18 收藏 0 点赞 0 评论 0
@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;
}
Tiles.java 文件源码 项目:StructPro 阅读 26 收藏 0 点赞 0 评论 0
/**
 * 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());
        }
    }
}
ItemStackHandler.java 文件源码 项目:CustomWorldGen 阅读 21 收藏 0 点赞 0 评论 0
@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;
}
EntityArmorStand.java 文件源码 项目:Backmemed 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 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));
}
StructureStart.java 文件源码 项目:CustomWorldGen 阅读 25 收藏 0 点赞 0 评论 0
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;
}
TileEntityDispenser.java 文件源码 项目:BaseClient 阅读 20 收藏 0 点赞 0 评论 0
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");
    }
}
ItemBanner.java 文件源码 项目:BaseClient 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 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()));
            }
        }
    }
}
TileEntityIronFurnace.java 文件源码 项目:morefurnaces 阅读 23 收藏 0 点赞 0 评论 0
@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;
}
ItemEnchantedBook.java 文件源码 项目:DecompiledMinecraft 阅读 18 收藏 0 点赞 0 评论 0
/**
 * 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));
            }
        }
    }
}
EntityTippedArrow.java 文件源码 项目:CustomWorldGen 阅读 25 收藏 0 点赞 0 评论 0
/**
 * (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);
    }
}
TileEntityBanner.java 文件源码 项目:BaseClient 阅读 26 收藏 0 点赞 0 评论 0
/**
 * 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);
                }
            }
        }
    }
}
ItemWritableBook.java 文件源码 项目:BaseClient 阅读 18 收藏 0 点赞 0 评论 0
/**
 * 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;
    }
}
StructureOceanMonument.java 文件源码 项目:DecompiledMinecraft 阅读 29 收藏 0 点赞 0 评论 0
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")));
        }
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号