mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-26 12:31:05 +01:00
add mobs item pickup
This commit is contained in:
parent
4ac41a793e
commit
e6b65af3b4
2 changed files with 23 additions and 2 deletions
|
@ -2935,6 +2935,20 @@ function mobs:gopath(self,target,callback_arrived)
|
|||
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
|
||||
-- returns true if mob died
|
||||
|
@ -3536,7 +3550,7 @@ end
|
|||
|
||||
-- main mob function
|
||||
local mob_step = function(self, dtime)
|
||||
|
||||
check_item_pickup(self)
|
||||
if not self.fire_resistant then
|
||||
mcl_burning.tick(self.object, dtime, self)
|
||||
end
|
||||
|
@ -3965,6 +3979,7 @@ minetest.register_entity(name, {
|
|||
texture_mods = {},
|
||||
shoot_arrow = def.shoot_arrow,
|
||||
sounds_child = def.sounds_child,
|
||||
pick_up = def.pick_up,
|
||||
explosion_strength = def.explosion_strength,
|
||||
suffocation_timer = 0,
|
||||
follow_velocity = def.follow_velocity or 2.4,
|
||||
|
@ -3988,6 +4003,8 @@ minetest.register_entity(name, {
|
|||
|
||||
on_grown = def.on_grown,
|
||||
|
||||
on_pick_up = def.on_pick_up,
|
||||
|
||||
on_detach_child = mob_detach_child,
|
||||
|
||||
on_activate = function(self, staticdata, dtime)
|
||||
|
|
|
@ -1239,6 +1239,10 @@ mobs:register_mob("mobs_mc:villager", {
|
|||
_id = nil,
|
||||
_profession = "unemployed",
|
||||
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)
|
||||
local trg=vector.new(0,9,0)
|
||||
if self._jobsite then
|
||||
|
|
Loading…
Reference in a new issue