Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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

  • Author

Ok. I replaced the code in the main mod class with

MinecraftForge.EVENT_BUS.register(new FPEventHandler());

yet, still nothing happens :-(

  • 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?

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.