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 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.

Note

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. ...

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