From d7995d81bbd4b1f8b11342995b78d2cfc6a09a16 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Tue, 7 May 2024 10:34:31 +0000 Subject: [PATCH 01/10] Fix indestructable blocks provided by mods --- mods/CORE/_mcl_autogroup/init.lua | 37 ++++++++++++++++++++++++++++++ mods/ITEMS/mcl_core/nodes_base.lua | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/mods/CORE/_mcl_autogroup/init.lua b/mods/CORE/_mcl_autogroup/init.lua index 8bebba4a8..08f59796b 100644 --- a/mods/CORE/_mcl_autogroup/init.lua +++ b/mods/CORE/_mcl_autogroup/init.lua @@ -309,6 +309,31 @@ function mcl_autogroup.get_wear(toolname, diggroup) return math.ceil(65535 / uses) end +local GROUP_MAP = { + ["choppy"] = "axey", + ["oddly_breakable_by_hand"] = "handy", + ["cracky"] = "pickaxey", + ["crumbly"] = "shovely", +} + +function mcl_autogroup.mod_compatibility(groups, ndef) + local grouped = false + for name,_ in pairs(groups) do + local new_group = GROUP_MAP[name] + if new_group then + groups[new_group] = 1 + ndef.groups[new_group] = 1 + end + if mcl_autogroup.registered_diggroups[name] then + grouped = true + end + end + + if not grouped then + groups.handy = 1 + end +end + local function overwrite() -- Refresh, now that all groups are known. hardness_values = get_hardness_values_for_groups() @@ -317,8 +342,19 @@ local function overwrite() -- hardness_value. Used for quick lookup. local hardness_lookup = get_hardness_lookup_for_groups(hardness_values) + local count = 0 for nname, ndef in pairs(minetest.registered_nodes) do + count = count + 1 local newgroups = table.copy(ndef.groups) + + if not newgroups.indestructable then + ndef.diggable = true + mcl_autogroup.mod_compatibility(newgroups, ndef) + if not ndef._mcl_hardness then + ndef._mcl_hardness = 0 + end + end + if (nname ~= "ignore" and ndef.diggable) then -- Automatically assign the "solid" group for solid nodes if (ndef.walkable == nil or ndef.walkable == true) @@ -363,6 +399,7 @@ local function overwrite() }) end end + minetest.log("verbose","Total registered blocks: "..tostring(count)) for tname, tdef in pairs(minetest.registered_items) do -- Assign groupcaps for digging the registered digging groups diff --git a/mods/ITEMS/mcl_core/nodes_base.lua b/mods/ITEMS/mcl_core/nodes_base.lua index 3ac2b28aa..2c9bde7fb 100644 --- a/mods/ITEMS/mcl_core/nodes_base.lua +++ b/mods/ITEMS/mcl_core/nodes_base.lua @@ -744,7 +744,7 @@ minetest.register_node("mcl_core:bedrock", { S("In the End dimension, starting a fire on this block will create an eternal fire."), tiles = {"mcl_core_bedrock.png"}, stack_max = 64, - groups = {creative_breakable=1, building_block=1, material_stone=1}, + groups = {creative_breakable=1, building_block=1, material_stone=1, indestructable=1}, sounds = mcl_sounds.node_sound_stone_defaults(), is_ground_content = false, on_blast = function() end, From b5a05857eb14f46affdb11b5c3b2b6c4ab75d9b1 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sun, 18 Aug 2024 19:42:13 -0500 Subject: [PATCH 02/10] Add conversion for nodes that shears act on --- mods/CORE/_mcl_autogroup/init.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/mods/CORE/_mcl_autogroup/init.lua b/mods/CORE/_mcl_autogroup/init.lua index 08f59796b..bf7c295c5 100644 --- a/mods/CORE/_mcl_autogroup/init.lua +++ b/mods/CORE/_mcl_autogroup/init.lua @@ -314,6 +314,7 @@ local GROUP_MAP = { ["oddly_breakable_by_hand"] = "handy", ["cracky"] = "pickaxey", ["crumbly"] = "shovely", + ["snappy"] = "shearsy", } function mcl_autogroup.mod_compatibility(groups, ndef) From 28b5e00e371420314b47c668a6d3bff7a2359e7f Mon Sep 17 00:00:00 2001 From: teknomunk Date: Mon, 19 Aug 2024 07:23:11 -0500 Subject: [PATCH 03/10] Add API documentation, change ndef to node_def to match documentation, change log message according to review comment --- mods/CORE/_mcl_autogroup/API.md | 9 +++++++++ mods/CORE/_mcl_autogroup/init.lua | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 mods/CORE/_mcl_autogroup/API.md diff --git a/mods/CORE/_mcl_autogroup/API.md b/mods/CORE/_mcl_autogroup/API.md new file mode 100644 index 000000000..36945ee3c --- /dev/null +++ b/mods/CORE/_mcl_autogroup/API.md @@ -0,0 +1,9 @@ +### Functions + +`mcl_autogroup.group_compatibility(groups, node_def)` + +Adds VoxeLibre-equivalent groups to `node_def.groups`. + +Arguments: +* `groups` - A list of groups to add compatiblity groups for. Normally this is a copy of `node_def.groups`. +* `node_def` - The node defintion to update groups for. diff --git a/mods/CORE/_mcl_autogroup/init.lua b/mods/CORE/_mcl_autogroup/init.lua index bf7c295c5..3d7a47bb4 100644 --- a/mods/CORE/_mcl_autogroup/init.lua +++ b/mods/CORE/_mcl_autogroup/init.lua @@ -317,13 +317,13 @@ local GROUP_MAP = { ["snappy"] = "shearsy", } -function mcl_autogroup.mod_compatibility(groups, ndef) +function mcl_autogroup.group_compatibility(groups, node_def) local grouped = false for name,_ in pairs(groups) do local new_group = GROUP_MAP[name] if new_group then groups[new_group] = 1 - ndef.groups[new_group] = 1 + node_def.groups[new_group] = 1 end if mcl_autogroup.registered_diggroups[name] then grouped = true @@ -350,7 +350,7 @@ local function overwrite() if not newgroups.indestructable then ndef.diggable = true - mcl_autogroup.mod_compatibility(newgroups, ndef) + mcl_autogroup.group_compatibility(newgroups, ndef) if not ndef._mcl_hardness then ndef._mcl_hardness = 0 end @@ -400,7 +400,7 @@ local function overwrite() }) end end - minetest.log("verbose","Total registered blocks: "..tostring(count)) + minetest.log("verbose","Total registered nodes: "..count) for tname, tdef in pairs(minetest.registered_items) do -- Assign groupcaps for digging the registered digging groups From e7978fc51556c33e76aac4a91c06eacf14232f57 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Mon, 19 Aug 2024 18:03:36 -0500 Subject: [PATCH 04/10] Move documentation to correct location, add backticks to existing mcl_autogroups documentation --- mods/CORE/_mcl_autogroup/API.md | 9 --------- mods/CORE/mcl_autogroup/API.md | 18 ++++++++++++------ 2 files changed, 12 insertions(+), 15 deletions(-) delete mode 100644 mods/CORE/_mcl_autogroup/API.md diff --git a/mods/CORE/_mcl_autogroup/API.md b/mods/CORE/_mcl_autogroup/API.md deleted file mode 100644 index 36945ee3c..000000000 --- a/mods/CORE/_mcl_autogroup/API.md +++ /dev/null @@ -1,9 +0,0 @@ -### Functions - -`mcl_autogroup.group_compatibility(groups, node_def)` - -Adds VoxeLibre-equivalent groups to `node_def.groups`. - -Arguments: -* `groups` - A list of groups to add compatiblity groups for. Normally this is a copy of `node_def.groups`. -* `node_def` - The node defintion to update groups for. diff --git a/mods/CORE/mcl_autogroup/API.md b/mods/CORE/mcl_autogroup/API.md index f95516882..d851b0f90 100644 --- a/mods/CORE/mcl_autogroup/API.md +++ b/mods/CORE/mcl_autogroup/API.md @@ -1,28 +1,34 @@ -# mcl_autogroup +# `mcl_autogroup` This mod emulates digging times from MC. -## mcl_autogroup.can_harvest(nodename, toolname, player) +## `mcl_autogroup.can_harvest(nodename, toolname, player)` Return true if `nodename` can be dig with `toolname` by . + * nodename: string, valid nodename * toolname: (optional) string, valid toolname * player: (optinal) ObjectRef, valid player -## mcl_autogroup.get_groupcaps(toolname, efficiency) +## `mcl_autogroup.get_groupcaps(toolname, efficiency)` This function is used to calculate diggroups for tools. WARNING: This function can only be called after mod initialization. * toolname: string, name of the tool being enchanted (like "mcl_tools:diamond_pickaxe") * efficiency: (optional) integer, the efficiency level the tool is enchanted with (default 0) -## mcl_autogroup.get_wear(toolname, diggroup) +## `mcl_autogroup.get_wear(toolname, diggroup)` Return the max wear of `toolname` with `diggroup` WARNING: This function can only be called after mod initialization. * toolname: string, name of the tool used * diggroup: string, the name of the diggroup the tool is used on -## mcl_autogroup.register_diggroup(group, def) +## `mcl_autogroup.register_diggroup(group, def)` * group: string, name of the group to register as a digging group * def: (optional) table, table with information about the diggroup (defaults to {} if unspecified) * level: (optional) string, if specified it is an array containing the names of the different digging levels the digging group supports -## mcl_autogroup.registered_diggroups +## `mcl_autogroup.registered_diggroups` List of registered diggroups, indexed by name. + +## `mcl_autogroup.group_compatibility(groups, node_def)` +Adds VoxeLibre-equivalent groups to `node_def.groups`. +* `groups` - A list of groups to add compatiblity groups for. Normally this is a copy of `node_def.groups`. +* `node_def` - The node defintion to update groups for. From 517024f9c11366588e0446234214876d9698cb66 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Mon, 19 Aug 2024 18:44:33 -0500 Subject: [PATCH 05/10] Finish adding backticks to documentation, switch from indestructable to unbreakable and make nodes with either group indestructable --- mods/CORE/_mcl_autogroup/init.lua | 2 +- mods/CORE/mcl_autogroup/API.md | 22 +++++++++++----------- mods/ITEMS/mcl_core/nodes_base.lua | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/mods/CORE/_mcl_autogroup/init.lua b/mods/CORE/_mcl_autogroup/init.lua index 3d7a47bb4..5f85e9d94 100644 --- a/mods/CORE/_mcl_autogroup/init.lua +++ b/mods/CORE/_mcl_autogroup/init.lua @@ -348,7 +348,7 @@ local function overwrite() count = count + 1 local newgroups = table.copy(ndef.groups) - if not newgroups.indestructable then + if not newgroups.unbreakable and not newgroups.indestructable then ndef.diggable = true mcl_autogroup.group_compatibility(newgroups, ndef) if not ndef._mcl_hardness then diff --git a/mods/CORE/mcl_autogroup/API.md b/mods/CORE/mcl_autogroup/API.md index d851b0f90..4d045aa67 100644 --- a/mods/CORE/mcl_autogroup/API.md +++ b/mods/CORE/mcl_autogroup/API.md @@ -2,28 +2,28 @@ This mod emulates digging times from MC. ## `mcl_autogroup.can_harvest(nodename, toolname, player)` -Return true if `nodename` can be dig with `toolname` by . +Return true if `nodename` can be dig with `toolname` by `player`. -* nodename: string, valid nodename -* toolname: (optional) string, valid toolname -* player: (optinal) ObjectRef, valid player +* `nodename`: string, valid nodename +* `toolname`: (optional) string, valid toolname +* `player`: (optinal) ObjectRef, valid player ## `mcl_autogroup.get_groupcaps(toolname, efficiency)` This function is used to calculate diggroups for tools. WARNING: This function can only be called after mod initialization. -* toolname: string, name of the tool being enchanted (like "mcl_tools:diamond_pickaxe") -* efficiency: (optional) integer, the efficiency level the tool is enchanted with (default 0) +* `toolname`: string, name of the tool being enchanted (like `"mcl_tools:diamond_pickaxe"`) +* `efficiency`: (optional) integer, the efficiency level the tool is enchanted with (default 0) ## `mcl_autogroup.get_wear(toolname, diggroup)` Return the max wear of `toolname` with `diggroup` WARNING: This function can only be called after mod initialization. -* toolname: string, name of the tool used -* diggroup: string, the name of the diggroup the tool is used on +* `toolname`: string, name of the tool used +* `diggroup`: string, the name of the diggroup the tool is used on ## `mcl_autogroup.register_diggroup(group, def)` -* group: string, name of the group to register as a digging group -* def: (optional) table, table with information about the diggroup (defaults to {} if unspecified) - * level: (optional) string, if specified it is an array containing the names of the different digging levels the digging group supports +* `group`: string, name of the group to register as a digging group +* `def`: (optional) table, table with information about the diggroup (defaults to `{}` if unspecified) + * `level`: (optional) string, if specified it is an array containing the names of the different digging levels the digging group supports ## `mcl_autogroup.registered_diggroups` List of registered diggroups, indexed by name. diff --git a/mods/ITEMS/mcl_core/nodes_base.lua b/mods/ITEMS/mcl_core/nodes_base.lua index 2c9bde7fb..790e66c40 100644 --- a/mods/ITEMS/mcl_core/nodes_base.lua +++ b/mods/ITEMS/mcl_core/nodes_base.lua @@ -744,7 +744,7 @@ minetest.register_node("mcl_core:bedrock", { S("In the End dimension, starting a fire on this block will create an eternal fire."), tiles = {"mcl_core_bedrock.png"}, stack_max = 64, - groups = {creative_breakable=1, building_block=1, material_stone=1, indestructable=1}, + groups = {creative_breakable=1, building_block=1, material_stone=1, unbreakable=1}, sounds = mcl_sounds.node_sound_stone_defaults(), is_ground_content = false, on_blast = function() end, From b6164ab6e66c946b8e2628ef75e85841f9c0ab61 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Tue, 20 Aug 2024 07:22:14 -0500 Subject: [PATCH 06/10] Fix spelling --- mods/CORE/_mcl_autogroup/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/CORE/_mcl_autogroup/init.lua b/mods/CORE/_mcl_autogroup/init.lua index 5f85e9d94..7c0b0179d 100644 --- a/mods/CORE/_mcl_autogroup/init.lua +++ b/mods/CORE/_mcl_autogroup/init.lua @@ -348,7 +348,7 @@ local function overwrite() count = count + 1 local newgroups = table.copy(ndef.groups) - if not newgroups.unbreakable and not newgroups.indestructable then + if not newgroups.unbreakable and not newgroups.indestructible then ndef.diggable = true mcl_autogroup.group_compatibility(newgroups, ndef) if not ndef._mcl_hardness then From 5257e7bc807e4bfd2281f95894602c3c03be128f Mon Sep 17 00:00:00 2001 From: teknomunk Date: Mon, 16 Sep 2024 06:10:59 -0500 Subject: [PATCH 07/10] Address review comments --- mods/CORE/_mcl_autogroup/init.lua | 9 ++++----- mods/CORE/mcl_autogroup/API.md | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/mods/CORE/_mcl_autogroup/init.lua b/mods/CORE/_mcl_autogroup/init.lua index 7c0b0179d..b56430bb5 100644 --- a/mods/CORE/_mcl_autogroup/init.lua +++ b/mods/CORE/_mcl_autogroup/init.lua @@ -317,13 +317,12 @@ local GROUP_MAP = { ["snappy"] = "shearsy", } -function mcl_autogroup.group_compatibility(groups, node_def) +function mcl_autogroup.group_compatibility(groups) local grouped = false - for name,_ in pairs(groups) do + for name,old_group_value in pairs(groups) do local new_group = GROUP_MAP[name] if new_group then - groups[new_group] = 1 - node_def.groups[new_group] = 1 + groups[new_group] = old_group_value end if mcl_autogroup.registered_diggroups[name] then grouped = true @@ -350,7 +349,7 @@ local function overwrite() if not newgroups.unbreakable and not newgroups.indestructible then ndef.diggable = true - mcl_autogroup.group_compatibility(newgroups, ndef) + mcl_autogroup.group_compatibility(newgroups) if not ndef._mcl_hardness then ndef._mcl_hardness = 0 end diff --git a/mods/CORE/mcl_autogroup/API.md b/mods/CORE/mcl_autogroup/API.md index 4d045aa67..1e2636877 100644 --- a/mods/CORE/mcl_autogroup/API.md +++ b/mods/CORE/mcl_autogroup/API.md @@ -2,7 +2,7 @@ This mod emulates digging times from MC. ## `mcl_autogroup.can_harvest(nodename, toolname, player)` -Return true if `nodename` can be dig with `toolname` by `player`. +Return true if `nodename` can be dug with `toolname` by `player`. * `nodename`: string, valid nodename * `toolname`: (optional) string, valid toolname From e8b934602684059b7b73a671c02d37f65daf1362 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Mon, 16 Sep 2024 06:27:58 -0500 Subject: [PATCH 08/10] Make blocks breakable when not passing in node definition to mcl_autogroup.group_compatibility() --- mods/CORE/_mcl_autogroup/init.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mods/CORE/_mcl_autogroup/init.lua b/mods/CORE/_mcl_autogroup/init.lua index b56430bb5..2d1bcca63 100644 --- a/mods/CORE/_mcl_autogroup/init.lua +++ b/mods/CORE/_mcl_autogroup/init.lua @@ -355,6 +355,9 @@ local function overwrite() end end + -- Make sure compatibility groups are present for the below logic + ndef.groups = newgroups + if (nname ~= "ignore" and ndef.diggable) then -- Automatically assign the "solid" group for solid nodes if (ndef.walkable == nil or ndef.walkable == true) @@ -394,6 +397,11 @@ local function overwrite() -- group. newgroups["creative_breakable"] = 1 + minetest.log(dump({ + groups = ndef.groups, + newgroups = newgroups, + })) + minetest.override_item(nname, { groups = newgroups }) From dccb07d36fe58036e00ad852e316f91aa213f9ed Mon Sep 17 00:00:00 2001 From: teknomunk Date: Mon, 16 Sep 2024 06:59:31 -0500 Subject: [PATCH 09/10] Remove log dump --- mods/CORE/_mcl_autogroup/init.lua | 5 ----- 1 file changed, 5 deletions(-) diff --git a/mods/CORE/_mcl_autogroup/init.lua b/mods/CORE/_mcl_autogroup/init.lua index 2d1bcca63..5d6afd87e 100644 --- a/mods/CORE/_mcl_autogroup/init.lua +++ b/mods/CORE/_mcl_autogroup/init.lua @@ -397,11 +397,6 @@ local function overwrite() -- group. newgroups["creative_breakable"] = 1 - minetest.log(dump({ - groups = ndef.groups, - newgroups = newgroups, - })) - minetest.override_item(nname, { groups = newgroups }) From a9f50e68afc74fa974a3b521df12a542a308b054 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 1 Jan 2025 11:52:57 -0600 Subject: [PATCH 10/10] Cleanup --- mods/CORE/_mcl_autogroup/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/CORE/_mcl_autogroup/init.lua b/mods/CORE/_mcl_autogroup/init.lua index 5d6afd87e..7fb14ed4b 100644 --- a/mods/CORE/_mcl_autogroup/init.lua +++ b/mods/CORE/_mcl_autogroup/init.lua @@ -143,7 +143,7 @@ local function get_digtimes(group, can_harvest, speed, efficiency) local digtimes = {} - for index, hardness in pairs(hardness_values[group]) do + for _, hardness in pairs(hardness_values[group]) do local digtime = (hardness or 0) / speed if can_harvest then digtime = digtime * 1.5 @@ -231,7 +231,7 @@ function mcl_autogroup.can_harvest(nodename, toolname, player) -- Check if it can be dug by hand if not player or not player:is_player() then return false end local name = player:get_inventory():get_stack("hand", 1):get_name() - local tdef = minetest.registered_items[name] + tdef = minetest.registered_items[name] if tdef then for g, gdef in pairs(tdef._mcl_diggroups) do if ndef.groups[g] then