Chapter 3. Fun with Explosions

Chapter 2 explained how to make your first mod. Now that the basic fundamentals are well understood, we can move at a slightly faster pace and make more interesting mods. This chapter will teach you how to make mods related to explosions.

First, you will make minecarts explode when they collide with a mob. Next, you will make anvils explode when they fall on an entity. Then, you will make diamond ore explode when mined. Lastly, you will increase the size of TNT explosions. Each mod will also include ways to use the mod, such as falling anvil traps or bouncing zombie towers!

Let’s make some explosions!

Exploding Minecarts

Minecarts are one of the main ways of transport in Minecraft. They use rails to travel and can carry mobs or players. However, they don’t do much besides that. This mod aims to make our minecarts do some fun stuff. With this mod, minecarts will make a small explosion when they collide with an entity, possibly killing the entity in question.

As explained in the last chapter, a group of mods need to have only one main file. We already created that, and so the only new file that needs to be created is an event handler. Create the event handler as explained in “Creating a Java Class for Event Handling”, and name it ExplodingMinecarts. Once again, you can use whatever name you like for the file, but it’s best to indicate the mod’s purpose in the filename.

Add a Java method to this class that will listen for the event. The code you will ...

Get Minecraft Modding with Forge now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.