The first step in creating your Minecraft game is to build the scene. These instructions explain how to create the scene for a basic game called Spleef. The scene in Spleef is an arena that has a fence around it.
To make this arena, you use the ArenaBuilder library on LearnToMod. A library is a mod that is already written for you. You can use it without having to know how it is written.
To explore the library, follow these steps:
You see these five functions:
Click the question mark (?) on each function.
A comment pops up, describing what the function does. For example, here is the comment for the Fence function.
Look through this code, and its parameters, to see what the code is doing.
Notice that there’s no main function, because this mod cannot run on its own in Minecraft. Instead, it must be called from other mods.
Also notice the block: export. The export block makes the function that’s written in the block accessible to other mods, meaning other mods can call the functions even though they’re in a different mod.
Three functions are being exported: ArenaWithFence, init, and move_drone.
Now you can use these three functions in your Spleef game.
After you have exposed the ArenaBuilder library, go back to your Spleef mod and import the library. Follow these steps:
Under the Misc category, find the import block.
Drag it into the mod and type sarah-ArenaBuilder to replace the text lib-name.
If you enter the mod name correctly, the block stays green and new functions appear under the Functions category.
Notice that the three functions you now have access to the three that were exported from the ArenaBuilder library.
Create a main function, and add a call to the init function from the ArenaBuilder library.
The init function, if you look back at the library, basically creates the drone that will be used to create the arena for you.
After your drone is ready to build your arena, add a call to the ArenaWithFence function from the ArenaBuilder library to the main function.
This shows how to make a 20 x 20 arena made of diamond with a fence that’s five blocks high and a platform width of one block. The arena will be filled with air. This makes the arena where you will play Spleef.
Even though you didn’t write the ArenaBuilder library, test your code as you’re building it. To test your code, make sure that the mod is saved, click the Mod button, and test the code in Minecraft.
You see a scene like this one.
Before moving on, refactor the code — change it without changing what it does.
In this case, you’re refactoring the code so that the arena is built in a function named arena and so that the arena function is called from main.
Congratulations — you’ve created the basic Spleef scene!