Sort items into correct categories (#2612)
authorAn0n3m0us <an0n3m0us@hotmail.com>
Mon, 6 Apr 2020 13:15:50 +0000 (14:15 +0100)
committerGitHub <noreply@github.com>
Mon, 6 Apr 2020 13:15:50 +0000 (15:15 +0200)
game_api.txt
mods/creative/inventory.lua
mods/doors/init.lua
mods/xpanes/init.lua

index fda371c6fd8fc0690b40dc799918d102d339559b..6d8b08f70a97c0b4c88e838a2ce805478bef6450 100644 (file)
@@ -103,6 +103,13 @@ The contents of `creative.formspec_add` is appended to every creative inventory
 page. Mods can use it to add additional formspec elements onto the default
 creative inventory formspec to be drawn after each update.
 
+Group overrides can be used for any registered item, node or tool. Use one of
+the groups stated below to pick which category it will appear in.
+
+       node = 1      -- Appears in the Nodes category
+       tool = 1      -- Appears in the Tools category
+       craftitem = 1 -- Appears in the Items category
+
 
 Chests API
 ----------
index 2e93e5ff4efa1aa8acbd284dddc9afe76b185987..ad82a3eaf2146ccb63e29ff5ea65edca5fd85756 100644 (file)
@@ -199,10 +199,29 @@ function creative.register_tab(name, title, items)
        })
 end
 
+-- Sort registered items
+local registered_nodes = {}
+local registered_tools = {}
+local registered_craftitems = {}
+
+minetest.register_on_mods_loaded(function()
+       for name, def in pairs(minetest.registered_items) do
+               local group = def.groups or {}
+
+               if group.node or minetest.registered_nodes[name] then
+                       registered_nodes[name] = def
+               elseif group.tool or minetest.registered_tools[name] then
+                       registered_tools[name] = def
+               elseif group.craftitem or minetest.registered_craftitems[name] then
+                       registered_craftitems[name] = def
+               end
+       end
+end)
+
 creative.register_tab("all", S("All"), minetest.registered_items)
-creative.register_tab("nodes", S("Nodes"), minetest.registered_nodes)
-creative.register_tab("tools", S("Tools"), minetest.registered_tools)
-creative.register_tab("craftitems", S("Items"), minetest.registered_craftitems)
+creative.register_tab("nodes", S("Nodes"), registered_nodes)
+creative.register_tab("tools", S("Tools"), registered_tools)
+creative.register_tab("craftitems", S("Items"), registered_craftitems)
 
 local old_homepage_name = sfinv.get_homepage_name
 function sfinv.get_homepage_name(player)
index ee4a188c9c6eb54e464213dfc52c6a1a3bff162a..5bfa1d42e5dd849055105ade80732b95a233cfa1 100644 (file)
@@ -457,7 +457,7 @@ doors.register("door_wood", {
                tiles = {{ name = "doors_door_wood.png", backface_culling = true }},
                description = S("Wooden Door"),
                inventory_image = "doors_item_wood.png",
-               groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
+               groups = {node = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
                recipe = {
                        {"group:wood", "group:wood"},
                        {"group:wood", "group:wood"},
@@ -470,7 +470,7 @@ doors.register("door_steel", {
                description = S("Steel Door"),
                inventory_image = "doors_item_steel.png",
                protected = true,
-               groups = {cracky = 1, level = 2},
+               groups = {node = 1, cracky = 1, level = 2},
                sounds = default.node_sound_metal_defaults(),
                sound_open = "doors_steel_door_open",
                sound_close = "doors_steel_door_close",
@@ -485,7 +485,7 @@ doors.register("door_glass", {
                tiles = {"doors_door_glass.png"},
                description = S("Glass Door"),
                inventory_image = "doors_item_glass.png",
-               groups = {cracky=3, oddly_breakable_by_hand=3},
+               groups = {node = 1, cracky=3, oddly_breakable_by_hand=3},
                sounds = default.node_sound_glass_defaults(),
                sound_open = "doors_glass_door_open",
                sound_close = "doors_glass_door_close",
@@ -500,7 +500,7 @@ doors.register("door_obsidian_glass", {
                tiles = {"doors_door_obsidian_glass.png"},
                description = S("Obsidian Glass Door"),
                inventory_image = "doors_item_obsidian_glass.png",
-               groups = {cracky=3},
+               groups = {node = 1, cracky=3},
                sounds = default.node_sound_glass_defaults(),
                sound_open = "doors_glass_door_open",
                sound_close = "doors_glass_door_close",
index 4f4f0f5654212c8f832fe27b3d11ddd6424e97e3..e195dbbceebb6ed41c79214b6f8cbd29c3cc3a6d 100644 (file)
@@ -223,7 +223,7 @@ if minetest.get_modpath("doors") then
                description = S("Steel Bar Door"),
                inventory_image = "xpanes_item_steel_bar.png",
                protected = true,
-               groups = {cracky = 1, level = 2},
+               groups = {node = 1, cracky = 1, level = 2},
                sounds = default.node_sound_metal_defaults(),
                sound_open = "xpanes_steel_bar_door_open",
                sound_close = "xpanes_steel_bar_door_close",
@@ -241,7 +241,7 @@ if minetest.get_modpath("doors") then
                tile_front = "xpanes_trapdoor_steel_bar.png",
                tile_side = "xpanes_trapdoor_steel_bar_side.png",
                protected = true,
-               groups = {cracky = 1, level = 2, door = 1},
+               groups = {node = 1, cracky = 1, level = 2, door = 1},
                sounds = default.node_sound_metal_defaults(),
                sound_open = "xpanes_steel_bar_door_open",
                sound_close = "xpanes_steel_bar_door_close",