Getting Started: Improve chapter
This commit is contained in:
parent
e4bb144c7d
commit
e88b892551
@ -12,18 +12,18 @@ redirect_from:
|
||||
## Introduction <!-- omit in toc -->
|
||||
|
||||
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)
|
||||
- [Where are mods stored?](#where-are-mods-stored)
|
||||
- [Mod Directory](#mod-directory)
|
||||
- [mod.conf](#modconf)
|
||||
- [Dependencies](#dependencies)
|
||||
- [Mod Packs](#mod-packs)
|
||||
- [Example](#example)
|
||||
- [Mod Folder](#mod-folder)
|
||||
- [Creating your first mod](#creating-your-first-mod)
|
||||
- [Mod directory](#mod-directory)
|
||||
- [mod.conf](#modconf)
|
||||
- [init.lua](#initlua)
|
||||
- [mod.conf](#modconf-1)
|
||||
- [Summary](#summary)
|
||||
- [Dependencies](#dependencies)
|
||||
- [Mod Packs](#mod-packs)
|
||||
|
||||
|
||||
## What are Games and Mods?
|
||||
@ -53,7 +53,7 @@ and is applicable for both game developers and modders.
|
||||
<a name="mod-locations"></a>
|
||||
|
||||
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*.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
## Mod Directory
|
||||
## Creating your first mod
|
||||
|
||||

|
||||
### Mod directory
|
||||
|
||||
A *mod name* is used to refer to a mod. Each mod should have a unique name.
|
||||
Mod names can include letters, numbers, and underscores. A good name should
|
||||
describe what the mod does, and the directory which 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
|
||||
Go to the global mods directory (About > Open user data directory > mods) and
|
||||
create a new folder called "mymod". `mymod` is the mod name.
|
||||
|
||||
Each mod should have a unique *mod name*, a technical identifier (id) used to
|
||||
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).
|
||||
|
||||
mymod
|
||||
├── init.lua (required) - Runs when the game loads.
|
||||
├── mod.conf (recommended) - Contains description and dependencies.
|
||||
├── textures (optional)
|
||||
│ └── ... any textures or images
|
||||
├── sounds (optional)
|
||||
│ └── ... any sounds
|
||||
└── ... any other files or directories
|
||||
├── textures
|
||||
│ └── mymod_node.png files
|
||||
├── init.lua
|
||||
└── mod.conf
|
||||
|
||||
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
|
||||
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
|
||||
information.
|
||||
|
||||
For example:
|
||||
### init.lua
|
||||
|
||||
name = mymod
|
||||
description = Adds foo, bar, and bo.
|
||||
depends = modone, modtwo
|
||||
Create an init.lua file with the following content:
|
||||
|
||||
### 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.
|
||||
One mod may require another mod's code, items, or other resources to be available
|
||||
for it to use.
|
||||
One mod may require another mod's code, items, or other resources to be
|
||||
available for it to use.
|
||||
|
||||
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
|
||||
available, a hard dependency will cause the mod to fail to load, while an optional
|
||||
dependency might lead to fewer features being enabled.
|
||||
|
||||
An optional dependency is useful if you want to optionally support another mod; it can
|
||||
enable extra content if the user wishes to use both the mods at the same time.
|
||||
An optional dependency is useful if you want to optionally support another mod;
|
||||
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.
|
||||
|
||||
@ -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*.
|
||||
Games have their own organisational structure which will be explained in the
|
||||
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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user