From 95c32cb4af2481dba67503de15bdde6e522e587d Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Mon, 21 Sep 2020 09:48:45 +0100 Subject: [PATCH] Added spawn.lua check for custom mob spawning with example file --- bee.lua | 2 + bunny.lua | 2 + chicken.lua | 3 + cow.lua | 2 + init.lua | 47 +++++++---- kitten.lua | 2 + panda.lua | 2 +- penguin.lua | 4 +- rat.lua | 2 + sheep.lua | 2 + spawn_example.lua | 195 ++++++++++++++++++++++++++++++++++++++++++++++ warthog.lua | 3 +- 12 files changed, 249 insertions(+), 17 deletions(-) create mode 100644 spawn_example.lua diff --git a/bee.lua b/bee.lua index c642a20..70e4d38 100644 --- a/bee.lua +++ b/bee.lua @@ -46,6 +46,7 @@ mobs:register_mob("mobs_animal:bee", { -- end, }) +if not mobs.custom_spawn_animal then mobs:spawn({ name = "mobs_animal:bee", nodes = {"group:flower"}, @@ -56,6 +57,7 @@ mobs:spawn({ max_height = 200, day_toggle = true, }) +end mobs:register_egg("mobs_animal:bee", S("Bee"), "mobs_bee_inv.png") diff --git a/bunny.lua b/bunny.lua index 32c33f8..3948003 100644 --- a/bunny.lua +++ b/bunny.lua @@ -113,6 +113,7 @@ if minetest.get_modpath("ethereal") then spawn_on = "ethereal:prairie_dirt" end +if not mobs.custom_spawn_animal then mobs:spawn({ name = "mobs_animal:bunny", nodes = {spawn_on}, @@ -124,6 +125,7 @@ mobs:spawn({ max_height = 200, day_toggle = true, }) +end mobs:register_egg("mobs_animal:bunny", S("Bunny"), "mobs_bunny_inv.png", 0) diff --git a/chicken.lua b/chicken.lua index 1f16c6b..dd2eb8c 100644 --- a/chicken.lua +++ b/chicken.lua @@ -100,6 +100,8 @@ if minetest.get_modpath("ethereal") then spawn_on = {"ethereal:bamboo_dirt", "ethereal:prairie_dirt"} end + +if not mobs.custom_spawn_animal then mobs:spawn({ name = "mobs_animal:chicken", nodes = spawn_on, @@ -111,6 +113,7 @@ mobs:spawn({ max_height = 200, day_toggle = true, }) +end mobs:register_egg("mobs_animal:chicken", S("Chicken"), "mobs_chicken_inv.png", 0) diff --git a/cow.lua b/cow.lua index f9a19fd..2ceb8ad 100644 --- a/cow.lua +++ b/cow.lua @@ -135,6 +135,7 @@ mobs:register_mob("mobs_animal:cow", { }) +if not mobs.custom_spawn_animal then mobs:spawn({ name = "mobs_animal:cow", nodes = {"default:dirt_with_grass", "ethereal:green_dirt"}, @@ -146,6 +147,7 @@ mobs:spawn({ max_height = 200, day_toggle = true, }) +end mobs:register_egg("mobs_animal:cow", S("Cow"), "mobs_cow_inv.png") diff --git a/init.lua b/init.lua index 241ad08..149897f 100644 --- a/init.lua +++ b/init.lua @@ -1,23 +1,44 @@ -- 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_animal") 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_animal = true + input:close() + input = nil +end + + -- Animals -dofile(path .. "/chicken.lua") -- JKmurray -dofile(path .. "/cow.lua") -- KrupnoPavel -dofile(path .. "/rat.lua") -- PilzAdam -dofile(path .. "/sheep.lua") -- PilzAdam -dofile(path .. "/warthog.lua") -- KrupnoPavel -dofile(path .. "/bee.lua") -- KrupnoPavel -dofile(path .. "/bunny.lua") -- ExeterDad -dofile(path .. "/kitten.lua") -- Jordach/BFD -dofile(path .. "/penguin.lua") -- D00Med -dofile(path .. "/panda.lua") -- AspireMint +dofile(path .. "chicken.lua") -- JKmurray +dofile(path .. "cow.lua") -- KrupnoPavel +dofile(path .. "rat.lua") -- PilzAdam +dofile(path .. "sheep.lua") -- PilzAdam +dofile(path .. "warthog.lua") -- KrupnoPavel +dofile(path .. "bee.lua") -- KrupnoPavel +dofile(path .. "bunny.lua") -- ExeterDad +dofile(path .. "kitten.lua") -- Jordach/BFD +dofile(path .. "penguin.lua") -- D00Med +dofile(path .. "panda.lua") -- AspireMint + + +-- Load custom spawning +if mobs.custom_spawn_animal then + dofile(path .. "spawn.lua") +end + -- Lucky Blocks -dofile(path .. "/lucky_block.lua") +dofile(path .. "lucky_block.lua") + print (S("[MOD] Mobs Redo Animals loaded")) diff --git a/kitten.lua b/kitten.lua index 123ef93..1f5233a 100644 --- a/kitten.lua +++ b/kitten.lua @@ -115,6 +115,7 @@ if minetest.get_modpath("ethereal") then spawn_on = "ethereal:grove_dirt" end +if not mobs.custom_spawn_animal then mobs:spawn({ name = "mobs_animal:kitten", nodes = {spawn_on}, @@ -126,6 +127,7 @@ mobs:spawn({ max_height = 50, day_toggle = true, }) +end mobs:register_egg("mobs_animal:kitten", S("Kitten"), "mobs_kitten_inv.png", 0) diff --git a/panda.lua b/panda.lua index c49fc3e..d008e57 100644 --- a/panda.lua +++ b/panda.lua @@ -68,7 +68,7 @@ stepheight = 0.6, end, }) -if minetest.get_modpath("ethereal") then +if minetest.get_modpath("ethereal") and not mobs.custom_spawn_animal then mobs:spawn({ name = "mobs_animal:panda", diff --git a/penguin.lua b/penguin.lua index 98f2156..5b26312 100644 --- a/penguin.lua +++ b/penguin.lua @@ -60,7 +60,7 @@ stepheight = 0.6, end, }) - +if not mobs.custom_spawn_animal then mobs:spawn({ name = "mobs_animal:penguin", nodes = {"default:snowblock"}, @@ -71,6 +71,6 @@ mobs:spawn({ max_height = 200, day_toggle = true, }) - +end mobs:register_egg("mobs_animal:penguin", S("Penguin"), "mobs_penguin_inv.png") diff --git a/rat.lua b/rat.lua index 562b394..930a985 100644 --- a/rat.lua +++ b/rat.lua @@ -67,6 +67,7 @@ local function rat_spawn(self, pos) self.health = 100 end +if not mobs.custom_spawn_animal then mobs:spawn({ name = "mobs_animal:rat", nodes = {"default:stone"}, @@ -77,6 +78,7 @@ mobs:spawn({ max_height = 0, -- on_spawn = rat_spawn, }) +end mobs:register_egg("mobs_animal:rat", S("Rat"), "mobs_rat_inv.png") diff --git a/sheep.lua b/sheep.lua index 027d4da..afc3742 100644 --- a/sheep.lua +++ b/sheep.lua @@ -207,6 +207,7 @@ mobs:register_egg("mobs_animal:sheep_"..col[1], S("@1 Sheep", col[2]), "wool_".. end +if not mobs.custom_spawn_animal then mobs:spawn({ name = "mobs_animal:sheep_white", nodes = {"default:dirt_with_grass", "ethereal:green_dirt"}, @@ -218,6 +219,7 @@ mobs:spawn({ max_height = 200, day_toggle = true, }) +end mobs:alias_mob("mobs:sheep", "mobs_animal:sheep_white") -- compatibility diff --git a/spawn_example.lua b/spawn_example.lua new file mode 100644 index 0000000..22814c1 --- /dev/null +++ b/spawn_example.lua @@ -0,0 +1,195 @@ + +--[[ 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 +}) +]]-- + + +-- Bee + +mobs:spawn({ + name = "mobs_animal:bee", + nodes = {"group:flower"}, + min_light = 14, + interval = 60, + chance = 7000, + min_height = 3, + max_height = 200, + day_toggle = true, +}) + +-- Bunny + +mobs:spawn({ + name = "mobs_animal:bunny", + nodes = {"default:dirt_with_grass"}, + neighbors = {"group:grass"}, + min_light = 14, + interval = 60, + chance = 8000, + min_height = 5, + max_height = 200, + day_toggle = true, +}) + +-- Chicken + +mobs:spawn({ + name = "mobs_animal:chicken", + nodes = {"default:dirt_with_grass"}, + neighbors = {"group:grass"}, + min_light = 14, + interval = 60, + chance = 8000, + min_height = 5, + max_height = 200, + day_toggle = true, +}) + +-- Cow + +mobs:spawn({ + name = "mobs_animal:cow", + nodes = {"default:dirt_with_grass", "ethereal:green_dirt"}, + neighbors = {"group:grass"}, + min_light = 14, + interval = 60, + chance = 8000, + min_height = 5, + max_height = 200, + day_toggle = true, +}) + +-- Kitten + +mobs:spawn({ + name = "mobs_animal:kitten", + nodes = {"default:dirt_with_grass"}, + neighbors = {"group:grass"}, + min_light = 14, + interval = 60, + chance = 10000, + min_height = 5, + max_height = 50, + day_toggle = true, +}) + +-- Panda + +mobs:spawn({ + name = "mobs_animal:panda", + nodes = {"ethereal:bamboo_dirt"}, + neighbors = {"group:grass"}, + min_light = 14, + interval = 60, + chance = 8000, + min_height = 10, + max_height = 80, + day_toggle = true, +}) + +-- Penguin + +mobs:spawn({ + name = "mobs_animal:penguin", + nodes = {"default:snowblock"}, + min_light = 14, + interval = 60, + chance = 20000, + min_height = 0, + max_height = 200, + day_toggle = true, +}) + +-- Rat + +mobs:spawn({ + name = "mobs_animal:rat", + nodes = {"default:stone"}, + min_light = 3, + max_light = 9, + interval = 60, + chance = 8000, + max_height = 0, +}) + +-- Sheep + +mobs:spawn({ + name = "mobs_animal:sheep_white", + nodes = {"default:dirt_with_grass", "ethereal:green_dirt"}, + neighbors = {"group:grass"}, + min_light = 14, + interval = 60, + chance = 8000, + min_height = 0, + max_height = 200, + day_toggle = true, +}) + +-- Warthog + +mobs:spawn({ + name = "mobs_animal:pumba", + nodes = {"default:dirt_with_dry_grass", "default:dry_dirt_with_dry_grass"}, + neighbors = {"group:dry_grass"}, + min_light = 14, + interval = 60, + chance = 8000, + min_height = 0, + max_height = 200, + day_toggle = true, +}) diff --git a/warthog.lua b/warthog.lua index 9405620..4c56d5b 100644 --- a/warthog.lua +++ b/warthog.lua @@ -72,6 +72,7 @@ if minetest.get_modpath("ethereal") then spawn_by = {"flowers:mushroom_brown", "flowers:mushroom_red"} end +if not mobs.custom_spawn_animal then mobs:spawn({ name = "mobs_animal:pumba", nodes = spawn_on, @@ -83,7 +84,7 @@ mobs:spawn({ max_height = 200, day_toggle = true, }) - +end mobs:register_egg("mobs_animal:pumba", S("Warthog"), "mobs_pumba_inv.png")