diff --git a/spawners_mobs/api.lua b/spawners_mobs/api.lua index d456adb..735bd9b 100644 --- a/spawners_mobs/api.lua +++ b/spawners_mobs/api.lua @@ -1,6 +1,6 @@ -- main tables -spawners = {} -spawners.mob_tables = {} +spawners_mobs = {} +spawners_mobs.mob_tables = {} -- check if mods exists and build tables for k, mob_mod in ipairs(ENABLED_MODS) do @@ -13,8 +13,7 @@ for k, mob_mod in ipairs(ENABLED_MODS) do -- disabled extra check for mobs redo due to incompatibility with Lua 5.1, this method is available from Lua 5.2 -- if mob_mod == "mobs" and not (mobs.mod == "redo") then goto continue end - table.insert(spawners.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}) - + table.insert(spawners_mobs.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}) -- use custom egg or create a default egg if mob.egg_name_custom ~= "" then mob_egg = mob.egg_name_custom @@ -40,7 +39,7 @@ for k, mob_mod in ipairs(ENABLED_MODS) do end -- start spawning mobs -function spawners.start_spawning(pos, how_many, mob_name, mod_prefix, sound_custom) +function spawners_mobs.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 @@ -80,7 +79,7 @@ function spawners.start_spawning(pos, how_many, mob_name, mod_prefix, sound_cust end end -function spawners.check_around_radius(pos) +function spawners_mobs.check_around_radius(pos) local player_near = false local radius = 21 @@ -93,8 +92,8 @@ function spawners.check_around_radius(pos) return player_near end -function spawners.check_node_status(pos, mob, night_only) - local player_near = spawners.check_around_radius(pos) +function spawners_mobs.check_node_status(pos, mob, night_only) + local player_near = spawners_mobs.check_around_radius(pos) if player_near then local random_pos = false diff --git a/spawners_mobs/depends.txt b/spawners_mobs/depends.txt index 16022f5..a35c5e8 100644 --- a/spawners_mobs/depends.txt +++ b/spawners_mobs/depends.txt @@ -2,4 +2,4 @@ default xpanes? fire? mobs? -creatures? +creatures? \ No newline at end of file diff --git a/spawners_mobs/init.lua b/spawners_mobs/init.lua index e0d9009..aa246bd 100644 --- a/spawners_mobs/init.lua +++ b/spawners_mobs/init.lua @@ -15,4 +15,4 @@ if minetest.get_modpath("mobs") then dofile(minetest.get_modpath(MOD_NAME).."/nodes_additional.lua") end -print ("[Mod] Spawners Mobs 0.6 Loaded.") \ No newline at end of file +print ("[Mod] Spawners Mobs 0.6 Loaded.") diff --git a/spawners_mobs/spawners_mobs.lua b/spawners_mobs/spawners_mobs.lua index 521ecf7..774025d 100644 --- a/spawners_mobs/spawners_mobs.lua +++ b/spawners_mobs/spawners_mobs.lua @@ -4,7 +4,7 @@ local max_obj_per_mapblock = tonumber(minetest.setting_get("max_objects_per_bloc -- * CREATE ALL SPAWNERS NODES * -- -function spawners.create(mob_name, mod_prefix, size, offset, mesh, texture, night_only, sound_custom) +function spawners_mobs.create(mob_name, mod_prefix, size, offset, mesh, texture, night_only, sound_custom) -- -- DUMMY INSIDE THE SPAWNER @@ -127,7 +127,7 @@ function spawners.create(mob_name, mod_prefix, size, offset, mesh, texture, nigh groups = {cracky=1,level=2}, stack_max = 1, on_construct = function(pos) - local random_pos, waiting = spawners.check_node_status(pos, mob_name, night_only) + local random_pos, waiting = spawners_mobs.check_node_status(pos, mob_name, night_only) if random_pos then minetest.set_node(pos, {name="spawners_mobs:"..mod_prefix.."_"..mob_name.."_spawner_active"}) @@ -180,7 +180,7 @@ function spawners.create(mob_name, mod_prefix, size, offset, mesh, texture, nigh catch_up = false, action = function(pos, node, active_object_count, active_object_count_wider) - local random_pos, waiting = spawners.check_node_status(pos, mob_name, night_only) + local random_pos, waiting = spawners_mobs.check_node_status(pos, mob_name, night_only) -- minetest.log("action", "[Mod][Spawners] checking for: "..mob_name.." at "..minetest.pos_to_string(pos)) @@ -208,7 +208,7 @@ function spawners.create(mob_name, mod_prefix, size, offset, mesh, texture, nigh end -- enough place to spawn more mobs - spawners.start_spawning(random_pos, 1, "spawners_mobs:"..mob_name, mod_prefix, sound_custom) + spawners_mobs.start_spawning(random_pos, 1, "spawners_mobs:"..mob_name, mod_prefix, sound_custom) elseif waiting then -- waiting status @@ -235,9 +235,9 @@ end -- CALL 'CREATE' FOR ALL SPAWNERS -- -for i, mob_table in ipairs(spawners.mob_tables) do +for i, mob_table in ipairs(spawners_mobs.mob_tables) do if mob_table then - spawners.create(mob_table.name, mob_table.mod_prefix, mob_table.dummy_size, mob_table.dummy_offset, mob_table.dummy_mesh, mob_table.dummy_texture, mob_table.night_only, mob_table.sound_custom) + spawners_mobs.create(mob_table.name, mob_table.mod_prefix, mob_table.dummy_size, mob_table.dummy_offset, mob_table.dummy_mesh, mob_table.dummy_texture, mob_table.night_only, mob_table.sound_custom) end end \ No newline at end of file diff --git a/spawners_ores/api.lua b/spawners_ores/api.lua index 41453d0..3899b9e 100644 --- a/spawners_ores/api.lua +++ b/spawners_ores/api.lua @@ -1,7 +1,7 @@ -- main tables -spawners = {} +spawners_ores = {} -function spawners.add_effects(pos, radius) +function spawners_ores.add_effects(pos, radius) minetest.add_particlespawner({ amount = 32, time = 2, @@ -15,12 +15,12 @@ function spawners.add_effects(pos, radius) maxexptime = 2, minsize = .5, maxsize = 8, - texture = "spawners_smoke_particle.png", + texture = "spawners_ores_smoke_particle.png", }) end -- start spawning ores -function spawners.start_spawning_ores(pos, ore_name, sound_custom, spawners_pos) +function spawners_ores.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 @@ -38,7 +38,7 @@ function spawners.start_spawning_ores(pos, ore_name, sound_custom, spawners_pos) for i=1, how_many do if i > 1 then - player_near, pos = spawners.check_around_radius_ores(pos, "default:stone") + player_near, pos = spawners_ores.check_around_radius_ores(pos, "default:stone") if not pos then return end @@ -49,7 +49,7 @@ function spawners.start_spawning_ores(pos, ore_name, sound_custom, spawners_pos) }) minetest.set_node(pos, {name=ore_name}) - spawners.add_effects(pos, 1) + spawners_ores.add_effects(pos, 1) else minetest.sound_play(sound_name, { pos = pos, @@ -58,14 +58,28 @@ function spawners.start_spawning_ores(pos, ore_name, sound_custom, spawners_pos) }) minetest.set_node(pos, {name=ore_name}) - spawners.add_effects(pos, 1) + spawners_ores.add_effects(pos, 1) end end end -function spawners.check_around_radius_ores(pos, check_node) - local player_near = spawners.check_around_radius(pos); +function spawners_ores.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_ores.check_around_radius_ores(pos, check_node) + local player_near = spawners_ores.check_around_radius(pos); local found_node = false local node_ore_pos = nil if check_node then @@ -80,10 +94,10 @@ function spawners.check_around_radius_ores(pos, check_node) return player_near, found_node end -function spawners.check_node_status_ores(pos, ore_name, check_node) +function spawners_ores.check_node_status_ores(pos, ore_name, check_node) if not check_node then return end - local player_near, found_node = spawners.check_around_radius_ores(pos, check_node) + local player_near, found_node = spawners_ores.check_around_radius_ores(pos, check_node) if player_near and found_node then return true, found_node diff --git a/spawners_ores/depends.txt b/spawners_ores/depends.txt index 4ad96d5..8754ca5 100644 --- a/spawners_ores/depends.txt +++ b/spawners_ores/depends.txt @@ -1 +1,3 @@ default +xpanes? +fire? \ No newline at end of file diff --git a/spawners_ores/init.lua b/spawners_ores/init.lua index 12a768a..e9e50a1 100644 --- a/spawners_ores/init.lua +++ b/spawners_ores/init.lua @@ -1,42 +1,9 @@ --- Main settings -dofile(minetest.get_modpath("spawners").."/settings.txt") - --- Spawners configurations -dofile(minetest.get_modpath("spawners").."/config.lua") +MOD_NAME = minetest.get_current_modname() -- API -dofile(minetest.get_modpath("spawners").."/API.lua") - --- Spawners for mobs -dofile(minetest.get_modpath("spawners").."/spawners_mobs.lua") +dofile(minetest.get_modpath(MOD_NAME).."/api.lua") -- Spawners for ores -dofile(minetest.get_modpath("spawners").."/spawners_ores.lua") +dofile(minetest.get_modpath(MOD_NAME).."/spawners_ores.lua") --- include mummy mobs redo addon (mob) -if minetest.get_modpath("mobs") then - dofile(minetest.get_modpath("spawners").."/mob_mummy.lua") -end - --- Spawners Pyramids -if SPAWN_PYRAMIDS then - dofile(minetest.get_modpath("spawners").."/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") - - print("[Mod][spawners] Spawners generate enabled") -end - --- Add Chests to dungeons, temples.. -if CHESTS_GENERATE then - dofile(minetest.get_modpath("spawners").."/chests_gen.lua") - - print("[Mod][spawners] Chests generate enabled") -end - -print ("[Mod] Spawners 0.6 Loaded.") \ No newline at end of file +print ("[Mod] Spawners Ores 0.6 Loaded.") diff --git a/spawners_ores/sounds/strike.ogg b/spawners_ores/sounds/spawners_ores_strike.ogg similarity index 100% rename from spawners_ores/sounds/strike.ogg rename to spawners_ores/sounds/spawners_ores_strike.ogg diff --git a/spawners_ores/spawners_ores.lua b/spawners_ores/spawners_ores.lua index 8ecfede..2fa905f 100644 --- a/spawners_ores/spawners_ores.lua +++ b/spawners_ores/spawners_ores.lua @@ -13,7 +13,13 @@ local ore_formspec = "listring[current_player;main]".. default.get_hotbar_bg(0, 4.25) -function spawners.get_formspec(pos) +local function can_dig(pos, player) + local meta = minetest.get_meta(pos); + local inv = meta:get_inventory() + return inv:is_empty("fuel") +end + +function spawners_ores.get_formspec(pos) -- Inizialize metadata local meta = minetest.get_meta(pos) @@ -32,12 +38,6 @@ function spawners.get_formspec(pos) meta:set_string("formspec", ore_formspec) end -local function can_dig(pos, player) - local meta = minetest.get_meta(pos); - local inv = meta:get_inventory() - return inv:is_empty("fuel") -end - local function allow_metadata_inventory_put(pos, listname, index, stack, player) if minetest.is_protected(pos, player:get_player_name()) then minetest.record_protection_violation(pos, player:get_player_name()) @@ -87,8 +87,8 @@ local function on_receive_fields(pos, formname, fields, sender) local fuellist = inv:get_list("fuel") if inv:is_empty("fuel") then - if ore_node.name ~= "spawners:stone_with_"..ingot[3].."_spawner" then - minetest.swap_node(pos, {name="spawners:stone_with_"..ingot[3].."_spawner"}) + if ore_node.name ~= "spawners_ores:stone_with_"..ingot[3].."_spawner" then + minetest.swap_node(pos, {name="spawners_ores:stone_with_"..ingot[3].."_spawner"}) end meta:set_string("infotext", ingot[3].." ore spawner is empty") else @@ -107,12 +107,12 @@ local function on_receive_fields(pos, formname, fields, sender) ingot[3] = "iron" end - local waiting, found_node = spawners.check_node_status_ores(pos, "stone_with_"..ingot[3], "default:stone") + local waiting, found_node = spawners_ores.check_node_status_ores(pos, "stone_with_"..ingot[3], "default:stone") if found_node then - minetest.swap_node(pos, {name="spawners:stone_with_"..ingot[3].."_spawner_active"}) + minetest.swap_node(pos, {name="spawners_ores:stone_with_"..ingot[3].."_spawner_active"}) elseif waiting then - minetest.swap_node(pos, {name="spawners:stone_with_"..ingot[3].."_spawner_waiting"}) + minetest.swap_node(pos, {name="spawners_ores:stone_with_"..ingot[3].."_spawner_waiting"}) meta:set_string("infotext", "Waiting status - player was away or no stone around, "..ingot[3].." ore spawner fuel: "..inv:get_stack("fuel", 1):get_count()) else @@ -122,7 +122,7 @@ local function on_receive_fields(pos, formname, fields, sender) end -- Ores creation -function spawners.create_ore(ore_name, mod_prefix, size, offset, texture, sound_custom) +function spawners_ores.create_ore(ore_name, mod_prefix, size, offset, texture, sound_custom) -- dummy inside the spawner local dummy_ore_definition = { hp_max = 1, @@ -150,16 +150,16 @@ function spawners.create_ore(ore_name, mod_prefix, size, offset, texture, sound_ self.timer = self.timer + dtime local n = minetest.get_node_or_nil(self.object:getpos()) if self.timer > 2 then - if n and n.name and n.name ~= "spawners:"..ore_name.."_spawner_active" and n.name ~= "spawners:"..ore_name.."_spawner_waiting" and n.name ~= "spawners:"..ore_name.."_spawner" then + if n and n.name and n.name ~= "spawners_ores:"..ore_name.."_spawner_active" and n.name ~= "spawners_ores:"..ore_name.."_spawner_waiting" and n.name ~= "spawners_ores:"..ore_name.."_spawner" then self.object:remove() end end end - minetest.register_entity("spawners:dummy_ore_"..ore_name, dummy_ore_definition) + minetest.register_entity("spawners_ores:dummy_ore_"..ore_name, dummy_ore_definition) -- node spawner active - minetest.register_node("spawners:"..ore_name.."_spawner_active", { + minetest.register_node("spawners_ores:"..ore_name.."_spawner_active", { description = ore_name.." spawner active", paramtype = "light", light_source = 4, @@ -170,7 +170,7 @@ function spawners.create_ore(ore_name, mod_prefix, size, offset, texture, sound_ sunlight_propagates = true, tiles = { { - name = "spawners_spawner_animated.png", + name = "spawners_ores_spawner_animated.png", animation = { type = "vertical_frames", aspect_w = 32, @@ -181,7 +181,7 @@ function spawners.create_ore(ore_name, mod_prefix, size, offset, texture, sound_ }, is_ground_content = true, groups = {cracky=1,level=2,igniter=1,not_in_creative_inventory=1}, - drop = "spawners:"..ore_name.."_spawner", + drop = "spawners_ores:"..ore_name.."_spawner", can_dig = can_dig, allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_take = allow_metadata_inventory_take, @@ -189,7 +189,7 @@ function spawners.create_ore(ore_name, mod_prefix, size, offset, texture, sound_ }) -- node spawner waiting - no stone around or no fuel - minetest.register_node("spawners:"..ore_name.."_spawner_waiting", { + minetest.register_node("spawners_ores:"..ore_name.."_spawner_waiting", { description = ore_name.." spawner waiting", paramtype = "light", light_source = 2, @@ -199,7 +199,7 @@ function spawners.create_ore(ore_name, mod_prefix, size, offset, texture, sound_ sunlight_propagates = true, tiles = { { - name = "spawners_spawner_waiting_animated.png", + name = "spawners_ores_spawner_waiting_animated.png", animation = { type = "vertical_frames", aspect_w = 32, @@ -210,7 +210,7 @@ function spawners.create_ore(ore_name, mod_prefix, size, offset, texture, sound_ }, is_ground_content = true, groups = {cracky=1,level=2,not_in_creative_inventory=1}, - drop = "spawners:"..ore_name.."_spawner", + drop = "spawners_ores:"..ore_name.."_spawner", can_dig = can_dig, allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_take = allow_metadata_inventory_take, @@ -218,22 +218,22 @@ function spawners.create_ore(ore_name, mod_prefix, size, offset, texture, sound_ }) -- node spawner inactive (default) - minetest.register_node("spawners:"..ore_name.."_spawner", { + minetest.register_node("spawners_ores:"..ore_name.."_spawner", { description = ore_name.." spawner", paramtype = "light", drawtype = "allfaces", walkable = true, sounds = default.node_sound_stone_defaults(), sunlight_propagates = true, - tiles = {"spawners_spawner.png"}, + tiles = {"spawners_ores_spawner.png"}, is_ground_content = true, groups = {cracky=1,level=2}, stack_max = 1, on_construct = function(pos) local meta = minetest.get_meta(pos) - spawners.get_formspec(pos) + spawners_ores.get_formspec(pos) pos.y = pos.y + offset - minetest.add_entity(pos,"spawners:dummy_ore_"..ore_name) + minetest.add_entity(pos,"spawners_ores:dummy_ore_"..ore_name) meta:set_string("infotext", ore[3].." ore spawner is empty") end, @@ -246,21 +246,20 @@ function spawners.create_ore(ore_name, mod_prefix, size, offset, texture, sound_ -- ABM minetest.register_abm({ - nodenames = {"spawners:"..ore_name.."_spawner_active", "spawners:"..ore_name.."_spawner_waiting"}, + nodenames = {"spawners_ores:"..ore_name.."_spawner_active", "spawners_ores:"..ore_name.."_spawner_waiting"}, interval = 5.0, chance = 5, action = function(pos, node, active_object_count, active_object_count_wider) - local waiting, found_node = spawners.check_node_status_ores(pos, ore_name, "default:stone") - + local waiting, found_node = spawners_ores.check_node_status_ores(pos, ore_name, "default:stone") local meta = minetest.get_meta(pos) local inv = meta:get_inventory() if found_node then -- make sure the right node status is shown - if node.name ~= "spawners:"..ore_name.."_spawner_active" then - minetest.swap_node(pos, {name="spawners:"..ore_name.."_spawner_active"}) + if node.name ~= "spawners_ores:"..ore_name.."_spawner_active" then + minetest.swap_node(pos, {name="spawners_ores:"..ore_name.."_spawner_active"}) end @@ -274,18 +273,18 @@ function spawners.create_ore(ore_name, mod_prefix, size, offset, texture, sound_ meta:set_string("infotext", ore[3].." ore spawner fuel: "..inv:get_stack("fuel", 1):get_count()) -- enough place to spawn more ores - spawners.start_spawning_ores(found_node, "default:"..ore_name, sound_custom) + spawners_ores.start_spawning_ores(found_node, "default:"..ore_name, sound_custom) -- empty / no fuel if inv:is_empty("fuel") then - minetest.swap_node(pos, {name="spawners:"..ore_name.."_spawner"}) + minetest.swap_node(pos, {name="spawners_ores:"..ore_name.."_spawner"}) meta:set_string("infotext", ore[3].." ore spawner is empty.") end else -- waiting status - if node.name ~= "spawners:"..ore_name.."_spawner_waiting" then - minetest.swap_node(pos, {name="spawners:"..ore_name.."_spawner_waiting"}) + if node.name ~= "spawners_ores:"..ore_name.."_spawner_waiting" then + minetest.swap_node(pos, {name="spawners_ores:"..ore_name.."_spawner_waiting"}) meta:set_string("infotext", "Waiting status - player was away or no stone around, "..ore[3].." ore spawner fuel: "..inv:get_stack("fuel", 1):get_count()) end @@ -297,18 +296,18 @@ function spawners.create_ore(ore_name, mod_prefix, size, offset, texture, sound_ end -- default:stone_with_gold -spawners.create_ore("stone_with_gold", "", {x=.33,y=.33}, 0, {"default_stone.png^default_mineral_gold.png"}, "strike") +spawners_ores.create_ore("stone_with_gold", "", {x=.33,y=.33}, 0, {"default_stone.png^default_mineral_gold.png"}, "spawners_ores_strike") -- default:stone_with_iron -spawners.create_ore("stone_with_iron", "", {x=.33,y=.33}, 0, {"default_stone.png^default_mineral_gold.png"}, "strike") +spawners_ores.create_ore("stone_with_iron", "", {x=.33,y=.33}, 0, {"default_stone.png^default_mineral_gold.png"}, "spawners_ores_strike") -- default:stone_with_copper -spawners.create_ore("stone_with_copper", "", {x=.33,y=.33}, 0, {"default_stone.png^default_mineral_gold.png"}, "strike") +spawners_ores.create_ore("stone_with_copper", "", {x=.33,y=.33}, 0, {"default_stone.png^default_mineral_gold.png"}, "spawners_ores_strike") -- recipes minetest.register_craft({ - output = "spawners:stone_with_gold_spawner", + output = "spawners_ores:stone_with_gold_spawner", recipe = { {"default:diamondblock", "fire:flint_and_steel", "default:diamondblock"}, {"xpanes:bar_flat", "default:goldblock", "xpanes:bar_flat"}, @@ -317,7 +316,7 @@ minetest.register_craft({ }) minetest.register_craft({ - output = "spawners:stone_with_iron_spawner", + output = "spawners_ores:stone_with_iron_spawner", recipe = { {"default:diamondblock", "fire:flint_and_steel", "default:diamondblock"}, {"xpanes:bar_flat", "default:steelblock", "xpanes:bar_flat"}, @@ -326,7 +325,7 @@ minetest.register_craft({ }) minetest.register_craft({ - output = "spawners:stone_with_copper_spawner", + output = "spawners_ores:stone_with_copper_spawner", recipe = { {"default:diamondblock", "fire:flint_and_steel", "default:diamondblock"}, {"xpanes:bar_flat", "default:copperblock", "xpanes:bar_flat"}, diff --git a/spawners_ores/textures/spawners_smoke_particle.png b/spawners_ores/textures/spawners_ores_smoke_particle.png similarity index 100% rename from spawners_ores/textures/spawners_smoke_particle.png rename to spawners_ores/textures/spawners_ores_smoke_particle.png diff --git a/spawners_ores/textures/spawners_spawner.png b/spawners_ores/textures/spawners_ores_spawner.png similarity index 100% rename from spawners_ores/textures/spawners_spawner.png rename to spawners_ores/textures/spawners_ores_spawner.png diff --git a/spawners_ores/textures/spawners_spawner_animated.png b/spawners_ores/textures/spawners_ores_spawner_animated.png similarity index 100% rename from spawners_ores/textures/spawners_spawner_animated.png rename to spawners_ores/textures/spawners_ores_spawner_animated.png diff --git a/spawners_ores/textures/spawners_spawner_normal.png b/spawners_ores/textures/spawners_ores_spawner_normal.png similarity index 100% rename from spawners_ores/textures/spawners_spawner_normal.png rename to spawners_ores/textures/spawners_ores_spawner_normal.png diff --git a/spawners_ores/textures/spawners_spawner_waiting_animated.png b/spawners_ores/textures/spawners_ores_spawner_waiting_animated.png similarity index 100% rename from spawners_ores/textures/spawners_spawner_waiting_animated.png rename to spawners_ores/textures/spawners_ores_spawner_waiting_animated.png