Posted May 10, 201312 yr Hi, i got a problem. Maybe first the code: public class ItemBandage extends Item { public ItemBandage(int par1) { super(par1); //par1 is ID setCreativeTab(CreativeTabs.tabMisc); } public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if (hamrInjurys.brokenFootBoolean==true){ --par1ItemStack.stackSize; hamrInjurys.brokenFootBoolean = false; } return par1ItemStack; } } brokenFootBoolean gets true once a certain potion of mine is activated. That is working. So when rightclicked, --par1ItemStack.stackSize makes sure it gets removed from my inventory (it cant be stacked) And then setting brokenFootBoolean is for something else. So then, the spot where the bandage was is empty. But if i rightclick again once or twice, the item returns. You could see that as eating your food, right clicking with your hand in the air, and getting it back. How can i fix that? Edit, main class (RS_HAMR) : In class itself: public static Item bandage; In @init : bandage = new ItemBandage(7000).setUnlocalizedName("bandage").setMaxStackSize(1); LanguageRegistry.addName(bandage, "Bandage"); EDIT 2: Seems you only get it back when you rightclick a block, not the air.
May 10, 201312 yr Use par3EntityPlayer.inventoryContainer.detectAndSendChanges(); after you decrease your itemstack. May help. If i helped you, don't forget pressing "Thank You" button. Thanks for your time.
May 10, 201312 yr Author Use par3EntityPlayer.inventoryContainer.detectAndSendChanges(); after you decrease your itemstack. May help. You mean like this? : public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if (hamrInjurys.brokenFootBoolean==true){ --par1ItemStack.stackSize; par3EntityPlayer.inventoryContainer.detectAndSendChanges(); hamrInjurys.brokenFootBoolean = false; } return par1ItemStack; } Sorry, but it didnt chance anything in-game. The problem still happens.
May 10, 201312 yr Hmmm... That code actually worked for me when in classic mode, but not in creative... Don't know then. Sorry. If i helped you, don't forget pressing "Thank You" button. Thanks for your time.
May 10, 201312 yr The returned ItemStack is what you are left holding after the method is processed. To decrement a stack, just use ItemStack.stackSize-- and return the new stack (checking for if the new size is zero and nulling if necessary). To remove it entirely, return null. Follow my mod(s) here: http://www.minecraftforum.net/topic/1969694-
May 15, 201312 yr I use it, and it works... Follow my mod(s) here: http://www.minecraftforum.net/topic/1969694-
May 15, 201312 yr player.inventory.setInventorySlotContents(slot, null); but you need to iterate throught the players inventory to get the slot.
May 16, 201312 yr If you know the slot in advance (like it was the active item), iteration is not necessary. Follow my mod(s) here: http://www.minecraftforum.net/topic/1969694-
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.