From 385d34df33202ef14adc928ab85c89fc5b6693d7 Mon Sep 17 00:00:00 2001 From: Guy Liner Date: Tue, 4 Jan 2022 23:15:48 -0500 Subject: [PATCH 1/4] Added comments and figured out away to fix mob spawning bug --- mods/ENTITIES/mcl_mobs/api/api.lua | 129 ++++++++--------------------- 1 file changed, 36 insertions(+), 93 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api/api.lua b/mods/ENTITIES/mcl_mobs/api/api.lua index 639eb517d..e86827efa 100644 --- a/mods/ENTITIES/mcl_mobs/api/api.lua +++ b/mods/ENTITIES/mcl_mobs/api/api.lua @@ -436,55 +436,6 @@ function mobs:register_mob(name, def) end -- END mobs:register_mob function - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- register arrow for shoot attack function mobs:register_arrow(name, def) @@ -586,36 +537,6 @@ function mobs:register_arrow(name, def) self.object:remove(); return end - - --[[ - local entity = player:get_luaentity() - - if entity - and self.hit_mob - and entity._cmi_is_mob == true - and tostring(player) ~= self.owner_id - and entity.name ~= self.object:get_luaentity().name - and (self._shooter and entity.name ~= self._shooter:get_luaentity().name) then - - --self.hit_mob(self, player) - self.object:remove(); - return - end - ]]-- - - --[[ - if entity - and self.hit_object - and (not entity._cmi_is_mob) - and tostring(player) ~= self.owner_id - and entity.name ~= self.object:get_luaentity().name - and (self._shooter and entity.name ~= self._shooter:get_luaentity().name) then - - --self.hit_object(self, player) - self.object:remove(); - return - end - ]]-- end end @@ -630,7 +551,6 @@ end -- * spawn_egg=1: Spawn egg (generic mob, no metadata) -- * spawn_egg=2: Spawn egg (captured/tamed mob, metadata) function mobs:register_egg(mob, desc, background, addegg, no_creative) - local grp = {spawn_egg = 1} -- do NOT add this egg to creative inventory (e.g. dungeon master) @@ -647,7 +567,6 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative) -- register old stackable mob egg minetest.register_craftitem(mob, { - description = desc, inventory_image = invimg, groups = grp, @@ -668,20 +587,49 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative) if pos --and within_limits(pos, 0) + + --testing to see if the block you are trying to mess with is protected and not minetest.is_protected(pos, placer:get_player_name()) then + --getting the name of the player that placed the egg, and their privileges. local name = placer:get_player_name() local privs = minetest.get_player_privs(name) + if mod_mobspawners and under.name == "mcl_mobspawners:spawner" then + --If the thing you are trying to spawn the egg on is protected + --the violation gets reported if minetest.is_protected(pointed_thing.under, name) then minetest.record_protection_violation(pointed_thing.under, name) return itemstack end + if not privs.maphack then minetest.chat_send_player(name, S("You need the “maphack” privilege to change the mob spawner.")) return itemstack end - mcl_mobspawners.setup_spawner(pointed_thing.under, itemstack:get_name()) + + --Changes the mob spawner type with the egg that you used to click on it + --determining monster spawn lvl + local monster_lightlvl = { + zombie = 0 + } + + local hold_light = 15 + local mon_name + + --Extracts mob name from item name + for name in string.gmatch(itemstack:get_name(), ":%a.*") do + mon_name = name:gsub(":", "") + end + + for name, lightlvl in pairs(monster_lightlvl) do + print(mon_name == name) + if name == mon_name then + hold_light = lightlvl + end + end + mcl_mobspawners.setup_spawner(pointed_thing.under, itemstack:get_name(), 0, hold_light) + if not mobs.is_creative(name) then itemstack:take_item() end @@ -691,7 +639,8 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative) if not minetest_registered_entities[mob] then return itemstack end - + + --If only peaceful mobs are allowed, player is not allowed to spawn a monster if minetest_settings:get_bool("only_peaceful_mobs", false) and minetest_registered_entities[mob].type == "monster" then minetest.chat_send_player(name, S("Only peaceful mobs allowed!")) @@ -699,18 +648,11 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative) end local mob = minetest_add_entity(pos, mob) + + --Log that a mob was spawned by the player who spawned it and the coordinates minetest.log("action", "Mob spawned: "..name.." at "..minetest.pos_to_string(pos)) local ent = mob:get_luaentity() - -- don't set owner if monster or sneak pressed - --[[ - if ent.type ~= "monster" - and not placer:get_player_control().sneak then - ent.owner = placer:get_player_name() - ent.tamed = true - end - ]]-- - -- set nametag local nametag = itemstack:get_meta():get_string("name") if nametag ~= "" then @@ -721,7 +663,8 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative) --update_tag(ent) end - -- if not in creative then take item + -- if not in creative then remove the item from the stack + -- taking the player's item if not mobs.is_creative(placer:get_player_name()) then itemstack:take_item() end From 04a81af4a13e6a179b2bbd45465695d5a2aa7eda Mon Sep 17 00:00:00 2001 From: Guy Liner Date: Wed, 5 Jan 2022 10:42:50 -0500 Subject: [PATCH 2/4] Make sure that the player is not in creative mode before giving them experience points --- mods/ITEMS/mcl_mobspawners/init.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_mobspawners/init.lua b/mods/ITEMS/mcl_mobspawners/init.lua index 0795fb611..37720e1e8 100644 --- a/mods/ITEMS/mcl_mobspawners/init.lua +++ b/mods/ITEMS/mcl_mobspawners/init.lua @@ -317,7 +317,12 @@ minetest.register_node("mcl_mobspawners:spawner", { if obj then obj:remove() end - mcl_experience.throw_xp(pos, math.random(15, 43)) + + --Make sure the player is not in creative mode before + --giving them xp + if not minetest.is_creative_enabled(name) then + mcl_experience.throw_xp(pos, math.random(15, 43)) + end end, on_punch = function(pos) From a9eb6cb747bafa699218b3a342b642e05096b1e5 Mon Sep 17 00:00:00 2001 From: Guy Liner Date: Wed, 5 Jan 2022 10:44:01 -0500 Subject: [PATCH 3/4] Moved that table that contains every monster's light spawning levels to a different file, added some comments --- mods/ENTITIES/mcl_mobs/api/api.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api/api.lua b/mods/ENTITIES/mcl_mobs/api/api.lua index e86827efa..ea7589f47 100644 --- a/mods/ENTITIES/mcl_mobs/api/api.lua +++ b/mods/ENTITIES/mcl_mobs/api/api.lua @@ -144,6 +144,7 @@ dofile(api_path .. "mob_effects.lua") dofile(api_path .. "projectile_handling.lua") dofile(api_path .. "breeding.lua") dofile(api_path .. "head_logic.lua") +dofile(api_path .. "monster_light.lua") mobs.spawning_mobs = {} @@ -610,9 +611,6 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative) --Changes the mob spawner type with the egg that you used to click on it --determining monster spawn lvl - local monster_lightlvl = { - zombie = 0 - } local hold_light = 15 local mon_name @@ -622,12 +620,16 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative) mon_name = name:gsub(":", "") end + --For every monster in the monster_lightlvl table check if + --it matches the spawn egg you're holding for name, lightlvl in pairs(monster_lightlvl) do print(mon_name == name) if name == mon_name then hold_light = lightlvl end end + + --Switch out the mob spawner to spawn mobs from the egg that you're holding mcl_mobspawners.setup_spawner(pointed_thing.under, itemstack:get_name(), 0, hold_light) if not mobs.is_creative(name) then From 502f85f63763bd3bea5e830abcd069303d8dc559 Mon Sep 17 00:00:00 2001 From: Guy Liner Date: Wed, 5 Jan 2022 10:45:15 -0500 Subject: [PATCH 4/4] Added a file that contains a table of every monsters light spawning levels --- .../api/mob_functions/monster_light.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 mods/ENTITIES/mcl_mobs/api/mob_functions/monster_light.lua diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/monster_light.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/monster_light.lua new file mode 100644 index 000000000..266ade6f8 --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/monster_light.lua @@ -0,0 +1,18 @@ +-- This file contains all of the light levels for monsters in the game +-- If the mob is not here they either do not exist or can spawn at any light level +monster_lightlvl = { + zombie = 0, + skeleton = 0, + stray = 0, + blaze = 11, + skeleton_wither = 7, + pigman = 10, + baby_pigman = 10, + slime_big = 7, + creeper = 0, + witch = 0, + spider = 0, + silverfish = 11, + endermen = 7, + bat = 3 +}