Jump to content

Recommended Posts

Posted

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());

Posted

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?

Posted

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?

 

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.