Chapter 4. Entities
Now that you have a good understanding of how to make mods with event handlers, we can move on to other types of mods. The theme of Chapter 3 was explosions, which are fun, but this chapter’s theme will be entities. First, you will make pigs drop diamonds in addition to their normal drop of porkchops. Next, you will make all zombies receive diamond armor and a diamond axe when they spawn. Finally, you will allow creepers to spawn five reinforcements when they die.
Pigs Dropping Diamonds
Pigs are passive entities. They will follow you if you hold a carrot. You can also breed them with a carrot. You can even ride on them with a saddle and a carrot on a stick. When pigs die, they drop porkchops. Wouldn’t it be fun to make them drop diamonds or some other material instead? Let’s do that!
First, create an event handler class called PigsDroppingDiamonds. The method code you need to add is shown in Example 4-1.