Skip to Content
Minecraft Modding with Forge
book

Minecraft Modding with Forge

by Aditya Gupta, Arun Gupta
April 2015
Intermediate content levelIntermediate
200 pages
4h 17m
English
O'Reilly Media, Inc.
Content preview from Minecraft Modding with Forge

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.

Example 4-1. Pigs dropping diamonds method code
@SubscribeEvent
public void dropDiamonds(LivingDeathEvent event){ 1
	if (!(event.entity instanceof EntityPig)) { 2
		return;
	}

	Random random = new Random(); 3

	if (!event.entity.worldObj.isRemote) { 
		event.entity ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Minecraft Modding with Forge

Minecraft Modding with Forge

Aditya Gupta, Arun Gupta

Publisher Resources

ISBN: 9781491918883Errata Page