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 end -- END mobs:register_mob function
-- register arrow for shoot attack -- register arrow for shoot attack
function mobs:register_arrow(name, def) function mobs:register_arrow(name, def)
@ -586,36 +537,6 @@ function mobs:register_arrow(name, def)
self.object:remove(); self.object:remove();
return return
end 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
end end
@ -630,7 +551,6 @@ end
-- * spawn_egg=1: Spawn egg (generic mob, no metadata) -- * spawn_egg=1: Spawn egg (generic mob, no metadata)
-- * spawn_egg=2: Spawn egg (captured/tamed mob, metadata) -- * spawn_egg=2: Spawn egg (captured/tamed mob, metadata)
function mobs:register_egg(mob, desc, background, addegg, no_creative) function mobs:register_egg(mob, desc, background, addegg, no_creative)
local grp = {spawn_egg = 1} local grp = {spawn_egg = 1}
-- do NOT add this egg to creative inventory (e.g. dungeon master) -- 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 -- register old stackable mob egg
minetest.register_craftitem(mob, { minetest.register_craftitem(mob, {
description = desc, description = desc,
inventory_image = invimg, inventory_image = invimg,
groups = grp, groups = grp,
@ -668,20 +587,49 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative)
if pos if pos
--and within_limits(pos, 0) --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 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 name = placer:get_player_name()
local privs = minetest.get_player_privs(name) local privs = minetest.get_player_privs(name)
if mod_mobspawners and under.name == "mcl_mobspawners:spawner" then 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 if minetest.is_protected(pointed_thing.under, name) then
minetest.record_protection_violation(pointed_thing.under, name) minetest.record_protection_violation(pointed_thing.under, name)
return itemstack return itemstack
end end
if not privs.maphack then if not privs.maphack then
minetest.chat_send_player(name, S("You need the “maphack” privilege to change the mob spawner.")) minetest.chat_send_player(name, S("You need the “maphack” privilege to change the mob spawner."))
return itemstack return itemstack
end 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 if not mobs.is_creative(name) then
itemstack:take_item() itemstack:take_item()
end end
@ -691,7 +639,8 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative)
if not minetest_registered_entities[mob] then if not minetest_registered_entities[mob] then
return itemstack return itemstack
end end
--If only peaceful mobs are allowed, player is not allowed to spawn a monster
if minetest_settings:get_bool("only_peaceful_mobs", false) if minetest_settings:get_bool("only_peaceful_mobs", false)
and minetest_registered_entities[mob].type == "monster" then and minetest_registered_entities[mob].type == "monster" then
minetest.chat_send_player(name, S("Only peaceful mobs allowed!")) 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 end
local mob = minetest_add_entity(pos, mob) 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)) minetest.log("action", "Mob spawned: "..name.." at "..minetest.pos_to_string(pos))
local ent = mob:get_luaentity() 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 -- set nametag
local nametag = itemstack:get_meta():get_string("name") local nametag = itemstack:get_meta():get_string("name")
if nametag ~= "" then if nametag ~= "" then
@ -721,7 +663,8 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative)
--update_tag(ent) --update_tag(ent)
end 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 if not mobs.is_creative(placer:get_player_name()) then
itemstack:take_item() itemstack:take_item()
end end