Initial Upload

master
Jeija 2012-02-18 12:03:20 +01:00
commit d5a80d4fcf
4 changed files with 237 additions and 0 deletions

2
README Normal file
View File

@ -0,0 +1,2 @@
This is a modding tutorial for minetest.
If noone else does it, the german one will be discontinued.

103
mtmoddev.txt Normal file
View File

@ -0,0 +1,103 @@
Minetest-c55 Modding in Lua
Einführung:
Minetest-c55 (test.mine.bz) ist ein Minecraft-Klon, entwickelt vom finnischen Programmierer 'celeron55'.
Es verfügt unter anderem über einen sogenannte ScriptAPI, die zur Programmierung von Mods eingesetzt wird.
Dieses Tutorial soll erklären, wie die Entwicklung von Mods funktioniert.
Voraussetzungen:
Um dieses Tutorial richtig verstehen zu können, sollten sie Grundlegende Kenntnisse in der Programmierung, bevorzugt Lua haben.
Kapitel 0: Anlegen eines Mods
Um einen Mod zu programmieren, muss unter dem Verzeichnis ~/.minetest/usermods ein Ordner mit dem Namen des Mods angelegt werden. Darin muss zum einen die Datei 'init.lua', die die Programme enthält und ein weiterer Ordner mit dem Namen 'textures' angelegt werden.
Kapitel 1: Der erste Mod!
Als ersten Mod werden sie einen Holzblock erstellen, der aber zu Dekorationszwecken verwendet werden kann. Dazu wird der Ordner 'tutorial' und die dazugehörigen Dateien wie in Kapitel 0 beschrieben erstellt.
In die init.lua muss der folgende Quellcode:
minetest.register_node("tutorial:holz", {
tile_images = {"holz.png"},
material = minetest.digprop_constanttime(1),
})
In den Ordner textures muss die Datei 'holz.png' aus dem Projektordner 'Texturen' kopiert werden.
Wenn minetest nun gestartet wird, wird dabei automatisch der Quellcode kompiliert und geladen.
Nun 'ingame' das Chatfenster mit 'T' öffnen und sich durch '/giveme tutorial:holz' einen Holzblock erschummeln. Fertig ist der erste Mod!
Nehmen wir einmal den Quellcode auseinander:
Die Funktion 'minetest.register_node' ist dafür verantwortlich, neue Blöcke zum Spiel hinzuzufügen.
Als Parameter müssen zum einen der Namen des neuen Blocks ("tutorial:holz") sowie eine Lua-Tabelle mit verschiedenen Parametern übergeben werden.
Darunter befindet sich tile_images, was die Textur des Blocks vorgibt, und mit Komma getrennt material, was die Eigenschaften bezüglich der Abbaugeschwindigkeit angibt. 'minetest.digprop_constanttime(1)' gibt demzufolge an, dass der Spieler, egal welches Werkzeug er verwendet, 1 Sekunde zum Abbauen des Blocks braucht.
Alternativ könnte man zum Beispiel auch
material = minetest.digprop_woodlike(1.5),
verwenden. Dadurch brauch das abbauen des Blocks 1.5 mal so lang, als bei einem normalen Holzblock.
Außerdem bevorzugt dieser Wert auch Äxte, da diese Holz schneller abbauen als andere Werkzeuge.
Kapitel 2: Crafting!
Obwohl das Spiel Minetest im Gegensatz zu MineCraft das Wort nicht im Namen trägt, ist Crafting dennoch ein Grundlegender Bestandteil des Spielprinzips. Als Crafting bezeichnet man das Herstellen von Gegentständen aus anderen. So wird z.B. eine Steinaxt aus Stöcken und Steinen hergestellt. [Screenshot]
Um das Deko-Holz aus Kapitel 1 auch craften zu können , müssen sie den folgenden Code in die init.lua einfügen:
minetest.register_craft({
output = '"tutorial:holz" 2',
recipe = {
{'default:wood', 'default:wood', ''},
{'default:wood', 'default:wood', ''},
{'', '', ''},
}
})
[screenshot]
Die Funktion minetest.register_craft() registriert einen 'crafting'-Vorgang. Der Parameter output gibt an, welcher Gegenstand beim Vorgang herauskommt, hier unser Holz. Die 2 gibt an, dass 2 Blöcke Holz entstehen. Das Rezept unten gibt an, woraus das Holz 'gecraftet' werden kann; Jeder String steht für ein Feld beim Crafting. Probieren sie auch andere Kombinationen aus!
Was bedeutet eigentlich das default vor wood?
'default' steht ,wie tutorial:* für den tutorial-mod, für den default-mod. Dieser definiert alle grundlegenden im Spiel vorkommende Gegenstände.
Der default mod findet sich bei einer run-in-place-version von minetest unter minetest/data/mods/default/init.lua
Darin enthalten ist auch z.B. default:wood.
Kaptiel 4: ABMs & Positionen!
ABMs sind Arbeitsbeschaffungsmaßnahmen für Blöcke, sie verschaffen unserem Tutorial-Holz sinnlose aufgaben. Wie wäre es, wenn das Tutorial-Holz einfach nach einer bestimmten Zeit wieder zu normalem Holz wird?
Dazu müssen Sie diesen Code noch an die init.lua dranhängen:
minetest.register_abm(
{nodenames = {"tutorial:holz"},
interval = 30,
chance = 1,
action = function(pos)
minetest.env:add_node(pos, {name="default:wood"})
end,
})
Die Funktion minetest.register_abm registriert eine für jeden Block einer Sorte auszuführende Aktion. 'nodenames = {"tutorial:holz"}' gibt an, dass dass die Aktion für alle Tutorial-Holzblöcke ausgeführt wird. Probieren Sie doch auch einmal "default:stone", um auch alle Steinblöcke zu verwandeln. 'interval = 30' bedeutet, dass die Aktion alle 30 Sekunden ausgeführt wird und chance = 1 dass die Wahrscheinlichkeit dafür 1 (also immer) beträgt. Als Aktion (action) kann nun eine Funktion gesetzt werden, die pos (die Position des tutorial-Holzblockes) als Parameter hat.
Mit minetest.env:add_node(pos, NodeTable) kann nun ein Block an der Position pos mit den Attributen in NodeTable hinzugefügt werden. Um zu definieren, dass es sich um einen Default-Holzblock handelt, reicht es den namen anzugeben.
Lehnen sie sich jetzt zurück und schauen sie zu, wie sich ihre Freunde aufregen, dass ihre Kreationen aus Deko-Holz wieder zu Standard-Holz werden.
Angenommen, Sie wollen jetzt aber erreichen, dass auf jedem Erde-mit-Grass-Block hohes Grass wächst (also default:junglegrass). Dazu müssen Sie die Position pos modifizieren können.
Dazu müssen Sie wissen, dass pos eine Tabelle ist die die folgenden Variablen enthält: x, y, z.
x und z sind Koordinaten in der Blockwelt nach Vorne-Hinten, Rechts-Links.
y hingegen ist die Oben-Unten-Koordinate (je höher, desto größer y).
Um nun hohes Grass über Erde-mit-Grass Blöcken wachsen zu lassen, können Sie den folgenden Code verwenden:
minetest.register_abm(
{nodenames = {"default:dirt_with_grass"},
interval = 1,
chance = 100,
action = function(pos)
pos.y=pos.y+1
minetest.env:add_node(pos, {name="default:junglegrass"})
end,
})
Die Zeile pos.y=pos.y+1 manipuliert die Position so, dass es sich nun um die Position direkt über dem Erde-mit-Grass-Block handelt. Das Ausführ-Intervall beträgt hier 1 Sekunde, die Wahrscheinlichkeit, dass die Funktion aber wirklich ausgeführt wird liegt bei 1/100. So wird ihr minetest-Garten langsam aber sicher mit hohem Grass überwuchert.
Dies ist nur eine kurze Eiführung in Minetest Lua Modding. Eine Englische Fassung dieses Tutorials finden sie unter [Forum Thread URL noch einfügen]. Die Englische Fassung ist umfangreicher als die Deutsche Version.
Ich hoffe sie haben hiermit schon einen kurzen Einblick in die Modprogrammierung erhalten haben und diese Kenntnisse auch bei anderen Programmen hilfreich sind.
Für weitere Informationen steht ihnen das Wiki von Minetest zu verfügung:
http://c55.me/minetest/wiki/doku.php?id=code:lua_api
Beide Links dienen nur als Kurzreferenz. Außerdem können sie im Minetestforum unter
c55.me/minetest/forum
ihre Fragen loswerden oder ihre selbstgeschriebenen Mods präsentieren.
Für fragen zu diesem Tutorial, schreiben sie eine eMail an
norrepli[at]gmail.com

