mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-11-24 11:53:46 +01:00
Merge pull request 'Standardise despawn logic and add asserts. Add persistent flag for mobs that have been interacted with.' (#3688) from despawn_refactor into master
Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/3688
This commit is contained in:
commit
1694780d3f
@ -78,11 +78,10 @@ function mob_class:get_staticdata()
|
||||
for _,p in pairs(minetest.get_connected_players()) do
|
||||
self:remove_particlespawners(p:get_player_name())
|
||||
end
|
||||
|
||||
-- remove mob when out of range unless tamed
|
||||
if remove_far
|
||||
and self.can_despawn
|
||||
and self.remove_ok
|
||||
and ((not self.nametag) or (self.nametag == ""))
|
||||
and self:despawn_allowed()
|
||||
and self.lifetimer <= 20 then
|
||||
if spawn_logging then
|
||||
minetest.log("action", "[mcl_mobs] Mob "..tostring(self.name).." despawns at "..minetest.pos_to_string(vector.round(self.object:get_pos())) .. " - out of range")
|
||||
@ -91,7 +90,6 @@ function mob_class:get_staticdata()
|
||||
return "remove"-- nil
|
||||
end
|
||||
|
||||
self.remove_ok = true
|
||||
self.attack = nil
|
||||
self.following = nil
|
||||
self.state = "stand"
|
||||
|
@ -74,6 +74,7 @@ function mob_class:feed_tame(clicker, feed_count, breed, tame, notake)
|
||||
if self.food >= feed_count then
|
||||
self.food = 0
|
||||
self.horny = true
|
||||
self.persistent = true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1071,15 +1071,43 @@ if mobs_spawn then
|
||||
end)
|
||||
end
|
||||
|
||||
local function despawn_allowed(self)
|
||||
local nametag = self.nametag and self.nametag ~= ""
|
||||
local not_busy = self.state ~= "attack" and self.following == nil
|
||||
if self.can_despawn == true then
|
||||
if not nametag and not_busy and not self.tamed == true and not self.persistent == true then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mob_class:despawn_allowed()
|
||||
despawn_allowed(self)
|
||||
end
|
||||
|
||||
|
||||
assert(despawn_allowed({can_despawn=false}) == false, "despawn_allowed - can_despawn false failed")
|
||||
assert(despawn_allowed({can_despawn=true}) == true, "despawn_allowed - can_despawn true failed")
|
||||
|
||||
assert(despawn_allowed({can_despawn=true, nametag=""}) == true, "despawn_allowed - blank nametag failed")
|
||||
assert(despawn_allowed({can_despawn=true, nametag=nil}) == true, "despawn_allowed - nil nametag failed")
|
||||
assert(despawn_allowed({can_despawn=true, nametag="bob"}) == false, "despawn_allowed - nametag failed")
|
||||
|
||||
assert(despawn_allowed({can_despawn=true, state="attack"}) == false, "despawn_allowed - attack state failed")
|
||||
assert(despawn_allowed({can_despawn=true, following="blah"}) == false, "despawn_allowed - following state failed")
|
||||
|
||||
assert(despawn_allowed({can_despawn=true, tamed=false}) == true, "despawn_allowed - not tamed")
|
||||
assert(despawn_allowed({can_despawn=true, tamed=true}) == false, "despawn_allowed - tamed")
|
||||
|
||||
assert(despawn_allowed({can_despawn=true, persistent=true}) == false, "despawn_allowed - persistent")
|
||||
assert(despawn_allowed({can_despawn=true, persistent=false}) == true, "despawn_allowed - not persistent")
|
||||
|
||||
function mob_class:check_despawn(pos, dtime)
|
||||
self.lifetimer = self.lifetimer - dtime
|
||||
|
||||
-- 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 remove_far and despawn_allowed(self) then
|
||||
if self.despawn_immediately or self.lifetimer <= 0 then
|
||||
if logging then
|
||||
minetest.log("action", "[mcl_mobs] Mob "..self.name.." despawns at "..minetest.pos_to_string(pos, 1) .. " lifetimer ran out")
|
||||
|
@ -24,6 +24,12 @@
|
||||
-- added rain damage.
|
||||
-- fixed the grass_with_dirt issue.
|
||||
|
||||
-- How freqeuntly to take and place blocks, in seconds
|
||||
local take_frequency_min = 235
|
||||
local take_frequency_max = 245
|
||||
local place_frequency_min = 235
|
||||
local place_frequency_max = 245
|
||||
|
||||
minetest.register_entity("mobs_mc:ender_eyes", {
|
||||
visual = "mesh",
|
||||
mesh = "mobs_mc_spider.b3d",
|
||||
@ -60,13 +66,6 @@ end
|
||||
|
||||
local pr = PseudoRandom(os.time()*(-334))
|
||||
|
||||
-- How freqeuntly to take and place blocks, in seconds
|
||||
local take_frequency_min = 235
|
||||
local take_frequency_max = 245
|
||||
local place_frequency_min = 235
|
||||
local place_frequency_max = 245
|
||||
|
||||
|
||||
-- Texuture overrides for enderman block. Required for cactus because it's original is a nodebox
|
||||
-- and the textures have tranparent pixels.
|
||||
local block_texture_overrides
|
||||
@ -491,7 +490,7 @@ mcl_mobs.register_mob("mobs_mc:enderman", {
|
||||
local dug = minetest.get_node_or_nil(take_pos)
|
||||
if dug and dug.name == "air" then
|
||||
self._taken_node = node.name
|
||||
self.can_despawn = false
|
||||
self.persistent = true
|
||||
local def = minetest.registered_nodes[self._taken_node]
|
||||
-- Update animation and texture accordingly (adds visibly carried block)
|
||||
local block_type
|
||||
@ -542,7 +541,7 @@ mcl_mobs.register_mob("mobs_mc:enderman", {
|
||||
if success then
|
||||
local def = minetest.registered_nodes[self._taken_node]
|
||||
-- Update animation accordingly (removes visible block)
|
||||
self.can_despawn = true
|
||||
self.persistent = false
|
||||
self.animation = select_enderman_animation("normal")
|
||||
self:set_animation(self.animation.current)
|
||||
if def.sounds and def.sounds.place then
|
||||
|
@ -109,7 +109,7 @@ mcl_mobs.register_mob("mobs_mc:villager_zombie", {
|
||||
clicker:set_wielded_item(wielditem)
|
||||
self._curing = math.random(3 * 60, 5 * 60)
|
||||
self.shaking = true
|
||||
self.can_despawn = false
|
||||
self.persistent = true
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
Loading…
Reference in New Issue
Block a user