Merge pull request 'Fix indestructable blocks provided by mods' (#4285) from teknomunk/MineClone2:fix-indestructable-blocks into master

Reviewed-on: https://git.minetest.land/VoxeLibre/VoxeLibre/pulls/4285
Reviewed-by: Mikita Wiśniewski <rudzik8@protonmail.com>
This commit is contained in:
the-real-herowl 2025-01-07 16:18:09 +01:00
commit 71256def7f
3 changed files with 66 additions and 20 deletions

@ -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
@ -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",
["snappy"] = "shearsy",
}
function mcl_autogroup.group_compatibility(groups)
local grouped = false
for name,old_group_value in pairs(groups) do
local new_group = GROUP_MAP[name]
if new_group then
groups[new_group] = old_group_value
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,22 @@ 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.unbreakable and not newgroups.indestructible then
ndef.diggable = true
mcl_autogroup.group_compatibility(newgroups)
if not ndef._mcl_hardness then
ndef._mcl_hardness = 0
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)
@ -363,6 +402,7 @@ local function overwrite()
})
end
end
minetest.log("verbose","Total registered nodes: "..count)
for tname, tdef in pairs(minetest.registered_items) do
-- Assign groupcaps for digging the registered digging groups

@ -1,28 +1,34 @@
# mcl_autogroup
# `mcl_autogroup`
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>.
* nodename: string, valid nodename
* toolname: (optional) string, valid toolname
* player: (optinal) ObjectRef, valid player
## `mcl_autogroup.can_harvest(nodename, toolname, player)`
Return true if `nodename` can be dug with `toolname` by `player`.
## mcl_autogroup.get_groupcaps(toolname, efficiency)
* `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)
## `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
## `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.

@ -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, unbreakable=1},
sounds = mcl_sounds.node_sound_stone_defaults(),
is_ground_content = false,
on_blast = function() end,