1
0
Fork 0

Rename _mcl_autogroup_groupcaps to _mcl_diggroups

dyable-leather-armor
Elias Åström 2021-03-16 20:36:38 +01:00
parent 7b93f68ed8
commit cff0130506
4 changed files with 38 additions and 40 deletions

4
API.md
View File

@ -18,8 +18,8 @@ Items can have these fields:
See `mcl_banners` for an example. See `mcl_banners` for an example.
Tools can have these fields: Tools can have these fields:
* `_mcl_autogroup_groupcaps`: Specifies the digging groups that a tool can dig * `_mcl_diggroups`: Specifies the digging groups that a tool can dig and how
and how efficiently. See `_mcl_autogroup` for more information. efficiently. See `_mcl_autogroup` for more information.
All nodes can have these fields: All nodes can have these fields:

View File

@ -38,11 +38,11 @@ the group indicates which digging level the node requires.
pickaxe of level 4 be mined. pickaxe of level 4 be mined.
For tools to be able to dig nodes of digging groups they need to use the have For tools to be able to dig nodes of digging groups they need to use the have
the custom field "_mcl_autogroup_groupcaps" function to get the groupcaps. The the custom field "_mcl_diggroups" function to get the groupcaps. The value of
value of this field is a table which defines which groups the tool can dig and this field is a table which defines which groups the tool can dig and how
how efficiently. efficiently.
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
handy = { tool_multiplier = 1, level = 1, uses = 0 }, handy = { tool_multiplier = 1, level = 1, uses = 0 },
pickaxey = { tool_multiplier = 1, level = 0, uses = 0 }, pickaxey = { tool_multiplier = 1, level = 0, uses = 0 },
} }
@ -54,8 +54,7 @@ dig speed on that digging group.
The "level" field indicates which levels of the group the tool can harvest. A The "level" field indicates which levels of the group the tool can harvest. A
level of 0 means that the tool cannot harvest blocks of that node. A level of 1 level of 0 means that the tool cannot harvest blocks of that node. A level of 1
or above means that the tool can harvest nodes with that level or below. See or above means that the tool can harvest nodes with that level or below. See
"mcl_tools/init.lua" for examples on how "_mcl_autogroup_groupcaps" is used in "mcl_tools/init.lua" for examples on how "_mcl_diggroups" is used in practice.
practice.
Information about the mod Information about the mod
========================= =========================
@ -175,8 +174,8 @@ local function get_groupcap(group, can_harvest, multiplier, efficiency, uses)
} }
end end
-- Add the groupcaps from a field in "_mcl_autogroup_groupcaps" to the groupcaps -- Add the groupcaps from a field in "_mcl_diggroups" to the groupcaps of a
-- of a tool. -- tool.
local function add_groupcaps(toolname, groupcaps, groupcaps_def, efficiency) local function add_groupcaps(toolname, groupcaps, groupcaps_def, efficiency)
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
@ -211,7 +210,7 @@ function mcl_autogroup.can_harvest(nodename, toolname)
-- Check if it can be dug by tool -- Check if it can be dug by tool
local tdef = minetest.registered_tools[toolname] local tdef = minetest.registered_tools[toolname]
if tdef then if tdef then
for g, gdef in pairs(tdef._mcl_autogroup_groupcaps) do for g, gdef in pairs(tdef._mcl_diggroups) do
if ndef.groups[g] then if ndef.groups[g] then
if ndef.groups[g] <= gdef.level then if ndef.groups[g] <= gdef.level then
return true return true
@ -223,7 +222,7 @@ function mcl_autogroup.can_harvest(nodename, toolname)
-- Check if it can be dug by hand -- Check if it can be dug by hand
local tdef = minetest.registered_tools[""] local tdef = minetest.registered_tools[""]
if tdef then if tdef then
for g, gdef in pairs(tdef._mcl_autogroup_groupcaps) do for g, gdef in pairs(tdef._mcl_diggroups) do
if ndef.groups[g] then if ndef.groups[g] then
if ndef.groups[g] <= gdef.level then if ndef.groups[g] <= gdef.level then
return true return true
@ -259,7 +258,7 @@ end
function mcl_autogroup.get_groupcaps(toolname, efficiency) function mcl_autogroup.get_groupcaps(toolname, efficiency)
local tdef = minetest.registered_tools[toolname] local tdef = minetest.registered_tools[toolname]
local groupcaps = table.copy(tdef.tool_capabilities.groupcaps or {}) local groupcaps = table.copy(tdef.tool_capabilities.groupcaps or {})
add_groupcaps(toolname, groupcaps, tdef._mcl_autogroup_groupcaps, efficiency) add_groupcaps(toolname, groupcaps, tdef._mcl_diggroups, efficiency)
return groupcaps return groupcaps
end end
@ -275,7 +274,7 @@ end
-- loading order. -- loading order.
function mcl_autogroup.get_wear(toolname, diggroup) function mcl_autogroup.get_wear(toolname, diggroup)
local tdef = minetest.registered_tools[toolname] local tdef = minetest.registered_tools[toolname]
local uses = tdef._mcl_autogroup_groupcaps[diggroup].uses local uses = tdef._mcl_diggroups[diggroup].uses
return math.ceil(65535 / uses) return math.ceil(65535 / uses)
end end
@ -321,9 +320,8 @@ local overwrite = function()
for tname, tdef in pairs(minetest.registered_tools) do for tname, tdef in pairs(minetest.registered_tools) do
-- Assign groupcaps for digging the registered digging groups -- Assign groupcaps for digging the registered digging groups
-- depending on the _mcl_autogroup_groupcaps in the tool -- depending on the _mcl_diggroups in the tool definition
-- definition if tdef._mcl_diggroups then
if tdef._mcl_autogroup_groupcaps then
local toolcaps = table.copy(tdef.tool_capabilities) or {} local toolcaps = table.copy(tdef.tool_capabilities) or {}
toolcaps.groupcaps = mcl_autogroup.get_groupcaps(tname) toolcaps.groupcaps = mcl_autogroup.get_groupcaps(tname)

