Don't drop when node dug by too weak tool

This commit is contained in:
Wuzzy 2017-08-03 01:01:44 +02:00
parent e955be8e03
commit 627d103b20
1 changed files with 58 additions and 0 deletions

View File

@ -154,11 +154,69 @@ minetest.register_globalstep(function(dtime)
end
end)
local minigroups = { "shearsy", "swordy", "shearsy_wool", "swordy_cobweb" }
local basegroups = { "pickaxey", "axey", "shovely" }
local materials = { "wood", "gold", "stone", "iron", "diamond" }
-- Checks if the given node would drop its useful drop if dug by a tool
-- with the given tool capabilities. Returns true if it will yield its useful
-- drop, false otherwise.
local check_can_drop = function(node_name, tool_capabilities)
local handy = minetest.get_item_group(node_name, "handy")
local dig_immediate = minetest.get_item_group(node_name, "dig_immediate")
if handy == 1 or dig_immediate == 2 or dig_immediate == 3 then
return true
else
local toolgroupcaps
if tool_capabilities then
toolgroupcaps = tool_capabilities.groupcaps
else
return false
end
-- Compare node groups with tool capabilities
for m=1, #minigroups do
local minigroup = minigroups[m]
local g = minetest.get_item_group(node_name, minigroup)
if g ~= 0 then
local plus = minigroup .. "_dig"
if toolgroupcaps[plus] then
return true
end
end
end
for b=1, #basegroups do
local basegroup = basegroups[b]
local g = minetest.get_item_group(node_name, basegroup)
if g ~= 0 then
for m=g, #materials do
local plus = basegroup .. "_dig_"..materials[m]
if toolgroupcaps[plus] then
return true
end
end
end
end
return false
end
end
function minetest.handle_node_drops(pos, drops, digger)
local doTileDrops = minetest.setting_getbool("mcl_doTileDrops") or true
if minetest.setting_getbool("creative_mode") or doTileDrops == false then
return
end
-- Check if node will yield its useful drop by the digger's tool
local dug_node = minetest.get_node(pos)
local tool = digger:get_wielded_item()
local toolcaps = tool:get_tool_capabilities()
if not check_can_drop(dug_node.name, toolcaps) then
return
end
for _,item in ipairs(drops) do
local count, name
if type(item) == "string" then