mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2025-02-06 05:40:21 +01:00
add pick_up and on_pick_up features.
This commit is contained in:
parent
4b825b3e86
commit
c62b013825
36
api.lua
36
api.lua
@ -18,7 +18,7 @@ end
|
|||||||
-- Global table
|
-- Global table
|
||||||
|
|
||||||
mobs = {
|
mobs = {
|
||||||
mod = "redo", version = "20250201",
|
mod = "redo", version = "20250204",
|
||||||
spawning_mobs = {}, translate = S,
|
spawning_mobs = {}, translate = S,
|
||||||
node_snow = has(minetest.registered_aliases["mapgen_snow"])
|
node_snow = has(minetest.registered_aliases["mapgen_snow"])
|
||||||
or has("mcl_core:snow") or has("default:snow") or "air",
|
or has("mcl_core:snow") or has("default:snow") or "air",
|
||||||
@ -1382,6 +1382,35 @@ function mob_class:replace(pos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- look directly around mob to see if it can pickup any dropped items
|
||||||
|
|
||||||
|
function mob_class:check_item_pickup(pos)
|
||||||
|
|
||||||
|
if not self.on_pick_up or not self.pick_up or #self.pick_up == 0 then return end
|
||||||
|
|
||||||
|
for _,o in pairs(minetest.get_objects_inside_radius(pos, 2)) do
|
||||||
|
|
||||||
|
local l = o:get_luaentity()
|
||||||
|
|
||||||
|
if l and l.name == "__builtin:item" then
|
||||||
|
|
||||||
|
for k,v in pairs(self.pick_up) do
|
||||||
|
|
||||||
|
if self.on_pick_up and l.itemstring:find(v) then
|
||||||
|
|
||||||
|
local r = self.on_pick_up(self, l)
|
||||||
|
|
||||||
|
if r and r.is_empty and not r:is_empty() then
|
||||||
|
l.itemstring = r:to_string()
|
||||||
|
elseif r and r.is_empty and r:is_empty() then
|
||||||
|
o:remove()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- check if daytime and also if mob is docile during daylight hours
|
-- check if daytime and also if mob is docile during daylight hours
|
||||||
|
|
||||||
function mob_class:day_docile()
|
function mob_class:day_docile()
|
||||||
@ -3169,6 +3198,9 @@ function mob_class:on_step(dtime, moveresult)
|
|||||||
|
|
||||||
-- node replace check (cow eats grass etc.)
|
-- node replace check (cow eats grass etc.)
|
||||||
self:replace(pos)
|
self:replace(pos)
|
||||||
|
|
||||||
|
-- dropped item pickup check
|
||||||
|
self:check_item_pickup(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- knockback timer
|
-- knockback timer
|
||||||
@ -3328,6 +3360,8 @@ function mobs:register_mob(name, def)
|
|||||||
replace_what = def.replace_what,
|
replace_what = def.replace_what,
|
||||||
replace_with = def.replace_with,
|
replace_with = def.replace_with,
|
||||||
replace_offset = def.replace_offset,
|
replace_offset = def.replace_offset,
|
||||||
|
pick_up = def.pick_up,
|
||||||
|
on_pick_up = def.on_pick_up,
|
||||||
reach = def.reach,
|
reach = def.reach,
|
||||||
texture_list = def.textures,
|
texture_list = def.textures,
|
||||||
texture_mods = def.texture_mods or "",
|
texture_mods = def.texture_mods or "",
|
||||||
|
19
api.txt
19
api.txt
@ -310,6 +310,25 @@ eating.
|
|||||||
properties. (DEPRECATED, use on_replace to make changes).
|
properties. (DEPRECATED, use on_replace to make changes).
|
||||||
|
|
||||||
|
|
||||||
|
Pickup Items
|
||||||
|
------------
|
||||||
|
|
||||||
|
'pick_up' table of itemstrings the mob will pick up.
|
||||||
|
'on_pick_up' function that will be called on item pickup - arguments are
|
||||||
|
(self, itemstring) and can return nil or a a modified itemstack e.g.
|
||||||
|
|
||||||
|
on_pick_up = function(self, itemstring)
|
||||||
|
|
||||||
|
local istack = ItemStack(entity.itemstring)
|
||||||
|
|
||||||
|
print("-- took", istack:get_name())
|
||||||
|
|
||||||
|
istack:take_item(1)
|
||||||
|
|
||||||
|
return istack
|
||||||
|
end,
|
||||||
|
|
||||||
|
|
||||||
Custom Definition Functions
|
Custom Definition Functions
|
||||||
---------------------------
|
---------------------------
|
||||||
|
|
||||||
|
@ -31,6 +31,8 @@ https://forum.minetest.net/viewtopic.php?f=11&t=9917
|
|||||||
* Added {eatable} group to food items and HP in description
|
* Added {eatable} group to food items and HP in description
|
||||||
* Fixed timer bug when attacking
|
* Fixed timer bug when attacking
|
||||||
* Fixed fall damage check when riding mob
|
* Fixed fall damage check when riding mob
|
||||||
|
* Calculate damage before do_punch function called
|
||||||
|
* Add function to check for dropped items and for mob to do something with them
|
||||||
|
|
||||||
### Version 1.61
|
### Version 1.61
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user