From 5305b5c4cc06343113be796c829b5a4de309f9a2 Mon Sep 17 00:00:00 2001 From: Juraj Vajda Date: Sun, 9 Oct 2016 22:05:30 +0200 Subject: [PATCH] spawners_env initial commit --- spawners_env/api.lua | 278 ++++++++++++++++++++++++++++++++ spawners_env/config.example.lua | 241 +++++++++++++++++++++++++++ spawners_env/init.lua | 14 +- spawners_env/pyramids.lua | 22 +-- spawners_env/pyramids_nodes.lua | 8 +- spawners_env/pyramids_room.lua | 6 +- spawners_env/spawners_gen.lua | 4 +- 7 files changed, 547 insertions(+), 26 deletions(-) create mode 100644 spawners_env/api.lua create mode 100644 spawners_env/config.example.lua diff --git a/spawners_env/api.lua b/spawners_env/api.lua new file mode 100644 index 0000000..a54d484 --- /dev/null +++ b/spawners_env/api.lua @@ -0,0 +1,278 @@ +-- main tables +spawners = {} +spawners_env.mob_tables = {} + +-- check if mods exists and build tables +for k, mob_mod in ipairs(ENABLED_MODS) do + local modpath = minetest.get_modpath(mob_mod) + -- list of mobs and their info + if (modpath) then + for j, mob in ipairs(MOBS_PROPS[mob_mod]) do + local mob_egg = nil + + if mob_mod == "mobs" and not (mobs.mod == "redo") then goto continue end + + table.insert(spawners_env.mob_tables, {name=mob.name, mod_prefix=mob_mod, egg_name_custom=mob.egg_name_custom, dummy_size=mob.dummy_size, dummy_offset=mob.dummy_offset, dummy_mesh=mob.dummy_mesh, dummy_texture=mob.dummy_texture, night_only=mob.night_only, sound_custom=mob.sound_custom, env=mob.env}) + + -- use custom egg or create a default egg + if mob.egg_name_custom ~= "" then + mob_egg = mob.egg_name_custom + else + mob_egg = mob_mod..":"..mob.name + end + + -- recipes - not for environmental spawners + if not mob.env then + minetest.register_craft({ + output = "spawners_env:"..mob_mod.."_"..mob.name.."_spawner", + recipe = { + {"default:diamondblock", "fire:flint_and_steel", "default:diamondblock"}, + {"xpanes:bar_flat", mob_egg, "xpanes:bar_flat"}, + {"default:diamondblock", "xpanes:bar_flat", "default:diamondblock"}, + } + }) + end + + ::continue:: + end + else + -- print something ? + end +end + +-- start spawning mobs +function spawners_env.start_spawning(pos, how_many, mob_name, mod_prefix, sound_custom) + if not (pos or how_many or mob_name) then return end + + local sound_name + -- remove 'spawners_env:' from the string + local mob_name = string.sub(mob_name,10) + + -- use custom sounds + if sound_custom ~= "" then + sound_name = sound_custom + else + sound_name = mod_prefix.."_"..mob_name + end + + -- use random colours for sheeps + if mob_name == "sheep_white" then + local mob_name1 = "" + local sheep_colours = {"black", "blue", "brown", "cyan", "dark_green", "dark_grey", "green", "grey", "magenta", "orange", "pink", "red", "violet", "white", "yellow"} + local random_colour = math.random(1, #sheep_colours) + mob_name1 = string.split(mob_name, "_") + mob_name1 = mob_name1[1] + mob_name = mob_name1.."_"..sheep_colours[random_colour] + end + + for i=1,how_many do + pos.y = pos.y+1 + local obj = minetest.add_entity(pos, mod_prefix..":"..mob_name) + + if obj then + if sound_name then + minetest.sound_play(sound_name, { + pos = pos, + max_hear_distance = 32, + gain = 10, + }) + end + end + end +end + +function spawners_env.add_effects(pos, radius) + minetest.add_particlespawner({ + amount = 32, + time = 2, + minpos = vector.subtract({x=pos.x, y=pos.y+1, z=pos.z}, radius / 2), + maxpos = vector.add({x=pos.x, y=pos.y+1, z=pos.z}, radius / 2), + minvel = {x=-0.5, y=3, z=-0.5}, + maxvel = {x=0.5, y=10, z=0.5}, + minacc = vector.new(), + maxacc = vector.new(), + minexptime = .5, + maxexptime = 2, + minsize = .5, + maxsize = 8, + texture = "spawners_smoke_particle.png", + }) +end + +-- start spawning ores +function spawners_env.start_spawning_ores(pos, ore_name, sound_custom, spawners_pos) + if not pos or not ore_name then return end + local sound_name + local player_near = false + + -- use custom sounds + if sound_custom ~= "" then + sound_name = sound_custom + else + sound_name = false + end + + local how_many = math.random(1,2) + -- how_many = how_many+1 + + for i=1, how_many do + + if i > 1 then + player_near, pos = spawners_env.check_around_radius_ores(pos, "default:stone") + + if not pos then return end + + minetest.sound_play(sound_name, { + pos = pos, + max_hear_distance = 32, + gain = 20, + }) + + minetest.set_node(pos, {name=ore_name}) + spawners_env.add_effects(pos, 1) + else + minetest.sound_play(sound_name, { + pos = pos, + max_hear_distance = 32, + gain = 20, + }) + + minetest.set_node(pos, {name=ore_name}) + spawners_env.add_effects(pos, 1) + end + end + +end + +function spawners_env.check_around_radius(pos) + local player_near = false + local radius = 21 + local node_ore_pos = nil + + for _,obj in ipairs(minetest.get_objects_inside_radius(pos, radius)) do + if obj:is_player() then + player_near = true + end + end + + return player_near +end + +function spawners_env.check_around_radius_ores(pos, check_node) + local player_near = spawners_env.check_around_radius(pos); + local found_node = false + local node_ore_pos = nil + if check_node then + + node_ore_pos = minetest.find_node_near(pos, 2, {check_node}) + + if node_ore_pos then + found_node = node_ore_pos + end + end + + return player_near, found_node +end + +function spawners_env.check_node_status(pos, mob, night_only) + local player_near = spawners_env.check_around_radius(pos) + + if player_near then + local random_pos = false + local min_node_light = 10 + local tod = minetest.get_timeofday() * 24000 + local node_light = minetest.get_node_light(pos) + + if not node_light then + return false + end + + local spawn_positions = {} + local right = minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z}) + local front = minetest.get_node({x=pos.x, y=pos.y, z=pos.z+1}) + local left = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z}) + local back = minetest.get_node({x=pos.x, y=pos.y, z=pos.z-1}) + local top = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}) + local bottom = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}) + + -- make sure that at least one side of the spawner is open + if right.name == "air" then + table.insert(spawn_positions, {x=pos.x+1.5, y=pos.y, z=pos.z}) + end + if front.name == "air" then + table.insert(spawn_positions, {x=pos.x, y=pos.y, z=pos.z+1.5}) + end + if left.name == "air" then + table.insert(spawn_positions, {x=pos.x-1.5, y=pos.y, z=pos.z}) + end + if back.name == "air" then + table.insert(spawn_positions, {x=pos.x, y=pos.y, z=pos.z-1.5}) + end + if top.name == "air" then + table.insert(spawn_positions, {x=pos.x, y=pos.y+1.5, z=pos.z}) + end + if bottom.name == "air" then + table.insert(spawn_positions, {x=pos.x, y=pos.y-1.5, z=pos.z}) + end + + if #spawn_positions < 1 then + -- spawner is cloed from all sides + return false + else + -- pick random from the open sides + local pick_random + + if #spawn_positions == 1 then + pick_random = #spawn_positions + else + pick_random = math.random(1,#spawn_positions) + end + + for k, v in pairs (spawn_positions) do + if k == pick_random then + random_pos = v + end + end + end + + -- check the node above and below the found air node + local node_above = minetest.get_node({x=random_pos.x, y=random_pos.y+1, z=random_pos.z}).name + local node_below = minetest.get_node({x=random_pos.x, y=random_pos.y-1, z=random_pos.z}).name + + if not (node_above == "air" or node_below == "air") then + return false + end + + if night_only ~= "disable" then + -- spawn only at day + if not night_only and node_light < min_node_light then + return false, true + end + + -- spawn only at night + if night_only then + if not (19359 > tod and tod > 5200) or node_light < min_node_light then + return random_pos + else + return false, true + end + end + end + + return random_pos, false + else + return false, true + end +end + +function spawners_env.check_node_status_ores(pos, ore_name, check_node) + if not check_node then return end + + local player_near, found_node = spawners_env.check_around_radius_ores(pos, check_node) + + if player_near and found_node then + return true, found_node + else + return true, false + end +end \ No newline at end of file diff --git a/spawners_env/config.example.lua b/spawners_env/config.example.lua new file mode 100644 index 0000000..782cc56 --- /dev/null +++ b/spawners_env/config.example.lua @@ -0,0 +1,241 @@ +-- * [name : string] - Name of the mob used in the mod. + +-- [egg_name_custom : string] - Custom name for the egg item. If empty default name will be used i.e. 'mobs:chicken'. + +-- * [dummy_size : table] - Size of the rotating dummy inside the node. + +-- * [dummy_offset : integer] - Offset on Y axis of the dummy inside the node. + +-- * [dummy_mesh : string] - Filename of the model used fot he mob. + +-- * [dummy_texture : table] - Textures used for the mob. + +-- * [night_only : boolean : string] - If true mobs will spawn only during the night or in dark areas, default:true. Writing "disable" will disable light check and it will spawn in both states (night and day) + +-- [sound_custom : string] - Custom name for the sound file name if differ from default: i.e 'mobs_cow'. + +-- [env : boolean] - This spawner will become environmental spawner. Environmental spawners have different properties/behaviour (used for map gen) and cannot be crafted. + +-- [*] -> MANDATORY - has to be filled in! + +-- mods what should be enabled and loded, remove/add the one you want to load +ENABLED_MODS = {"mobs", "pyramids", "creatures"} + +-- mobs properties - setup all you mobs here +MOBS_PROPS = { + + ["mobs"] = { -- MOBS REDO CONFIG + { + name="sheep_white", + egg_name_custom="", + dummy_size={x=0.52,y=0.52}, + dummy_offset=0.2, + dummy_mesh="mobs_sheep.b3d", + dummy_texture={"mobs_sheep_wool.png^mobs_sheep_base.png"}, + night_only=false, + sound_custom="mobs_sheep" + }, + { + name="cow", + egg_name_custom="", + dummy_size={x=0.3,y=0.3}, + dummy_offset=-0.3, + dummy_mesh="mobs_cow.x", + dummy_texture={"mobs_cow.png"}, + night_only=false, + sound_custom="" + }, + { + name="chicken", + egg_name_custom="", + dummy_size={x=0.9,y=0.9}, + dummy_offset=0.2, + dummy_mesh="mobs_chicken.x", + dummy_texture={"mobs_chicken.png", "mobs_chicken.png", "mobs_chicken.png", "mobs_chicken.png", "mobs_chicken.png", "mobs_chicken.png", "mobs_chicken.png", "mobs_chicken.png", "mobs_chicken.png"}, + night_only=false, + sound_custom="" + }, + { + name="pumba", + egg_name_custom="", + dummy_size={x=0.62,y=0.62}, + dummy_offset=-0.3, + dummy_mesh="mobs_pumba.x", + dummy_texture={"mobs_pumba.png"}, + night_only=false, + sound_custom="mobs_pig" + }, + { + name="bunny", + egg_name_custom="", + dummy_size={x=1,y=1}, + dummy_offset=0.2, + dummy_mesh="mobs_bunny.b3d", + dummy_texture={"mobs_bunny_brown.png"}, + night_only=false, + sound_custom="spawners_bunny" + }, + { + name="kitten", + egg_name_custom="", + dummy_size={x=0.32,y=0.32}, + dummy_offset=0, + dummy_mesh="mobs_kitten.b3d", + dummy_texture={"mobs_kitten_ginger.png"}, + night_only=false, + sound_custom="" + }, + { + name="spider", + egg_name_custom="", + dummy_size={x=2,y=2}, + dummy_offset=-0.2, + dummy_mesh="mobs_spider.x", + dummy_texture={"mobs_spider.png"}, + night_only=false, + sound_custom="" + }, + { + name="spider", + egg_name_custom="", + dummy_size={x=2,y=2}, + dummy_offset=-0.2, + dummy_mesh="mobs_spider.x", + dummy_texture={"mobs_spider.png"}, + night_only="disable", + sound_custom="", + env = true + }, + { + name="stone_monster", + egg_name_custom="", + dummy_size={x=0.5,y=0.5}, + dummy_offset=0.05, + dummy_mesh="mobs_stone_monster.b3d", + dummy_texture={"mobs_stone_monster.png"}, + night_only=false, + sound_custom="mobs_stonemonster" + }, + { + name="oerkki", + egg_name_custom="", + dummy_size={x=0.5,y=0.5}, + dummy_offset=0.05, + dummy_mesh="mobs_oerkki.b3d", + dummy_texture={"mobs_oerkki.png"}, + night_only=true, + sound_custom="" + }, + { + name="tree_monster", + egg_name_custom="", + dummy_size={x=0.4,y=0.4}, + dummy_offset=0.05, + dummy_mesh="mobs_tree_monster.b3d", + dummy_texture={"mobs_tree_monster.png"}, + night_only=true, + sound_custom="mobs_treemonster" + } + }, + + ["pyramids"] = { -- PYRAMIDS MOD CONFIG + { + name="mummy", + egg_name_custom="pyramids:spawn_egg", + dummy_size={x=3.3,y=3.3}, + dummy_offset=-0.3, + dummy_mesh="pyramids_mummy.x", + dummy_texture={"pyramids_mummy.png"}, + night_only=false, + sound_custom="mummy" + } + }, + + ["creatures"] = { -- CREATURES MOD CONFIG + { + name="chicken", + egg_name_custom="creatures:chicken_spawn_egg", + dummy_size={x=0.9,y=0.9}, + dummy_offset=-0.3, + dummy_mesh="creatures_chicken.b3d", + dummy_texture={"creatures_chicken.png"}, + night_only=false, + sound_custom="" + }, + { + name="ghost", + egg_name_custom="creatures:ghost_spawn_egg", + dummy_size={x=0.7,y=0.7}, + dummy_offset=-0.5, + dummy_mesh="creatures_ghost.b3d", + dummy_texture={"creatures_ghost.png"}, + night_only=true, + sound_custom="" + }, + { + name="sheep", + egg_name_custom="creatures:sheep_spawn_egg", + dummy_size={x=0.6,y=0.6}, + dummy_offset=-0.3, + dummy_mesh="creatures_sheep.b3d", + dummy_texture={"creatures_sheep.png^creatures_sheep_white.png"}, + night_only=false, + sound_custom="" + }, + { + name="zombie", + egg_name_custom="creatures:zombie_spawn_egg", + dummy_size={x=0.5,y=0.5}, + dummy_offset=-0.5, + dummy_mesh="creatures_zombie.b3d", + dummy_texture={"creatures_zombie.png"}, + night_only=false, + sound_custom="" + }, + { + name="oerrki", + egg_name_custom="creatures:oerrki_spawn_egg", + dummy_size={x=0.4,y=0.4}, + dummy_offset=-0.5, + dummy_mesh="creatures_oerrki.b3d", + dummy_texture={"creatures_oerrki.png"}, + night_only=false, + sound_custom="creatures_oerrki_idle" + } + } +} + +-- +-- check for 3rd party dependencies +-- + +-- include mummy mobs redo addon (spawner) +if minetest.get_modpath("mobs") ~= nil then + -- enable spawner + table.insert(ENABLED_MODS, "spawners") + + -- configure spawner + MOBS_PROPS["spawners"] = { + { + name="mummy", + egg_name_custom="", + dummy_size={x=0.4,y=0.4}, + dummy_offset=0, + dummy_mesh="spawners_mob_mummy.b3d", + dummy_texture={"spawners_mob_mummy.png"}, + night_only="disable", + sound_custom="spawners_mob_mummy" + }, + { + name="mummy", + egg_name_custom="", + dummy_size={x=0.4,y=0.4}, + dummy_offset=0, + dummy_mesh="spawners_mob_mummy.b3d", + dummy_texture={"spawners_mob_mummy.png"}, + night_only="disable", + sound_custom="spawners_mob_mummy", + env=true + } + } +end \ No newline at end of file diff --git a/spawners_env/init.lua b/spawners_env/init.lua index 1ed17d3..5aa68c4 100644 --- a/spawners_env/init.lua +++ b/spawners_env/init.lua @@ -1,29 +1,31 @@ +MOD_NAME = minetest.get_current_modname() + -- Main settings -dofile(minetest.get_modpath("spawners").."/settings.txt") +dofile(minetest.get_modpath(MOD_NAME).."/settings.txt") -- Spawners configurations -dofile(minetest.get_modpath("spawners").."/config.lua") +dofile(minetest.get_modpath(MOD_NAME).."/config.lua") -- API -dofile(minetest.get_modpath("spawners").."/api.lua") +dofile(minetest.get_modpath(MOD_NAME).."/api.lua") -- Spawners Pyramids if SPAWN_PYRAMIDS then - dofile(minetest.get_modpath("spawners").."/pyramids.lua") + dofile(minetest.get_modpath(MOD_NAME).."/pyramids.lua") print("[Mod][spawners] Pyramids enabled") end -- Add Spawners to dungeons, temples.. if SPAWNERS_GENERATE then - dofile(minetest.get_modpath("spawners").."/spawners_gen.lua") + dofile(minetest.get_modpath(MOD_NAME).."/spawners_gen.lua") print("[Mod][spawners] Spawners generate enabled") end -- Add Chests to dungeons, temples.. if CHESTS_GENERATE then - dofile(minetest.get_modpath("spawners").."/chests_gen.lua") + dofile(minetest.get_modpath(MOD_NAME).."/chests_gen.lua") print("[Mod][spawners] Chests generate enabled") end diff --git a/spawners_env/pyramids.lua b/spawners_env/pyramids.lua index beabee5..74a26a9 100644 --- a/spawners_env/pyramids.lua +++ b/spawners_env/pyramids.lua @@ -79,7 +79,7 @@ function pyramids.spawn_mummy(pos, number) -- needs mobs redo if minetest.get_modpath("mobs") ~= nil then for i=0,number do - minetest.add_entity(pos,"spawners:mummy") + minetest.add_entity(pos,"spawners_env:mummy") end end end @@ -87,7 +87,7 @@ end local function add_spawner(pos) -- needs mobs redo if minetest.get_modpath("mobs") ~= nil then - minetest.set_node(pos, {name="spawners:spawners_mummy_spawner_env"}) + minetest.set_node(pos, {name="spawners_env:spawners_mummy_spawner_env"}) if not minetest.setting_getbool("only_peaceful_mobs") then pyramids.spawn_mummy({x=pos.x,y=pos.y,z=pos.z-2},2) end @@ -235,26 +235,26 @@ end) -- -- spawner mummy -minetest.register_alias("pyramids:spawner_mummy", "spawners:spawners_mummy_spawner_env") --- minetest.register_alias("pyramids:mummy_spawner", "spawners:spawners_mummy_spawner_env") +minetest.register_alias("pyramids:spawner_mummy", "spawners_env:spawners_mummy_spawner_env") +-- minetest.register_alias("pyramids:mummy_spawner", "spawners_env:spawners_mummy_spawner_env") -- spawn egg -minetest.register_alias("pyramids:spawn_egg", "spawners:mummy") +minetest.register_alias("pyramids:spawn_egg", "spawners_env:mummy") -- mummy entity -minetest.register_alias("pyramids:mummy", "spawners:mummy") +minetest.register_alias("pyramids:mummy", "spawners_env:mummy") -- deco stone 1 -minetest.register_alias("pyramids:deco_stone1", "spawners:deco_stone1") +minetest.register_alias("pyramids:deco_stone1", "spawners_env:deco_stone1") -- deco stone 2 -minetest.register_alias("pyramids:deco_stone2", "spawners:deco_stone2") +minetest.register_alias("pyramids:deco_stone2", "spawners_env:deco_stone2") -- deco stone 3 -minetest.register_alias("pyramids:deco_stone3", "spawners:deco_stone3") +minetest.register_alias("pyramids:deco_stone3", "spawners_env:deco_stone3") -- deco trap -minetest.register_alias("pyramids:trap", "spawners:trap") +minetest.register_alias("pyramids:trap", "spawners_env:trap") -- deco trap 2 -minetest.register_alias("pyramids:trap_2", "spawners:trap_2") +minetest.register_alias("pyramids:trap_2", "spawners_env:trap_2") diff --git a/spawners_env/pyramids_nodes.lua b/spawners_env/pyramids_nodes.lua index 1f95507..0e8bb46 100644 --- a/spawners_env/pyramids_nodes.lua +++ b/spawners_env/pyramids_nodes.lua @@ -1,7 +1,7 @@ local img = {"eye", "men", "sun"} for i=1,3 do - minetest.register_node("spawners:deco_stone"..i, { + minetest.register_node("spawners_env:deco_stone"..i, { description = "Sandstone with "..img[i], tiles = {"default_sandstone.png^pyramids_"..img[i]..".png"}, is_ground_content = true, @@ -17,7 +17,7 @@ trap_on_timer = function (pos, elapsed) local n = minetest.get_node(pos) if n and n.name then if minetest.registered_nodes[n.name].crack and minetest.registered_nodes[n.name].crack < 2 then - minetest.set_node(pos, {name="spawners:trap_2"}) + minetest.set_node(pos, {name="spawners_env:trap_2"}) nodeupdate(pos) end end @@ -26,7 +26,7 @@ trap_on_timer = function (pos, elapsed) return true end -minetest.register_node("spawners:trap", { +minetest.register_node("spawners_env:trap", { description = "Cracked sandstone brick", tiles = {"default_sandstone_brick.png^pyramids_crack.png"}, is_ground_content = true, @@ -40,7 +40,7 @@ minetest.register_node("spawners:trap", { drop = "", }) -minetest.register_node("spawners:trap_2", { +minetest.register_node("spawners_env:trap_2", { description = "trapstone", tiles = {"default_sandstone_brick.png^pyramids_crack.png^[transformR90"}, is_ground_content = true, diff --git a/spawners_env/pyramids_room.lua b/spawners_env/pyramids_room.lua index cec8c4c..211c99c 100644 --- a/spawners_env/pyramids_room.lua +++ b/spawners_env/pyramids_room.lua @@ -32,15 +32,15 @@ code["t"] = "trap" local function replace(str,iy) local out = "default:" if iy < 4 and str == "c" then str = "a" end - if iy == 0 and str == "s" then out = "spawners:" str = "sun" end - if iy == 3 and str == "s" then out = "spawners:" str = "men" end + if iy == 0 and str == "s" then out = "spawners_env:" str = "sun" end + if iy == 3 and str == "s" then out = "spawners_env:" str = "men" end if str == "a" then out = "" end return out..code[str] end local function replace2(str,iy) local out = "default:" - if iy == 0 and str == "l" then out = "spawners:" str = "t" + if iy == 0 and str == "l" then out = "spawners_env:" str = "t" elseif iy < 3 and str == "l" then str = "a" end if str == "a" then out = "" end diff --git a/spawners_env/spawners_gen.lua b/spawners_env/spawners_gen.lua index 620f7bb..9b2c6e6 100644 --- a/spawners_env/spawners_gen.lua +++ b/spawners_env/spawners_gen.lua @@ -14,11 +14,11 @@ local function place_spawner(param) if gen_obj == "dungeon" then minetest.log("action", "[Mod][Spawners] dungeon spawner placed at: "..minetest.pos_to_string(pos)) - minetest.set_node(pos, {name = "spawners:spawners_mummy_spawner_env"}) + minetest.set_node(pos, {name = "spawners_env:spawners_mummy_spawner_env"}) else minetest.log("action", "[Mod][Spawners] temple spawner placed at: "..minetest.pos_to_string(pos)) - minetest.set_node(pos, {name = "spawners:mobs_spider_spawner_env"}) + minetest.set_node(pos, {name = "spawners_env:mobs_spider_spawner_env"}) end end