add mobs item pickup

This commit is contained in:
cora 2022-05-19 05:43:37 +02:00
parent 4ac41a793e
commit e6b65af3b4
2 changed files with 23 additions and 2 deletions

View file

@ -2935,6 +2935,20 @@ function mobs:gopath(self,target,callback_arrived)
end end
end end
local function check_item_pickup(self)
if self.pick_up and #self.pick_up > 0 then
for _,o in pairs(minetest.get_objects_inside_radius(self.object:get_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
if self.on_pick_up(self,l) == nil then o:remove() end
end
end
end
end
end
end
-- falling and fall damage -- falling and fall damage
-- returns true if mob died -- returns true if mob died
@ -3536,7 +3550,7 @@ end
-- main mob function -- main mob function
local mob_step = function(self, dtime) local mob_step = function(self, dtime)
check_item_pickup(self)
if not self.fire_resistant then if not self.fire_resistant then
mcl_burning.tick(self.object, dtime, self) mcl_burning.tick(self.object, dtime, self)
end end
@ -3964,7 +3978,8 @@ minetest.register_entity(name, {
child = def.child or false, child = def.child or false,
texture_mods = {}, texture_mods = {},
shoot_arrow = def.shoot_arrow, shoot_arrow = def.shoot_arrow,
sounds_child = def.sounds_child, sounds_child = def.sounds_child,
pick_up = def.pick_up,
explosion_strength = def.explosion_strength, explosion_strength = def.explosion_strength,
suffocation_timer = 0, suffocation_timer = 0,
follow_velocity = def.follow_velocity or 2.4, follow_velocity = def.follow_velocity or 2.4,
@ -3988,6 +4003,8 @@ minetest.register_entity(name, {
on_grown = def.on_grown, on_grown = def.on_grown,
on_pick_up = def.on_pick_up,
on_detach_child = mob_detach_child, on_detach_child = mob_detach_child,
on_activate = function(self, staticdata, dtime) on_activate = function(self, staticdata, dtime)

View file

@ -1239,6 +1239,10 @@ mobs:register_mob("mobs_mc:villager", {
_id = nil, _id = nil,
_profession = "unemployed", _profession = "unemployed",
look_at_player = true, look_at_player = true,
pick_up = {"mcl_farming:bread"},
on_pick_up = function(self,itementity)
minetest.log("picked up "..itementity.itemstring)
end,
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)
local trg=vector.new(0,9,0) local trg=vector.new(0,9,0)
if self._jobsite then if self._jobsite then