From 627d103b20508a53b7fe69893bfa9d48f6c15c07 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 3 Aug 2017 01:01:44 +0200 Subject: [PATCH] Don't drop when node dug by too weak tool --- mods/ENTITIES/mcl_item_entity/init.lua | 58 ++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index 871c7fd04..8e8cdf47c 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -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