Chapter 6. New Commands

In this chapter, you’ll learn how to add new commands to the game and customize them to your liking. Minecraft already has many commands—for example, the /summon command lets you spawn an entity wherever you want to, and /setblock lets you place a block anywhere you wish. Each new command you create using Forge requires two things: first, a new file containing the command’s details, and second, a line in a new method that registers the command in the main file. This chapter has a lot more Java code than the previous ones, so pay attention carefully.

The first command you will create will spawn a specified number of flaming pigs at the sender’s location. This can be used for fun things like a cloud of particles or tons of porkchops. Then, you will make a command that lets you choose two locations, and when you use the command, the area between the two locations gets filled with the block of your choice.

Flaming Pigs

In Minecraft, pigs aren’t normally on fire. The only way to ignite them is to push them into a fire block or into lava. This mod will add a command that lets you spawn whatever number of pigs you want and also sets them on fire. It isn’t really very useful—it’s just funny to see a bunch of pigs on fire. And isn’t that what the entire game of Minecraft is about?

First, create a new class and call it FlamingPigs. This will be the file that stores all of the command’s details. We will fill in all the details of this class later. Server commands ...

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.