O'Reilly logo

Minecraft™ Mod Development in 24 Hours, Sams Teach Yourself by Jimmy Koene

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Giving Your Armor Egg-Throwing Abilities

Another interesting thing you can do with events is make the player throw eggs when right-clicking with an empty hand as long as it has a full set of armor on. This feature will be added to the armor created in Hour 8, “Creating Armor.”

To do this, use an event called PlayerInteractEvent. This is an event located in an fml folder, which means this event class has to be registered using the FML EVENT_BUS, as shown previously.

The method inside of the SamEventHandler looks like this:

@SubscribeEventpublic void throwEggs(PlayerInteractEvent event){}

Within this method, you must check several things before the egg is thrown. The code within this method should do something like ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required