132
mtmoddeven.txt Normal file
View File

@ -0,0 +1,132 @@
Minetest-c55: Modding in Lua
Introduction:
Minetest-c55 (Website: test.mine.bz) is a Minecraft clone, developed by the finnish programmer 'celeron55'.
It has a so-called ScriptAPI, which is used in order program Mods.
Requirements:
Basic Programming Knowledge, at best in Lua Language
Chapter 0: Create a mod
For creating a minetest mod you have to create a folder with the name of you mod in ~/.minetest/usermods/ (Linux Systemwide) / minetest/data/mods/ (Windows + Linux Run-in-place).
In this folder, make another one called 'textures'. You should put the textures in this one.
Additionally, create a file called 'init.lua'. This is the file that contains the source code of your mod.
Chapter 1: Your first mod!
First of all let's program a mod that adds a special kind of wood that can only be used for decoration.
For this, create a mod called 'tutorial' as described in Chapter 0.
Now copy-paste this into 'init.lua':
minetest.register_node("tutorial:decowood", {
tile_images = {"tutorial_decowood.png"},
material = minetest.digprop_constanttime(1),
})
You also have to copy the file 'tutorial_decowood.png' from the folder with this Document to the textures folder mentioned in Chapter 0.
When launching the game now, the mods are automatically loaded and compiled. This means when changing the code you simply have to 'Disconnect' and 'Start Game/Connect' again to try out the changes.
Let's try out the first mod! Open the chat window ingame (press t) and enter "/giveme tutorial:decowood 99" (Without "" of course). This will add 99 blocks of the decorative wood to your inventory!
Let's have a look at the source code:
The function minetest.register_node(name, table) is responsible for adding new blocks to the game (node=block, but also torches, rails, ...) . It takes 2 Parameters: The name of the new block ("tutorial:decowood", the string before : MUST be the name of the mod folder) and a table with several properties of the block.
In this case we use 2 properties:
tile_images: Sets the texture of the block; You can use only 1 texture or multiple textures,
seperated by commas {"tex1.png", "tex2.png", ...}. The game checks for the texture files in ALL textures folders of the game.
material: This sets the time it takes to destroy the block. In this case (minetest.digprop_constanttime(1)) it is a constant time of 1 second.
You could also use minetest.digprop_woodlike(1.5) which makes destruction with axes faster.
Chapter 2: Crafting!
Crafting does not only play an important role in minecraft, also minetest uses different crafting recipes. Therefore it is important to know what crafting means and how to code it! Crafting means creating Tools/Blocks/Other Objects. In minetest you have a 3x3 crafting area by default with a 1x1 output field. For example, a stone pickaxe can be made out of 2 Sticks and 3 Cobblestones:
C C C
S
S
S=Stick C=Cobblestone; Looks quite logic, doesn't it?
So let's make a crafting recipe for the decorative wood of Chapter 0!
Just append this to your init.lua:
minetest.register_craft({
output = '"tutorial:decowood" 2',
recipe = {
{'default:wood', 'default:wood', ''},
{'default:wood', 'default:wood', ''},
{'', '', ''},
}
})
The function minetest.register_craft() registers a crafting process, it defines the recipe for something. It takes 1 parameter which is a table that contains 2 properties: output which sets the outcome of the crafting process and recipe which is the actual recipe for the output.
Recipe must be a table with other tables inside. Every of the 3 tables defines another row of the crafting field. Every row contains 3 columns. In this case The crafting recipe is like that:
W W
W W
W=Wood
Easy, isn't it? You may also try out some other combinations!
But why are wooden planks not simply called wood but 'default:wood'? Indeed, The name of a tool/block/other object MUST be modname:name. In this case, the mod is called 'tutorial' (name is preset by the folder name) and the block is called 'decowood', so it's tutorial:decowood.
So what is 'default'? 'default' is the most important "mod" of minetest, in fact minetest itself is more like just a game engine, all the contents, materials, and other stuff are in several mods, like 'default' (standard tools/blocks), 'bucket' (Buckets: Lava/Water),...
If you want to find out more about these mods and maybe use features they contain, just have a look in their init.lua!
For Windows & Linux run-in-place these mods are in minetest/data; for Linux systemwide installation, these mods are in /usr/share/minetest/mods.
Chapter 4: ABMs & Positioning
ABMs add actions to blocks. For instance, the tutorial-wood could become normal wood after a few seconds. Append this code to your init.lua:
minetest.register_abm(
{nodenames = {"tutorial:decowood"},
interval = 30,
chance = 1,
action = function(pos)
minetest.env:add_node(pos, {name="default:wood"})
end,
})
Try it out! It's really annoying to see all your decowood creations destroyed after 30 seconds, they simple become normal wood.
But how does this work?
The function minetest.register_abm registers an action for each block of the same type.
nodenames = {"tutorial:decowood'} means that the action is processed for each decowood block.
You could also try "default:stone" instead of that to turn all stone blocks into wood.
interval = 30 means that the action is performed every 30 seconds. It starts counting at the beginning of the game. After 30 seconds all actions are processed, it doesn't matter when the block was placed.
This is not a per-block timer!
chance = 1 means that the probability of the action is 1:1, it happens in every case.
A higher value means that it's less probable.
action = function(pos) is the function that is actually performed.
It contiains the command minetest.env:add_node. This takes two parameters:
First of all the position parameter (more informations later) and also a table which defines the properties of the block, e.g. the name, the direction it faces, ...
In this case the name is enought to define what block you can see.
So let's assume we want to create a mod that makes junglegrass grow above every dirt-with-grass block. This should be a slow process, one dirt-with-grass block after the other should be grown over.
This is what we do:
minetest.register_abm(
{nodenames = {"default:dirt_with_grass"},
interval = 1,
chance = 100,
action = function(pos)
pos.y=pos.y+1
minetest.env:add_node(pos, {name="default:junglegrass"})
end,
})
You should already know everything else but the line pos.y=pos.y+1.
What is that for?
To understand it, you should know what a position variable in minetest is a table made up out of
3 values:
x, y and z.
x and z are forward/backward; left/right values. Y is the up/down value. The player usually spawns near 0,0,0.
The line pos.y=pos.y+1 manipulates the position to 1 Block above the dirt-with-grass node.
There are some small other differences to our first abm. The interval is 1 in this case, but the chance (probability) is 100. Therefore the function is executed every second, but only in 1 of 100 cases. This makes your minetest garden slowly been overgrown by junglegrass.
This is Jeija's modding tutorial Version 20120218.
Check for new version on github.com/Jeija/minetest-modding-tutorial.
For more information about minetest modding have a look at this reference:
http://c55.me/minetest/wiki/doku.php?id=code:lua_api
For generic modding questions or specific questions, feel free to ask in the minetest forum:
c55.me/minetest/forum
For questions about this tutorial, ask in the thread for this tutorial:
c55.me/minetest/forum/...
Thanks for reading! Let's go develop your first own mod!!

BIN
textures/holz.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB