minetest_modding_book/chapters/folders.md

111 lines
3.2 KiB
Markdown
Raw Normal View History

2014-12-11 00:56:37 -08:00
---
2014-12-11 12:04:07 -08:00
title: Folder Structure
2014-12-11 00:56:37 -08:00
layout: default
2014-12-12 01:13:30 -08:00
root: ../
2014-12-11 00:56:37 -08:00
---
2015-02-22 02:28:37 -08:00
## Introduction
2014-12-11 00:56:37 -08:00
2015-02-19 06:55:37 -08:00
In this chapter we will learn the basic structure of a mod's folder.
This is an essential skill when creating mods.
2014-12-11 00:56:37 -08:00
* Mod Folders
2014-12-12 12:04:24 -08:00
* Dependencies
2014-12-11 00:56:37 -08:00
* Mod Packs
2015-02-22 02:28:37 -08:00
## Mod Folders
2014-12-11 00:56:37 -08:00
2015-02-19 06:55:37 -08:00
![Find the mod's folder]({{ page.root }}/static/folder_modfolder.jpg)
2014-12-18 10:57:13 -08:00
2015-11-08 07:57:40 -08:00
Each mod has its own folder where all its Lua code, textures, models, and sounds
are placed. These folders need to be placed in a mod location such as
minetest/mods. Mods can be grouped into mod packs which are explained below.
2014-12-11 00:56:37 -08:00
2015-02-19 06:55:37 -08:00
A "mod name" is used to refer to a mod. Each mod should have a unique mod name,
2016-06-04 12:22:26 -07:00
which you can choose - a good mod name should describe what the mod does.
2015-11-08 07:57:40 -08:00
Mod names can be made up of letters, numbers, or underscores. The folder a mod is
2015-02-19 06:55:37 -08:00
in needs to be called the same as the mod name.
2014-12-18 10:57:13 -08:00
2014-12-11 00:56:37 -08:00
### Mod Folder Structure
2015-02-19 06:55:37 -08:00
Mod name (eg: "mymod")
2014-12-11 00:56:37 -08:00
- init.lua - the main scripting code file, which is run when the game loads.
- (optional) depends.txt - a list of mod names that needs to be loaded before this mod.
- (optional) textures/ - place images here, commonly in the format modname_itemname.png
- (optional) sounds/ - place sounds in here
- (optional) models/ - place 3d models in here
...and any other lua files to be included by init.lua
2015-11-08 07:57:40 -08:00
Only the init.lua file is required in a mod for it to run on game load; however,
2015-02-19 06:55:37 -08:00
the other items are needed by some mods to perform their functionality.
2014-12-11 00:56:37 -08:00
2015-02-22 02:28:37 -08:00
## Dependencies
2014-12-11 00:56:37 -08:00
2015-11-08 07:57:40 -08:00
The depends text file allows you to specify which mods this mod requires to run and what
2014-12-11 00:56:37 -08:00
needs to be loaded before this mod.
2014-12-31 08:51:24 -08:00
**depends.txt**
2014-12-11 00:56:37 -08:00
modone
modtwo
modthree?
2015-02-19 06:55:37 -08:00
As you can see, each modname is on its own line.
2014-12-12 08:52:20 -08:00
Mod names with a question mark following them are optional dependencies.
If an optional dependency is installed, it is loaded before the mod.
However, if the dependency is not installed, the mod still loads.
2015-11-08 07:57:40 -08:00
This is in contrast to normal dependencies which will cause the current
mod not to work if the dependency is not installed.
2014-12-11 00:56:37 -08:00
2015-02-22 02:28:37 -08:00
## Mod Packs
2014-12-11 00:56:37 -08:00
2015-11-08 07:57:40 -08:00
Modpacks allow multiple mods to be packaged together and be moved together.
2015-02-19 06:55:37 -08:00
They are useful if you want to supply multiple mods to a player but don't
2014-12-12 08:52:20 -08:00
want to make them download each one individually.
2014-12-11 00:56:37 -08:00
### Mod Pack Folder Structure
2014-12-12 08:52:20 -08:00
modpackfolder/
2014-12-11 00:56:37 -08:00
- modone/
- modtwo/
- modthree/
- modfour/
2014-12-12 08:52:20 -08:00
- modpack.txt signals that this is a mod pack, content does not matter
2014-12-11 00:56:37 -08:00
2015-02-22 02:28:37 -08:00
## Example Time
2014-12-11 00:56:37 -08:00
Are you confused? Don't worry, here is an example putting all of this together.
### Mod Folder
mymod/
- textures/
- - mymod_node.png
2014-12-11 00:56:37 -08:00
- init.lua
- depends.txt
### depends.txt
default
### init.lua
{% highlight lua %}
2014-12-11 11:49:41 -08:00
print("This file will be run at load time!")
2015-02-19 06:55:37 -08:00
minetest.register_node("mymod:node", {
2014-12-11 11:49:41 -08:00
description = "This is a node",
tiles = {
"mymod_node.png",
"mymod_node.png",
"mymod_node.png",
"mymod_node.png",
"mymod_node.png",
"mymod_node.png"
},
groups = {cracky = 1}
})
2014-12-11 00:56:37 -08:00
{% endhighlight %}
Our mod has a name of "mymod". It has two text files: init.lua and depends.txt.\\
The script prints a message and then registers a node which will be explained in the next chapter.\\
2015-11-08 07:57:40 -08:00
The depends text file adds a dependency to the default mod which is in minetest_game.\\
There is also a texture in textures/ for the node.