In this video we will be making the first our first mod. As you can see it's going to be pretty basic, just a new full grass node, and recipe.
The first step is to create a new directory in our mods directory for all the mod files. We're going to call our first mod 'grass' so we'll create a directory called grass.
This mod is going to be very basic so we're only going to need two files. init.lua and mod.conf. You can create these in the file browser, or in the code editor.
I'm going to open the project directory in Pulsar and create the two needed files.
init.lua will hold the actual code for the mod, mod.conf stores some configuration data that tells Luanti about the mod. Every mod will need at very least these two files.
We'll take care of the mod.conf file first. Luanti expects a few different bits of data; a name, title, description, dependencies, and an author.
The name is the internal name of the mod, all nodes and items will be named this name:something.
The title is a human friendly name, and will be displayed in the mod selection dialog in Luanti. For this mod we'll use grass for both.
The description is a short sentence explaining what the mod is/does/adds, etc.
Dependencies tell Luanti what mods your mod needs or can use. We'll cover them more in a later video. This mod will only depend on default
Lastly the Author should be set to your ContentDB username if you have an account there.
Now to writing some actual code!
We'll start with registering a new node called grass:grass. Remember every node in this mod needs to start with grass:
The description will be shown when hovering the node in most inventory screens.
The tiles are the textures that Luanti will render on the faces of the node. If all the faces have the same texture we only need to list the texture once. We'll cover this more in a future video.
Groups do many different things, in this case the crumbly group is needed for tools so Luanti knows what tools should be able to break the node. The soil group is used by other mods but we'll just include it for compatibility.
When we break this node we don't want to get back the full grass block, but rather dirt, so we tell the engine that on breaking the node should drop default:dirt. We can do a lot more with the drop table, but we'll cover that in another video.
This is a basic node registration, nodes can have callbacks so that they are more interactive, but for the time being this will suffice.
Right now there is no way to craft this node, we can get it via creative, or using the give command, but it would be nice to be able to craft it.
So let's add a craft recipe. This is structured a bit different than the node registration, we use an output to say what node/item is made.
The recipe is a table, and he default craft grid is a 3x3 square so we have nine items max we can use. We need to know the item strings for each ingredient. A blank entry means the inventory slot should be empty. How do we know the item string though, there are many different items in a game, and it would be nearly impossible to ever remember all of them. The easiest way is to open Luanti, go into settings, click on the User Interfaces heading on the side, and check the Append Item Name option. Now if we launch a world, with creative enabled we can search for any item and hover it in inventory to get the itemstring. Some inventory mods will also give us this data without enabling this option.
We want to use grass and dirt to make the full grass block, but there are several different stages of grass in the game. Thankfully they all drop the same item, so we can just use default:grass_1 in the recipe. Our recipe will be one dirt in the center with one grass on top, right, bottom and left.
Launching a world, with our new mod enabled we can dig up some dirt and collect a bit of grass and craft our new node!
Let's add another recipe just for fun. This recipe will only be one dirt, and one grass, our table doesn't need to have two rows of blanks, so we can put the entire recipe on one line. We'll set our output to default:dirt_with_grass. Mods can make recipes for nodes that other mods provide. We just need to make sure that the other mods we want to use items from are listed in our dependencies in the mod.conf file.
That wraps this lesson up, but before you go, HOMEWORK!!!
Add the other grasses to this mod, so we can craft full grass nodes of all the grasses, and make craft recipes for them as well.