Added "remove_far_mobs" switch to delete mobs out of sight

This commit is contained in:
TenPlus1 2015-08-04 18:10:54 +01:00
parent 7a280aad1d
commit ffc01c35be

24
api.lua
View File

@ -1,12 +1,13 @@
-- Mobs Api (1st August 2015) -- Mobs Api (4th August 2015)
mobs = {} mobs = {}
mobs.mod = "redo" mobs.mod = "redo"
-- Initial settings check -- Initial settings check
local damage_enabled = minetest.setting_getbool("enable_damage") local damage_enabled = minetest.setting_getbool("enable_damage") or true
local peaceful_only = minetest.setting_getbool("only_peaceful_mobs") local peaceful_only = minetest.setting_getbool("only_peaceful_mobs") or false
local enable_blood = minetest.setting_getbool("mobs_enable_blood") or true local enable_blood = minetest.setting_getbool("mobs_enable_blood") or true
mobs.protected = tonumber(minetest.setting_get("mobs_spawn_protected")) or 0 mobs.protected = tonumber(minetest.setting_get("mobs_spawn_protected")) or 0
mobs.remove = minetest.setting_getbool("remove_far_mobs") or false
function mobs:register_mob(name, def) function mobs:register_mob(name, def)
minetest.register_entity(name, { minetest.register_entity(name, {
@ -787,8 +788,8 @@ end
self.timer = 0 self.timer = 0
self.blinktimer = 0 self.blinktimer = 0
else else
self.timer = 0 self.timer = 0
self.blinktimer = 0 self.blinktimer = 0
if self.get_velocity(self) <= 0.5 if self.get_velocity(self) <= 0.5
and self.object:getvelocity().y == 0 then and self.object:getvelocity().y == 0 then
local v = self.object:getvelocity() local v = self.object:getvelocity()
@ -905,7 +906,7 @@ end
local vec = {x = p.x - s.x, y = p.y - s.y, z = p.z - s.z} local vec = {x = p.x - s.x, y = p.y - s.y, z = p.z - s.z}
yaw = (math.atan(vec.z / vec.x) + math.pi / 2) - self.rotate yaw = (math.atan(vec.z / vec.x) + math.pi / 2) - self.rotate
if p.x > s.x then if p.x > s.x then
yaw = yaw+math.pi yaw = yaw + math.pi
end end
self.object:setyaw(yaw) self.object:setyaw(yaw)
-- attack distance is 2 + half of mob width so the bigger mobs can attack (like slimes) -- attack distance is 2 + half of mob width so the bigger mobs can attack (like slimes)
@ -1080,6 +1081,8 @@ end
self.object:set_hp( self.health ) self.object:set_hp( self.health )
self.object:set_armor_groups({fleshy = self.armor}) self.object:set_armor_groups({fleshy = self.armor})
self.state = "stand" self.state = "stand"
self.order = "stand"
self.following = nil
self.old_y = self.object:getpos().y self.old_y = self.object:getpos().y
self.object:setyaw(math.random(1, 360) / 180 * math.pi) self.object:setyaw(math.random(1, 360) / 180 * math.pi)
self.sounds.distance = (self.sounds.distance or 10) self.sounds.distance = (self.sounds.distance or 10)
@ -1093,6 +1096,15 @@ end
end, end,
get_staticdata = function(self) get_staticdata = function(self)
-- remove mob when out of range unless tamed
if mobs.remove == true and self.remove_ok and not self.tamed then
print ("REMOVED", self.remove_ok, self.name)
self.object:remove()
end
self.remove_ok = true
self.attack = nil
local tmp = {} local tmp = {}
for _,stat in pairs(self) do for _,stat in pairs(self) do
local t = type(stat) local t = type(stat)