From 699c2884ad8780d89290f614b2bca5c66bc29076 Mon Sep 17 00:00:00 2001 From: Jordan Leppert Date: Thu, 30 Dec 2021 12:21:12 +0000 Subject: [PATCH] Use sheep from animalia or mobs_animal if they are installed, instead of own built-in sheep. --- init.lua | 24 +++++++++++++++++++++--- magic.lua | 21 +++++++-------------- mod.conf | 2 +- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/init.lua b/init.lua index b7d4882..a073d9f 100644 --- a/init.lua +++ b/init.lua @@ -60,15 +60,33 @@ dofile(path .. "/utilities.lua") dofile(path .. "/ui.lua") dofile(path .. "/items.lua") dofile(path .. "/nodes.lua") -dofile(path .. "/sheep.lua") + +-- This gets the list of possible sheep that an enemy can be turned into +if minetest.get_modpath("animalia") then + witches.sheep = {"animalia:sheep"} +elseif minetest.get_modpath("mobs_animal") then + witches.sheep = {} + for key, value in pairs(minetest.registered_entities) do + if string.sub(key, 1, #("mobs_animal:sheep_")) == "mobs_animal:sheep_" then + witches.sheep[#witches.sheep + 1] = key + end + end +else + dofile(path .. "/sheep.lua") + witches.sheep = {} + for _, col in ipairs(witches.sheep_colors) do + witches.sheep[#witches.sheep + 1] = "witches:sheep_" .. col[1] + end +end + dofile(path .. "/magic.lua") if not minetest.get_modpath("handle_schematics") then print("optional handle_schematics not found!\n Witch cottages not available!") --dofile(path .. "/cottages.lua") - + else - + dofile(path .. "/basic_houses.lua") print("handle_schematics found! Witch cottages enabled!") end diff --git a/magic.lua b/magic.lua index 4b94d87..8ee1ec4 100644 --- a/magic.lua +++ b/magic.lua @@ -1,5 +1,4 @@ witches.magic = {} -local wsc = witches.sheep_colors local magic_texture = "bubble.png" local magic_animation = nil @@ -136,20 +135,13 @@ end function witches.magic.polymorph(self, target, mob, duration) duration = duration or 0 - local colors = {} local caster_pos = self.object:get_pos() minetest.sound_play(self.sounds.polymorph or "witches_magic02", { pos = caster_pos, gain = 1.0, max_hear_distance = self.sounds and self.sounds.distance or 32 }, true) - - for _, col in ipairs(wsc) do - table.insert(colors,col[1]) - end - local r_sheep = "witches:sheep_"..colors[math.random(#colors)] - mob = mob or r_sheep - + local ent = target:get_luaentity() local ent_pos = ent.object:get_pos() @@ -167,9 +159,10 @@ function witches.magic.polymorph(self, target, mob, duration) witches.magic.effect_area01(vol_ent[1],vol_ent[2],200) - local new_obj = minetest.add_entity(ent_pos, mob) - --local new_ent = new_obj:get_luaentity() - --new_ent.old_mob_name = ent.name + mob = mob or witches.sheep[math.random(1, #witches.sheep)] + if mob then + local new_obj = minetest.add_entity(ent_pos, mob) + end end --volume is a vector! @@ -190,9 +183,9 @@ function witches.magic.splash(self,target,volume,height,node) ) local air_nodes = minetest.find_nodes_in_area(vol[1],vol[2], {"air"}) - + if air_nodes then - for i=1, #air_nodes do + for i=1, #air_nodes do minetest.add_node(air_nodes[i], {name=node}) witches.magic.effect_area01(vol[1],vol[2],100) diff --git a/mod.conf b/mod.conf index 5d2609a..e1ca887 100644 --- a/mod.conf +++ b/mod.conf @@ -1,4 +1,4 @@ name = witches descriptions = adds witches depends = default, mobs -optional_depends = handle_schematics +optional_depends = handle_schematics, animalia, mobs_animal