Posted February 9, 201411 yr I'm trying to get it so that if I right-click mid-air with an item, that item will disappear and a new item will appear in the inventory. However, when I run the game and right-click, nothing happens (no item lost or gained). I've got everything registered but I was wondering if anyone knows what the problem is. Thanks in advance. Here's the code: Code in a class called FPEventHandler @SubscribeEvent public void playerInteractEvent(PlayerInteractEvent event) { EntityPlayer player = event.entityPlayer; ItemStack tankEmpty = new ItemStack(FreshPower.getItem("fp_tankEmpty"),1); ItemStack tankAir = new ItemStack(FreshPower.getItem("fp_tankEmpty"),1); if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem() == tankEmpty) { if(event.action == Action.RIGHT_CLICK_AIR) { player.inventory.addItemStackToInventory(tankAir); --player.getCurrentEquippedItem().stackSize; } } } This line is in my init constructor of my main mod class FMLCommonHandler.instance().bus().register(new FPEventHandler());
February 9, 201411 yr Author Ok. I replaced the code in the main mod class with MinecraftForge.EVENT_BUS.register(new FPEventHandler()); yet, still nothing happens :-(
February 9, 201411 yr Author Thanks for the help. The issue is fixed but now another one has risen. If I have a full inventory and right-click the air, I lose the item but I don't gain the item I want. I've tried different ways of fixing this but none of them work. Has anyone got any ideas as to what I can do?
February 11, 201411 yr AI haven't tried it, but I would probably test for room in inventory in the event and cancel it (set result to cancelled), if it would result in too many items/stacks. I am curious about the function 'net.minecraft.item.Item:onItemRightClick( ... )' which returns an ItemStack. I suspect overriding it in your Item subclass might accomplish the same effect easier. Anyone know for sure? -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
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.