mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-19 01:21:05 +01:00
Move on_step despawning to separate function
This commit is contained in:
parent
c9c2b874be
commit
5e177c61f6
2 changed files with 28 additions and 23 deletions
|
@ -366,29 +366,8 @@ end
|
||||||
-- main mob function
|
-- main mob function
|
||||||
function mob_class:on_step(dtime)
|
function mob_class:on_step(dtime)
|
||||||
self.lifetimer = self.lifetimer - dtime
|
self.lifetimer = self.lifetimer - dtime
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
-- Despawning: when lifetimer expires, remove mob
|
if self:check_despawn(pos) then return true end
|
||||||
if remove_far
|
|
||||||
and self.can_despawn == true
|
|
||||||
and ((not self.nametag) or (self.nametag == ""))
|
|
||||||
and self.state ~= "attack"
|
|
||||||
and self.following == nil then
|
|
||||||
if self.despawn_immediately or self.lifetimer <= 0 then
|
|
||||||
if spawn_logging then
|
|
||||||
minetest.log("action", "[mcl_mobs] Mob "..self.name.." despawns at "..minetest.pos_to_string(pos, 1) .. " lifetimer ran out")
|
|
||||||
end
|
|
||||||
mcl_burning.extinguish(self.object)
|
|
||||||
self.object:remove()
|
|
||||||
return
|
|
||||||
elseif self.lifetimer <= 10 then
|
|
||||||
if math.random(10) < 4 then
|
|
||||||
self.despawn_immediately = true
|
|
||||||
else
|
|
||||||
self.lifetimer = 20
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local v = self.object:get_velocity()
|
local v = self.object:get_velocity()
|
||||||
local d = 0.85
|
local d = 0.85
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
--lua locals
|
--lua locals
|
||||||
local minetest,vector,math,table = minetest,vector,math,table
|
local math, vector, minetest, mcl_mobs = math, vector, minetest, mcl_mobs
|
||||||
|
local mob_class = mcl_mobs.mob_class
|
||||||
|
|
||||||
local get_node = minetest.get_node
|
local get_node = minetest.get_node
|
||||||
local get_item_group = minetest.get_item_group
|
local get_item_group = minetest.get_item_group
|
||||||
local get_node_light = minetest.get_node_light
|
local get_node_light = minetest.get_node_light
|
||||||
|
@ -722,6 +724,30 @@ if mobs_spawn then
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function mob_class:check_despawn(pos)
|
||||||
|
-- Despawning: when lifetimer expires, remove mob
|
||||||
|
if remove_far
|
||||||
|
and self.can_despawn == true
|
||||||
|
and ((not self.nametag) or (self.nametag == ""))
|
||||||
|
and self.state ~= "attack"
|
||||||
|
and self.following == nil then
|
||||||
|
if self.despawn_immediately or self.lifetimer <= 0 then
|
||||||
|
if spawn_logging then
|
||||||
|
minetest.log("action", "[mcl_mobs] Mob "..self.name.." despawns at "..minetest.pos_to_string(pos, 1) .. " lifetimer ran out")
|
||||||
|
end
|
||||||
|
mcl_burning.extinguish(self.object)
|
||||||
|
self.object:remove()
|
||||||
|
return true
|
||||||
|
elseif self.lifetimer <= 10 then
|
||||||
|
if math.random(10) < 4 then
|
||||||
|
self.despawn_immediately = true
|
||||||
|
else
|
||||||
|
self.lifetimer = 20
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_chatcommand("mobstats",{
|
minetest.register_chatcommand("mobstats",{
|
||||||
privs = { debug = true },
|
privs = { debug = true },
|
||||||
func = function(n,param)
|
func = function(n,param)
|
||||||
|
|
Loading…
Reference in a new issue