mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2024-11-13 05:50:17 +01:00
add ability to read 'looting_level' from tool definition and meta for extra drops
This commit is contained in:
parent
b0df8145bd
commit
5c9e057ad1
26
api.lua
26
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
|
||||
|
|
8
api.txt
8
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"
|
||||
------------------------------------
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue
Block a user