Compare commits
5 Commits
eea4a4a535
...
a642d324bf
Author | SHA1 | Date |
---|---|---|
James Stevenson | a642d324bf | |
James Stevenson | fe218059fa | |
James Stevenson | 08310b4296 | |
James Stevenson | 40e02cf1e2 | |
James Stevenson | d2fab280a9 |
|
@ -2921,6 +2921,7 @@ local mob_step = function(self, dtime)
|
||||||
do_states(self, dtime)
|
do_states(self, dtime)
|
||||||
do_jump(self)
|
do_jump(self)
|
||||||
runaway_from(self)
|
runaway_from(self)
|
||||||
|
--[[
|
||||||
local stepper = self.stepper or random()
|
local stepper = self.stepper or random()
|
||||||
self.stepper = stepper + dtime
|
self.stepper = stepper + dtime
|
||||||
if self.stepper < 10 then
|
if self.stepper < 10 then
|
||||||
|
@ -2929,6 +2930,7 @@ local mob_step = function(self, dtime)
|
||||||
self.stepper = random()
|
self.stepper = random()
|
||||||
end
|
end
|
||||||
local t = 0
|
local t = 0
|
||||||
|
--]]
|
||||||
--[[
|
--[[
|
||||||
for k, v in pairs(minetest.get_objects_inside_radius(pos, 24)) do
|
for k, v in pairs(minetest.get_objects_inside_radius(pos, 24)) do
|
||||||
local s = v:get_luaentity()
|
local s = v:get_luaentity()
|
||||||
|
@ -2944,6 +2946,7 @@ local mob_step = function(self, dtime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--]]
|
--]]
|
||||||
|
--[[
|
||||||
undercrowd(pos, 8)
|
undercrowd(pos, 8)
|
||||||
if minetest.find_node_near(pos, 8, "mobs:spawner") then
|
if minetest.find_node_near(pos, 8, "mobs:spawner") then
|
||||||
return
|
return
|
||||||
|
@ -2966,6 +2969,7 @@ local mob_step = function(self, dtime)
|
||||||
end
|
end
|
||||||
--print("Mob spawns Spawny the Spawner!")
|
--print("Mob spawns Spawny the Spawner!")
|
||||||
minetest.get_node_timer(pos):start(0)
|
minetest.get_node_timer(pos):start(0)
|
||||||
|
--]]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ local random = math.random
|
||||||
local redo = mobs.redo
|
local redo = mobs.redo
|
||||||
local check_for_player = mobs.check_for_player
|
local check_for_player = mobs.check_for_player
|
||||||
local limiter = mobs.limiter
|
local limiter = mobs.limiter
|
||||||
|
local erase = mobs.erase
|
||||||
|
|
||||||
minetest.register_node("mobs:spawner", {
|
minetest.register_node("mobs:spawner", {
|
||||||
description = "I spawn things!",
|
description = "I spawn things!",
|
||||||
|
@ -25,11 +26,25 @@ minetest.register_node("mobs:spawner", {
|
||||||
on_blast = function()
|
on_blast = function()
|
||||||
end,
|
end,
|
||||||
on_timer = function(pos, elapsed)
|
on_timer = function(pos, elapsed)
|
||||||
if check_for_player(pos) then
|
if elapsed > 10 then
|
||||||
minetest.get_node_timer(pos):set(10, 0)
|
erase(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
limiter(pos)
|
if elapsed < 10 then
|
||||||
|
minetest.get_node_timer(pos):set(10, elapsed + 0.1)
|
||||||
|
return
|
||||||
|
else
|
||||||
|
minetest.get_node_timer(pos):start(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
if check_for_player(pos) then
|
||||||
|
minetest.get_node_timer(pos):start(0)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if limiter(pos) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local node = minetest.get_node_or_nil({
|
local node = minetest.get_node_or_nil({
|
||||||
x = pos.x,
|
x = pos.x,
|
||||||
|
@ -40,7 +55,8 @@ minetest.register_node("mobs:spawner", {
|
||||||
if node and node.name then
|
if node and node.name then
|
||||||
local node_below = minetest.registered_nodes[node.name]
|
local node_below = minetest.registered_nodes[node.name]
|
||||||
if node_below and not node_below.walkable then
|
if node_below and not node_below.walkable then
|
||||||
return redo(pos)
|
erase(pos)
|
||||||
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -102,7 +118,7 @@ minetest.register_node("mobs:spawner", {
|
||||||
|
|
||||||
print("Spawning " .. mob)
|
print("Spawning " .. mob)
|
||||||
minetest.add_entity(spawn_pos, mob)
|
minetest.add_entity(spawn_pos, mob)
|
||||||
redo(pos)
|
erase(pos)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -115,7 +131,9 @@ minetest.register_abm({
|
||||||
catch_up = false,
|
catch_up = false,
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
--print(active_object_count, active_object_count_wider)
|
--print(active_object_count, active_object_count_wider)
|
||||||
limiter(pos)
|
if limiter(pos) then
|
||||||
|
minetest.set_node(pos, {name = "air"})
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,23 @@
|
||||||
local random = math.random
|
local random = math.random
|
||||||
|
local stepper = 0
|
||||||
|
|
||||||
mobs.check_for_player = function(pos)
|
mobs.erase = function(pos)
|
||||||
local objects_in_radius = minetest.get_objects_inside_radius(pos, 16)
|
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)
|
||||||
for i = 1, #objects_in_radius do
|
for i = 1, #objects_in_radius do
|
||||||
local object = objects_in_radius[i]
|
local object = objects_in_radius[i]
|
||||||
local player = object:is_player()
|
local player = object:is_player()
|
||||||
|
@ -13,7 +29,7 @@ mobs.check_for_player = function(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
mobs.undercrowd = function(pos, radius)
|
mobs.undercrowd = function(pos, radius)
|
||||||
radius = radius or 3
|
radius = radius or 8
|
||||||
local r = minetest.get_objects_inside_radius(pos, radius)
|
local r = minetest.get_objects_inside_radius(pos, radius)
|
||||||
local t = 0
|
local t = 0
|
||||||
for _, v in pairs(r) do
|
for _, v in pairs(r) do
|
||||||
|
@ -28,10 +44,10 @@ mobs.undercrowd = function(pos, radius)
|
||||||
t = t + 1
|
t = t + 1
|
||||||
end
|
end
|
||||||
if t > 5 then
|
if t > 5 then
|
||||||
print("Overcrowded.")
|
v:remove()
|
||||||
return v:remove()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return t
|
||||||
end
|
end
|
||||||
local undercrowd = mobs.undercrowd
|
local undercrowd = mobs.undercrowd
|
||||||
|
|
||||||
|
@ -48,8 +64,6 @@ minetest.register_on_mods_loaded(function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
mobs.redo = function(pos, radius)
|
mobs.redo = function(pos, radius)
|
||||||
print("Redoing.")
|
|
||||||
|
|
||||||
radius = radius or 1
|
radius = radius or 1
|
||||||
|
|
||||||
local p1 = {
|
local p1 = {
|
||||||
|
@ -68,21 +82,18 @@ mobs.redo = function(pos, radius)
|
||||||
if n then
|
if n then
|
||||||
local t = minetest.get_node_timer(n)
|
local t = minetest.get_node_timer(n)
|
||||||
if not t:is_started() then
|
if not t:is_started() then
|
||||||
print("Restarting timer.")
|
t:start(0)
|
||||||
t:start(1)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local a = minetest.find_nodes_in_area_under_air(p1, p2, "group:reliable")
|
local a = minetest.find_nodes_in_area_under_air(p1, p2, "group:reliable")
|
||||||
if a and a[1] then
|
if a and a[1] then
|
||||||
print("Setting spawner.")
|
|
||||||
local an = a[random(#a)]
|
local an = a[random(#a)]
|
||||||
local np = {
|
local np = {
|
||||||
x = an.x,
|
x = an.x,
|
||||||
y = an.y + 1,
|
y = an.y + 1,
|
||||||
z = an.z,
|
z = an.z,
|
||||||
}
|
}
|
||||||
print("Setting spawner.")
|
|
||||||
minetest.set_node(np, {name = "mobs:spawner"})
|
minetest.set_node(np, {name = "mobs:spawner"})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -95,7 +106,7 @@ mobs.limiter = function(pos, radius, limit, immediate_surrounding, surrounding)
|
||||||
minetest.get_objects_inside_radius(pos, radius)
|
minetest.get_objects_inside_radius(pos, radius)
|
||||||
|
|
||||||
if #immediate_surrounding > 6 then
|
if #immediate_surrounding > 6 then
|
||||||
return
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local surrounding = surrounding or
|
local surrounding = surrounding or
|
||||||
|
@ -114,12 +125,11 @@ mobs.limiter = function(pos, radius, limit, immediate_surrounding, surrounding)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if h > limit then
|
if h > limit then
|
||||||
return
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
--[[
|
||||||
local stepper = 0
|
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
if stepper < 10 then
|
if stepper < 10 then
|
||||||
stepper = stepper + dtime
|
stepper = stepper + dtime
|
||||||
|
@ -127,6 +137,7 @@ minetest.register_globalstep(function(dtime)
|
||||||
else
|
else
|
||||||
stepper = 0
|
stepper = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
local players = minetest.get_connected_players()
|
local players = minetest.get_connected_players()
|
||||||
for i = 1, #players do
|
for i = 1, #players do
|
||||||
if players[i] == "" then
|
if players[i] == "" then
|
||||||
|
@ -137,7 +148,9 @@ minetest.register_globalstep(function(dtime)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
undercrowd(pos, 8)
|
if undercrowd(pos, 32) > 3 then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
if minetest.find_node_near(pos, 8, "mobs:spawner") then
|
if minetest.find_node_near(pos, 8, "mobs:spawner") then
|
||||||
break
|
break
|
||||||
|
@ -160,3 +173,4 @@ minetest.register_globalstep(function(dtime)
|
||||||
minetest.get_node_timer(pos):start(0)
|
minetest.get_node_timer(pos):start(0)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
--]]
|
||||||
|
|
Loading…
Reference in New Issue