Posted September 13, 20187 yr 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 September 13, 20187 yr by Poseidon5001 clarity
September 13, 20187 yr 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 September 13, 20187 yr by Poseidon5001 fixed up a bit
September 16, 20187 yr 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.