10% less tick timer

This commit is contained in:
Juraj Vajda 2018-10-17 21:25:16 -04:00
parent 0b8d40bc8b
commit 8f8ea3075f

View File

@ -31,12 +31,12 @@ for k, mob_mod in ipairs(ENABLED_MODS) do
} }
) )
-- use custom egg or create a default egg -- use custom egg or create a default egg
if mob.egg_name_custom ~= "" then if mob.egg_name_custom ~= "" then
mob_egg = mob.egg_name_custom mob_egg = mob.egg_name_custom
else else
mob_egg = mob_mod..":"..mob.name mob_egg = mob_mod..":"..mob.name
end end
-- recipes -- recipes
minetest.register_craft({ minetest.register_craft({
output = "spawners_mobs:"..mob_mod.."_"..mob.name.."_spawner", output = "spawners_mobs:"..mob_mod.."_"..mob.name.."_spawner",
@ -52,9 +52,9 @@ for k, mob_mod in ipairs(ENABLED_MODS) do
end end
end end
-- --
-- Particles -- Particles
-- --
function spawners_mobs.cloud_booom(pos) function spawners_mobs.cloud_booom(pos)
if not enable_particles then return end if not enable_particles then return end
@ -115,16 +115,16 @@ function spawners_mobs.add_smoke_effects(pos)
}) })
end end
-- --
-- Timers -- Timers
-- --
-- how often node timers for spawners will tick, +/- some random value -- how often node timers for spawners will tick, +/- some random value
function spawners_mobs.tick(pos) function spawners_mobs.tick(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local tick_counter = meta:get_int("tick") local tick_counter = meta:get_int("tick")
local owner = meta:get_string("owner") local owner = meta:get_string("owner")
local privs = minetest.get_player_privs(owner); local privs = minetest.get_player_privs(owner);
-- not for admin -- not for admin
if not privs.privs then if not privs.privs then
tick_counter = tick_counter + 1 tick_counter = tick_counter + 1
@ -138,7 +138,7 @@ function spawners_mobs.tick(pos)
spawners_mobs.set_status(pos, "rusty") spawners_mobs.set_status(pos, "rusty")
return return
end end
minetest.get_node_timer(pos):start(math.random(80, 214)) minetest.get_node_timer(pos):start(math.random(72, 193))
-- minetest.get_node_timer(pos):start(math.random(20, 30)) -- minetest.get_node_timer(pos):start(math.random(20, 30))
end end
@ -146,7 +146,7 @@ end
function spawners_mobs.tick_short(pos) function spawners_mobs.tick_short(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local tick_short_counter = meta:get_int("tick_short") local tick_short_counter = meta:get_int("tick_short")
if tick_short_counter >= tick_short_max then if tick_short_counter >= tick_short_max then
spawners_mobs.tick(pos) spawners_mobs.tick(pos)
return return
@ -159,16 +159,16 @@ function spawners_mobs.tick_short(pos)
-- minetest.get_node_timer(pos):start(math.random(10, 20)) -- minetest.get_node_timer(pos):start(math.random(10, 20))
end end
-- --
-- Core Functions -- Core Functions
-- --
-- start spawning mobs -- start spawning mobs
function spawners_mobs.start_spawning(spawn_area_random_pos, mob_name, mod_prefix, sound_custom) function spawners_mobs.start_spawning(spawn_area_random_pos, mob_name, mod_prefix, sound_custom)
if not (spawn_area_random_pos or how_many or mob_name) then return end if not (spawn_area_random_pos or how_many or mob_name) then return end
local sound_name = mod_prefix.."_"..mob_name local sound_name = mod_prefix.."_"..mob_name
-- use custom sounds -- use custom sounds
if sound_custom ~= "" then if sound_custom ~= "" then
sound_name = sound_custom sound_name = sound_custom
end end
@ -181,7 +181,7 @@ function spawners_mobs.start_spawning(spawn_area_random_pos, mob_name, mod_prefi
for i = 1, #spawn_area_random_pos do for i = 1, #spawn_area_random_pos do
-- spawn a bit more above the block - prevent spawning inside the block -- spawn a bit more above the block - prevent spawning inside the block
spawn_area_random_pos[i].y = spawn_area_random_pos[i].y + 0.5 spawn_area_random_pos[i].y = spawn_area_random_pos[i].y + 0.5
spawners_mobs.cloud_booom(spawn_area_random_pos[i]) spawners_mobs.cloud_booom(spawn_area_random_pos[i])
minetest.after(1, function() minetest.after(1, function()
@ -269,7 +269,7 @@ function spawners_mobs.on_timer(pos, elapsed)
local random_pos = spawn_area_pos[math.random(#spawn_area_pos)] local random_pos = spawn_area_pos[math.random(#spawn_area_pos)]
local random_pos_above = minetest.get_node({ x = random_pos.x, y = random_pos.y + 1, z = random_pos.z }).name local random_pos_above = minetest.get_node({ x = random_pos.x, y = random_pos.y + 1, z = random_pos.z }).name
if random_pos_above == "air" and not minetest.is_protected(random_pos, owner) then if random_pos_above == "air" and not minetest.is_protected(random_pos, owner) then
table.insert(spawn_area_random_pos, random_pos) table.insert(spawn_area_random_pos, random_pos)
-- print("spawn_area_random_pos: "..#spawn_area_random_pos) -- print("spawn_area_random_pos: "..#spawn_area_random_pos)
@ -282,7 +282,7 @@ function spawners_mobs.on_timer(pos, elapsed)
end end
-- print(dump(spawn_area_random_pos)) -- print(dump(spawn_area_random_pos))
-- check if there is still enough place to spawn mob -- check if there is still enough place to spawn mob
if #spawn_area_random_pos < 1 then if #spawn_area_random_pos < 1 then
spawners_mobs.set_status(pos, "waiting") spawners_mobs.set_status(pos, "waiting")
@ -324,7 +324,7 @@ function spawners_mobs.on_timer(pos, elapsed)
if string.find(tmp_mob_name, "sheep") and string.find(mob_name, "sheep") and not string.find(tmp_mob_name, "dummy") then if string.find(tmp_mob_name, "sheep") and string.find(mob_name, "sheep") and not string.find(tmp_mob_name, "dummy") then
-- print("found entity: "..tmp_mob_name) -- print("found entity: "..tmp_mob_name)
entities_near = entities_near + 1 entities_near = entities_near + 1
elseif tmp_mob_name == mob_name then elseif tmp_mob_name == mob_name then
-- print("found entity: "..tmp_mob_name) -- print("found entity: "..tmp_mob_name)
entities_near = entities_near + 1 entities_near = entities_near + 1
@ -344,7 +344,7 @@ function spawners_mobs.on_timer(pos, elapsed)
-- don't do anything and try again later when player not near or max entities reached -- don't do anything and try again later when player not near or max entities reached
if entities_near >= entities_max or not player_near then if entities_near >= entities_max or not player_near then
spawners_mobs.set_status(pos, "waiting") spawners_mobs.set_status(pos, "waiting")
-- sheeps have color in the name -- sheeps have color in the name
local name = mob_name local name = mob_name
if string.find(mob_name, "sheep") then if string.find(mob_name, "sheep") then
@ -355,7 +355,7 @@ function spawners_mobs.on_timer(pos, elapsed)
spawners_mobs.tick_short(pos) spawners_mobs.tick_short(pos)
return return
end end
-- start spawning -- start spawning
spawners_mobs.start_spawning(spawn_area_random_pos, mob_name, mod_prefix, sound_custom) spawners_mobs.start_spawning(spawn_area_random_pos, mob_name, mod_prefix, sound_custom)
@ -377,7 +377,7 @@ function spawners_mobs.set_status(pos, set_status)
local mob_table = spawners_mobs.mob_tables[idx] or false local mob_table = spawners_mobs.mob_tables[idx] or false
if not mob_table then return end if not mob_table then return end
local mod_prefix = mob_table.mod_prefix local mod_prefix = mob_table.mod_prefix
local mob_name = mob_table.name local mob_name = mob_table.name
local offset = mob_table.dummy_offset local offset = mob_table.dummy_offset
@ -410,7 +410,7 @@ function spawners_mobs.set_status(pos, set_status)
meta:set_int("id_smoke", id_smoke) meta:set_int("id_smoke", id_smoke)
-- print("#1 add id_flame: "..id_flame.." at "..minetest.pos_to_string(pos)) -- print("#1 add id_flame: "..id_flame.." at "..minetest.pos_to_string(pos))
-- print("#1 add id_smoke: "..id_smoke.." at "..minetest.pos_to_string(pos)) -- print("#1 add id_smoke: "..id_smoke.." at "..minetest.pos_to_string(pos))
if meta_status ~= set_status then if meta_status ~= set_status then
-- add dummy entity -- add dummy entity
minetest.add_entity({ x = pos.x, y = pos.y + offset, z = pos.z },"spawners_mobs:dummy_"..mod_prefix.."_"..mob_name) minetest.add_entity({ x = pos.x, y = pos.y + offset, z = pos.z },"spawners_mobs:dummy_"..mod_prefix.."_"..mob_name)