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_jump(self)
|
||||
runaway_from(self)
|
||||
--[[
|
||||
local stepper = self.stepper or random()
|
||||
self.stepper = stepper + dtime
|
||||
if self.stepper < 10 then
|
||||
|
@ -2929,6 +2930,7 @@ 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()
|
||||
|
@ -2944,6 +2946,7 @@ local mob_step = function(self, dtime)
|
|||
end
|
||||
end
|
||||
--]]
|
||||
--[[
|
||||
undercrowd(pos, 8)
|
||||
if minetest.find_node_near(pos, 8, "mobs:spawner") then
|
||||
return
|
||||
|
@ -2966,6 +2969,7 @@ local mob_step = function(self, dtime)
|
|||
end
|
||||
--print("Mob spawns Spawny the Spawner!")
|
||||
minetest.get_node_timer(pos):start(0)
|
||||
--]]
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ 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!",
|
||||
|
@ -25,11 +26,25 @@ minetest.register_node("mobs:spawner", {
|
|||
on_blast = function()
|
||||
end,
|
||||
on_timer = function(pos, elapsed)
|
||||
if check_for_player(pos) then
|
||||
minetest.get_node_timer(pos):set(10, 0)
|
||||
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)
|
||||
end
|
||||
|
||||
limiter(pos)
|
||||
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({
|
||||
x = pos.x,
|
||||
|
@ -40,7 +55,8 @@ 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
|
||||
return redo(pos)
|
||||
erase(pos)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -102,7 +118,7 @@ minetest.register_node("mobs:spawner", {
|
|||
|
||||
print("Spawning " .. mob)
|
||||
minetest.add_entity(spawn_pos, mob)
|
||||
redo(pos)
|
||||
erase(pos)
|
||||
end,
|
||||
})
|
||||
|
||||
|
@ -115,7 +131,9 @@ 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)
|
||||
limiter(pos)
|
||||
if limiter(pos) then
|
||||
minetest.set_node(pos, {name = "air"})
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
|
|
|
@ -1,7 +1,23 @@
|
|||
local random = math.random
|
||||
local stepper = 0
|
||||
|
||||
mobs.check_for_player = function(pos)
|
||||
local objects_in_radius = minetest.get_objects_inside_radius(pos, 16)
|
||||
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)
|
||||
for i = 1, #objects_in_radius do
|
||||
local object = objects_in_radius[i]
|
||||
local player = object:is_player()
|
||||
|
@ -13,7 +29,7 @@ mobs.check_for_player = function(pos)
|
|||
end
|
||||
|
||||
mobs.undercrowd = function(pos, radius)
|
||||
radius = radius or 3
|
||||
radius = radius or 8
|
||||
local r = minetest.get_objects_inside_radius(pos, radius)
|
||||
local t = 0
|
||||
for _, v in pairs(r) do
|
||||
|
@ -28,10 +44,10 @@ mobs.undercrowd = function(pos, radius)
|
|||
t = t + 1
|
||||
end
|
||||
if t > 5 then
|
||||
print("Overcrowded.")
|
||||
return v:remove()
|
||||
v:remove()
|
||||
end
|
||||
end
|
||||
return t
|
||||
end
|
||||
local undercrowd = mobs.undercrowd
|
||||
|
||||
|
@ -48,8 +64,6 @@ minetest.register_on_mods_loaded(function()
|
|||
end)
|
||||
|
||||
mobs.redo = function(pos, radius)
|
||||
print("Redoing.")
|
||||
|
||||
radius = radius or 1
|
||||
|
||||
local p1 = {
|
||||
|
@ -68,21 +82,18 @@ mobs.redo = function(pos, radius)
|
|||
if n then
|
||||
local t = minetest.get_node_timer(n)
|
||||
if not t:is_started() then
|
||||
print("Restarting timer.")
|
||||
t:start(1)
|
||||
t:start(0)
|
||||
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
|
||||
|
@ -95,7 +106,7 @@ mobs.limiter = function(pos, radius, limit, immediate_surrounding, surrounding)
|
|||
minetest.get_objects_inside_radius(pos, radius)
|
||||
|
||||
if #immediate_surrounding > 6 then
|
||||
return
|
||||
return true
|
||||
end
|
||||
|
||||
local surrounding = surrounding or
|
||||
|
@ -114,12 +125,11 @@ mobs.limiter = function(pos, radius, limit, immediate_surrounding, surrounding)
|
|||
end
|
||||
end
|
||||
if h > limit then
|
||||
return
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local stepper = 0
|
||||
--[[
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if stepper < 10 then
|
||||
stepper = stepper + dtime
|
||||
|
@ -127,6 +137,7 @@ minetest.register_globalstep(function(dtime)
|
|||
else
|
||||
stepper = 0
|
||||
end
|
||||
|
||||
local players = minetest.get_connected_players()
|
||||
for i = 1, #players do
|
||||
if players[i] == "" then
|
||||
|
@ -137,7 +148,9 @@ minetest.register_globalstep(function(dtime)
|
|||
break
|
||||
end
|
||||
|
||||
undercrowd(pos, 8)
|
||||
if undercrowd(pos, 32) > 3 then
|
||||
break
|
||||
end
|
||||
|
||||
if minetest.find_node_near(pos, 8, "mobs:spawner") then
|
||||
break
|
||||
|
@ -160,3 +173,4 @@ minetest.register_globalstep(function(dtime)
|
|||
minetest.get_node_timer(pos):start(0)
|
||||
end
|
||||
end)
|
||||
--]]
|
||||
|
|
Loading…
Reference in New Issue