Posted October 13, 201312 yr So my last topic I posted in this section on PlayerInteractEvent was a bit messed up. I've rethought what's wrong and fixed it. But now there is a second problem. Here is the code: @ForgeSubscribe public void playerInteractEvent(PlayerInteractEvent event) { EntityPlayer player = event.entityPlayer; if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().itemID == Base.tankEmpty.itemID && event.action == Action.RIGHT_CLICK_AIR) { if (!player.capabilities.isCreativeMode) { --player.getCurrentEquippedItem().stackSize; } player.inventory.addItemStackToInventory(new ItemStack(Base.tankAir)); if (!player.inventory.addItemStackToInventory(new ItemStack(Base.tankAir))) { player.dropPlayerItem(new ItemStack(Base.tankAir.itemID, 1, 0)); } } } The code looks fine to me and it works. However, when I play the game and right click mid air with my "tankEmpty", it returns 2 "tankAir" instead of just 1. Does anyone know why this is and how I can fix this? Thanks in advance.
October 13, 201312 yr if (player.worldObj.isRemote) return; if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().itemID == Base.tankEmpty.itemID && event.action == Action.RIGHT_CLICK_AIR) { If you guys dont get it.. then well ya.. try harder...
October 13, 201312 yr Author if (player.worldObj.isRemote) return; if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().itemID == Base.tankEmpty.itemID && event.action == Action.RIGHT_CLICK_AIR) { All that's done is cause the stack to decrease in size but now NO items are returned at all.
October 13, 201312 yr player.inventory.addItemStackToInventory(new ItemStack(Base.tankAir)); if (!player.inventory.addItemStackToInventory(new ItemStack(Base.tankAir))) ... You are giving it twice here. I'd recommend removing the first line.
October 14, 201312 yr Author player.inventory.addItemStackToInventory(new ItemStack(Base.tankAir)); if (!player.inventory.addItemStackToInventory(new ItemStack(Base.tankAir))) ... You are giving it twice here. I'd recommend removing the first line. Hum are you sure? The addItemStackToInventory in the brackets of the if statement just checks if its been added. I wouldn't think it would cause it to return twice. I'll try out what you said and get back to you asap. So I tried your recommendation. It didn't work. Now, with space in the inventory, nothing returns but the stack size of empty tanks still decrease and when my inventory is full, the air tank that should be returned is dropped (as it should do). Unfortunately though it did not work. Any other ideas anyone?
October 14, 201312 yr Author Ok so this is my new code: if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().itemID == Base.tankEmpty.itemID) { if(event.action == Action.RIGHT_CLICK_AIR) { player.inventory.addItemStackToInventory(new ItemStack(Base.tankAir)); if (!player.capabilities.isCreativeMode && player.inventory.addItemStackToInventory(new ItemStack(Base.tankAir)) == true) { --player.getCurrentEquippedItem().stackSize; } } } I've changed it so that when there's no more space, the empty tank stack size does not decrease. This works fine. However the issue of 2 items returning instead of 1 is back. I can see how the bit && player.inventory.addItemStackToInventory(new ItemStack(Base.tankAir)) == true) causes this. Question: is there a better way to check if the itemstack has been added (one that does not cause 2 of the item to return)?
October 15, 201312 yr Hi I might be missing something obvious, but is this what you want? if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().itemID == Base.tankEmpty.itemID) { if(event.action == Action.RIGHT_CLICK_AIR) { boolean itemWasAdded = player.inventory.addItemStackToInventory(new ItemStack(Base.tankAir)); if (!player.capabilities.isCreativeMode && itemWasAdded) { --player.getCurrentEquippedItem().stackSize; } } } -TGG
October 15, 201312 yr Author Hi I might be missing something obvious, but is this what you want? if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().itemID == Base.tankEmpty.itemID) { if(event.action == Action.RIGHT_CLICK_AIR) { boolean itemWasAdded = player.inventory.addItemStackToInventory(new ItemStack(Base.tankAir)); if (!player.capabilities.isCreativeMode && itemWasAdded) { --player.getCurrentEquippedItem().stackSize; } } } -TGG Wow, that worked. Thank you so much. You sir are going on my "awesome list"
October 16, 201312 yr Hi Wow, that worked. Thank you so much. You sir are going on my "awesome list" ha ha, I've got a looong way to go before I'm worthy of that title. Plenty of folks on this list are far more awesome than me! Glad I could help. -TGG
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.