From 7db2c2545a72052f8b7c67308c83aba8a0725bba Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Mon, 21 Sep 2020 10:20:51 +0100 Subject: [PATCH] Added spawn.lua check for custom mob spawning, example file included --- init.lua | 31 ++++++++++++--- npc.lua | 2 + spawn_example.lua | 98 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 spawn_example.lua diff --git a/init.lua b/init.lua index 74c6fe5..04fa67f 100644 --- a/init.lua +++ b/init.lua @@ -1,16 +1,37 @@ -- Load support for intllib. -local path = minetest.get_modpath(minetest.get_current_modname()) +local path = minetest.get_modpath(minetest.get_current_modname()) .. "/" + local S = minetest.get_translator and minetest.get_translator("mobs_npc") or - dofile(path .. "/intllib.lua") + dofile(path .. "intllib.lua") + mobs.intllib = S + +-- Check for custom mob spawn file +local input = io.open(path .. "spawn.lua", "r") + +if input then + mobs.custom_spawn_npc = true + input:close() + input = nil +end + + -- NPCs -dofile(path .. "/npc.lua") -- TenPlus1 -dofile(path .. "/trader.lua") -dofile(path .. "/igor.lua") +dofile(path .. "npc.lua") -- TenPlus1 +dofile(path .. "trader.lua") +dofile(path .. "igor.lua") + + +-- Load custom spawning +if mobs.custom_spawn_npc then + dofile(path .. "spawn.lua") +end + -- Lucky Blocks dofile(path .. "/lucky_block.lua") + print (S("[MOD] Mobs Redo NPCs loaded")) diff --git a/npc.lua b/npc.lua index fd83f95..c2c8d01 100644 --- a/npc.lua +++ b/npc.lua @@ -120,6 +120,7 @@ mobs:register_mob("mobs_npc:npc", { end, }) +if not mobs.custom_spawn_npc then mobs:spawn({ name = "mobs_npc:npc", nodes = {"default:brick"}, @@ -130,6 +131,7 @@ mobs:spawn({ min_height = 0, day_toggle = true, }) +end mobs:register_egg("mobs_npc:npc", S("Npc"), "default_brick.png", 1) diff --git a/spawn_example.lua b/spawn_example.lua new file mode 100644 index 0000000..6e472f4 --- /dev/null +++ b/spawn_example.lua @@ -0,0 +1,98 @@ + +--[[ Spawn Template, defaults to values shown if line not provided + +mobs:spawn({ + + name = "", + + - Name of mob, must be provided e.g. "mymod:my_mob" + + nodes = {"group:soil, "group:stone"}, + + - Nodes to spawn on top of. + + neighbors = {"air"}, + + - Nodes to spawn beside. + + min_light = 0, + + - Minimum light level. + + max_light = 15, + + - Maximum light level, 15 is sunlight only. + + interval = 30, + + - Spawn interval in seconds. + + chance = 5000, + + - Spawn chance, 1 in every 5000 nodes. + + active_object_count = 1, + + - Active mobs of this type in area. + + min_height = -31000, + + - Minimum height level. + + max_height = 31000, + + - Maximum height level. + + day_toggle = nil, + + - Daytime toggle, true to spawn during day, false for night, nil for both + + on_spawn = nil, + + - On spawn function to run when mob spawns in world + + on_map_load = nil, + + - On map load, when true mob only spawns in newly generated map areas +}) +]]-- + + +-- NPC + +mobs:spawn({ + name = "mobs_npc:npc", + nodes = {"default:brick"}, + neighbors = {"default:grass_3"}, + min_light = 10, + chance = 10000, + active_object_count = 1, + min_height = 0, + day_toggle = true, +}) + +-- Igor + +mobs:spawn({ + name = "mobs_npc:igor", + nodes = {"mobs:meatblock"}, + neighbors = {"default:brick"}, + min_light = 10, + chance = 10000, + active_object_count = 1, + min_height = 0, + day_toggle = true, +}) + +-- Trader + +mobs:spawn({ + name = "mobs_npc:trader", + nodes = {"default:diamondblock"}, + neighbors = {"default:brick"}, + min_light = 10, + chance = 10000, + active_object_count = 1, + min_height = 0, + day_toggle = true, +})