forked from VoxeLibre/VoxeLibre
Fix despawning
This commit is contained in:
parent
97cab0d91f
commit
3093462ee3
|
@ -3406,21 +3406,20 @@ end
|
||||||
-- get entity staticdata
|
-- get entity staticdata
|
||||||
local mob_staticdata = function(self)
|
local mob_staticdata = function(self)
|
||||||
|
|
||||||
--[[
|
|
||||||
-- remove mob when out of range unless tamed
|
-- remove mob when out of range unless tamed
|
||||||
if remove_far
|
if remove_far
|
||||||
and self.can_despawn
|
and self.can_despawn
|
||||||
and self.remove_ok
|
and self.remove_ok
|
||||||
and ((not self.nametag) or (self.nametag == ""))
|
and ((not self.nametag) or (self.nametag == ""))
|
||||||
and self.lifetimer <= 20 then
|
and self.lifetimer <= 20 then
|
||||||
|
minetest.log("action", "Mob "..tostring(self.name).." despawns in mob_staticdata at "..minetest.pos_to_string(self.object:get_pos()))
|
||||||
minetest.log("action", "Mob "..name.." despawns in mob_staticdata at "..minetest.pos_to_string(self.object.get_pos(), 1))
|
|
||||||
mcl_burning.extinguish(self.object)
|
mcl_burning.extinguish(self.object)
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
|
||||||
return ""-- nil
|
return "remove"-- nil
|
||||||
end
|
end
|
||||||
--]]
|
|
||||||
self.remove_ok = true
|
self.remove_ok = true
|
||||||
self.attack = nil
|
self.attack = nil
|
||||||
self.following = nil
|
self.following = nil
|
||||||
|
@ -3456,6 +3455,11 @@ local mob_activate = function(self, staticdata, def, dtime)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if staticdata == "remove" then
|
||||||
|
mcl_burning.extinguish(self.object)
|
||||||
|
self.object:remove()
|
||||||
|
return
|
||||||
|
end
|
||||||
-- load entity variables
|
-- load entity variables
|
||||||
local tmp = minetest.deserialize(staticdata)
|
local tmp = minetest.deserialize(staticdata)
|
||||||
|
|
||||||
|
@ -3623,6 +3627,7 @@ end
|
||||||
|
|
||||||
-- main mob function
|
-- main mob function
|
||||||
local mob_step = function(self, dtime)
|
local mob_step = function(self, dtime)
|
||||||
|
self.lifetimer = self.lifetimer - dtime
|
||||||
check_item_pickup(self)
|
check_item_pickup(self)
|
||||||
check_aggro(self,dtime)
|
check_aggro(self,dtime)
|
||||||
if not self.fire_resistant then
|
if not self.fire_resistant then
|
||||||
|
@ -3836,12 +3841,11 @@ local mob_step = function(self, dtime)
|
||||||
and ((not self.nametag) or (self.nametag == ""))
|
and ((not self.nametag) or (self.nametag == ""))
|
||||||
and self.state ~= "attack"
|
and self.state ~= "attack"
|
||||||
and self.following == nil then
|
and self.following == nil then
|
||||||
|
|
||||||
self.lifetimer = self.lifetimer - dtime
|
|
||||||
if self.despawn_immediately or self.lifetimer <= 0 then
|
if self.despawn_immediately or self.lifetimer <= 0 then
|
||||||
minetest.log("action", "Mob "..self.name.." despawns in mob_step at "..minetest.pos_to_string(pos, 1))
|
minetest.log("action", "Mob "..self.name.." despawns in mob_step at "..minetest.pos_to_string(pos, 1))
|
||||||
mcl_burning.extinguish(self.object)
|
mcl_burning.extinguish(self.object)
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
return
|
||||||
elseif self.lifetimer <= 10 then
|
elseif self.lifetimer <= 10 then
|
||||||
if math.random(10) < 4 then
|
if math.random(10) < 4 then
|
||||||
self.despawn_immediately = true
|
self.despawn_immediately = true
|
||||||
|
|
|
@ -466,6 +466,15 @@ local function spawn_check(pos,spawn_def)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function mcl_mobs.spawn(pos,id)
|
||||||
|
local def = minetest.registered_entities[id] or minetest.registered_entities["mobs_mc:"..id] or minetest.registered_entities["extra_mobs:"..id]
|
||||||
|
if not def or (def.can_spawn and not def.can_spawn(pos)) or not def.is_mob then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return minetest.add_entity(pos, def.name)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local function spawn_group(p,mob,spawn_on,group_max,group_min)
|
local function spawn_group(p,mob,spawn_on,group_max,group_min)
|
||||||
if not group_min then group_min = 1 end
|
if not group_min then group_min = 1 end
|
||||||
local nn= minetest.find_nodes_in_area_under_air(vector.offset(p,-5,-3,-5),vector.offset(p,5,3,5),spawn_on)
|
local nn= minetest.find_nodes_in_area_under_air(vector.offset(p,-5,-3,-5),vector.offset(p,5,3,5),spawn_on)
|
||||||
|
@ -488,13 +497,7 @@ local function spawn_group(p,mob,spawn_on,group_max,group_min)
|
||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
function mcl_mobs.spawn(pos,id)
|
mcl_mobs.spawn_group = spawn_group
|
||||||
local def = minetest.registered_entities[id] or minetest.registered_entities["mobs_mc:"..id] or minetest.registered_entities["extra_mobs:"..id]
|
|
||||||
if not def or (def.can_spawn and not def.can_spawn(pos)) or not def.is_mob then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
return minetest.add_entity(pos, def.name)
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.register_chatcommand("spawn_mob",{
|
minetest.register_chatcommand("spawn_mob",{
|
||||||
privs = { debug = true },
|
privs = { debug = true },
|
||||||
|
|
Loading…
Reference in New Issue