From 58ed1a5e1c10dafc29803c9536f30892e628c099 Mon Sep 17 00:00:00 2001 From: Duane Robertson Date: Thu, 26 May 2016 01:49:08 -0500 Subject: [PATCH] Better delay --- danglers.lua | 5 +---- goblin_coal.lua | 5 +---- goblin_cobbler.lua | 5 +---- goblin_copper.lua | 5 +---- goblin_diamond.lua | 5 +---- goblin_digger.lua | 5 +---- goblin_gold.lua | 5 +---- goblin_ice.lua | 5 +---- goblin_iron.lua | 5 +---- goblin_king.lua | 5 +---- mapgen.lua | 2 +- mobs.lua | 11 ++++++++++- spider.lua | 4 ++++ spider_ice.lua | 4 ++++ 14 files changed, 29 insertions(+), 42 deletions(-) diff --git a/danglers.lua b/danglers.lua index 64b86d4..779682d 100644 --- a/danglers.lua +++ b/danglers.lua @@ -70,10 +70,7 @@ mobs:register_mob("fun_caves:dangler", { --replace_with = "air", --replace_offset = -1, do_custom = function(self) - if not self.custom_time or self.custom_time % fun_caves.custom_delay == 0 then - self.custom_time = fun_caves.custom_delay - 1 - else - self.custom_time = self.custom_time - 1 + if not fun_caves.custom_ready(self) then return end diff --git a/goblin_coal.lua b/goblin_coal.lua index 70dcde8..f610cf9 100644 --- a/goblin_coal.lua +++ b/goblin_coal.lua @@ -108,10 +108,7 @@ mobs:register_mob("fun_caves:goblin_coal", { end, do_custom = function(self) - if not self.custom_time or self.custom_time % fun_caves.custom_delay == 0 then - self.custom_time = fun_caves.custom_delay - 1 - else - self.custom_time = self.custom_time - 1 + if not fun_caves.custom_ready(self) then return end diff --git a/goblin_cobbler.lua b/goblin_cobbler.lua index ddb9939..47d1f52 100644 --- a/goblin_cobbler.lua +++ b/goblin_cobbler.lua @@ -112,10 +112,7 @@ mobs:register_mob("fun_caves:goblin_cobble", { end, do_custom = function(self) - if not self.custom_time or self.custom_time % fun_caves.custom_delay == 0 then - self.custom_time = fun_caves.custom_delay - 1 - else - self.custom_time = self.custom_time - 1 + if not fun_caves.custom_ready(self) then return end diff --git a/goblin_copper.lua b/goblin_copper.lua index 067f346..e9c893b 100644 --- a/goblin_copper.lua +++ b/goblin_copper.lua @@ -108,10 +108,7 @@ mobs:register_mob("fun_caves:goblin_copper", { end, do_custom = function(self) - if not self.custom_time or self.custom_time % fun_caves.custom_delay == 0 then - self.custom_time = fun_caves.custom_delay - 1 - else - self.custom_time = self.custom_time - 1 + if not fun_caves.custom_ready(self) then return end diff --git a/goblin_diamond.lua b/goblin_diamond.lua index 7c607ce..858a22a 100644 --- a/goblin_diamond.lua +++ b/goblin_diamond.lua @@ -110,10 +110,7 @@ mobs:register_mob("fun_caves:goblin_diamond", { end, do_custom = function(self) - if not self.custom_time or self.custom_time % fun_caves.custom_delay == 0 then - self.custom_time = fun_caves.custom_delay - 1 - else - self.custom_time = self.custom_time - 1 + if not fun_caves.custom_ready(self) then return end diff --git a/goblin_digger.lua b/goblin_digger.lua index 6a72e86..bd75ca9 100644 --- a/goblin_digger.lua +++ b/goblin_digger.lua @@ -204,10 +204,7 @@ mobs:register_mob("fun_caves:goblin_digger", { end, do_custom = function(self) - if not self.custom_time or self.custom_time % fun_caves.custom_delay == 0 then - self.custom_time = fun_caves.custom_delay - 1 - else - self.custom_time = self.custom_time - 1 + if not fun_caves.custom_ready(self) then return end diff --git a/goblin_gold.lua b/goblin_gold.lua index 4eda469..18028e0 100644 --- a/goblin_gold.lua +++ b/goblin_gold.lua @@ -108,10 +108,7 @@ mobs:register_mob("fun_caves:goblin_gold", { end, do_custom = function(self) - if not self.custom_time or self.custom_time % fun_caves.custom_delay == 0 then - self.custom_time = fun_caves.custom_delay - 1 - else - self.custom_time = self.custom_time - 1 + if not fun_caves.custom_ready(self) then return end diff --git a/goblin_ice.lua b/goblin_ice.lua index 6093943..ed84501 100644 --- a/goblin_ice.lua +++ b/goblin_ice.lua @@ -107,10 +107,7 @@ mobs:register_mob("fun_caves:goblin_ice", { end, do_custom = function(self) - if not self.custom_time or self.custom_time % fun_caves.custom_delay == 0 then - self.custom_time = fun_caves.custom_delay - 1 - else - self.custom_time = self.custom_time - 1 + if not fun_caves.custom_ready(self) then return end diff --git a/goblin_iron.lua b/goblin_iron.lua index a4a00bd..0c26814 100644 --- a/goblin_iron.lua +++ b/goblin_iron.lua @@ -110,10 +110,7 @@ mobs:register_mob("fun_caves:goblin_iron", { end, do_custom = function(self) - if not self.custom_time or self.custom_time % fun_caves.custom_delay == 0 then - self.custom_time = fun_caves.custom_delay - 1 - else - self.custom_time = self.custom_time - 1 + if not fun_caves.custom_ready(self) then return end diff --git a/goblin_king.lua b/goblin_king.lua index 550e74d..6f5e835 100644 --- a/goblin_king.lua +++ b/goblin_king.lua @@ -109,10 +109,7 @@ mobs:register_mob("fun_caves:goblin_king", { end, do_custom = function(self) - if not self.custom_time or self.custom_time % fun_caves.custom_delay == 0 then - self.custom_time = fun_caves.custom_delay - 1 - else - self.custom_time = self.custom_time - 1 + if not fun_caves.custom_ready(self) then return end diff --git a/mapgen.lua b/mapgen.lua index d713e62..184c39c 100644 --- a/mapgen.lua +++ b/mapgen.lua @@ -1,4 +1,4 @@ -local DEBUG = true +local DEBUG = false local cave_noise_1 = {offset = 0, scale = 1, seed = 3901, spread = {x = 40, y = 10, z = 40}, octaves = 3, persist = 1, lacunarity = 2} local cave_noise_2 = {offset = 0, scale = 1, seed = -8402, spread = {x = 40, y = 20, z = 40}, octaves = 3, persist = 1, lacunarity = 2} diff --git a/mobs.lua b/mobs.lua index 44a50f8..78be404 100644 --- a/mobs.lua +++ b/mobs.lua @@ -48,7 +48,16 @@ fun_caves.surface_damage = function(self, cold_natured) end -fun_caves.custom_delay = 50 +local custom_delay = 1000000 +fun_caves.custom_ready = function(self) + local time = minetest.get_us_time() + if not self.custom_time or time - self.custom_time > custom_delay then + self.custom_time = time + return true + else + return false + end +end local path = minetest.get_modpath(minetest.get_current_modname()) dofile(path .. "/danglers.lua") diff --git a/spider.lua b/spider.lua index 2e0bd7e..e0daddc 100644 --- a/spider.lua +++ b/spider.lua @@ -48,6 +48,10 @@ mobs:register_mob("fun_caves:spider", { punch_end = 90, }, do_custom = function(self) + if not fun_caves.custom_ready(self) then + return + end + fun_caves.surface_damage(self) end, }) diff --git a/spider_ice.lua b/spider_ice.lua index ec07cf5..b6f0f89 100644 --- a/spider_ice.lua +++ b/spider_ice.lua @@ -49,6 +49,10 @@ mobs:register_mob("fun_caves:spider_ice", { punch_end = 90, }, do_custom = function(self) + if not fun_caves.custom_ready(self) then + return + end + fun_caves.surface_damage(self, true) end, })