1
0
Fork 0

Fix crash when cannot get wear for tool

This commit is contained in:
ancientmarinerdev 2023-03-25 00:34:38 +00:00 committed by Gitea
parent b72dbf17a6
commit 6c8113dec8
2 changed files with 14 additions and 3 deletions

View File

@ -300,6 +300,10 @@ 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]
if not tdef then
minetest.log("warning", "Adding wear for tool: " .. tostring(toolname) .. " failed with diggroup: " .. tostring(diggroup))
return nil
end
local uses = tdef._mcl_diggroups[diggroup].uses local uses = tdef._mcl_diggroups[diggroup].uses
return math.ceil(65535 / uses) return math.ceil(65535 / uses)
end end

View File

@ -183,8 +183,10 @@ local make_grass_path = function(itemstack, placer, pointed_thing)
-- Add wear (as if digging a shovely node) -- Add wear (as if digging a shovely node)
local toolname = itemstack:get_name() local toolname = itemstack:get_name()
local wear = mcl_autogroup.get_wear(toolname, "shovely") local wear = mcl_autogroup.get_wear(toolname, "shovely")
if wear then
itemstack:add_wear(wear) itemstack:add_wear(wear)
end end
end
minetest.sound_play({name="default_grass_footstep", gain=1}, {pos = above}, true) minetest.sound_play({name="default_grass_footstep", gain=1}, {pos = above}, true)
minetest.swap_node(pointed_thing.under, {name="mcl_core:grass_path"}) minetest.swap_node(pointed_thing.under, {name="mcl_core:grass_path"})
end end
@ -212,8 +214,11 @@ if minetest.get_modpath("mcl_farming") then
-- Add wear (as if digging a shearsy node) -- Add wear (as if digging a shearsy node)
local toolname = itemstack:get_name() local toolname = itemstack:get_name()
local wear = mcl_autogroup.get_wear(toolname, "shearsy") local wear = mcl_autogroup.get_wear(toolname, "shearsy")
if wear then
itemstack:add_wear(wear) itemstack:add_wear(wear)
end end
end
minetest.sound_play({name="default_grass_footstep", gain=1}, {pos = pointed_thing.above}, true) minetest.sound_play({name="default_grass_footstep", gain=1}, {pos = pointed_thing.above}, true)
local dir = vector.subtract(pointed_thing.under, pointed_thing.above) local dir = vector.subtract(pointed_thing.under, pointed_thing.above)
local param2 = minetest.dir_to_facedir(dir) local param2 = minetest.dir_to_facedir(dir)
@ -379,9 +384,11 @@ local function make_stripped_trunk(itemstack, placer, pointed_thing)
-- Add wear (as if digging a axey node) -- Add wear (as if digging a axey node)
local toolname = itemstack:get_name() local toolname = itemstack:get_name()
local wear = mcl_autogroup.get_wear(toolname, "axey") local wear = mcl_autogroup.get_wear(toolname, "axey")
if wear then
itemstack:add_wear(wear) itemstack:add_wear(wear)
end end
end end
end
return itemstack return itemstack
end end