Getting Started: Improve chapter

This commit is contained in:
rubenwardy 2022-07-31 17:20:24 +01:00
parent e4bb144c7d
commit e88b892551

View File

@ -12,18 +12,18 @@ redirect_from:
## Introduction <!-- omit in toc --> ## Introduction <!-- omit in toc -->
Understanding the basic structure of a mod's folder is an essential skill when Understanding the basic structure of a mod's folder is an essential skill when
creating mods. creating mods. In this chapter, you'll learn about how modding in Minetest works
and create your first mod.
- [What are Games and Mods?](#what-are-games-and-mods) - [What are Games and Mods?](#what-are-games-and-mods)
- [Where are mods stored?](#where-are-mods-stored) - [Where are mods stored?](#where-are-mods-stored)
- [Mod Directory](#mod-directory) - [Creating your first mod](#creating-your-first-mod)
- [Mod directory](#mod-directory)
- [mod.conf](#modconf) - [mod.conf](#modconf)
- [init.lua](#initlua)
- [Summary](#summary)
- [Dependencies](#dependencies) - [Dependencies](#dependencies)
- [Mod Packs](#mod-packs) - [Mod Packs](#mod-packs)
- [Example](#example)
- [Mod Folder](#mod-folder)
- [init.lua](#initlua)
- [mod.conf](#modconf-1)
## What are Games and Mods? ## What are Games and Mods?
@ -53,7 +53,7 @@ and is applicable for both game developers and modders.
<a name="mod-locations"></a> <a name="mod-locations"></a>
Each mod has its own directory where its Lua code, textures, models, and Each mod has its own directory where its Lua code, textures, models, and
sounds are placed. Minetest checks in a number of different locations for sounds are placed. Minetest checks in several different locations for
mods. These locations are commonly called *mod load paths*. mods. These locations are commonly called *mod load paths*.
For a given world/save game, three mod locations are checked. For a given world/save game, three mod locations are checked.
@ -78,54 +78,91 @@ mod will be loaded in place of the earlier mod. This means that you can override
game mods by placing a mod with the same name in the global mod location. game mods by placing a mod with the same name in the global mod location.
## Mod Directory ## Creating your first mod
![Find the mod's directory]({{ page.root }}/static/folder_modfolder.jpg) ### Mod directory
A *mod name* is used to refer to a mod. Each mod should have a unique name. Go to the global mods directory (About > Open user data directory > mods) and
Mod names can include letters, numbers, and underscores. A good name should create a new folder called "mymod". `mymod` is the mod name.
describe what the mod does, and the directory which contains the components of a mod
must have the same name as the mod name. Each mod should have a unique *mod name*, a technical identifier (id) used to
To find out if a mod name is available, try searching for it on refer to the mod. Mod names can include letters, numbers, and underscores. A
good name should describe what the mod does, and the directory that contains
the components of a mod must have the same name as the mod name. To find out if
a mod name is available, try searching for it on
[content.minetest.net](https://content.minetest.net). [content.minetest.net](https://content.minetest.net).
mymod mymod
├── init.lua (required) - Runs when the game loads. ├── textures
├── mod.conf (recommended) - Contains description and dependencies. │   └── mymod_node.png files
├── textures (optional) ├── init.lua
│   └── ... any textures or images └── mod.conf
├── sounds (optional)
│   └── ... any sounds
└── ... any other files or directories
Only the init.lua file is required in a mod for it to run on game load; Mods only require an init.lua file;
however, mod.conf is recommended and other components may be needed however, mod.conf is recommended and other components may be needed
depending on the mod's functionality. depending on the mod's functionality.
## mod.conf ### mod.conf
Create a mod.conf file with the following content:
```
name = mymod
description = Adds foo, bar, and bo.
depends = default
```
This file is used for mod metadata including the mod's name, description, and other This file is used for mod metadata including the mod's name, description, and other
information. information.
For example: ### init.lua
name = mymod Create an init.lua file with the following content:
description = Adds foo, bar, and bo.
depends = modone, modtwo
### Dependencies ```lua
print("This file will be run at load time!")
minetest.register_node("mymod:node", {
description = "This is a node",
tiles = {"mymod_node.png"},
groups = {cracky = 1}
})
minetest.register_craft({
type = "shapeless",
output = "mymod:node 3",
recipe = { "default:dirt", "default:stone" },
})
```
The init.lua file is the entrypoint to a mod, and runs when the mod is loaded.
### Summary
This mod has the name "mymod". It has two text files: init.lua and mod.conf. The
script prints a message and then registers a node and a craft recipe these
will be explained later on. There's a single dependency, the
[default mod](https://content.minetest.net/metapackages/default/), which is
usually found in Minetest Game. There is also a texture in textures/ for the
node.
## Dependencies
A dependency occurs when a mod requires another mod to be loaded before itself. A dependency occurs when a mod requires another mod to be loaded before itself.
One mod may require another mod's code, items, or other resources to be available One mod may require another mod's code, items, or other resources to be
for it to use. available for it to use.
There are two types of dependencies: hard and optional dependencies. There are two types of dependencies: hard and optional dependencies.
Both require the mod to be loaded first. If the mod being depended on isn't Both require the mod to be loaded first. If the mod being depended on isn't
available, a hard dependency will cause the mod to fail to load, while an optional available, a hard dependency will cause the mod to fail to load, while an optional
dependency might lead to fewer features being enabled. dependency might lead to fewer features being enabled.
An optional dependency is useful if you want to optionally support another mod; it can An optional dependency is useful if you want to optionally support another mod;
enable extra content if the user wishes to use both the mods at the same time. it can enable extra content if the user wishes to use both the mods at the same
time.
Dependencies are specified in a comma-separated list in mod.conf. Dependencies are specified in a comma-separated list in mod.conf.
@ -148,43 +185,3 @@ a player, but don't want to make them download each one individually.
Please note that a modpack is not a *game*. Please note that a modpack is not a *game*.
Games have their own organisational structure which will be explained in the Games have their own organisational structure which will be explained in the
Games chapter. Games chapter.
## Example
Here is an example which puts all of this together:
### Mod Folder
mymod
├── textures
│   └── mymod_node.png files
├── init.lua
└── mod.conf
### init.lua
```lua
print("This file will be run at load time!")
minetest.register_node("mymod:node", {
description = "This is a node",
tiles = {"mymod_node.png"},
groups = {cracky = 1}
})
minetest.register_craft({
type = "shapeless",
output = "mymod:node 3",
recipe = { "default:dirt", "default:stone" },
})
```
### mod.conf
name = mymod
descriptions = Adds a node
depends = default
This mod has the name "mymod". It has two text files: init.lua and mod.conf. The
script prints a message and then registers a node and craft recipe these will
be explained later on. There's a single dependency, the
[default mod](https://content.minetest.net/metapackages/default/),
which is usually found in Minetest Game. There is also a texture in textures/
for the node.