Jump to content

Recommended Posts

Posted

Quick question. I have an item that has a reagent requirment. The items works fine if the reagent requirment is set to one of the item. I am trying to make it that you need more than one of the reagent. So you want to use the item, thats fine however you need at least 2 of the reagent in your inventory, and if you have at least two in the inventory it will proceed with using the item and then consume the two reagents. All that works. Here is my consume function:

private void consumeReagent(ItemStack stack, World worldIn, EntityPlayer entityLiving) { entityLiving.inventory.clearMatchingItems(eAngelusItems.mystalDust, -1, dustRequirement, null); }

 

dustRequirment is currenty a configurable option set to default at two so it consumes two of the items. The check works like this: 

   

@Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
    {
        ItemStack itemStack = playerIn.getHeldItem(handIn);
        boolean hasReagent = playerIn.inventory.hasItemStack(new ItemStack(eAngelusItems.mystalDust));
            if (hasReagent)
            {
                itemStack.damageItem(1, playerIn);
                playerIn.addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("speed"), 400, 4));
                this.consumeReagent(itemStack, worldIn, playerIn);
            } else {
                ChatUtil.sendNoSpam(playerIn, "\u00A74Mystal Dust is a required Catalyst.");
            }
        return  new ActionResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
    }

 

Now normally to check the contents of the inventory i would do this: 

if (playerIn.inventory.hasItemStack(new ItemStack(eAngelusItems.mystalDust)))

But i can't figure out how to check if you have at least two of those items. I am sure it is a function somwhere and I just haven't found it yet.

Posted (edited)
On 7/16/2017 at 7:40 AM, diesieben07 said:

There is no such method, you need to write it yourself. But it should be pretty straightforward, just loop through the inventory and sum all the stack sizes of items matching your criteria. When you found at least two, you can stop searching.

Yeah, figured so and made one. Just wanted to ask anyway in case something changed. Thanks.

Edited by HalestormXV

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.