From 28cdeb0a94656e44ac2103a133276f108cf1f284 Mon Sep 17 00:00:00 2001 From: ROllerozxa Date: Mon, 24 Jul 2023 11:48:56 +0000 Subject: [PATCH] Keeping World Compatibility: edit --- pages/Keeping_World_Compatibility.md | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 pages/Keeping_World_Compatibility.md diff --git a/pages/Keeping_World_Compatibility.md b/pages/Keeping_World_Compatibility.md new file mode 100644 index 0000000..294b752 --- /dev/null +++ b/pages/Keeping_World_Compatibility.md @@ -0,0 +1,37 @@ +If your game or mod is stable and played by many players then it is a good idea to keep compatibility with old worlds as much as possible, in order to prevent unknown or glitched nodes showing up in players worlds. + +## Aliases +Nodes and items support itemstring aliases, allowing you to alias an outdated itemstring to a new one. + +```lua +minetest.register_alias('mymod:old_item_name', 'mymod:new_item_name') +``` + +This is also very useful for keeping compatibility when refactoring and/or namespacing technical mod names in a game: + +```lua +for _, item in ipairs{ + "stone", "cobble", "dirt", "grass", -- etc... +} do + minetest.register_alias('oldmodname:'..item, 'game_newmodname:'..item) +end +``` + +## LBMs +LBMs (short for Loading Block Modifiers) can be used to run a callback function on any given nodes in mapblocks that get loaded and activated. They can be useful for doing more complex migrations of nodes that don't just require an itemstring alias, e.g. updating a node's formspec: + +```lua +minetest.register_lbm({ + label = "Update Cool Block formspec to v2", + name = "mymod:update_formspec_coolblock_v2", + nodenames = {"mymod:coolblock"}, + run_at_every_load = false, + action = function(pos, node) + local meta = minetest.get_meta(pos) + if meta:get_int('form_ver') < 2 then + meta:set_int('form_ver', 2) + meta:set_string('formspec', get_coolblock_formspec()) + end + end +}) +``` \ No newline at end of file