Jump to content

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


Poseidon5001

Recommended Posts

Source Code:

https://github.com/daPoseidonGuy/Poppets/tree/master/src/main

 

Problem:
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
clarity
Link to comment
Share on other sites

If I use this for fireEvent it seems to work:

    @SubscribeEvent
    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"));
            player.extinguish();
            event.setCanceled(true);
        }
    }

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

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