diff --git a/TODO.txt b/TODO.txt index a05f351..0251b35 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,3 +1,3 @@ TODO: -- add lifetime limit +- add option to remove mobs that aren't near any players diff --git a/init.lua b/init.lua index 8271833..a9bafdb 100644 --- a/init.lua +++ b/init.lua @@ -114,6 +114,8 @@ def.on_activate = function(self, staticdata) self.knockback = false self.state = math.random(1, 2) self.old_y = self.object:get_pos().y + self.lifetime = sneeker.lifetime + self.lifetimer = 0 local data = core.deserialize(staticdata) if data and type(data) == "table" then @@ -135,8 +137,17 @@ local function isnan(n) end def.on_step = function(self, dtime) + -- update lifetime timer + -- FIXME: this is longer than realtime + self.lifetimer = self.lifetimer + dtime + if self.lifetimer >= self.lifetime then + -- TODO: should have a death animation + self.object:remove() + return true + end + if self.knockback then - return + return false end local ANIM_STAND = 1 @@ -339,6 +350,8 @@ def.on_step = function(self, dtime) else self.object:set_acceleration({x=0, y=-10, z=0}) end + + return true end def.on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir) diff --git a/settings.lua b/settings.lua index 979315f..8c0a19a 100644 --- a/settings.lua +++ b/settings.lua @@ -3,6 +3,13 @@ local time_min = 60 +--- How long (in seconds) sneeker remains in world after spawn. +-- +-- Default: 15 minutes +-- +-- @setting sneeker.lifespan +sneeker.lifetime = tonumber(core.settings:get("sneeker.lifetime") or time_min * 15) + --- Loudness of explosion. -- -- @setting sneeker.boom_gain diff --git a/settingtypes.txt b/settingtypes.txt index 82c886a..4e73b5d 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -2,6 +2,11 @@ # Extra debugging messages. enable_debug_mods (Mod debugging) bool false +# How long (in seconds) sneeker remains in world after spawn. +# +# Default: 900 (15 minutes) +sneeker.lifetime (Sneeker lifetime) int 900 + # Loudness of explosion. # # Those with a weak heart might want to turn it down.