當前位置: 首頁>>代碼示例>>Java>>正文


Java NBTUtil.areNBTEquals方法代碼示例

本文整理匯總了Java中net.minecraft.nbt.NBTUtil.areNBTEquals方法的典型用法代碼示例。如果您正苦於以下問題:Java NBTUtil.areNBTEquals方法的具體用法?Java NBTUtil.areNBTEquals怎麽用?Java NBTUtil.areNBTEquals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.minecraft.nbt.NBTUtil的用法示例。


在下文中一共展示了NBTUtil.areNBTEquals方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: execute

import net.minecraft.nbt.NBTUtil; //導入方法依賴的package包/類
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 1)
    {
        throw new WrongUsageException("commands.testfor.usage", new Object[0]);
    }
    else
    {
        Entity entity = getEntity(server, sender, args[0]);
        NBTTagCompound nbttagcompound = null;

        if (args.length >= 2)
        {
            try
            {
                nbttagcompound = JsonToNBT.getTagFromJson(buildString(args, 1));
            }
            catch (NBTException nbtexception)
            {
                throw new CommandException("commands.testfor.tagError", new Object[] {nbtexception.getMessage()});
            }
        }

        if (nbttagcompound != null)
        {
            NBTTagCompound nbttagcompound1 = entityToNBT(entity);

            if (!NBTUtil.areNBTEquals(nbttagcompound, nbttagcompound1, true))
            {
                throw new CommandException("commands.testfor.failure", new Object[] {entity.getName()});
            }
        }

        notifyCommandListener(sender, this, "commands.testfor.success", new Object[] {entity.getName()});
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:40,代碼來源:CommandTestFor.java

示例2: clearMatchingItems

import net.minecraft.nbt.NBTUtil; //導入方法依賴的package包/類
/**
 * Clears all slots that contain the target item with given damage
 * @param targetId if null, not specific
 * @param targetDamage if <0, not specific
 * @param amount Number of items to remove. if 0, does not affect the inventory; if <=0, unlimited
 * @param targetNBT if null, not specific
 * @return the total number of items cleared
 */
@Override
public int clearMatchingItems(Item targetId, int targetDamage, int amount, NBTTagCompound targetNBT) {
    int stacks = super.clearMatchingItems(targetId, targetDamage, amount, targetNBT);
    if(amount > 0 && stacks >= amount){
        return stacks;
    }
    for (int i = 0; i < extraItems.length; i++) {
        ItemStack stack = extraItems[i];
        if (stack != null &&
                (targetId == null || stack.getItem() == targetId) &&
                (targetDamage <= -1 || stack.getMetadata() == targetDamage) &&
                (targetNBT == null || NBTUtil.areNBTEquals(targetNBT, stack.getTagCompound(), true))) {
            int temp = amount <= 0 ? stack.getCount() : Math.min(amount - stacks, stack.getCount());
            stacks += temp;
            if(amount != 0) {
                extraItems[i].shrink(temp);
                if(extraItems[i].getCount() == 0){
                    extraItems[i] = ItemStack.EMPTY;
                    hasChanged = true;
                }
                if(amount > 0 && stacks >= amount){
                    return stacks;
                }
            }
        }
    }
    return stacks;
}
 
開發者ID:Mine-and-blade-admin,項目名稱:Battlegear2,代碼行數:37,代碼來源:InventoryPlayerBattle.java

示例3: clearMatchingItems

import net.minecraft.nbt.NBTUtil; //導入方法依賴的package包/類
/**
 * Removes matching items from the inventory.
 * @param itemIn The item to match, null ignores.
 * @param metadataIn The metadata to match, -1 ignores.
 * @param removeCount The number of items to remove. If less than 1, removes all matching items.
 * @param itemNBT The NBT data to match, null ignores.
 * @return The number of items removed from the inventory.
 */
public int clearMatchingItems(@Nullable Item itemIn, int metadataIn, int removeCount, @Nullable NBTTagCompound itemNBT)
{
    int i = 0;

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

        if (!itemstack.func_190926_b() && (itemIn == null || itemstack.getItem() == itemIn) && (metadataIn <= -1 || itemstack.getMetadata() == metadataIn) && (itemNBT == null || NBTUtil.areNBTEquals(itemNBT, itemstack.getTagCompound(), true)))
        {
            int k = removeCount <= 0 ? itemstack.func_190916_E() : Math.min(removeCount - i, itemstack.func_190916_E());
            i += k;

            if (removeCount != 0)
            {
                itemstack.func_190918_g(k);

                if (itemstack.func_190926_b())
                {
                    this.setInventorySlotContents(j, ItemStack.field_190927_a);
                }

                if (removeCount > 0 && i >= removeCount)
                {
                    return i;
                }
            }
        }
    }

    if (!this.itemStack.func_190926_b())
    {
        if (itemIn != null && this.itemStack.getItem() != itemIn)
        {
            return i;
        }

        if (metadataIn > -1 && this.itemStack.getMetadata() != metadataIn)
        {
            return i;
        }

        if (itemNBT != null && !NBTUtil.areNBTEquals(itemNBT, this.itemStack.getTagCompound(), true))
        {
            return i;
        }

        int l = removeCount <= 0 ? this.itemStack.func_190916_E() : Math.min(removeCount - i, this.itemStack.func_190916_E());
        i += l;

        if (removeCount != 0)
        {
            this.itemStack.func_190918_g(l);

            if (this.itemStack.func_190926_b())
            {
                this.itemStack = ItemStack.field_190927_a;
            }

            if (removeCount > 0 && i >= removeCount)
            {
                return i;
            }
        }
    }

    return i;
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:77,代碼來源:InventoryPlayer.java

示例4: areItemStacksExactlyEqual

import net.minecraft.nbt.NBTUtil; //導入方法依賴的package包/類
private boolean areItemStacksExactlyEqual(ItemStack stack1, ItemStack stack2)
{
    return ItemStack.areItemsEqual(stack1, stack2) && (!stack2.hasTagCompound() || stack1.hasTagCompound() && NBTUtil.areNBTEquals(stack2.getTagCompound(), stack1.getTagCompound(), false));
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:5,代碼來源:MerchantRecipeList.java

示例5: addPlayerScore

import net.minecraft.nbt.NBTUtil; //導入方法依賴的package包/類
protected void addPlayerScore(ICommandSender sender, String[] p_184918_2_, int p_184918_3_, MinecraftServer server) throws CommandException
{
    String s = p_184918_2_[p_184918_3_ - 1];
    int i = p_184918_3_;
    String s1 = getEntityName(server, sender, p_184918_2_[p_184918_3_++]);

    if (s1.length() > 40)
    {
        throw new SyntaxErrorException("commands.scoreboard.players.name.tooLong", new Object[] {s1, Integer.valueOf(40)});
    }
    else
    {
        ScoreObjective scoreobjective = this.convertToObjective(p_184918_2_[p_184918_3_++], true, server);
        int j = "set".equalsIgnoreCase(s) ? parseInt(p_184918_2_[p_184918_3_++]) : parseInt(p_184918_2_[p_184918_3_++], 0);

        if (p_184918_2_.length > p_184918_3_)
        {
            Entity entity = getEntity(server, sender, p_184918_2_[i]);

            try
            {
                NBTTagCompound nbttagcompound = JsonToNBT.getTagFromJson(buildString(p_184918_2_, p_184918_3_));
                NBTTagCompound nbttagcompound1 = entityToNBT(entity);

                if (!NBTUtil.areNBTEquals(nbttagcompound, nbttagcompound1, true))
                {
                    throw new CommandException("commands.scoreboard.players.set.tagMismatch", new Object[] {s1});
                }
            }
            catch (NBTException nbtexception)
            {
                throw new CommandException("commands.scoreboard.players.set.tagError", new Object[] {nbtexception.getMessage()});
            }
        }

        Scoreboard scoreboard = this.getScoreboard(server);
        Score score = scoreboard.getOrCreateScore(s1, scoreobjective);

        if ("set".equalsIgnoreCase(s))
        {
            score.setScorePoints(j);
        }
        else if ("add".equalsIgnoreCase(s))
        {
            score.increaseScore(j);
        }
        else
        {
            score.decreaseScore(j);
        }

        notifyCommandListener(sender, this, "commands.scoreboard.players.set.success", new Object[] {scoreobjective.getName(), s1, Integer.valueOf(score.getScorePoints())});
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:55,代碼來源:CommandScoreboard.java

示例6: applyPlayerTag

import net.minecraft.nbt.NBTUtil; //導入方法依賴的package包/類
protected void applyPlayerTag(MinecraftServer server, ICommandSender sender, String[] p_184924_3_, int p_184924_4_) throws CommandException
{
    String s = getEntityName(server, sender, p_184924_3_[p_184924_4_]);
    Entity entity = getEntity(server, sender, p_184924_3_[p_184924_4_++]);
    String s1 = p_184924_3_[p_184924_4_++];
    Set<String> set = entity.getTags();

    if ("list".equals(s1))
    {
        if (!set.isEmpty())
        {
            TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("commands.scoreboard.players.tag.list", new Object[] {s});
            textcomponenttranslation.getStyle().setColor(TextFormatting.DARK_GREEN);
            sender.addChatMessage(textcomponenttranslation);
            sender.addChatMessage(new TextComponentString(joinNiceString(set.toArray())));
        }

        sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, set.size());
    }
    else if (p_184924_3_.length < 5)
    {
        throw new WrongUsageException("commands.scoreboard.players.tag.usage", new Object[0]);
    }
    else
    {
        String s2 = p_184924_3_[p_184924_4_++];

        if (p_184924_3_.length > p_184924_4_)
        {
            try
            {
                NBTTagCompound nbttagcompound = JsonToNBT.getTagFromJson(buildString(p_184924_3_, p_184924_4_));
                NBTTagCompound nbttagcompound1 = entityToNBT(entity);

                if (!NBTUtil.areNBTEquals(nbttagcompound, nbttagcompound1, true))
                {
                    throw new CommandException("commands.scoreboard.players.tag.tagMismatch", new Object[] {s});
                }
            }
            catch (NBTException nbtexception)
            {
                throw new CommandException("commands.scoreboard.players.tag.tagError", new Object[] {nbtexception.getMessage()});
            }
        }

        if ("add".equals(s1))
        {
            if (!entity.addTag(s2))
            {
                throw new CommandException("commands.scoreboard.players.tag.tooMany", new Object[] {Integer.valueOf(1024)});
            }

            notifyCommandListener(sender, this, "commands.scoreboard.players.tag.success.add", new Object[] {s2});
        }
        else
        {
            if (!"remove".equals(s1))
            {
                throw new WrongUsageException("commands.scoreboard.players.tag.usage", new Object[0]);
            }

            if (!entity.removeTag(s2))
            {
                throw new CommandException("commands.scoreboard.players.tag.notFound", new Object[] {s2});
            }

            notifyCommandListener(sender, this, "commands.scoreboard.players.tag.success.remove", new Object[] {s2});
        }
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:71,代碼來源:CommandScoreboard.java

示例7: clearMatchingItems

import net.minecraft.nbt.NBTUtil; //導入方法依賴的package包/類
/**
 * Removes matching items from the inventory.
 * @param itemIn The item to match, null ignores.
 * @param metadataIn The metadata to match, -1 ignores.
 * @param removeCount The number of items to remove. If less than 1, removes all matching items.
 * @param itemNBT The NBT data to match, null ignores.
 * @return The number of items removed from the inventory.
 */
public int clearMatchingItems(@Nullable Item itemIn, int metadataIn, int removeCount, @Nullable NBTTagCompound itemNBT)
{
    int i = 0;

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

        if (itemstack != null && (itemIn == null || itemstack.getItem() == itemIn) && (metadataIn <= -1 || itemstack.getMetadata() == metadataIn) && (itemNBT == null || NBTUtil.areNBTEquals(itemNBT, itemstack.getTagCompound(), true)))
        {
            int k = removeCount <= 0 ? itemstack.stackSize : Math.min(removeCount - i, itemstack.stackSize);
            i += k;

            if (removeCount != 0)
            {
                itemstack.stackSize -= k;

                if (itemstack.stackSize == 0)
                {
                    this.setInventorySlotContents(j, (ItemStack)null);
                }

                if (removeCount > 0 && i >= removeCount)
                {
                    return i;
                }
            }
        }
    }

    if (this.itemStack != null)
    {
        if (itemIn != null && this.itemStack.getItem() != itemIn)
        {
            return i;
        }

        if (metadataIn > -1 && this.itemStack.getMetadata() != metadataIn)
        {
            return i;
        }

        if (itemNBT != null && !NBTUtil.areNBTEquals(itemNBT, this.itemStack.getTagCompound(), true))
        {
            return i;
        }

        int l = removeCount <= 0 ? this.itemStack.stackSize : Math.min(removeCount - i, this.itemStack.stackSize);
        i += l;

        if (removeCount != 0)
        {
            this.itemStack.stackSize -= l;

            if (this.itemStack.stackSize == 0)
            {
                this.itemStack = null;
            }

            if (removeCount > 0 && i >= removeCount)
            {
                return i;
            }
        }
    }

    return i;
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:77,代碼來源:InventoryPlayer.java

示例8: equalNBT

import net.minecraft.nbt.NBTUtil; //導入方法依賴的package包/類
public static boolean equalNBT(ItemStack stack0, ItemStack stack1) {
    if(stack0.hasTagCompound() != stack1.hasTagCompound()) return false;
    if(!stack0.hasTagCompound()) return true;
    return NBTUtil.areNBTEquals(stack0.getTagCompound(), stack1.getTagCompound(), false);
}
 
開發者ID:Creysys,項目名稱:GuideBook,代碼行數:6,代碼來源:RecipeManager.java


注:本文中的net.minecraft.nbt.NBTUtil.areNBTEquals方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。