Jump to content

[1.8] PlayerInteractEvent Action RIGHT_CLICK_AIR isn't working?


Ferrettomato

Recommended Posts

I'm attempting to follow the instructions laid out by "Sams Teach Yourself Minecraft Mod Development in 24 Hours" that allows the player to throw eggs when they right click with an empty hand if they're wearing certain armor. Unfortunately, when I attempt to use this function in-game, it only works if the player is targeting a block. RIGHT_CLICK_AIR and RIGHT_CLICK_BLOCK are located in the same part of my code, so what's going on?

 

Method inside of FerretEventHandler:

	@SubscribeEvent
public void throwEggs(PlayerInteractEvent event)
{

	if(!event.world.isRemote)
	{
		if(event.action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR || event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)
		{
			if(event.entityPlayer.getCurrentEquippedItem() == null)
			{
				boolean hasFullSuit = true;
				for(int i = 0; i < 4; i++)
				{
					if(event.entityPlayer.getCurrentArmor(i) == null)
					{
						hasFullSuit = false;
						return;
					}
					else if(!(event.entityPlayer.getCurrentArmor(i).getItem() instanceof ItemLightArmor))
					{
						hasFullSuit = false;
					}
					if(hasFullSuit)
					{
						event.entityPlayer.worldObj.spawnEntityInWorld(new EntityEgg(event.entityPlayer.getEntityWorld(), event.entityPlayer));
					}
				}
			}
		}
	}
}

Link to comment
Share on other sites

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.