1
0
Fork 0

Rename register_digtime_group to register_diggroup

This commit is contained in:
Elias Åström 2021-03-11 15:06:30 +01:00
parent fa86d4e5eb
commit 0c90dda04c
3 changed files with 25 additions and 30 deletions

View File

@ -20,9 +20,9 @@ In MineClone 2, all diggable node have the hardness set in the custom field
"_mcl_hardness" (0 by default). Digging groups are registered using the "_mcl_hardness" (0 by default). Digging groups are registered using the
following code: following code:
mcl_autogroup.register_digtime_group("pickaxey", { levels = 5 }) mcl_autogroup.register_diggroup("pickaxey", { levels = 5 })
mcl_autogroup.register_digtime_group("shovely") mcl_autogroup.register_diggroup("shovely")
mcl_autogroup.register_digtime_group("shovely") mcl_autogroup.register_diggroup("shovely")
The first line registers "pickaxey" as a digging group. The "levels" field The first line registers "pickaxey" as a digging group. The "levels" field
indicates that the digging group have 5 levels (in this case one for each indicates that the digging group have 5 levels (in this case one for each
@ -51,24 +51,18 @@ _mcl_autogroup contains most of the code. The leading underscore in the name
as possible. Minetest loads mods in reverse alphabetical order. as possible. Minetest loads mods in reverse alphabetical order.
--]] --]]
-- The groups which affect dig times
local basegroups = {}
for group, _ in pairs(mcl_autogroup.registered_digtime_groups) do
table.insert(basegroups, group)
end
-- Returns a table containing the unique "_mcl_hardness" for nodes belonging to -- Returns a table containing the unique "_mcl_hardness" for nodes belonging to
-- each basegroup. -- each diggroup.
local function get_hardness_values_for_groups() local function get_hardness_values_for_groups()
local maps = {} local maps = {}
local values = {} local values = {}
for _, g in pairs(basegroups) do for g, _ in pairs(mcl_autogroup.registered_diggroups) do
maps[g] = {} maps[g] = {}
values[g] = {} values[g] = {}
end end
for _, ndef in pairs(minetest.registered_nodes) do for _, ndef in pairs(minetest.registered_nodes) do
for _, g in pairs(basegroups) do for g, _ in pairs(mcl_autogroup.registered_diggroups) do
if ndef.groups[g] ~= nil then if ndef.groups[g] ~= nil then
maps[g][ndef._mcl_hardness or 0] = true maps[g][ndef._mcl_hardness or 0] = true
end end
@ -81,14 +75,14 @@ local function get_hardness_values_for_groups()
end end
end end
for _, g in pairs(basegroups) do for g, _ in pairs(mcl_autogroup.registered_diggroups) do
table.sort(values[g]) table.sort(values[g])
end end
return values return values
end end
-- Returns a table containing a table indexed by "_mcl_hardness_value" to get -- Returns a table containing a table indexed by "_mcl_hardness_value" to get
-- its index in the list of unique hardnesses for each basegroup. -- its index in the list of unique hardnesses for each diggroup.
local function get_hardness_lookup_for_groups(hardness_values) local function get_hardness_lookup_for_groups(hardness_values)
map = {} map = {}
for g, values in pairs(hardness_values) do for g, values in pairs(hardness_values) do
@ -117,7 +111,8 @@ local function compute_creativetimes(group)
return creativetimes return creativetimes
end end
-- Get the list of digging times for using a specific tool on a specific group. -- Get the list of digging times for using a specific tool on a specific
-- diggroup.
-- --
-- Parameters: -- Parameters:
-- group - the group which it is digging -- group - the group which it is digging
@ -190,7 +185,7 @@ local function add_groupcaps(groupcaps, groupcaps_def)
for g, capsdef in pairs(groupcaps_def) do for g, capsdef in pairs(groupcaps_def) do
local mult = capsdef.tool_multiplier or 1 local mult = capsdef.tool_multiplier or 1
local eff = capsdef.efficiency or 0 local eff = capsdef.efficiency or 0
local def = mcl_autogroup.registered_digtime_groups[g] local def = mcl_autogroup.registered_diggroups[g]
local level = capsdef.level or 1 local level = capsdef.level or 1
local max_level = def.levels or 0 local max_level = def.levels or 0
@ -247,7 +242,7 @@ local overwrite = function()
-- Assign groups used for digging this node depending on -- Assign groups used for digging this node depending on
-- the registered digging groups -- the registered digging groups
for g, gdef in pairs(mcl_autogroup.registered_digtime_groups) do for g, gdef in pairs(mcl_autogroup.registered_diggroups) do
local index = hardness_lookup[g][ndef._mcl_hardness] local index = hardness_lookup[g][ndef._mcl_hardness]
if ndef.groups[g] then if ndef.groups[g] then
if gdef.levels then if gdef.levels then

View File

@ -9,8 +9,8 @@ _mcl_autogroup contains most of the code. The leading underscore in the name
as possible. Minetest loads mods in reverse alphabetical order. as possible. Minetest loads mods in reverse alphabetical order.
--]] --]]
mcl_autogroup = {} mcl_autogroup = {}
mcl_autogroup.registered_digtime_groups = {} mcl_autogroup.registered_diggroups = {}
function mcl_autogroup.register_digtime_group(group, def) function mcl_autogroup.register_diggroup(group, def)
mcl_autogroup.registered_digtime_groups[group] = def or {} mcl_autogroup.registered_diggroups[group] = def or {}
end end

View File

@ -3,16 +3,16 @@ mcl_core = {}
-- Repair percentage for toolrepair -- Repair percentage for toolrepair
mcl_core.repair = 0.05 mcl_core.repair = 0.05
mcl_autogroup.register_digtime_group("handy") mcl_autogroup.register_diggroup("handy")
mcl_autogroup.register_digtime_group("pickaxey", { levels = 5 }) mcl_autogroup.register_diggroup("pickaxey", { levels = 5 })
mcl_autogroup.register_digtime_group("axey") mcl_autogroup.register_diggroup("axey")
mcl_autogroup.register_digtime_group("shovely") mcl_autogroup.register_diggroup("shovely")
mcl_autogroup.register_digtime_group("shearsy") mcl_autogroup.register_diggroup("shearsy")
mcl_autogroup.register_digtime_group("shearsy_wool") mcl_autogroup.register_diggroup("shearsy_wool")
mcl_autogroup.register_digtime_group("shearsy_cobweb") mcl_autogroup.register_diggroup("shearsy_cobweb")
mcl_autogroup.register_digtime_group("swordy") mcl_autogroup.register_diggroup("swordy")
mcl_autogroup.register_digtime_group("swordy_cobweb") mcl_autogroup.register_diggroup("swordy_cobweb")
mcl_autogroup.register_digtime_group("creative_breakable") mcl_autogroup.register_diggroup("creative_breakable")
-- Load files -- Load files
local modpath = minetest.get_modpath("mcl_core") local modpath = minetest.get_modpath("mcl_core")