1
0
mirror of https://codeberg.org/tenplus1/mobs_redo.git synced 2025-07-01 16:00:23 +02:00

add ability to read 'looting_level' from tool definition and meta for extra drops

This commit is contained in:
tenplus1
2022-11-15 10:39:59 +00:00
parent b0df8145bd
commit 5c9e057ad1
3 changed files with 31 additions and 5 deletions

26
api.lua
View File

@ -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