Jump to content

[1.12.2] ItemStack only contains Item in undamaged state, when it should contain it regardless of damage


Recommended Posts

Source Code:



In this file: https://github.com/daPoseidonGuy/Poppets/blob/master/src/main/java/com/tenzinpelletier/poppets/ForgeEventHandler.java

For fireEvent, the if statement seems to fail if the fire poppet is damaged at all, and I can't seem to figure out why. Am I doing the ItemStack wrong? The function executes fine, and damages the item, but once it is damaged it no longer works.


Any help is appreciated

Edited by Poseidon5001
Link to comment
Share on other sites

If I use this for fireEvent it seems to work:

    public static void fireEvent(LivingHurtEvent event) {
        boolean found=false;
        if ((event.getEntity() instanceof EntityPlayer)&&(event.getSource()==DamageSource.ON_FIRE)) {
            EntityPlayer player = (EntityPlayer) event.getEntity();
            for(int i=0;i<player.inventory.getSizeInventory();i++) {
                if(player.inventory.getStackInSlot(i).getItem() == ModItems.firePoppet) {
                    player.sendMessage(new TextComponentString("Hoorah!"));
                    player.inventory.getStackInSlot(i).damageItem(1, player);
                    found = true;
        if (found==true) {
            EntityPlayer player = (EntityPlayer) event.getEntity();
            player.sendMessage(new TextComponentString("You have been saved from fire"));

However I feel there must be a more elegant solution.

Edited by Poseidon5001
fixed up a bit
Link to comment
Share on other sites

Looks like you were using InventoryPlayer#hasItemStack. That method calls ItemStack#isItemEqual, which compares the item's damage and requires it to be the same. I recently needed to do something very similar to you and ended up with a similar solution (iterating over the inventory to find the item in question). For what it's worth, hasItemStack iterates over the inventory anyway, so the main difference is you're now doing it yourself.

  • Like 1
Link to comment
Share on other sites

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.

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.

  • Create New...

Important Information

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