Added comments and figured out away to fix mob spawning bug

This commit is contained in:
Guy Liner 2022-01-04 23:15:48 -05:00
parent 627c37cd97
commit 385d34df33
1 changed files with 36 additions and 93 deletions

View File

@ -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
@ -692,6 +640,7 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative)
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