From ece4c892f451aea6acd72bb481f28db54bea3ff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Tue, 16 Mar 2021 20:19:19 +0100 Subject: [PATCH] Force tools to include levels in their diggroups --- mods/CORE/_mcl_autogroup/init.lua | 12 ++++++----- mods/ITEMS/mcl_tools/init.lua | 36 +++++++++++++++---------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/mods/CORE/_mcl_autogroup/init.lua b/mods/CORE/_mcl_autogroup/init.lua index 503cd3b89b..db6effdda9 100644 --- a/mods/CORE/_mcl_autogroup/init.lua +++ b/mods/CORE/_mcl_autogroup/init.lua @@ -177,13 +177,15 @@ end -- Add the groupcaps from a field in "_mcl_autogroup_groupcaps" to the groupcaps -- of a tool. -local function add_groupcaps(groupcaps, groupcaps_def, efficiency) +local function add_groupcaps(toolname, groupcaps, groupcaps_def, efficiency) for g, capsdef in pairs(groupcaps_def) do local mult = capsdef.tool_multiplier or 1 local uses = capsdef.uses local def = mcl_autogroup.registered_diggroups[g] local max_level = def.levels and #def.levels or 1 - local level = math.min(capsdef.level or max_level, max_level) + + assert(capsdef.level, toolname .. ' is missing level for ' .. g) + local level = math.min(capsdef.level, max_level) if def.levels then groupcaps[g .. "_dig_default"] = get_groupcap(g, false, mult, efficiency, uses) @@ -211,7 +213,7 @@ function mcl_autogroup.can_harvest(nodename, toolname) if tdef then for g, gdef in pairs(tdef._mcl_autogroup_groupcaps) do if ndef.groups[g] then - if not gdef.level or ndef.groups[g] <= gdef.level then + if ndef.groups[g] <= gdef.level then return true end end @@ -223,7 +225,7 @@ function mcl_autogroup.can_harvest(nodename, toolname) if tdef then for g, gdef in pairs(tdef._mcl_autogroup_groupcaps) do if ndef.groups[g] then - if not gdef.level or ndef.groups[g] <= gdef.level then + if ndef.groups[g] <= gdef.level then return true end end @@ -257,7 +259,7 @@ end function mcl_autogroup.get_groupcaps(toolname, efficiency) local tdef = minetest.registered_tools[toolname] local groupcaps = table.copy(tdef.tool_capabilities.groupcaps or {}) - add_groupcaps(groupcaps, tdef._mcl_autogroup_groupcaps, efficiency) + add_groupcaps(toolname, groupcaps, tdef._mcl_autogroup_groupcaps, efficiency) return groupcaps end diff --git a/mods/ITEMS/mcl_tools/init.lua b/mods/ITEMS/mcl_tools/init.lua index 3e5ea1452f..dfe872adb8 100644 --- a/mods/ITEMS/mcl_tools/init.lua +++ b/mods/ITEMS/mcl_tools/init.lua @@ -273,7 +273,7 @@ minetest.register_tool("mcl_tools:shovel_wood", { _repair_material = "group:wood", _mcl_toollike_wield = true, _mcl_autogroup_groupcaps = { - shovely = { tool_multiplier = 2, uses = 60 } + shovely = { tool_multiplier = 2, level = 1, uses = 60 } }, }) minetest.register_tool("mcl_tools:shovel_stone", { @@ -294,7 +294,7 @@ minetest.register_tool("mcl_tools:shovel_stone", { _repair_material = "mcl_core:cobble", _mcl_toollike_wield = true, _mcl_autogroup_groupcaps = { - shovely = { tool_multiplier = 4, uses = 132 } + shovely = { tool_multiplier = 4, level = 3, uses = 132 } }, }) minetest.register_tool("mcl_tools:shovel_iron", { @@ -315,7 +315,7 @@ minetest.register_tool("mcl_tools:shovel_iron", { _repair_material = "mcl_core:iron_ingot", _mcl_toollike_wield = true, _mcl_autogroup_groupcaps = { - shovely = { tool_multiplier = 6, uses = 251 } + shovely = { tool_multiplier = 6, level = 4, uses = 251 } }, }) minetest.register_tool("mcl_tools:shovel_gold", { @@ -336,7 +336,7 @@ minetest.register_tool("mcl_tools:shovel_gold", { _repair_material = "mcl_core:gold_ingot", _mcl_toollike_wield = true, _mcl_autogroup_groupcaps = { - shovely = { tool_multiplier = 12, uses = 33 } + shovely = { tool_multiplier = 12, level = 2, uses = 33 } }, }) minetest.register_tool("mcl_tools:shovel_diamond", { @@ -357,7 +357,7 @@ minetest.register_tool("mcl_tools:shovel_diamond", { _repair_material = "mcl_core:diamond", _mcl_toollike_wield = true, _mcl_autogroup_groupcaps = { - shovely = { tool_multiplier = 8, uses = 1562 } + shovely = { tool_multiplier = 8, level = 5, uses = 1562 } }, }) @@ -379,7 +379,7 @@ minetest.register_tool("mcl_tools:axe_wood", { _repair_material = "group:wood", _mcl_toollike_wield = true, _mcl_autogroup_groupcaps = { - axey = { tool_multiplier = 2, uses = 60 } + axey = { tool_multiplier = 2, level = 1, uses = 60 } }, }) minetest.register_tool("mcl_tools:axe_stone", { @@ -398,7 +398,7 @@ minetest.register_tool("mcl_tools:axe_stone", { _repair_material = "mcl_core:cobble", _mcl_toollike_wield = true, _mcl_autogroup_groupcaps = { - axey = { tool_multiplier = 4, uses = 132 } + axey = { tool_multiplier = 4, level = 3, uses = 132 } }, }) minetest.register_tool("mcl_tools:axe_iron", { @@ -418,7 +418,7 @@ minetest.register_tool("mcl_tools:axe_iron", { _repair_material = "mcl_core:iron_ingot", _mcl_toollike_wield = true, _mcl_autogroup_groupcaps = { - axey = { tool_multiplier = 6, uses = 251 } + axey = { tool_multiplier = 6, level = 4, uses = 251 } }, }) minetest.register_tool("mcl_tools:axe_gold", { @@ -437,7 +437,7 @@ minetest.register_tool("mcl_tools:axe_gold", { _repair_material = "mcl_core:gold_ingot", _mcl_toollike_wield = true, _mcl_autogroup_groupcaps = { - axey = { tool_multiplier = 12, uses = 33 } + axey = { tool_multiplier = 12, level = 2, uses = 33 } }, }) minetest.register_tool("mcl_tools:axe_diamond", { @@ -456,7 +456,7 @@ minetest.register_tool("mcl_tools:axe_diamond", { _repair_material = "mcl_core:diamond", _mcl_toollike_wield = true, _mcl_autogroup_groupcaps = { - axey = { tool_multiplier = 8, uses = 1562 } + axey = { tool_multiplier = 8, level = 5, uses = 1562 } }, }) @@ -498,8 +498,8 @@ minetest.register_tool("mcl_tools:sword_stone", { _repair_material = "mcl_core:cobble", _mcl_toollike_wield = true, _mcl_autogroup_groupcaps = { - swordy = { tool_multiplier = 4, level = 1, uses = 132 }, - swordy_cobweb = { tool_multiplier = 4, level = 1, uses = 132 } + swordy = { tool_multiplier = 4, level = 3, uses = 132 }, + swordy_cobweb = { tool_multiplier = 4, level = 3, uses = 132 } }, }) minetest.register_tool("mcl_tools:sword_iron", { @@ -518,8 +518,8 @@ minetest.register_tool("mcl_tools:sword_iron", { _repair_material = "mcl_core:iron_ingot", _mcl_toollike_wield = true, _mcl_autogroup_groupcaps = { - swordy = { tool_multiplier = 6, level = 1, uses = 251 }, - swordy_cobweb = { tool_multiplier = 6, level = 1, uses = 251 } + swordy = { tool_multiplier = 6, level = 4, uses = 251 }, + swordy_cobweb = { tool_multiplier = 6, level = 4, uses = 251 } }, }) minetest.register_tool("mcl_tools:sword_gold", { @@ -538,8 +538,8 @@ minetest.register_tool("mcl_tools:sword_gold", { _repair_material = "mcl_core:gold_ingot", _mcl_toollike_wield = true, _mcl_autogroup_groupcaps = { - swordy = { tool_multiplier = 12, level = 1, uses = 33 }, - swordy_cobweb = { tool_multiplier = 12, level = 1, uses = 33 } + swordy = { tool_multiplier = 12, level = 2, uses = 33 }, + swordy_cobweb = { tool_multiplier = 12, level = 2, uses = 33 } }, }) minetest.register_tool("mcl_tools:sword_diamond", { @@ -558,8 +558,8 @@ minetest.register_tool("mcl_tools:sword_diamond", { _repair_material = "mcl_core:diamond", _mcl_toollike_wield = true, _mcl_autogroup_groupcaps = { - swordy = { tool_multiplier = 8, level = 1, uses = 1562 }, - swordy_cobweb = { tool_multiplier = 8, level = 1, uses = 1562 } + swordy = { tool_multiplier = 8, level = 5, uses = 1562 }, + swordy_cobweb = { tool_multiplier = 8, level = 5, uses = 1562 } }, })