From 7650e9ba5c57a898e3764fb762bafde32d13466e Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Mon, 18 Oct 2021 08:32:12 +0100 Subject: [PATCH] tidy code, add custom spawn.lua check --- init.lua | 60 ++++++++++++++++++++++++--------------- spawn_example.lua | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 22 deletions(-) create mode 100644 spawn_example.lua diff --git a/init.lua b/init.lua index 1a3e9d9..f43dc01 100644 --- a/init.lua +++ b/init.lua @@ -1,8 +1,9 @@ -- Load support for intllib. -local MP = minetest.get_modpath(minetest.get_current_modname()) +local MP = minetest.get_modpath(minetest.get_current_modname()) .. "/" local S = minetest.get_translator and minetest.get_translator("mob_horse") or - dofile(MP .. "/intllib.lua") + dofile(MP .. "intllib.lua") + -- 0.4.17 or 5.0 check local y_off = 20 @@ -10,6 +11,7 @@ if minetest.features.object_independent_selectionbox then y_off = 10 end + -- horse shoes (speed, jump, break, overlay texture) local shoes = { ["mobs:horseshoe_steel"] = {7, 4, 2, "mobs_horseshoe_steelo.png"}, @@ -19,6 +21,7 @@ local shoes = { ["mobs:horseshoe_crystal"] = {11, 6, 9, "mobs_horseshoe_crystalo.png"} } + -- rideable horse mobs:register_mob("mob_horse:horse", { type = "animal", @@ -39,7 +42,7 @@ mobs:register_mob("mob_horse:horse", { walk_start = 75, walk_end = 100, run_start = 75, - run_end = 100, + run_end = 100 }, textures = { {"mobs_horse.png"}, -- textures by Mjollna @@ -227,16 +230,28 @@ mobs:register_mob("mob_horse:horse", { end }) -mobs:spawn({ - name = "mob_horse:horse", - nodes = {"default:dirt_with_grass", "ethereal:dry_dirt"}, - min_light = 14, - interval = 60, - chance = 16000, - min_height = 10, - max_height = 31000, - day_toggle = true, -}) + +-- check for custom spawn.lua +local input = io.open(MP .. "spawn.lua", "r") + +if input then + input:close() + input = nil + dofile(MP .. "spawn.lua") +else + + mobs:spawn({ + name = "mob_horse:horse", + nodes = {"default:dirt_with_grass", "ethereal:dry_dirt"}, + min_light = 14, + interval = 60, + chance = 16000, + min_height = 10, + max_height = 31000, + day_toggle = true + }) +end + mobs:register_egg("mob_horse:horse", S("Horse"), "wool_brown.png", 1) @@ -252,14 +267,14 @@ minetest.register_craft({ recipe = { {"", "default:steelblock", ""}, {"default:steel_ingot", "", "default:steel_ingot"}, - {"default:steel_ingot", "", "default:steel_ingot"}, + {"default:steel_ingot", "", "default:steel_ingot"} } }) -- bronze horseshoes minetest.register_craftitem(":mobs:horseshoe_bronze", { description = S("Bronze HorseShoes (use on horse to apply)"), - inventory_image = "mobs_horseshoe_bronze.png", + inventory_image = "mobs_horseshoe_bronze.png" }) minetest.register_craft({ @@ -267,14 +282,14 @@ minetest.register_craft({ recipe = { {"", "default:bronzeblock", ""}, {"default:bronze_ingot", "", "default:bronze_ingot"}, - {"default:bronze_ingot", "", "default:bronze_ingot"}, + {"default:bronze_ingot", "", "default:bronze_ingot"} } }) -- mese horseshoes minetest.register_craftitem(":mobs:horseshoe_mese", { description = S("Mese HorseShoes (use on horse to apply)"), - inventory_image = "mobs_horseshoe_mese.png", + inventory_image = "mobs_horseshoe_mese.png" }) minetest.register_craft({ @@ -282,14 +297,14 @@ minetest.register_craft({ recipe = { {"", "default:mese", ""}, {"default:mese_crystal_fragment", "", "default:mese_crystal_fragment"}, - {"default:mese_crystal_fragment", "", "default:mese_crystal_fragment"}, + {"default:mese_crystal_fragment", "", "default:mese_crystal_fragment"} } }) -- diamond horseshoes minetest.register_craftitem(":mobs:horseshoe_diamond", { description = S("Diamond HorseShoes (use on horse to apply)"), - inventory_image = "mobs_horseshoe_diamond.png", + inventory_image = "mobs_horseshoe_diamond.png" }) minetest.register_craft({ @@ -297,7 +312,7 @@ minetest.register_craft({ recipe = { {"", "default:diamondblock", ""}, {"default:diamond", "", "default:diamond"}, - {"default:diamond", "", "default:diamond"}, + {"default:diamond", "", "default:diamond"} } }) @@ -306,7 +321,7 @@ if minetest.get_modpath("ethereal") then minetest.register_craftitem(":mobs:horseshoe_crystal", { description = S("Crystal HorseShoes (use on horse to apply)"), - inventory_image = "mobs_horseshoe_crystal.png", + inventory_image = "mobs_horseshoe_crystal.png" }) minetest.register_craft({ @@ -314,12 +329,13 @@ minetest.register_craft({ recipe = { {"", "ethereal:crystal_block", ""}, {"ethereal:crystal_ingot", "", "ethereal:crystal_ingot"}, - {"ethereal:crystal_ingot", "", "ethereal:crystal_ingot"}, + {"ethereal:crystal_ingot", "", "ethereal:crystal_ingot"} } }) end + -- lucky blocks if minetest.get_modpath("lucky_block") then diff --git a/spawn_example.lua b/spawn_example.lua new file mode 100644 index 0000000..dba11f4 --- /dev/null +++ b/spawn_example.lua @@ -0,0 +1,72 @@ + +--[[ 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 +}) +]]-- + + +-- Horse + +mobs:spawn({ + name = "mob_horse:horse", + nodes = {"default:dirt_with_grass", "ethereal:dry_dirt"}, + min_light = 14, + interval = 60, + chance = 16000, + min_height = 10, + max_height = 31000, + day_toggle = true +})