https://dev.minetest.net/api.php?action=feedcontributions&user=Naj&feedformat=atomMinetest Developer Wiki - User contributions [en]2024-03-28T20:13:23ZUser contributionsMediaWiki 1.35.3https://dev.minetest.net/index.php?title=Mod_interoperability&diff=4415Mod interoperability2018-12-12T16:16:03Z<p>Naj: /* Templates */</p>
<hr />
<div>This page is aimed towards modders and lists a couple of mods and conventions which are known in the community.<br />
<br />
The main goal is to improve interoperability between mods and reduce code duplication. Often it is better to use existing APIs rather than trying to reinvent the wheel to reduce code duplication, redundancy and overall chaos. Of course, deciding to not use existing APIs may still be aviable choice if they do not suit your needs.<br />
<br />
This page will be a permanent work of progress since there are many different mods out there.<br />
<br />
== Mods ==<br />
One way to ensure interoperability is to know what other mods exist out there. This section will show you mods which you can use to achieve a particular task or point you to mods which might need some “special treatment” for maximum interoperability.<br />
<br />
=== Basics ===<br />
This section is about mods and practices which apply to almost every mod.<br />
<br />
==== Internationalization ====<br />
Minetest itself can be translated (mostly the main menu), but Minetest does not support direct translation for mods. This feature has been requested in [https://github.com/minetest/minetest/issues/2270 issue 2270]. In the meanwhile, a few mods have emerged to enable internationalization. Note, however, that mod-based internationalization is rather limited. A major problem with the existing mods is that all clients connected to a server will always see the language used by the server, rather than the language used by the client.<br />
<br />
These mods are known to enable internationalization (only use one mod at once):<br />
<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=4929 Internationalization Library] [intllib]<br />
<br />
==== Help ====<br />
”Help” refers to any form of in-game help, explanations or other things which aim to aid the player in understanding the game.<br />
<br />
===== Help modpack =====<br />
The [https://forum.minetest.net/viewtopic.php?f=9&t=15912 Help] modpack is a sophisticated in-game help system. It allows you to write help texts for almost everything; it could be used to document items, mods or even an entire game, entirely within the game only.<br />
<br />
The following Help mods are relevant for modding:<br />
<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=15912 Item Help] [doc_items]: Allows you to add long item explanations, an usage help and automatically generated help texts for items<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=15912 Lookup Tool] [doc_identifier]: The lookup tool opens up the appropriate help entry on almost everything it punches. It almost works out of the box, but manual intervention from the modder is required for any custom entity<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=15912 Documentation System] [doc]: Low-level core API (for advanced users). Allows you to add your own entries and even entire help categories from scratch. Also has many utility functions<br />
<br />
To get started with this modpack quickly, there's an example mod to demonstrate how to use these mods: [http://repo.or.cz/minetest_doc_example.git doc_example]<br />
<br />
=== General gameplay ===<br />
==== Status effects ====<br />
If you want to add temporary or permanent status effects for players (such as poisoning), you can use this:<br />
<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=9689 Player Effects] [playereffects]<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=14895 Player Monoids] [player_monoids]<br />
<br />
==== RPG-like elements ====<br />
This includes things usually found in RPGs (role-playing games) like stats, leveling up, experience points, quests, etc.<br />
<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=11154 Mana] [mana]: Adds a new player attribute (mana), could be used as resource for magic spells, weapons, tools, etc.<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=13199 Sunburn] [sunburn]: Makes sunlight dangerous, by causing sunburn (damage in direct sunlight)<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=11406 SkillsFramework] [skillsframework] Skills<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=11265 Quest framework] [quests]: Quest framework<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=14222 sys4_quests] [sys4_quests]: Another quest framework, depends on [quests]<br />
<br />
==== Mobs ====<br />
Mobs are non-player creatures to interact with the world, they may be peaceful or attack on sight. Usually they are based on entities. Minetest does not support mobs natively, but if you still want to add custom mobs, you have various mods to choose from, each of them with somewhat different priorities. Most APIs are not compatible which each other, so in general you should only use the API which suits your needs in the best way. If you want to create a game, you have to be very careful with interoperability.<br />
<br />
Note: Only mature mods with their own dedicated API are listed.<br />
Note: There are multiple mods with the short name “mobs”, you can only use one of these mods at once.<br />
<br />
* [https://forum.minetest.net/viewtopic.php?t=9917 Mobs Redo] [mobs] Fork of Simple Mobs, is backwards-compatible to Simple Mobs<br />
* [https://github.com/sapier/mobf_core/ Minetest MOB Framework] [mobf] Very feature-rich Mob API. Probably best known for being used as part of [https://forum.minetest.net/viewtopic.php?f=11&t=629 Animals Modpack]<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=8638 Creatures Mob Engine] [cme]<br />
* [https://forum.minetest.net/viewtopic.php?t=9836 general base for mobs] [mobapi]<br />
* [https://forum.minetest.net/viewtopic.php?t=3063 Simple Mobs] [mobs] One of the oldest mobs mods, many other mobs mods (including Mobs Redo) were forked from this mod.<br />
<br />
See also: [http://wiki.minetest.net/Mobs Mobs page on the Community Wiki]<br />
<br />
==== Protection ====<br />
“Protection” refers to a way to own a certain area in the world and preventing other players to make any changes in this area.<br/><br />
There are mods which add protection nodes, which protect within a range around the placed node, and mods which allow protecting whole chunks. <br />
<br />
Mods should use [[minetest.is_protected]] when testing whether a player owns a specific position. Protection mods simply override this function.<br />
<br />
This section needs to be finished. Notes for general interoperability requirements/recommendations should be added by someone more experienced.<br />
<br />
==== Other gameplay concepts ====<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=4870 Achievements] [awards]: API for adding your own achievements<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=7292 Treasurer] [treasurer]: API for randomly selecting a treasure out of a pool of previously registered treasures<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=15733 Skylayer] [skylayer]: Utility mod to help manage sky layers; supports smooth transitions<br />
<br />
==== Testing for pipeworks fake players ====<br />
[https://forum.minetest.net/viewtopic.php?f=11&t=2155 Pipeworks] [pipeworks] provides automation and creates fake players for that purpose. If you need to, these can be distinguished from real players by the field <code>is_fake_player</code> in their definition.<br />
<br />
=== Nodes ===<br />
==== Templates ====<br />
Many mods offer convenience functions to add new new nodes which follow a simple template, like a fence made from a different kind of wood.<br />
<br />
* Standalone mods<br />
** [https://forum.minetest.net/viewtopic.php?f=11&t=14910 Furniture] [furniture]: Tables, chairs and stools<br />
** [https://forum.minetest.net/viewtopic.php?f=11&t=15724 more shelves] [moreshelves]: Shelves<br />
** [https://forum.minetest.net/viewtopic.php?f=9&t=15265 flower pots] [flowerpots]: Flower pots<br />
** [https://forum.minetest.net/viewtopic.php?f=9&t=15731 Minetest Game Plus] [mtg_plus]: Cups<br />
** [https://forum.minetest.net/viewtopic.php?f=9&t=15399 corrupt shapes] [csh]: Additional shapes: Cylinders and related shapes<br />
** [https://forum.minetest.net/viewtopic.php?f=11&t=10425 mymillwork] [mymillwork]: Additional shapes: Crown moulds, beams, columns, baseboards<br />
** [https://forum.minetest.net/viewtopic.php?f=11&t=13762 kaeza's/VanessaE's signs library] [signs_lib]: Advanced signs<br />
** [https://forum.minetest.net/viewtopic.php?f=11&t=12999 Biome library] [biome_lib]: Growing plants<br />
** [https://github.com/pyrollo/display_api Display API] [display_api]: Nodes with a dynamic display, e.g. digital clocks. See [https://forum.minetest.net/viewtopic.php?f=11&t=13563 Display Modpack]<br />
** [https://github.com/pyrollo/font_api Font API] [font_api]: Make textures from text and fonts. See [https://forum.minetest.net/viewtopic.php?f=11&t=13563 Display Modpack]<br />
** [https://github.com/pyrollo/signs_api Signs API] [signs_api]: Combining Font API and Display API, easy creation of any kind of signs. See [https://forum.minetest.net/viewtopic.php?f=11&t=13563 Display Modpack]<br />
* [https://forum.minetest.net/viewtopic.php?f=15&t=9724 Minetest Game]<br />
** [default]: Fences<br />
** [beds]: Beds<br />
** [doors]: Doors and trapdoors<br />
** [farming]: Farming plants<br />
** [stairs]: Stairs and slabs<br />
** [tnt]: Explosives<br />
** [walls]: Walls<br />
** [xpanes]: Panes<br />
<br />
==== Modifications ====<br />
These mods extend the possibilities of node definitions:<br />
<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=15648 More ways for nodes to fall.] [falling_nodes]: Allows you to define nodes with different falling rules and behaviours<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=15991 Walkover] [walkover]: Adds callback function which is triggered when a player walks over the node<br />
<br />
==== Causing explosions ====<br />
Whenever you want to cause an explosion which affects other nodes, make sure you to try to call the node's [[minetest.register_node#on_blast|on_blast]] method first before using your own explosion handling. The reason for this is that e.g. your explosion could otherwise destroy a node which is normally immune to explosions.<br />
<br />
==== Suffering explosions ====<br />
If you are happy with what explosions caused by other mods do to your block (e.g. destroying it), you don't need to do anything. If you want to custumize the behaviour, define the on_blast method.<br />
<br />
==== Indestructible nodes ====<br />
Making a block truly indestructible in normal gameplay is not really obvious, so here's a tested and proven template which should prevent all well-programmed mods from destroying your block accidentally:<br />
<br />
<pre><br />
minetest.register_node("example:indestructible", {<br />
description = "Indestructible Block",<br />
is_ground_content = false,<br />
on_blast = function() end,<br />
on_destruct = function () end,<br />
can_dig = function() return false end,<br />
diggable = false,<br />
drop = "",<br />
})<br />
</pre><br />
<br />
Note: There is no way a node can “defend” against [[VoxelManip]]. If a mod for gameplay directly uses this without any checking, this is probably a bug in this mod, rather than the mod with the indestructible block.<br />
<br />
==== Destroying nodes ====<br />
Be very careful when you want to destroy a node by calling [[minetest.remove_node]] directly. There is no way a node can “defend” against such a call, so this needs to taken into consideration for interoperability.<br />
<br />
You should only use [[minetest.remove_node]] directly for technical and/or debugging mods, but for actual gameplay, you should do some checks first. Otherwise, you might end up accidentally destroying blocks which are supposed to be indestructible (see above).<br />
<br />
Recommendation: First check if any of the node's callback functions are appropriate to be called (e.g. call on_blast when you create an explosion). If you want to destroy a block in another manner, first check if the node is not indestructible (checking fields like <code>diggable</code> and other fields mentioned above might usually work). If the block does not seem to be indestructible, calling [[minetest.remove_node]] should normally be safe.<br />
<br />
==== Preventing pistons from pushing or pulling your node ====<br />
The [https://forum.minetest.net/viewtopic.php?f=11&t=628 Mesecons] modpack has pistons which are able to push and pull other blocks around. By default, this happens for pretty much all blocks. If you want to prevent this behaviour for your block, you have to explicitly exclude your block.<br />
<br />
To do this for a node “example:myblock”, add the line “mesecons_mvps?” to <code>depends.txt</code> and the following code after the registration function of your node:<br />
<br />
<pre>if minetest.global_exists(mesecon.register_mvps_stopper) then<br />
mesecon.register_mvps_stopper"example:myblock"<br />
end</pre><br />
<br />
==== Matching patterns of nodes ====<br />
The [https://forum.minetest.net/viewtopic.php?f=11&t=14129 multiblock] library provides functions for checking if some group of nodes form a certain structure, while returning "captures" of specific nodes within the structure.<br />
<br />
=== Interface ===<br />
==== Showing status information ====<br />
If you create a new player attribute/stat (like health) and you want to expose it to the interface somehow, you can use:<br />
<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=11153 HUD Bars] [hudbars]: Add your own indicators like the “hearts” for health. Displayed in either a “progress bar”-like fashion, the classic statbars like in vanilla Minetest or a variant of the classic statbars with a simple background<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=13795&p=202584 HUD Monitors API] [hud_monitors]: Simple API to add semi-permanent text messages on the player's screen<br />
<br />
==== Messages ====<br />
For showing messages to players.<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=12720 Central Message] [central_message]: Simple API to show messages at the center of the screen for a short time<br />
<br />
==== Inventory menu enhancements ====<br />
Some mods enhance or change the inventory menu and provide an API to add buttons and other things to the inventory menu. This can come in handy if you have made your own formspec and seek for ways to access them.<br />
<br />
* Simple Fast Inventory [sfinv]: Part of Minetest Game, you can add custom tabs to the inventory menu. See https://rubenwardy.com/minetest_modding_book/en/chapters/sfinv.html<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=16079&p=244441 Simple Fast Inventory Buttons] [sfinv_buttons]: Adds a new tab “More” to the inventory menu of Minetest Game, in which mods can add buttons for doing any action you want<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=12767 Unified Inventory] [unified_inventory]: Supports adding buttons for doing any action you want (undocumented API)<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=6204 Inventory++] [inventory_plus]: Supports adding buttons for adding “sub-menus” to the inventory menu. This mod does not work well together with newer versions of Minetest Game but it may still be usable for some other games<br />
<br />
==== Formspecs ====<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=7553&p=116028 Smart Formspecs] [smartfs]: Simplification and enhancement of the formspec API<br />
* [https://forum.minetest.net/viewtopic.php?t=20109 Select Item] [select_item]: Dialog to select an item<br />
<br />
=== Decorational ===<br />
==== Colors ====<br />
If your mod provides blocks in multiple colors, there are various mods and conventions to consider for ensuring the best interoperability.<br />
<br />
It is strongly recommended you only use colors which follow an agreed-upon set of predefined colors.<br />
A basic set of 15 colors is defined in the “dye” mod in Minetest Game. Read the source code to learn more. Other mods provide an extended set of dyes.<br />
The mod [https://forum.minetest.net/viewtopic.php?id=2178 Unified Dyes] [unifieddyes] extends the set of colors to 90 colors.<br />
<br />
Other specific mods for consideration:<br />
<br />
* Colorization by crafting: Consider if you want to add crafting recipes by adding a dye and your item (like wool in Minetest Game, read it source code to learn how it works)<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=6670 Color Machine] [colormachine]: Coloring support will be provided by the mod itself, as long as the authors update the mod. Your task would to to make sure that the names of the textures and nodes follow naming conventions<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=9170 Paint Roller] [paint_roller]: Use the API of this mod to enable the paint roller to colorize your blocks<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=14274 mypaint] [mypaint]: This mod allows to paint in arbitrary colors using paint buckets and brushes; internally it seems to work very different than the other mods<br />
<br />
==== Other ====<br />
* [https://github.com/pyrollo/display_modpack/tree/master/font_lib Font Lib] [font_lib]: A library for displaying text on entities. Part of [https://forum.minetest.net/viewtopic.php?f=11&t=13563 Display Modpack]<br />
<br />
== Groups ==<br />
Another way for interoperability is by using groups. If used properly, they can greatly increase ease-of-use when other modders want to work with our mod.<br />
The rule of thumb here is that you generally use groups which are already widely used if you can. Only if your needed group does not exist, you should define your own group.<br />
<br />
On this wiki, the [[Groups/Custom groups]] page tries to document the usage of groups and lists some commonly used groups. If your mod defines its own groups and they are *not* just to be used internally, please edit the Groups page to help other modders.<br />
<br />
<br />
[[Category:Mods]]</div>Najhttps://dev.minetest.net/index.php?title=Mod_interoperability&diff=4414Mod interoperability2018-12-12T16:14:16Z<p>Naj: /* Templates */</p>
<hr />
<div>This page is aimed towards modders and lists a couple of mods and conventions which are known in the community.<br />
<br />
The main goal is to improve interoperability between mods and reduce code duplication. Often it is better to use existing APIs rather than trying to reinvent the wheel to reduce code duplication, redundancy and overall chaos. Of course, deciding to not use existing APIs may still be aviable choice if they do not suit your needs.<br />
<br />
This page will be a permanent work of progress since there are many different mods out there.<br />
<br />
== Mods ==<br />
One way to ensure interoperability is to know what other mods exist out there. This section will show you mods which you can use to achieve a particular task or point you to mods which might need some “special treatment” for maximum interoperability.<br />
<br />
=== Basics ===<br />
This section is about mods and practices which apply to almost every mod.<br />
<br />
==== Internationalization ====<br />
Minetest itself can be translated (mostly the main menu), but Minetest does not support direct translation for mods. This feature has been requested in [https://github.com/minetest/minetest/issues/2270 issue 2270]. In the meanwhile, a few mods have emerged to enable internationalization. Note, however, that mod-based internationalization is rather limited. A major problem with the existing mods is that all clients connected to a server will always see the language used by the server, rather than the language used by the client.<br />
<br />
These mods are known to enable internationalization (only use one mod at once):<br />
<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=4929 Internationalization Library] [intllib]<br />
<br />
==== Help ====<br />
”Help” refers to any form of in-game help, explanations or other things which aim to aid the player in understanding the game.<br />
<br />
===== Help modpack =====<br />
The [https://forum.minetest.net/viewtopic.php?f=9&t=15912 Help] modpack is a sophisticated in-game help system. It allows you to write help texts for almost everything; it could be used to document items, mods or even an entire game, entirely within the game only.<br />
<br />
The following Help mods are relevant for modding:<br />
<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=15912 Item Help] [doc_items]: Allows you to add long item explanations, an usage help and automatically generated help texts for items<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=15912 Lookup Tool] [doc_identifier]: The lookup tool opens up the appropriate help entry on almost everything it punches. It almost works out of the box, but manual intervention from the modder is required for any custom entity<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=15912 Documentation System] [doc]: Low-level core API (for advanced users). Allows you to add your own entries and even entire help categories from scratch. Also has many utility functions<br />
<br />
To get started with this modpack quickly, there's an example mod to demonstrate how to use these mods: [http://repo.or.cz/minetest_doc_example.git doc_example]<br />
<br />
=== General gameplay ===<br />
==== Status effects ====<br />
If you want to add temporary or permanent status effects for players (such as poisoning), you can use this:<br />
<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=9689 Player Effects] [playereffects]<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=14895 Player Monoids] [player_monoids]<br />
<br />
==== RPG-like elements ====<br />
This includes things usually found in RPGs (role-playing games) like stats, leveling up, experience points, quests, etc.<br />
<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=11154 Mana] [mana]: Adds a new player attribute (mana), could be used as resource for magic spells, weapons, tools, etc.<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=13199 Sunburn] [sunburn]: Makes sunlight dangerous, by causing sunburn (damage in direct sunlight)<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=11406 SkillsFramework] [skillsframework] Skills<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=11265 Quest framework] [quests]: Quest framework<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=14222 sys4_quests] [sys4_quests]: Another quest framework, depends on [quests]<br />
<br />
==== Mobs ====<br />
Mobs are non-player creatures to interact with the world, they may be peaceful or attack on sight. Usually they are based on entities. Minetest does not support mobs natively, but if you still want to add custom mobs, you have various mods to choose from, each of them with somewhat different priorities. Most APIs are not compatible which each other, so in general you should only use the API which suits your needs in the best way. If you want to create a game, you have to be very careful with interoperability.<br />
<br />
Note: Only mature mods with their own dedicated API are listed.<br />
Note: There are multiple mods with the short name “mobs”, you can only use one of these mods at once.<br />
<br />
* [https://forum.minetest.net/viewtopic.php?t=9917 Mobs Redo] [mobs] Fork of Simple Mobs, is backwards-compatible to Simple Mobs<br />
* [https://github.com/sapier/mobf_core/ Minetest MOB Framework] [mobf] Very feature-rich Mob API. Probably best known for being used as part of [https://forum.minetest.net/viewtopic.php?f=11&t=629 Animals Modpack]<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=8638 Creatures Mob Engine] [cme]<br />
* [https://forum.minetest.net/viewtopic.php?t=9836 general base for mobs] [mobapi]<br />
* [https://forum.minetest.net/viewtopic.php?t=3063 Simple Mobs] [mobs] One of the oldest mobs mods, many other mobs mods (including Mobs Redo) were forked from this mod.<br />
<br />
See also: [http://wiki.minetest.net/Mobs Mobs page on the Community Wiki]<br />
<br />
==== Protection ====<br />
“Protection” refers to a way to own a certain area in the world and preventing other players to make any changes in this area.<br/><br />
There are mods which add protection nodes, which protect within a range around the placed node, and mods which allow protecting whole chunks. <br />
<br />
Mods should use [[minetest.is_protected]] when testing whether a player owns a specific position. Protection mods simply override this function.<br />
<br />
This section needs to be finished. Notes for general interoperability requirements/recommendations should be added by someone more experienced.<br />
<br />
==== Other gameplay concepts ====<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=4870 Achievements] [awards]: API for adding your own achievements<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=7292 Treasurer] [treasurer]: API for randomly selecting a treasure out of a pool of previously registered treasures<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=15733 Skylayer] [skylayer]: Utility mod to help manage sky layers; supports smooth transitions<br />
<br />
==== Testing for pipeworks fake players ====<br />
[https://forum.minetest.net/viewtopic.php?f=11&t=2155 Pipeworks] [pipeworks] provides automation and creates fake players for that purpose. If you need to, these can be distinguished from real players by the field <code>is_fake_player</code> in their definition.<br />
<br />
=== Nodes ===<br />
==== Templates ====<br />
Many mods offer convenience functions to add new new nodes which follow a simple template, like a fence made from a different kind of wood.<br />
<br />
* Standalone mods<br />
** [https://forum.minetest.net/viewtopic.php?f=11&t=14910 Furniture] [furniture]: Tables, chairs and stools<br />
** [https://forum.minetest.net/viewtopic.php?f=11&t=15724 more shelves] [moreshelves]: Shelves<br />
** [https://forum.minetest.net/viewtopic.php?f=9&t=15265 flower pots] [flowerpots]: Flower pots<br />
** [https://forum.minetest.net/viewtopic.php?f=9&t=15731 Minetest Game Plus] [mtg_plus]: Cups<br />
** [https://forum.minetest.net/viewtopic.php?f=9&t=15399 corrupt shapes] [csh]: Additional shapes: Cylinders and related shapes<br />
** [https://forum.minetest.net/viewtopic.php?f=11&t=10425 mymillwork] [mymillwork]: Additional shapes: Crown moulds, beams, columns, baseboards<br />
** [https://forum.minetest.net/viewtopic.php?f=11&t=13762 kaeza's/VanessaE's signs library] [signs_lib]: Advanced signs<br />
** [https://forum.minetest.net/viewtopic.php?f=11&t=12999 Biome library] [biome_lib]: Growing plants<br />
** [https://github.com/pyrollo/display_api Display API] [display_api]: Nodes with a dynamic display, e.g. digital clocks. See [https://forum.minetest.net/viewtopic.php?f=11&t=13563 Display Modpack]<br />
** [https://github.com/pyrollo/font_api Font API] [font_api]: Make textures from text and fonts. See [https://forum.minetest.net/viewtopic.php?f=11&t=13563 Display Modpack]<br />
* [https://forum.minetest.net/viewtopic.php?f=15&t=9724 Minetest Game]<br />
** [default]: Fences<br />
** [beds]: Beds<br />
** [doors]: Doors and trapdoors<br />
** [farming]: Farming plants<br />
** [stairs]: Stairs and slabs<br />
** [tnt]: Explosives<br />
** [walls]: Walls<br />
** [xpanes]: Panes<br />
<br />
==== Modifications ====<br />
These mods extend the possibilities of node definitions:<br />
<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=15648 More ways for nodes to fall.] [falling_nodes]: Allows you to define nodes with different falling rules and behaviours<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=15991 Walkover] [walkover]: Adds callback function which is triggered when a player walks over the node<br />
<br />
==== Causing explosions ====<br />
Whenever you want to cause an explosion which affects other nodes, make sure you to try to call the node's [[minetest.register_node#on_blast|on_blast]] method first before using your own explosion handling. The reason for this is that e.g. your explosion could otherwise destroy a node which is normally immune to explosions.<br />
<br />
==== Suffering explosions ====<br />
If you are happy with what explosions caused by other mods do to your block (e.g. destroying it), you don't need to do anything. If you want to custumize the behaviour, define the on_blast method.<br />
<br />
==== Indestructible nodes ====<br />
Making a block truly indestructible in normal gameplay is not really obvious, so here's a tested and proven template which should prevent all well-programmed mods from destroying your block accidentally:<br />
<br />
<pre><br />
minetest.register_node("example:indestructible", {<br />
description = "Indestructible Block",<br />
is_ground_content = false,<br />
on_blast = function() end,<br />
on_destruct = function () end,<br />
can_dig = function() return false end,<br />
diggable = false,<br />
drop = "",<br />
})<br />
</pre><br />
<br />
Note: There is no way a node can “defend” against [[VoxelManip]]. If a mod for gameplay directly uses this without any checking, this is probably a bug in this mod, rather than the mod with the indestructible block.<br />
<br />
==== Destroying nodes ====<br />
Be very careful when you want to destroy a node by calling [[minetest.remove_node]] directly. There is no way a node can “defend” against such a call, so this needs to taken into consideration for interoperability.<br />
<br />
You should only use [[minetest.remove_node]] directly for technical and/or debugging mods, but for actual gameplay, you should do some checks first. Otherwise, you might end up accidentally destroying blocks which are supposed to be indestructible (see above).<br />
<br />
Recommendation: First check if any of the node's callback functions are appropriate to be called (e.g. call on_blast when you create an explosion). If you want to destroy a block in another manner, first check if the node is not indestructible (checking fields like <code>diggable</code> and other fields mentioned above might usually work). If the block does not seem to be indestructible, calling [[minetest.remove_node]] should normally be safe.<br />
<br />
==== Preventing pistons from pushing or pulling your node ====<br />
The [https://forum.minetest.net/viewtopic.php?f=11&t=628 Mesecons] modpack has pistons which are able to push and pull other blocks around. By default, this happens for pretty much all blocks. If you want to prevent this behaviour for your block, you have to explicitly exclude your block.<br />
<br />
To do this for a node “example:myblock”, add the line “mesecons_mvps?” to <code>depends.txt</code> and the following code after the registration function of your node:<br />
<br />
<pre>if minetest.global_exists(mesecon.register_mvps_stopper) then<br />
mesecon.register_mvps_stopper"example:myblock"<br />
end</pre><br />
<br />
==== Matching patterns of nodes ====<br />
The [https://forum.minetest.net/viewtopic.php?f=11&t=14129 multiblock] library provides functions for checking if some group of nodes form a certain structure, while returning "captures" of specific nodes within the structure.<br />
<br />
=== Interface ===<br />
==== Showing status information ====<br />
If you create a new player attribute/stat (like health) and you want to expose it to the interface somehow, you can use:<br />
<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=11153 HUD Bars] [hudbars]: Add your own indicators like the “hearts” for health. Displayed in either a “progress bar”-like fashion, the classic statbars like in vanilla Minetest or a variant of the classic statbars with a simple background<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=13795&p=202584 HUD Monitors API] [hud_monitors]: Simple API to add semi-permanent text messages on the player's screen<br />
<br />
==== Messages ====<br />
For showing messages to players.<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=12720 Central Message] [central_message]: Simple API to show messages at the center of the screen for a short time<br />
<br />
==== Inventory menu enhancements ====<br />
Some mods enhance or change the inventory menu and provide an API to add buttons and other things to the inventory menu. This can come in handy if you have made your own formspec and seek for ways to access them.<br />
<br />
* Simple Fast Inventory [sfinv]: Part of Minetest Game, you can add custom tabs to the inventory menu. See https://rubenwardy.com/minetest_modding_book/en/chapters/sfinv.html<br />
* [https://forum.minetest.net/viewtopic.php?f=9&t=16079&p=244441 Simple Fast Inventory Buttons] [sfinv_buttons]: Adds a new tab “More” to the inventory menu of Minetest Game, in which mods can add buttons for doing any action you want<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=12767 Unified Inventory] [unified_inventory]: Supports adding buttons for doing any action you want (undocumented API)<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=6204 Inventory++] [inventory_plus]: Supports adding buttons for adding “sub-menus” to the inventory menu. This mod does not work well together with newer versions of Minetest Game but it may still be usable for some other games<br />
<br />
==== Formspecs ====<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=7553&p=116028 Smart Formspecs] [smartfs]: Simplification and enhancement of the formspec API<br />
* [https://forum.minetest.net/viewtopic.php?t=20109 Select Item] [select_item]: Dialog to select an item<br />
<br />
=== Decorational ===<br />
==== Colors ====<br />
If your mod provides blocks in multiple colors, there are various mods and conventions to consider for ensuring the best interoperability.<br />
<br />
It is strongly recommended you only use colors which follow an agreed-upon set of predefined colors.<br />
A basic set of 15 colors is defined in the “dye” mod in Minetest Game. Read the source code to learn more. Other mods provide an extended set of dyes.<br />
The mod [https://forum.minetest.net/viewtopic.php?id=2178 Unified Dyes] [unifieddyes] extends the set of colors to 90 colors.<br />
<br />
Other specific mods for consideration:<br />
<br />
* Colorization by crafting: Consider if you want to add crafting recipes by adding a dye and your item (like wool in Minetest Game, read it source code to learn how it works)<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=6670 Color Machine] [colormachine]: Coloring support will be provided by the mod itself, as long as the authors update the mod. Your task would to to make sure that the names of the textures and nodes follow naming conventions<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=9170 Paint Roller] [paint_roller]: Use the API of this mod to enable the paint roller to colorize your blocks<br />
* [https://forum.minetest.net/viewtopic.php?f=11&t=14274 mypaint] [mypaint]: This mod allows to paint in arbitrary colors using paint buckets and brushes; internally it seems to work very different than the other mods<br />
<br />
==== Other ====<br />
* [https://github.com/pyrollo/display_modpack/tree/master/font_lib Font Lib] [font_lib]: A library for displaying text on entities. Part of [https://forum.minetest.net/viewtopic.php?f=11&t=13563 Display Modpack]<br />
<br />
== Groups ==<br />
Another way for interoperability is by using groups. If used properly, they can greatly increase ease-of-use when other modders want to work with our mod.<br />
The rule of thumb here is that you generally use groups which are already widely used if you can. Only if your needed group does not exist, you should define your own group.<br />
<br />
On this wiki, the [[Groups/Custom groups]] page tries to document the usage of groups and lists some commonly used groups. If your mod defines its own groups and they are *not* just to be used internally, please edit the Groups page to help other modders.<br />
<br />
<br />
[[Category:Mods]]</div>Najhttps://dev.minetest.net/index.php?title=Modding_Intro&diff=4222Modding Intro2018-03-30T08:16:55Z<p>Naj: /* Mod folder structure */</p>
<hr />
<div>Another guide is available:<br />
<br />
<big>'''the [http://rubenwardy.com/minetest_modding_book/ Minetest Modding Online Tutorial Book] is a more complete and easier to understand guide in learning to mod Minetest.'''</big><br />
<br />
-------------------------<br />
<br />
<br />
<br />
<br />
<br />
Minetest has a scripting '''API''' ('''A'''pplication '''P'''rogramming '''I'''nterface), which is used to program '''mods''' (short for "modifications") for the game, extending its features and adding new items.<br />
<br />
This API is accessed using an easy-to-use programming language called Lua.<br />
<br />
The only thing you will need is ''basic'' programming knowledge. If you don't have any programming experience, you can use [http://www.codecademy.com/tracks/javascript Codecademy] to learn. It will teach you the basics of programming (it is JavaScript, not Lua, but still helps).<br />
<br />
More specifically, the version of Lua is 5.1. [http://www.lua.org/manual/5.1/ Reference manual], [http://www.lua.org/pil/ book]<br />
<br />
== Path of user data ==<br />
<br />
See [[Installing_Mods]].<br />
<br />
== Modding basics ==<br />
<br />
=== Types of objects in Minetest ===<br />
<br />
There are the three types of object that can be defined in Minetest. The type of the object is important as it plays a part in the properties of that object.<br />
* '''Node''' ([[minetest.register_node]]): A block from the world.<br />
* '''Tool''' ([[minetest.register_tool]]): A tool/weapon that can dig and damage things according to tool_capabilities.<br />
* '''Craftitem''' ([[minetest.register_craftitem]]): A miscellaneous item.<br />
<br />
=== Mod packs and item names ===<br />
<br />
Each Node, Tool and Craftitem needs a unique name to identify it in the API.<br />
<br />
The name's format is like this: <code>modname:itemname</code>. In this case, the mod is called <code>modname</code> (name is preset by the folder name) and the block is called <code>itemname</code>. In this tutorial, we will make the node <code>tutorial:decowood</code>.<br />
<br />
For example, <code>default:dirt</code> is the unique name for dirt.<br />
<br />
== Mod folder structure==<br />
<br />
The following describes the folder structure of a mod. The only required file is <code>init.lua</code><br />
<pre><br />
mods<br />
|-- modname<br />
| |-- description.txt<br />
| |-- depends.txt<br />
| |-- init.lua<br />
| |-- mod.conf<br />
| |-- readme.md<br />
| |-- screenshot.png<br />
| |-- settingtypes.txt<br />
| |-- textures<br />
| | |-- modname_stuff.png<br />
| | \-- modname_something_else.png<br />
| |-- sounds<br />
| |-- media<br />
| \-- custom_data<br />
|<br />
\-- another_mod<br />
<br />
</pre><br />
* <code>mods</code> — Path to Minetest's mods.<br />
* <code>modname</code> — The name of your mod.<br />
* <code>description.txt</code> — A description of your mod (used by mod managers). The first sentence should be less than 100 characters. It should be enough to describe the mod. Further information can be put into other sentences.<br />
* <code>depends.txt</code> — List of dependencies.<br>List of mods that have to be loaded before loading this mod. A single line contains a single modname.<br />
* <code>init.lua</code> — Main Lua script.<br>The main Lua script. Running this script should register everything it wants to register. Subsequent execution depends on Minetest calling the registered callbacks.<br />
* <code>mod.conf</code> — For now contains only "name = mod_name" but may contain many mod information in the future. See this [https://forum.minetest.net/viewtopic.php?f=47&t=14224 forum thread] for more information.<br />
* <code>readme.md</code> — Martkdown page describing and explaining your mod if you are using github.<br />
* <code>screenshot.png</code> — Screenshot of your mod (used by mod managers). It should be 3:2 with a minimum size of 300x200px.<br />
* <code>[[settingtypes.txt]]</code> — Mods settings displayed in the settings menu.<br />
* <code>textures</code>, <code>sounds</code>, <code>media</code> — Media files (textures, sounds, whatever).<br>These will be transferred to the client and will be available for use by the mod.<br />
<br />
See [https://forum.minetest.net/viewtopic.php?f=47&t=19589 modding standards forum thread] for up to date information about mod files.<br />
<br />
== Define a node ==<br />
<br />
We are going to make a mod that adds a special kind of wood that can only be used for decoration.<br />
<br />
First, create a folder called <code>tutorial</code> in the Minetest mods folder (see [[Installing Mods|installing mods]]).<br />
<br />
Next, create a file called <code>init.lua</code> and paste in the following:<br />
<source><br />
minetest.register_node("tutorial:decowood", {<br />
tiles = {"tutorial_decowood.png"},<br />
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3},<br />
})<br />
</source><br />
<br />
You can download the image by right clicking [https://raw.github.com/Jeija/minetest-modding-tutorial/master/textures/tutorial_decowood.png tutorial_decowood.png] and then click save as.<br />
<br />
The function <source enclose="none">minetest.register_node(name, table)</source> is responsible for adding new blocks to the game. Nodes are blocks as well as torches, signs, etc.<br />
<br />
It takes 2 Parameters: The name of the new block <code>tutorial:decowood</code>, and a table containing the properties of the block.<br />
<br />
The name of the block MUST start with the mod name, followed by a colon, eg. <code>tutorial:</code>.<br />
<br />
In this example we define the following properties:<br />
* <code>tiles</code> — Sets the texture of the block; You can use only 1 texture or multiple textures, separated by commas <code>{"tex1.png", "tex2.png", …}</code>. The game checks for the texture files in ALL textures folders of the game.<br />
* <code>groups</code> — This sets attributes about the block including the time it takes to destroy the block, and the tool required. It also defines that the node will burn when is close to fire or lava.<br />
<br />
== Try it out ==<br />
<br />
Launch the game now, and notice that the mods are automatically loaded and compiled.<br />
<br />
This means when changing the code you simply have to "Exit to Menu" and "Start Game/Connect" again to try out the changes.<br />
<br />
Let's try out our first mod! Open the chat window in-game (press t) and type <code>/giveme tutorial:decowood 99</code>. This will add 99 blocks of the decorative wood to your inventory!<br />
<br />
:{{Template:Note|The "give" privilege is required for the <code>/give</code> and <code>/giveme</code> commands to work. In singleplayer you have this privilege by default. On servers a server admin has to execute <code>/grant player_name give</code>}}<br />
<br />
== Define a crafting recipe ==<br />
<br />
Minetest also uses different crafting recipes. Therefore it is important to know what crafting means and how to code it.<br />
<br />
Crafting means to create tools, blocks and other stuff. Minetest offers a 3 × 3 crafting grid by default with one output slot.<br />
<br />
A stone pickaxe can be made out of 2 sticks and 3 cobblestone:<br />
<pre><br />
C C C <--- S = stick, C = stone group (cobblestone, stone, desert stone, …)<br />
S<br />
S<br />
</pre><br />
<br />
Let's make a crafting recipe for the decorative wood.<br />
<br />
Just add this to your <code>init.lua</code> file:<br />
<source><br />
minetest.register_craft({<br />
output = 'tutorial:decowood 2',<br />
recipe = {<br />
{'default:wood', 'default:wood', ''},<br />
{'default:wood', 'default:wood', ''},<br />
{'', '', ''},<br />
}<br />
})<br />
</source><br />
<br />
The function <source enclose="none">minetest.register_craft()</source> registers a crafting process, it defines the recipe for something.<br />
<br />
It takes 1 parameter which is a table that contains 2 properties: (and an optional third)<br />
* <code>output</code> — which sets the outcome of the crafting process and recipe which is the actual recipe for the output.<br />
* <code>recipe</code> — 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.<br />
* <code>type</code> — if you want to make it a furnace craft add <code>type="cook"</code><br />
<br />
Let's define a cooking recipe to see how that works. This will allow the node to be placed in the top of a furnace which will convert it to another item. Fuel must be added to the bottom of the furnace for the craft to take effect.<br />
<source><br />
minetest.register_craft({<br />
type = "cooking",<br />
recipe = "tutorial:decowood",<br />
output = "default:wood",<br />
})<br />
</source><br />
<br />
Let's also define a fuel recipe. This will allow the node to be placed in the furnace to fuel cooking recipes.<br />
<source><br />
minetest.register_craft({<br />
type = "fuel",<br />
recipe = "tutorial:decowood",<br />
burntime = 7,<br />
})<br />
</source><br />
<br />
You can use the [https://forum.minetest.net/viewtopic.php?f=9&t=5831 craft recipe checker] when modding to check for typos.<br />
<br />
:Why are wooden planks not simply called <code>wood</code> but <code>default:wood</code>?<br />
:Indeed, The name of a node/tool/craftitem object '''must''' be <code>modname:name</code> (with two exceptions: <code>air</code> and <code>ignore</code> which are built-in). In this case, the mod is called <code>tutorial</code> (name is preset by the folder name) and the block is called <code>decowood</code>, so it's <code>tutorial:decowood</code>.<br />
:The <code>default</code> mod is the most important “mod” in Minetest, in fact Minetest itself is more like just a game engine, all the contents, materials, and other stuff are in several mods, like <code>default</code> (standard tools/blocks), <code>bucket</code> (Buckets: Lava/Water), and many more.<br />
:If you want to find out more about these mods and maybe use features they contain, just have a look in their init.lua! <br />
:Windows: <code>Minetest/games/minetest_game/</code><br />
:GNU/Linux, run-in-place: <code>~/.minetest/games/minetest_game/</code><br />
:GNU/Linux, non-run-in-place (such as a package): <code>/usr/share/minetest/games/minetest_game</code><br />
<br />
== Define an ABM ==<br />
<br />
ABMs add actions to blocks. For instance, the tutorial-wood could become normal wood after a few seconds.<br />
<br />
Append this code to your <code>init.lua</code>:<br />
<source><br />
minetest.register_abm({<br />
nodenames = {"tutorial:decowood"},<br />
interval = 30,<br />
chance = 1,<br />
action = function(pos)<br />
minetest.add_node(pos, {name="default:wood"})<br />
end,<br />
})<br />
</source><br />
<br />
Try it out! It's really annoying to see all your decowood creations destroyed after 30 seconds, they simply become normal wood.<br />
<br />
''But how does this work?'' The function <source enclose="none">minetest.register_abm()</source> registers an action for each block of the same type.<br />
* <code>nodenames = {"tutorial:decowood'}</code> means that the action is processed for each decowood block. You could also try <code>"default:stone"</code> instead of that to turn all stone blocks into wood.<br />
* <code>interval</code> = 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!<br />
* <code>chance</code> = 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 (eg. 1:2, 1:3, …).<br />
* <code>action = function(pos)</code> is the function that is actually performed.<br />
<br />
It contains the command <source enclose="none">minetest.add_node()</source>. This takes two parameters:<br />
<br />
First of all the position parameter (more information 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 enough to define what block you can see.<br />
<br />
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:<br />
<source><br />
minetest.register_abm({<br />
nodenames = {"default:dirt_with_grass"},<br />
interval = 2,<br />
chance = 100,<br />
action = function(pos)<br />
pos.y = pos.y + 1<br />
minetest.add_node(pos, {name="default:junglegrass"})<br />
end,<br />
})<br />
</source><br />
<br />
You should already know everything else but the line <code>pos.y=pos.y+1</code>. What is that for?<br />
<br />
To understand it, you should know what a [[position]] variable in Minetest is a table made up out of 3 values: <code>x</code>, <code>y</code> and <code>z</code>.<br />
<br />
<code>x</code> and <code>z</code> are forward/backward; left/right values. <code>y</code> is the up/down value. The player usually spawns near <code>0,0,0</code>.<br />
<br />
The line <code>pos.y = pos.y + 1</code> manipulates the position to 1 block above the dirt-with-grass node.<br />
<br />
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.<br />
<br />
== Where to go next ==<br />
<br />
Have a look at the [http://rubenwardy.com/minetest_modding_book/ Minetest Modding Online Tutorial Book] for more complete guide.<br />
<br />
Check out the [http://minetest.net/forum/viewforum.php?f=11 Mod Releases forum] to see mods that have been published by the community.<br />
<br />
Get mod help from the [https://forum.minetest.net/viewtopic.php?f=9&t=4668 modding questions thread].<br />
<br />
Suggest a mod idea in the [https://forum.minetest.net/viewtopic.php?f=9&t=2434 mod request thread].<br />
<br />
<!--== Credits and afterword ==<br />
''Originally based on rubenwardy's version of Jeija's modding tutorial.''--><br />
<br />
[[Category:Misc]]<br />
[[Category:Modding API]]</div>Najhttps://dev.minetest.net/index.php?title=Mapgen_memory_optimisations&diff=4206Mapgen memory optimisations2018-03-21T08:49:38Z<p>Naj: Created page with "Retranscription of Paramat's [https://forum.minetest.net/viewtopic.php?t=16043 foum topic]. == Perlin noise objects: Only create once == The noise object is created by <code..."</p>
<hr />
<div>Retranscription of Paramat's [https://forum.minetest.net/viewtopic.php?t=16043 foum topic].<br />
<br />
== Perlin noise objects: Only create once ==<br />
<br />
The noise object is created by <code>minetest.get_perlin_map()</code>.<br />
It has to be created inside <code>register_on_generated()</code> to be usable, but only needs to be created once, many mapgen mods create it for every mapchunk, this consumes memory unnecessarily.<br />
<br />
Localise the noise object outside <code>register_on_generated()</code> and initialise it to <code>nil</code>.<br />
See the code below for how to create it once only.<br />
The creation of the perlin noise tables with <code>get3dMap_flat()</code> etc. is done per mapchunk<br />
<br />
<source><br />
local nobj_terrain = nil<br />
local nobj_biome = nil<br />
...<br />
...<br />
-- On generated function<br />
minetest.register_on_generated(function(minp, maxp, seed)<br />
...<br />
...<br />
nobj_terrain = nobj_terrain or minetest.get_perlin_map(np_terrain, chulens3d)<br />
nobj_biome = nobj_biome or minetest.get_perlin_map(np_biome, chulens2d)<br />
<br />
nobj_terrain:get3dMap_flat(minpos3d, nvals_terrain)<br />
nobj_biome:get2dMap_flat(minpos2d, nvals_biome)<br />
...<br />
...<br />
end)<br />
</source><br />
<br />
== Perlin noise tables: Re-use a single table ==<br />
<br />
The Lua table that stores the noise values for a mapchunk is big, especially for 3D noise (80 ^ 3 = 512000 values).<br />
Many Lua mapgens are creating a new table for every mapchunk, while the previous tables are only cleared out slowly by garbage collection, resulting in a large and unnecessary memory use.<br />
<br />
A <code>buffer</code> parameter was added in 0.4.13 to avoid this, a single table is re-used by overwriting the former values.<br />
<br />
For each of the functions with an optional `buffer` parameter: If `buffer` is not<br />
nil, this table will be used to store the result instead of creating a new table.<br />
<br />
#### Methods<br />
* `get2dMap_flat(pos, buffer)`: returns a flat `<size.x * size.y>` element array of 2D noise<br />
with values starting at `pos={x=,y=}`<br />
* `get3dMap_flat(pos, buffer)`: Same as `get2dMap_flat`, but 3D noise<br />
<br />
Localise the noise buffer outside <code>register_on_generated()</code><br />
Use the buffer parameter in <code>get3dMap_flat()</code> etc.<br />
<br />
<source><br />
-- Localise noise buffers<br />
local nvals_terrain = {}<br />
local nvals_biome = {}<br />
...<br />
...<br />
-- On generated function<br />
minetest.register_on_generated(function(minp, maxp, seed)<br />
...<br />
...<br />
nobj_terrain:get3dMap_flat(minpos3d, nvals_terrain)<br />
nobj_biome:get2dMap_flat(minpos2d, nvals_biome)<br />
...<br />
...<br />
end)<br />
</source><br />
<br />
== Lua voxelmanip table: Re-use a single table ==<br />
<br />
The Lua table that stores the node content ids for a mapchunk plus the mapblock shell is big (112 ^ 3 = 1404928 values).<br />
Many Lua mapgens are creating a new table for every mapchunk, while the previous tables are only cleared out slowly by garbage collection, resulting in a large and unnecessary memory use.<br />
<br />
A 'buffer' parameter was added in 0.4.13 to avoid this, a single table is re-used by overwriting the former values.<br />
<br />
Very recently a 'buffer' parameter was also added to 'get_param2_data()', so is only usable there in latest Minetest dev or in Minetest 0.4.15 stable or later.<br />
<br />
* `get_data([buffer])`: Retrieves the node content data loaded into the `VoxelManip` object<br />
* returns raw node data in the form of an array of node content IDs<br />
* if the param `buffer` is present, this table will be used to store the result instead<br />
* `get_param2_data([buffer])`: Gets the raw `param2` data read into the `VoxelManip` object<br />
* Returns an array (indices 1 to volume) of integers ranging from `0` to `255`<br />
* If the param `buffer` is present, this table will be used to store the result instead<br />
<br />
Localise the data buffer outside <code>register_on_generated()</code>.<br />
Use the buffer in <code>get_data()</code> or <code>get_param2_data()</code>.<br />
<br />
<source><br />
-- Localise data buffer<br />
local data = {}<br />
<br />
-- On generated function<br />
minetest.register_on_generated(function(minp, maxp, seed)<br />
...<br />
...<br />
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")<br />
local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}<br />
vm:get_data(data)<br />
...<br />
...<br />
end)<br />
</source><br />
<br />
[[Category:Misc]]<br />
[[Category:Mapgen]]</div>Najhttps://dev.minetest.net/index.php?title=settingtypes.txt&diff=4171settingtypes.txt2018-01-10T10:54:59Z<p>Naj: Created page with "Settingtypes.txt files contains mods settings displayed in the settings menu. Settings can be accessed with minetest.setting_get method. == General format == <source>na..."</p>
<hr />
<div>Settingtypes.txt files contains mods settings displayed in the settings menu.<br />
<br />
Settings can be accessed with [[minetest.setting_get]] method.<br />
<br />
== General format ==<br />
<br />
<source>name (Readable name) type type_args</source><br />
<br />
Note that the parts are separated by exactly one space <br />
<br />
'''type''' can be: <br />
* int <br />
* string <br />
* bool <br />
* float <br />
* enum <br />
* path <br />
* filepath <br />
* key (will be ignored in GUI, since a special key change dialog exists) <br />
* flags <br />
* noise_params_2d <br />
* noise_params_3d <br />
* v3f <br />
<br />
'''type_args''' can be: <br />
<br />
''int'': <br />
<br />
* default <br />
* default min max <br />
''string'':<br />
<br />
* default (if default is not specified then "" is set) <br />
''bool'':<br />
<br />
* default <br />
''float'':<br />
<br />
* default <br />
* default min max <br />
''enum'':<br />
<br />
* default value1,value2,... <br />
''path'':<br />
<br />
* default (if default is not specified then "" is set) <br />
''filepath'':<br />
<br />
* default (if default is not specified then "" is set) <br />
''key'':<br />
<br />
* default <br />
''flags'':<br />
<br />
Flags are always separated by comma without spaces. <br />
* default possible_flags <br />
''noise_params_2d'':<br />
<br />
Format is <offset>, <scale>, (<spreadX>, <spreadY>, <spreadZ>), <seed>, <octaves>, <persistance>, <lacunarity>[, <default flags>] <br />
* default <br />
''noise_params_3d'':<br />
<br />
Format is <offset>, <scale>, (<spreadX>, <spreadY>, <spreadZ>), <seed>, <octaves>, <persistance>, <lacunarity>[, <default flags>] <br />
* default <br />
''v3f'':<br />
<br />
Format is (<X>, <Y>, <Z>) <br />
* default</div>Naj