Skip to content

Commit

Permalink
Spawners: fix not enough light & not enough space. Remove `-- print(.…
Browse files Browse the repository at this point in the history
…..)`.
  • Loading branch information
alek13 committed Jul 22, 2024
1 parent dff2354 commit 0ab8b12
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 30 deletions.
1 change: 1 addition & 0 deletions mods/lord/Blocks/lord_spawners/src/lord_spawners.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ local function register_racial()
dummy_offset = 0.2,
dummy_mesh = 'lottarmor_character_old.b3d',
dummy_texture = { "lottmobs_" .. race .. ".png" },
night_only = "disable",
})
end
end
Expand Down
32 changes: 2 additions & 30 deletions mods/lord/Blocks/lord_spawners/src/lord_spawners/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,6 @@ function lord_spawners.tick(pos)
meta:set_int('tick', tick_counter)
end

-- print('tick_counter: ' .. tick_counter .. ' at ' .. minetest.pos_to_string(pos))

-- rusty spawner
if tick_counter >= tick_max then
lord_spawners.set_status(pos, 'rusty')
Expand All @@ -268,7 +266,6 @@ function lord_spawners.tick_short(pos)
else
tick_short_counter = tick_short_counter + 1
meta:set_int('tick_short', tick_short_counter)
-- print('tick_short_counter: ' .. tick_short_counter .. ' at ' .. minetest.pos_to_string(pos))
end
minetest.get_node_timer(pos):start(math.random(5, 10))
-- minetest.get_node_timer(pos):start(math.random(10, 20))
Expand Down Expand Up @@ -330,7 +327,7 @@ function lord_spawners.on_timer(pos, elapsed)
end

local posmin = { x = pos.x - 3, y = pos.y - 1, z = pos.z - 3 }
local posmax = { x = pos.x + 4, y = pos.y + 1, z = pos.z + 4 }
local posmax = { x = pos.x + 4, y = pos.y + 4, z = pos.z + 4 }
local player_near = false
local entities_near = 0
local entities_max = 6
Expand Down Expand Up @@ -368,7 +365,6 @@ function lord_spawners.on_timer(pos, elapsed)

-- dark
if (not node_light or node_light < node_light_min) and not night_only then
-- print('Too dark for mob ( ' .. mob_name .. ' ) to spawn. Waiting for day .. .')
lord_spawners.set_status(pos, 'waiting')

-- set infotext
Expand All @@ -380,7 +376,6 @@ function lord_spawners.on_timer(pos, elapsed)

elseif node_light >= node_light_min and night_only then
-- light
-- print('Too much light for mob ( ' .. mob_name .. ' ) to spawn. Waiting for night .. .')
lord_spawners.set_status(pos, 'waiting')

-- set infotext
Expand Down Expand Up @@ -420,19 +415,15 @@ function lord_spawners.on_timer(pos, elapsed)
{ 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' then
table.insert(spawn_area_random_pos, random_pos)
-- print('spawn_area_random_pos: ' .. #spawn_area_random_pos)
else
table.remove(spawn_area_pos, i)
-- print('spawn_area_pos: ' .. #spawn_area_pos)
end

end
end

-- print(dump(spawn_area_random_pos))

-- check if there is still enough place to spawn mob
if #spawn_area_random_pos < 1 then
lord_spawners.set_status(pos, 'waiting')
Expand Down Expand Up @@ -469,7 +460,6 @@ function lord_spawners.on_timer(pos, elapsed)
-- find player inside activation area
if object:is_player() then
player_near = true
-- print('found player: ' .. object:get_player_name())
end

-- find entities inside activation area
Expand All @@ -486,11 +476,8 @@ function lord_spawners.on_timer(pos, elapsed)
string.find(mob_name, 'sheep') and
not string.find(tmp_mob_name, 'dummy')
then
-- print('found entity: ' .. tmp_mob_name)
entities_near = entities_near + 1

elseif tmp_mob_name == mob_name then
-- print('found entity: ' .. tmp_mob_name)
entities_near = entities_near + 1
end
else
Expand All @@ -504,7 +491,6 @@ function lord_spawners.on_timer(pos, elapsed)

-- stop looping when met all conditions
if entities_near >= entities_max and player_near then
-- print('max entities reached ' .. entities_max .. ' and player_near found, breaking .. ')
break
end
end
Expand All @@ -513,12 +499,6 @@ function lord_spawners.on_timer(pos, elapsed)
if entities_near >= entities_max or not player_near then
lord_spawners.set_status(pos, 'waiting')

-- sheeps have color in the name
-- local name = mob_name
-- if string.find(mob_name, 'sheep') then
-- name = 'sheep'
-- end

meta:set_string(
'infotext',
mob_name .. ' spawner\nowner: ' .. owner .. '\nmax mobs reached: ' .. entities_near .. '/' .. entities_max
Expand Down Expand Up @@ -571,8 +551,6 @@ function lord_spawners.set_status(pos, set_status)
-- remove particles and add them again - keeps particles after server restart
-- delete particles
if id_flame ~= -1 and id_smoke ~= -1 then
-- print('#1 delete id_flame: ' .. id_flame .. ' at ' .. minetest.pos_to_string(pos))
-- print('#1 delete id_smoke: ' .. id_smoke .. ' at ' .. minetest.pos_to_string(pos))
minetest.delete_particlespawner(id_flame)
minetest.delete_particlespawner(id_smoke)
meta:set_int('id_flame', -1)
Expand All @@ -584,8 +562,6 @@ function lord_spawners.set_status(pos, set_status)
id_smoke = lord_spawners.add_smoke_effects(pos)
meta:set_int('id_flame', id_flame)
meta:set_int('id_smoke', id_smoke)
-- 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))

if meta_status ~= set_status then
-- add dummy entity
Expand All @@ -605,8 +581,6 @@ function lord_spawners.set_status(pos, set_status)

-- delete particles
if id_flame ~= -1 and id_smoke ~= -1 then
-- print('#2 delete id_flame: ' .. id_flame .. ' at ' .. minetest.pos_to_string(pos))
-- print('#2 delete id_smoke: ' .. id_smoke .. ' at ' .. minetest.pos_to_string(pos))
minetest.delete_particlespawner(id_flame)
minetest.delete_particlespawner(id_smoke)
meta:set_int('id_flame', -1)
Expand Down Expand Up @@ -636,8 +610,6 @@ function lord_spawners.set_status(pos, set_status)

-- delete particles
if id_flame ~= -1 and id_smoke ~= -1 then
-- print('#3 delete id_flame: ' .. id_flame .. ' at ' .. minetest.pos_to_string(pos))
-- print('#3 delete id_smoke: ' .. id_smoke .. ' at ' .. minetest.pos_to_string(pos))
minetest.delete_particlespawner(id_flame)
minetest.delete_particlespawner(id_smoke)
meta:set_int('id_flame', -1)
Expand Down

0 comments on commit 0ab8b12

Please sign in to comment.