Chapter 2. Block-Break Message

In the previous chapter, we looked at the sample mod that is bundled with Forge. It printed a message in the console when the game started. However, it is a very simple and boring mod, so in this chapter, we will make one that is slightly more interesting. This mod will send a chat message saying, “You broke a block!” whenever you break a block. This may sound simple, but it will demonstrate some of the fundamental aspects of modding that will be used throughout this book.

Creating the Main File

The most important file in your mods is the main file, a Java class. It is also the first file the mod goes to because it has a method that gets called when the game starts. A group of mods will typically have one main file, and this will be the main file for the mods created in this book.


If you are using a print version of this book, you will obviously not be able to copy and paste the code from it. Instead, follow the instructions in Appendix C to download the source code.

Each Java file needs to exist in a package. The sample mod from Chapter 1 is in the package com.example.examplemod, which makes sense because it is the example mod. For our mods, however, we will be using the package org.devoxx4kids.forge.mods. First, you have to create this package.

In Eclipse, right-click the src/main/java folder, and navigate to New→Package, as shown in Figure 2-1.

Figure 2-1. Creating a new package

A window asking for the name of the package should open. ...

Get Minecraft Modding with Forge now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.