View File

@ -236,7 +236,7 @@ function minetest.handle_node_drops(pos, drops, digger)
end end
end end
local diggroups = tooldef and tooldef._mcl_autogroup_groupcaps local diggroups = tooldef and tooldef._mcl_diggroups
local shearsy_level = diggroups and diggroups.shearsy and diggroups.shearsy.level local shearsy_level = diggroups and diggroups.shearsy and diggroups.shearsy.level
--[[ Special node drops when dug by shears by reading _mcl_shears_drop or with a silk touch tool reading _mcl_silk_touch_drop --[[ Special node drops when dug by shears by reading _mcl_shears_drop or with a silk touch tool reading _mcl_silk_touch_drop

View File

@ -68,7 +68,7 @@ minetest.register_tool(":", {
damage_groups = {fleshy=1}, damage_groups = {fleshy=1},
}, },
groups = hand_groups, groups = hand_groups,
_mcl_autogroup_groupcaps = hand_autogroup_groupcaps, _mcl_diggroups = hand_autogroup_groupcaps,
}) })
-- Help texts -- Help texts
@ -100,7 +100,7 @@ minetest.register_tool("mcl_tools:pick_wood", {
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
_repair_material = "group:wood", _repair_material = "group:wood",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
pickaxey = { tool_multiplier = 2, level = 1, uses = 60 } pickaxey = { tool_multiplier = 2, level = 1, uses = 60 }
}, },
}) })
@ -120,7 +120,7 @@ minetest.register_tool("mcl_tools:pick_stone", {
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:cobble", _repair_material = "mcl_core:cobble",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
pickaxey = { tool_multiplier = 4, level = 3, uses = 132 } pickaxey = { tool_multiplier = 4, level = 3, uses = 132 }
}, },
}) })
@ -140,7 +140,7 @@ minetest.register_tool("mcl_tools:pick_iron", {
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:iron_ingot", _repair_material = "mcl_core:iron_ingot",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
pickaxey = { tool_multiplier = 6, level = 4, uses = 251 } pickaxey = { tool_multiplier = 6, level = 4, uses = 251 }
}, },
}) })
@ -160,7 +160,7 @@ minetest.register_tool("mcl_tools:pick_gold", {
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:gold_ingot", _repair_material = "mcl_core:gold_ingot",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
pickaxey = { tool_multiplier = 12, level = 2, uses = 33 } pickaxey = { tool_multiplier = 12, level = 2, uses = 33 }
}, },
}) })
@ -180,7 +180,7 @@ minetest.register_tool("mcl_tools:pick_diamond", {
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:diamond", _repair_material = "mcl_core:diamond",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
pickaxey = { tool_multiplier = 8, level = 5, uses = 1562 } pickaxey = { tool_multiplier = 8, level = 5, uses = 1562 }
}, },
}) })
@ -272,7 +272,7 @@ minetest.register_tool("mcl_tools:shovel_wood", {
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
_repair_material = "group:wood", _repair_material = "group:wood",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
shovely = { tool_multiplier = 2, level = 1, uses = 60 } shovely = { tool_multiplier = 2, level = 1, uses = 60 }
}, },
}) })
@ -293,7 +293,7 @@ minetest.register_tool("mcl_tools:shovel_stone", {
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:cobble", _repair_material = "mcl_core:cobble",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
shovely = { tool_multiplier = 4, level = 3, uses = 132 } shovely = { tool_multiplier = 4, level = 3, uses = 132 }
}, },
}) })
@ -314,7 +314,7 @@ minetest.register_tool("mcl_tools:shovel_iron", {
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:iron_ingot", _repair_material = "mcl_core:iron_ingot",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
shovely = { tool_multiplier = 6, level = 4, uses = 251 } shovely = { tool_multiplier = 6, level = 4, uses = 251 }
}, },
}) })
@ -335,7 +335,7 @@ minetest.register_tool("mcl_tools:shovel_gold", {
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:gold_ingot", _repair_material = "mcl_core:gold_ingot",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
shovely = { tool_multiplier = 12, level = 2, uses = 33 } shovely = { tool_multiplier = 12, level = 2, uses = 33 }
}, },
}) })
@ -356,7 +356,7 @@ minetest.register_tool("mcl_tools:shovel_diamond", {
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:diamond", _repair_material = "mcl_core:diamond",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
shovely = { tool_multiplier = 8, level = 5, uses = 1562 } shovely = { tool_multiplier = 8, level = 5, uses = 1562 }
}, },
}) })
@ -378,7 +378,7 @@ minetest.register_tool("mcl_tools:axe_wood", {
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
_repair_material = "group:wood", _repair_material = "group:wood",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
axey = { tool_multiplier = 2, level = 1, uses = 60 } axey = { tool_multiplier = 2, level = 1, uses = 60 }
}, },
}) })
@ -397,7 +397,7 @@ minetest.register_tool("mcl_tools:axe_stone", {
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:cobble", _repair_material = "mcl_core:cobble",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
axey = { tool_multiplier = 4, level = 3, uses = 132 } axey = { tool_multiplier = 4, level = 3, uses = 132 }
}, },
}) })
@ -417,7 +417,7 @@ minetest.register_tool("mcl_tools:axe_iron", {
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:iron_ingot", _repair_material = "mcl_core:iron_ingot",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
axey = { tool_multiplier = 6, level = 4, uses = 251 } axey = { tool_multiplier = 6, level = 4, uses = 251 }
}, },
}) })
@ -436,7 +436,7 @@ minetest.register_tool("mcl_tools:axe_gold", {
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:gold_ingot", _repair_material = "mcl_core:gold_ingot",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
axey = { tool_multiplier = 12, level = 2, uses = 33 } axey = { tool_multiplier = 12, level = 2, uses = 33 }
}, },
}) })
@ -455,7 +455,7 @@ minetest.register_tool("mcl_tools:axe_diamond", {
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:diamond", _repair_material = "mcl_core:diamond",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
axey = { tool_multiplier = 8, level = 5, uses = 1562 } axey = { tool_multiplier = 8, level = 5, uses = 1562 }
}, },
}) })
@ -477,7 +477,7 @@ minetest.register_tool("mcl_tools:sword_wood", {
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
_repair_material = "group:wood", _repair_material = "group:wood",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
swordy = { tool_multiplier = 2, level = 1, uses = 60 }, swordy = { tool_multiplier = 2, level = 1, uses = 60 },
swordy_cobweb = { tool_multiplier = 2, level = 1, uses = 60 } swordy_cobweb = { tool_multiplier = 2, level = 1, uses = 60 }
}, },
@ -497,7 +497,7 @@ minetest.register_tool("mcl_tools:sword_stone", {
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:cobble", _repair_material = "mcl_core:cobble",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
swordy = { tool_multiplier = 4, level = 3, uses = 132 }, swordy = { tool_multiplier = 4, level = 3, uses = 132 },
swordy_cobweb = { tool_multiplier = 4, level = 3, uses = 132 } swordy_cobweb = { tool_multiplier = 4, level = 3, uses = 132 }
}, },
@ -517,7 +517,7 @@ minetest.register_tool("mcl_tools:sword_iron", {
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:iron_ingot", _repair_material = "mcl_core:iron_ingot",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
swordy = { tool_multiplier = 6, level = 4, uses = 251 }, swordy = { tool_multiplier = 6, level = 4, uses = 251 },
swordy_cobweb = { tool_multiplier = 6, level = 4, uses = 251 } swordy_cobweb = { tool_multiplier = 6, level = 4, uses = 251 }
}, },
@ -537,7 +537,7 @@ minetest.register_tool("mcl_tools:sword_gold", {
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:gold_ingot", _repair_material = "mcl_core:gold_ingot",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
swordy = { tool_multiplier = 12, level = 2, uses = 33 }, swordy = { tool_multiplier = 12, level = 2, uses = 33 },
swordy_cobweb = { tool_multiplier = 12, level = 2, uses = 33 } swordy_cobweb = { tool_multiplier = 12, level = 2, uses = 33 }
}, },
@ -557,7 +557,7 @@ minetest.register_tool("mcl_tools:sword_diamond", {
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
_repair_material = "mcl_core:diamond", _repair_material = "mcl_core:diamond",
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
swordy = { tool_multiplier = 8, level = 5, uses = 1562 }, swordy = { tool_multiplier = 8, level = 5, uses = 1562 },
swordy_cobweb = { tool_multiplier = 8, level = 5, uses = 1562 } swordy_cobweb = { tool_multiplier = 8, level = 5, uses = 1562 }
}, },
@ -579,7 +579,7 @@ minetest.register_tool("mcl_tools:shears", {
on_place = carve_pumpkin, on_place = carve_pumpkin,
sound = { breaks = "default_tool_breaks" }, sound = { breaks = "default_tool_breaks" },
_mcl_toollike_wield = true, _mcl_toollike_wield = true,
_mcl_autogroup_groupcaps = { _mcl_diggroups = {
shearsy = { tool_multiplier = 1.5, level = 1, uses = 238 }, shearsy = { tool_multiplier = 1.5, level = 1, uses = 238 },
shearsy_wool = { tool_multiplier = 5, level = 1, uses = 238 }, shearsy_wool = { tool_multiplier = 5, level = 1, uses = 238 },
shearsy_cobweb = { tool_multiplier = 15, level = 1, uses = 238 } shearsy_cobweb = { tool_multiplier = 15, level = 1, uses = 238 }