From 5c9e057ad1a3b0237c39c33303a728101daf1148 Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Tue, 15 Nov 2022 10:39:59 +0000 Subject: [PATCH] add ability to read 'looting_level' from tool definition and meta for extra drops --- api.lua | 26 ++++++++++++++++++++++---- api.txt | 8 ++++++++ readme.MD | 2 +- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/api.lua b/api.lua index b66d7da..e72ed66 100644 --- a/api.lua +++ b/api.lua @@ -25,7 +25,7 @@ local use_cmi = minetest.global_exists("cmi") mobs = { mod = "redo", - version = "20221031", + version = "20221115", intllib = S, invis = minetest.global_exists("invisibility") and invisibility or {} } @@ -773,8 +773,7 @@ function mob_class:item_drop() local pos = self.object:get_pos() -- check for drops function - self.drops = type(self.drops) == "function" - and self.drops(pos) or self.drops + self.drops = type(self.drops) == "function" and self.drops(pos) or self.drops -- check for nil or no drops if not self.drops or #self.drops == 0 then @@ -786,6 +785,25 @@ function mob_class:item_drop() and self.cause_of_death.puncher and self.cause_of_death.puncher:is_player() + -- check for tool 'looting_level' under tool_capabilities as default, or use + -- meta string 'looting_level' if found (max looting level is 3). + local looting = 0 + + if death_by_player then + + local wield_stack = self.cause_of_death.puncher:get_wielded_item() + local wield_name = wield_stack:get_name() + local wield_stack_meta = wield_stack:get_meta() + local item_def = minetest.registered_items[wield_name] + local item_looting = item_def and item_def.tool_capabilities and + item_def.tool_capabilities.looting_level or 0 + + looting = tonumber(wield_stack_meta:get_string("looting_level")) or item_looting + looting = min(looting, 3) + end + +--print("--- looting level", looting) + local obj, item, num for n = 1, #self.drops do @@ -808,7 +826,7 @@ function mob_class:item_drop() -- only drop rare items (drops.min = 0) if killed by player if death_by_player or self.drops[n].min ~= 0 then - obj = minetest.add_item(pos, ItemStack(item .. " " .. num)) + obj = minetest.add_item(pos, ItemStack(item .. " " .. (num + looting))) end if obj and obj:get_luaentity() then diff --git a/api.txt b/api.txt index 5c424bd..76095ae 100644 --- a/api.txt +++ b/api.txt @@ -715,6 +715,14 @@ This function returns true if the node name given is harmful to the mob (mob_obj it is mainly used when a mob is near a node it has to avoid. +Looting Level +------------- + +If a tool is used with 'looting_level' defined under tool_capabilities then mobs can drop +extra items per level up to a maximum of 3 levels. 'looting_level' can also be read from +the tools own meta to override the default. + + External Settings for "minetest.conf" ------------------------------------ diff --git a/readme.MD b/readme.MD index d0f062f..febcdb8 100644 --- a/readme.MD +++ b/readme.MD @@ -23,7 +23,7 @@ Lucky Blocks: 9 Changelog: -- 1.56 - Added arrow_override function to mob definition to tweak arrow entity settings, tamed monsters no longer despawn when outside loaded map area. +- 1.56 - Added arrow_override function to mob definition to tweak arrow entity settings, tamed monsters no longer despawn when outside loaded map area, 'looting_level' can be read from tool definition or tool meta to add extra drops when mob killed. - 1.55 - Add 'peaceful_player' privelage and setting so mobs don't attack specific players (thanks sfence), add support for MarkBu's pathfinder mod, remove need for default mod - 1.54 - Simplified animal breeding function, added editable settings (thanks Wuzzy), Child mobs now take 20 mins to grow up, reverted to simple mob spawning with setting to use area checks, on_flop added, air_damage added. - 1.53 - Added 'on_map_load' settings to mobs:spawn so that mobs will only spawn when new areas of map are loaded.