Compare commits

..

No commits in common. "a642d324bf6cdfba753500fd33d11f29ac055541" and "eea4a4a53567e10469dceafcb95a72449f3dabd7" have entirely different histories.

3 changed files with 22 additions and 58 deletions

View File

@ -2921,7 +2921,6 @@ local mob_step = function(self, dtime)
do_states(self, dtime)
do_jump(self)
runaway_from(self)
--[[
local stepper = self.stepper or random()
self.stepper = stepper + dtime
if self.stepper < 10 then
@ -2930,7 +2929,6 @@ local mob_step = function(self, dtime)
self.stepper = random()
end
local t = 0
--]]
--[[
for k, v in pairs(minetest.get_objects_inside_radius(pos, 24)) do
local s = v:get_luaentity()
@ -2946,7 +2944,6 @@ local mob_step = function(self, dtime)
end
end
--]]
--[[
undercrowd(pos, 8)
if minetest.find_node_near(pos, 8, "mobs:spawner") then
return
@ -2969,7 +2966,6 @@ local mob_step = function(self, dtime)
end
--print("Mob spawns Spawny the Spawner!")
minetest.get_node_timer(pos):start(0)
--]]
end

View File

@ -6,7 +6,6 @@ local random = math.random
local redo = mobs.redo
local check_for_player = mobs.check_for_player
local limiter = mobs.limiter
local erase = mobs.erase
minetest.register_node("mobs:spawner", {
description = "I spawn things!",
@ -26,25 +25,11 @@ minetest.register_node("mobs:spawner", {
on_blast = function()
end,
on_timer = function(pos, elapsed)
if elapsed > 10 then
erase(pos)
end
if elapsed < 10 then
minetest.get_node_timer(pos):set(10, elapsed + 0.1)
return
else
minetest.get_node_timer(pos):start(0)
if check_for_player(pos) then
minetest.get_node_timer(pos):set(10, 0)
end
if check_for_player(pos) then
minetest.get_node_timer(pos):start(0)
return
end
if limiter(pos) then
return
end
limiter(pos)
local node = minetest.get_node_or_nil({
x = pos.x,
@ -55,8 +40,7 @@ minetest.register_node("mobs:spawner", {
if node and node.name then
local node_below = minetest.registered_nodes[node.name]
if node_below and not node_below.walkable then
erase(pos)
return
return redo(pos)
end
end
@ -118,7 +102,7 @@ minetest.register_node("mobs:spawner", {
print("Spawning " .. mob)
minetest.add_entity(spawn_pos, mob)
erase(pos)
redo(pos)
end,
})
@ -131,9 +115,7 @@ minetest.register_abm({
catch_up = false,
action = function(pos, node, active_object_count, active_object_count_wider)
--print(active_object_count, active_object_count_wider)
if limiter(pos) then
minetest.set_node(pos, {name = "air"})
end
limiter(pos)
end,
})

View File

@ -1,23 +1,7 @@
local random = math.random
local stepper = 0
mobs.erase = function(pos)
local n = minetest.get_node_or_nil(pos)
local nn = n.name
if not nn then
return
end
if nn == "mobs:spawner" then
minetest.set_node(pos, {name = "air"})
return true
end
end
mobs.check_for_player = function(pos, radius)
radius = radius or 32
local objects_in_radius = minetest.get_objects_inside_radius(pos, radius)
mobs.check_for_player = function(pos)
local objects_in_radius = minetest.get_objects_inside_radius(pos, 16)
for i = 1, #objects_in_radius do
local object = objects_in_radius[i]
local player = object:is_player()
@ -29,7 +13,7 @@ mobs.check_for_player = function(pos, radius)
end
mobs.undercrowd = function(pos, radius)
radius = radius or 8
radius = radius or 3
local r = minetest.get_objects_inside_radius(pos, radius)
local t = 0
for _, v in pairs(r) do
@ -44,10 +28,10 @@ mobs.undercrowd = function(pos, radius)
t = t + 1
end
if t > 5 then
v:remove()
print("Overcrowded.")
return v:remove()
end
end
return t
end
local undercrowd = mobs.undercrowd
@ -64,6 +48,8 @@ minetest.register_on_mods_loaded(function()
end)
mobs.redo = function(pos, radius)
print("Redoing.")
radius = radius or 1
local p1 = {
@ -82,18 +68,21 @@ mobs.redo = function(pos, radius)
if n then
local t = minetest.get_node_timer(n)
if not t:is_started() then
t:start(0)
print("Restarting timer.")
t:start(1)
end
end
local a = minetest.find_nodes_in_area_under_air(p1, p2, "group:reliable")
if a and a[1] then
print("Setting spawner.")
local an = a[random(#a)]
local np = {
x = an.x,
y = an.y + 1,
z = an.z,
}
print("Setting spawner.")
minetest.set_node(np, {name = "mobs:spawner"})
end
end
@ -106,7 +95,7 @@ mobs.limiter = function(pos, radius, limit, immediate_surrounding, surrounding)
minetest.get_objects_inside_radius(pos, radius)
if #immediate_surrounding > 6 then
return true
return
end
local surrounding = surrounding or
@ -125,11 +114,12 @@ mobs.limiter = function(pos, radius, limit, immediate_surrounding, surrounding)
end
end
if h > limit then
return true
return
end
end
end
--[[
local stepper = 0
minetest.register_globalstep(function(dtime)
if stepper < 10 then
stepper = stepper + dtime
@ -137,7 +127,6 @@ minetest.register_globalstep(function(dtime)
else
stepper = 0
end
local players = minetest.get_connected_players()
for i = 1, #players do
if players[i] == "" then
@ -148,9 +137,7 @@ minetest.register_globalstep(function(dtime)
break
end
if undercrowd(pos, 32) > 3 then
break
end
undercrowd(pos, 8)
if minetest.find_node_near(pos, 8, "mobs:spawner") then
break
@ -173,4 +160,3 @@ minetest.register_globalstep(function(dtime)
minetest.get_node_timer(pos):start(0)
end
end)
--]]