Difference between revisions of "Modding FAQ"

From Minetest Developer Wiki
Jump to navigation Jump to search
(Contributed by HeroOfTheWinds but by my misleading it got posted in the wrong wiki.)
(Remove Misc category)
(23 intermediate revisions by 8 users not shown)
Line 1: Line 1:
 +
{{Languages}}
  
= Basic Modding =
+
This page includes frequently asked questions about mod and game development for Minetest. For general advice, see also [[Modding Tips]].
  
== What is a Mod ==
+
= Terminology =
 +
== What is a mod? ==
  
 
Mods (short for modifications) are user-created modifications to the game in such a way that alters gameplay. Some larger mods may add a lot of content to the game, while other smaller mods may add more settings/customization options, or optimize the speed, gameplay or graphics of Minetest. Server mods or plugins mainly give server admins more options and ease of use, and all mods for single-player can also be used in multiplayer.
 
Mods (short for modifications) are user-created modifications to the game in such a way that alters gameplay. Some larger mods may add a lot of content to the game, while other smaller mods may add more settings/customization options, or optimize the speed, gameplay or graphics of Minetest. Server mods or plugins mainly give server admins more options and ease of use, and all mods for single-player can also be used in multiplayer.
Line 8: Line 10:
 
''[http://wiki.minetest.net/Mods Read More]''
 
''[http://wiki.minetest.net/Mods Read More]''
  
== Installing Mods ==
+
== What is a formspec? ==
 +
A formspec is a specification for a form, written in string form. You can use formspecs to define all the forms in your mod. See [[formspec]] for more.
  
See [[Installing Mods]]
+
== What are listrings? ==
 +
Listrings are a convenience feature in Minetest to allow quick transfer of an itemstack from one inventory list to another with <kbd>Shift</kbd>+<kbd>Click</kbd>. Basically, listrings group several inventory lists together in a “ring” data structure. A shift-click will transfer an itemstack from one inventory list to the next inventory list in the listrings, and, if it is the final inventory list in the listring, it will be sent to the first inventory list.
  
 +
Listrings are documented in lua_api.txt.
  
== Where Do I Find Tutorials and Documentation About Modding? ==
+
= Basic modding =
Start at the [http://dev.minetest.net/ Minetest Developer Wiki]. It isn't just about changing the Minetest (C++) core program. There are articles and references about modding you can find right from the main page. Look for the "Develop a mod" and "Modding API" headings.<br />
+
== How do I install a mod? ==
<br />
+
 
 +
See [https://wiki.minetest.net/Installing_Mods Installing Mods] on the Minetest Wiki.
 +
 
 +
== Where do I find tutorials and documentation about modding? ==
 +
(related [[:Category:Modding API‏‎]])<br />
 +
Start on the [[Main Page]] here at the Minetest Developer Wiki. It isn't just about changing the Minetest (C++) core program. There are articles and references about modding you can find right from the main page. Look for the "Develop a mod" and "Modding API" headings. The Developer Wiki is very much a community project, so don't forget to come back and help document what you find!
 +
 
 +
=== Lua basics ===
 +
* [http://www.lua.org/pil/contents.html Programming in Lua], learn the Lua langauge (for Lua 5.0)
 +
* [http://www.lua.org/manual/5.1/ Lua 5.1 reference] (note that Minetest uses Lua 5.1)
 +
 
 +
=== Minetest modding ===
 +
* [[Intro|Introduction]] to the modding API on the wiki.
 +
* [http://rubenwardy.com/minetest_modding_book/ Minetest Modding Book] an online clear and easy guide in learning to make mods.
 +
* [https://github.com/minetest/minetest/blob/master/doc/lua_api.txt lua_api.txt] in minetest/docs/ contains an API Listing ([http://rubenwardy.com/minetest_modding_book/lua_api.html HTML Version]). Those links are to the latest development version, look in your docs/ folder for one specific to your Minetest version.
 +
* [https://www.youtube.com/playlist?list=PL-uTdq9t8wyyJWzahSrnCqmMz9lgUnuVF Youtube tutorials] Probably the largest collection of Minetest video tutorials available online.
 +
* Search the forum by web search (eg: googling) like this: "some search terms site:forum.minetest.net".
 +
* Ask the community for help in the [https://forum.minetest.net/viewforum.php?f=9 Modding General] section of the forum.
 +
 
 +
== How do I debug my mod? ==
 +
 
 +
The "lua" interpreter is not very useful for debugging mod code, because mods are built to run in an environment specific to Minetest (they expect to be loaded after their dependencies, have access to the Minetest API, etc.).  However, you may be able to break pieces of your logic into separate, stand-alone Lua library files that are not specific to Minetest.  Where you have an opportunity to do this, testing outside of Minetest (using Lua 5.1's "lua" interpreter or LuaJIT's "luajit" interpreter) can be helpful.  This might work for some utility functions and "class libraries".
  
For obscure details about the modding API that seem poorly documented or not yet documented at all, check the [https://github.com/minetest/minetest/blob/master/doc/lua_api.txt lua_api.txt] file shipped with Minetest, and other stuff under the [https://github.com/minetest/minetest/tree/master/doc doc] directory (links are to latest versions in Git; for ones that apply directly to your installed version of Minetest, see the files included in your download/install).  The Developer Wiki is very much a community project, so don't forget to go back there and help document what you find!<br />
+
There is no debugger built into Minetest itself, but there are a few functions that can help (see [[:Category:Debugging]]). Using these functions is generally equivalent to using "printf style debugging", meaning you'll have to modify your mod code and restart the server when you want to deduce what is going on, or carefully plan for debug logging in your code and provide some kind of debug level or flags.  There is also a [http://wiki.minetest.net/LuaCmd LuaCmd] mod that allows players having adequate permissions to execute Lua statements from Minetest's chat console, but using it to examine the state of your mod is limited to your public API (in other words, functions and variables you have put in a global table named after your mod, rather than <code>local</code> variables defined in your mod files).
<br />
 
  
Finally, for more interactive support head over to the [https://forum.minetest.net/viewforum.php?f=9 Modding General] section of the Minetest forums.  The forum search seems to be mostly broken, but the forums are crawled and indexed so you can always try a narrowed web search (e.g. include the term <code>site:forum.minetest.net</code> in a Google search).<br />
+
== Specific questions regarding node definitions ==
 
<br />
 
<br />
  
== Specific Questions Regarding Node Definitions ==
+
=== How do I add a new node? ===
 +
See [http://dev.minetest.net/minetest.register_node minetest.register_node].
 
<br />
 
<br />
  
'''General Wiki for Registering Nodes:''' [http://dev.minetest.net/minetest.register_node minetest.register_node]<br />
+
=== How can I make my new nodes transparent in certain sections? ===
 
 
 
 
'''How can I make my new nodes transparent in certain sections?'''<br />
 
 
<br />
 
<br />
  
Line 35: Line 58:
 
<br />
 
<br />
  
'''What if I only want it partially transparent, such as with tinted glass?'''<br />
+
=== What if I only want it partially transparent, such as with tinted glass? ===
 
<br />
 
<br />
 
To do this, add <code>use_texture_alpha = true</code> to the node definition while following the directions above.<br />
 
To do this, add <code>use_texture_alpha = true</code> to the node definition while following the directions above.<br />
  
== How Do I Generate a Custom Map? ==
+
== How do I generate a custom map? ==
First, there are a bunch of [http://dev.minetest.net/Mapgen_Parameters mapgen parameters] you can change for the built-in mapgens, so you might be able to get what you want without touching Lua at all.  You may also be able to find an existing [[Mods|mod]] that does what you want, so check the [[mod list]] here and the [https://forum.minetest.net/viewforum.php?f=11 Mod Releases] section of the forums (the community has already written several mods for various map generation, importing real-world data, editing sections of existing worlds, etc.).  Finally, the Lua modding API has recently been enhanced to make custom mapgens more feasible to write without modifying the core Minetest engine.  It's not for the feint of heart but if you want to dive in, start by reading up in the Developer Wiki on:
+
First, there are a bunch of [[Mapgen Parameters|mapgen parameters]] you can change for the built-in mapgens, so you might be able to get what you want without touching Lua at all.  You may also be able to find an existing mod that does what you want, so check the [http://wiki.minetest.net/Mod_list mod list] on the main Minetest Wiki and the [https://forum.minetest.net/viewforum.php?f=11 Mod Releases] section of the forums (the community has already written several mods for various map generation, importing real-world data, editing sections of existing worlds, etc.).  Finally, the Lua modding API has recently been enhanced to make custom mapgens more feasible to write without modifying the core Minetest engine.  It's not for the faint of heart but if you want to dive in, start by reading up on:
* [http://dev.minetest.net/Category:Mapgen Category:Mapgen]
+
* [[:Category:Mapgen]]
* [http://dev.minetest.net/Voxel_Manipulator VoxelManip]: the voxel manipulator, for fast modification of large chunks of nodes.
+
* [[VoxelManip]]: the voxel manipulator, for fast modification of large chunks of nodes.
* [http://dev.minetest.net/minetest.register_on_generated minetest.register_on_generated]: for handling freshly-minted, previously unexplored sections of the map.
+
* [[minetest.register_on_generated]]: for handling freshly-minted, previously unexplored sections of the map.
* [http://dev.minetest.net/minetest.spawn_tree minetest.spawn_tree].  L-system generation for trees and other interesting constructs.
+
* [[minetest.spawn_tree]].  L-system generation for trees and other interesting constructs.
* [http://dev.minetest.net/minetest.create_schematic minetest.create_schematic] and [http://dev.minetest.net/minetest.place_schematic minetest.place_schematic]: schematics/templates for cookie-cutter placement of pre-planned sections that can include minor variation.
+
* [[minetest.create_schematic]] and [[minetest.place_schematic]]: schematics/templates for cookie-cutter placement of pre-planned sections that can include minor variation.
 
This is a pretty advanced task to do in a mod, so expect to also have to do some digging and research in the lua_api.txt document.
 
This is a pretty advanced task to do in a mod, so expect to also have to do some digging and research in the lua_api.txt document.
  
= Advanced Modding =
+
= Advanced modding =
 +
== How do I properly balance the biomes? ==
 +
As decribed in <code>lua_api.txt</code>, biomes are defined by heat and humidity points in a Voronoi diagram, with heat and humidity usually ranging from 0 and 100, but in extreme cases they can even reach -25 and 125.
 +
 
 +
Paramat shows how it works for Minetest Game here: [https://forum.minetest.net/viewtopic.php?f=47&t=15272&start=250#p257528]
 +
 
 +
[https://www.geogebra.org/ GeoGebra] is a software tool which can be used to graphically align the Voronoi cells, making balancing a lot easier. Paramat explained it here: [https://forum.minetest.net/viewtopic.php?p=230857#p230857]
  
[[Category:Mods]]
+
[[Category:Mods]] [[Category:Modding API]]

Revision as of 19:53, 26 June 2020

Language: [[::Modding FAQ|English]]

This page includes frequently asked questions about mod and game development for Minetest. For general advice, see also Modding Tips.

Terminology

What is a mod?

Mods (short for modifications) are user-created modifications to the game in such a way that alters gameplay. Some larger mods may add a lot of content to the game, while other smaller mods may add more settings/customization options, or optimize the speed, gameplay or graphics of Minetest. Server mods or plugins mainly give server admins more options and ease of use, and all mods for single-player can also be used in multiplayer.

Read More

What is a formspec?

A formspec is a specification for a form, written in string form. You can use formspecs to define all the forms in your mod. See formspec for more.

What are listrings?

Listrings are a convenience feature in Minetest to allow quick transfer of an itemstack from one inventory list to another with Shift+Click. Basically, listrings group several inventory lists together in a “ring” data structure. A shift-click will transfer an itemstack from one inventory list to the next inventory list in the listrings, and, if it is the final inventory list in the listring, it will be sent to the first inventory list.

Listrings are documented in lua_api.txt.

Basic modding

How do I install a mod?

See Installing Mods on the Minetest Wiki.

Where do I find tutorials and documentation about modding?

(related Category:Modding API‏‎)
Start on the Main Page here at the Minetest Developer Wiki. It isn't just about changing the Minetest (C++) core program. There are articles and references about modding you can find right from the main page. Look for the "Develop a mod" and "Modding API" headings. The Developer Wiki is very much a community project, so don't forget to come back and help document what you find!

Lua basics

Minetest modding

  • Introduction to the modding API on the wiki.
  • Minetest Modding Book an online clear and easy guide in learning to make mods.
  • lua_api.txt in minetest/docs/ contains an API Listing (HTML Version). Those links are to the latest development version, look in your docs/ folder for one specific to your Minetest version.
  • Youtube tutorials Probably the largest collection of Minetest video tutorials available online.
  • Search the forum by web search (eg: googling) like this: "some search terms site:forum.minetest.net".
  • Ask the community for help in the Modding General section of the forum.

How do I debug my mod?

The "lua" interpreter is not very useful for debugging mod code, because mods are built to run in an environment specific to Minetest (they expect to be loaded after their dependencies, have access to the Minetest API, etc.). However, you may be able to break pieces of your logic into separate, stand-alone Lua library files that are not specific to Minetest. Where you have an opportunity to do this, testing outside of Minetest (using Lua 5.1's "lua" interpreter or LuaJIT's "luajit" interpreter) can be helpful. This might work for some utility functions and "class libraries".

There is no debugger built into Minetest itself, but there are a few functions that can help (see Category:Debugging). Using these functions is generally equivalent to using "printf style debugging", meaning you'll have to modify your mod code and restart the server when you want to deduce what is going on, or carefully plan for debug logging in your code and provide some kind of debug level or flags. There is also a LuaCmd mod that allows players having adequate permissions to execute Lua statements from Minetest's chat console, but using it to examine the state of your mod is limited to your public API (in other words, functions and variables you have put in a global table named after your mod, rather than local variables defined in your mod files).

Specific questions regarding node definitions


How do I add a new node?

See minetest.register_node.

How can I make my new nodes transparent in certain sections?


To make a node have transparent patches, you need to do two things: Have your image texture be transparent where you need it to be, and second, you need to specify the node's drawtype to be one of the following: "glasslike", "glasslike_framed", "allfaces", or "allfaces_optional".

What if I only want it partially transparent, such as with tinted glass?


To do this, add use_texture_alpha = true to the node definition while following the directions above.

How do I generate a custom map?

First, there are a bunch of mapgen parameters you can change for the built-in mapgens, so you might be able to get what you want without touching Lua at all. You may also be able to find an existing mod that does what you want, so check the mod list on the main Minetest Wiki and the Mod Releases section of the forums (the community has already written several mods for various map generation, importing real-world data, editing sections of existing worlds, etc.). Finally, the Lua modding API has recently been enhanced to make custom mapgens more feasible to write without modifying the core Minetest engine. It's not for the faint of heart but if you want to dive in, start by reading up on:

This is a pretty advanced task to do in a mod, so expect to also have to do some digging and research in the lua_api.txt document.

Advanced modding

How do I properly balance the biomes?

As decribed in lua_api.txt, biomes are defined by heat and humidity points in a Voronoi diagram, with heat and humidity usually ranging from 0 and 100, but in extreme cases they can even reach -25 and 125.

Paramat shows how it works for Minetest Game here: [1]

GeoGebra is a software tool which can be used to graphically align the Voronoi cells, making balancing a lot easier. Paramat explained it here: [2]