Posted June 6, 201510 yr Hey, Im trying to make an item and when you right click it you will get another item (same one) and this: @Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { player.inventory.addItemStackToInventory(new ItemStack(this)); return stack ; } i know why but is there any way to solve it ? I'm beginner in java and in minecraft modding. Please be specific. Any code examples are appreciated. Sorry for my english i'm from Czech republic. Please hit that thank you button if i helped
June 6, 201510 yr See that the return value is an ItemStack? Return a different one. The one you have, 'stack', is the ItemStack that called the method. http://i.imgur.com/NdrFdld.png[/img]
June 6, 201510 yr Author Basically what i need to do - the current stack + another one. I'm beginner in java and in minecraft modding. Please be specific. Any code examples are appreciated. Sorry for my english i'm from Czech republic. Please hit that thank you button if i helped
June 6, 201510 yr Well, you can't have two stacks in one inventory slot, so you'll need to put one of them somewhere else. You can use player.inventory.addItemStackToInventory(new ItemStack(whatever)) to do just that, and then return the original stack as you have it there. http://i.imgur.com/NdrFdld.png[/img]
June 6, 201510 yr Author I did that here : @Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { player.inventory.addItemStackToInventory(new ItemStack(this)); return stack ; } or i dont understand you I'm beginner in java and in minecraft modding. Please be specific. Any code examples are appreciated. Sorry for my english i'm from Czech republic. Please hit that thank you button if i helped
June 7, 201510 yr You don't understand java and/or ItemStack. A method that returns object (ItemStack) can't suddenly return two stacks. What exacly do you need to do? Right now: @Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { // When player right-clicks player.inventory.addItemStackToInventory(new ItemStack(this)); //add to player's first free or stackable slot a new ItemStack of this item return stack ; // return the stack you have right-clicked with } 1.7.10 is no longer supported by forge, you are on your own.
June 7, 201510 yr Author So its not possible then... I'm beginner in java and in minecraft modding. Please be specific. Any code examples are appreciated. Sorry for my english i'm from Czech republic. Please hit that thank you button if i helped
June 7, 201510 yr You should add the itemstack on the server side, ie: !world.isRemote. You might have to call player.inventoryContainer.detectAndSendChanges(); after you add the new itemstack for it to update to the client.
June 7, 201510 yr Author WHAT is not possible? I don't think anyone in this thread actually understood what you want to happen. I want just add the same item when the item is right clicked no matter what. Idealy the onItemRightClick would be void. I just dont know how to deal with the return statement. I'm beginner in java and in minecraft modding. Please be specific. Any code examples are appreciated. Sorry for my english i'm from Czech republic. Please hit that thank you button if i helped
June 7, 201510 yr I just tried this: @Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){ if (!world.isRemote){ player.inventory.addItemStackToInventory(new ItemStack(SirenMod.FireExtinguisherItem, 1)); player.inventoryContainer.detectAndSendChanges(); } return stack; } and it worked fine for me.
June 7, 201510 yr Author Wow cool i just dont understand the detectAndSendChanges thing but thank you very much I'm beginner in java and in minecraft modding. Please be specific. Any code examples are appreciated. Sorry for my english i'm from Czech republic. Please hit that thank you button if i helped
June 7, 201510 yr detectAndSendChanges() scans the players server side inventory and pushes the changes to the client, forcing it to update.
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.