spawners/spawners_mobs/spawners_mobs.lua

146 lines
4.0 KiB
Lua
Raw Normal View History

2016-10-08 21:54:26 +03:00
--
2018-01-07 07:31:21 +03:00
-- CREATE ALL SPAWNERS NODES
2016-10-08 21:54:26 +03:00
--
2018-01-07 07:31:21 +03:00
function spawners_mobs.create(mob_table, idx)
local mob_name = mob_table.name
local mod_prefix = mob_table.mod_prefix
local size = mob_table.dummy_size
local mesh = mob_table.dummy_mesh
local texture = mob_table.dummy_texture
2016-10-08 21:54:26 +03:00
--
-- DUMMY INSIDE THE SPAWNER
--
2018-01-07 07:31:21 +03:00
minetest.register_entity("spawners_mobs:dummy_"..mod_prefix.."_"..mob_name, {
2016-10-08 21:54:26 +03:00
hp_max = 1,
visual = "mesh",
visual_size = size,
2018-01-07 07:31:21 +03:00
collisionbox = {0,0,0,0,0,0},
2016-10-08 21:54:26 +03:00
mesh = mesh,
textures = texture,
2018-01-07 07:31:21 +03:00
physical = false,
2016-10-08 21:54:26 +03:00
makes_footstep_sound = false,
automatic_rotate = math.pi * -3,
2018-01-07 07:31:21 +03:00
static_save = false,
2016-10-08 21:54:26 +03:00
2018-01-07 07:31:21 +03:00
on_activate = function(self, staticdata, dtime_s)
self.object:setvelocity({x = 0, y = 0, z = 0})
self.object:setacceleration({x = 0, y = 0, z = 0})
self.object:set_armor_groups({immortal = 1})
2016-10-08 21:54:26 +03:00
end
2018-01-07 07:31:21 +03:00
})
2016-10-08 21:54:26 +03:00
--
2018-01-07 07:31:21 +03:00
-- DEFAULT SPAWNER
2016-10-08 21:54:26 +03:00
--
2018-01-07 07:31:21 +03:00
minetest.register_node("spawners_mobs:"..mod_prefix.."_"..mob_name.."_spawner", {
description = mod_prefix.."_"..mob_name.." spawner",
2016-10-08 21:54:26 +03:00
paramtype = "light",
2017-07-27 22:05:41 +03:00
paramtype2 = "glasslikeliquidlevel",
drawtype = "glasslike_framed_optional",
2016-10-08 21:54:26 +03:00
walkable = true,
2016-11-13 18:53:40 +03:00
sounds = default.node_sound_metal_defaults(),
2016-10-08 21:54:26 +03:00
sunlight_propagates = true,
2016-10-12 22:57:06 +03:00
tiles = {"spawners_mobs_spawner_16.png"},
2018-01-07 07:31:21 +03:00
is_ground_content = false,
groups = {cracky=1,level=2},
stack_max = 1,
light_source = 6,
2018-01-07 07:31:21 +03:00
on_timer = spawners_mobs.on_timer,
2018-01-07 07:31:21 +03:00
on_construct = function(pos)
-- set meta
local meta = minetest.get_meta(pos)
meta:set_int("idx", idx)
meta:set_int("tick", 0)
meta:set_int("tick_short", 0)
2018-01-07 07:31:21 +03:00
spawners_mobs.set_status(pos, "active")
spawners_mobs.tick_short(pos)
2016-10-12 22:57:06 +03:00
end,
2018-01-07 07:31:21 +03:00
after_place_node = function(pos, placer, itemstack, pointed_thing)
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name())
2018-01-07 22:04:27 +03:00
meta:set_string("infotext", mob_name.." spawner\nowner: "..placer:get_player_name().."\nspawner is active")
end,
2018-01-07 07:31:21 +03:00
on_destruct = function(pos)
-- delete particles and remove dummy
spawners_mobs.set_status(pos, "waiting")
end
2016-10-08 21:54:26 +03:00
})
--
-- WAITING SPAWNER
--
minetest.register_node("spawners_mobs:"..mod_prefix.."_"..mob_name.."_spawner_waiting", {
description = mod_prefix.."_"..mob_name.." spawner waiting",
paramtype = "light",
2017-07-27 22:05:41 +03:00
paramtype2 = "glasslikeliquidlevel",
drawtype = "glasslike_framed_optional",
2016-11-13 18:53:40 +03:00
sounds = default.node_sound_metal_defaults(),
2018-01-07 07:31:21 +03:00
walkable = true,
2016-10-08 21:54:26 +03:00
sunlight_propagates = true,
tiles = {
{
name = "spawners_mobs_spawner_waiting_animated_16.png",
2016-10-08 21:54:26 +03:00
animation = {
type = "vertical_frames",
2016-12-07 23:37:36 +03:00
aspect_w = 16,
aspect_h = 16,
2016-10-08 21:54:26 +03:00
length = 2.0
},
}
},
2018-01-07 07:31:21 +03:00
is_ground_content = false,
2016-10-08 21:54:26 +03:00
groups = {cracky=1,level=2,not_in_creative_inventory=1},
2018-01-07 07:31:21 +03:00
light_source = 4,
2016-10-08 21:54:26 +03:00
drop = "spawners_mobs:"..mod_prefix.."_"..mob_name.."_spawner",
2018-01-07 07:31:21 +03:00
on_timer = spawners_mobs.on_timer
2016-10-08 21:54:26 +03:00
})
--
2018-01-07 07:31:21 +03:00
-- RUSTY SPAWNER
2016-10-08 21:54:26 +03:00
--
2018-01-07 07:31:21 +03:00
minetest.register_node("spawners_mobs:"..mod_prefix.."_"..mob_name.."_spawner_rusty", {
description = mod_prefix.."_"..mob_name.." spawner rusty",
2016-10-08 21:54:26 +03:00
paramtype = "light",
2017-07-27 22:05:41 +03:00
paramtype2 = "glasslikeliquidlevel",
drawtype = "glasslike_framed_optional",
2016-11-13 18:53:40 +03:00
sounds = default.node_sound_metal_defaults(),
2018-01-07 07:31:21 +03:00
walkable = true,
2016-10-08 21:54:26 +03:00
sunlight_propagates = true,
2018-01-07 07:31:21 +03:00
tiles = {"spawners_mobs_spawner_rusty.png"},
is_ground_content = false,
groups = {cracky=1,level=2,not_in_creative_inventory=1},
drop = "spawners_mobs:"..mod_prefix.."_"..mob_name.."_spawner"
2016-10-08 21:54:26 +03:00
})
--
2018-01-07 07:31:21 +03:00
-- replacement LBM for pre-nodetimer spawners
2016-10-08 21:54:26 +03:00
--
2018-01-07 07:31:21 +03:00
minetest.register_lbm({
name = "spawners_mobs:start_nodetimer_"..mod_prefix.."_"..mob_name.."_spawner",
nodenames = "spawners_mobs:"..mod_prefix.."_"..mob_name.."_spawner",
action = function(pos, node)
spawners_mobs.tick_short(pos)
2016-10-08 21:54:26 +03:00
end,
})
--
2018-01-07 07:31:21 +03:00
-- COMPATIBILITY
2016-10-08 21:54:26 +03:00
--
2018-01-07 07:31:21 +03:00
minetest.register_alias("spawners_mobs:"..mod_prefix.."_"..mob_name.."_spawner_active", "spawners_mobs:"..mod_prefix.."_"..mob_name.."_spawner")
2016-10-08 21:54:26 +03:00
end
--
2018-01-07 07:31:21 +03:00
-- INIT 'CREATE' FOR ALL SPAWNERS
2016-10-08 21:54:26 +03:00
--
for i, mob_table in ipairs(spawners_mobs.mob_tables) do
2018-01-07 07:31:21 +03:00
spawners_mobs.create(mob_table, i)
end