From: An0n3m0us Date: Mon, 6 Apr 2020 13:15:50 +0000 (+0100) Subject: Sort items into correct categories (#2612) X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=05fad37b3c5d69b792a4b1998e7d2f13d6f8dbe4;p=oweals%2Fminetest_game.git Sort items into correct categories (#2612) --- diff --git a/game_api.txt b/game_api.txt index fda371c6..6d8b08f7 100644 --- a/game_api.txt +++ b/game_api.txt @@ -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 ---------- diff --git a/mods/creative/inventory.lua b/mods/creative/inventory.lua index 2e93e5ff..ad82a3ea 100644 --- a/mods/creative/inventory.lua +++ b/mods/creative/inventory.lua @@ -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) diff --git a/mods/doors/init.lua b/mods/doors/init.lua index ee4a188c..5bfa1d42 100644 --- a/mods/doors/init.lua +++ b/mods/doors/init.lua @@ -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", diff --git a/mods/xpanes/init.lua b/mods/xpanes/init.lua index 4f4f0f56..e195dbbc 100644 --- a/mods/xpanes/init.lua +++ b/mods/xpanes/init.lua @@ -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",