Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

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

  • Author

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

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.