better entity checking, few fixes

This commit is contained in:
TenPlus1 2017-09-08 09:37:30 +01:00
parent 80cf1ddb1c
commit e90369ee21
2 changed files with 27 additions and 26 deletions

48
api.lua
View File

@ -1,9 +1,9 @@
-- Mobs Api (5th September 2017) -- Mobs Api (8th September 2017)
mobs = {} mobs = {}
mobs.mod = "redo" mobs.mod = "redo"
mobs.version = "20170905" mobs.version = "20170908"
-- Intllib -- Intllib
@ -1963,12 +1963,13 @@ local do_states = function(self, dtime)
p.y = p.y + (self.collisionbox[2] + self.collisionbox[5]) / 2 p.y = p.y + (self.collisionbox[2] + self.collisionbox[5]) / 2
if minetest.registered_entities[self.arrow] then
local obj = minetest.add_entity(p, self.arrow) local obj = minetest.add_entity(p, self.arrow)
local ent = obj:get_luaentity() local ent = obj:get_luaentity()
if ent then
local amount = (vec.x * vec.x + vec.y * vec.y + vec.z * vec.z) ^ 0.5 local amount = (vec.x * vec.x + vec.y * vec.y + vec.z * vec.z) ^ 0.5
local v = ent.velocity or 1 -- or set to default local v = ent.velocity or 1 -- or set to default
ent.switch = 1 ent.switch = 1
ent.owner_id = tostring(self.object) -- add unique owner id to arrow ent.owner_id = tostring(self.object) -- add unique owner id to arrow
@ -1979,8 +1980,6 @@ local do_states = function(self, dtime)
vec.z = vec.z * (v / amount) vec.z = vec.z * (v / amount)
obj:setvelocity(vec) obj:setvelocity(vec)
else
obj:remove() -- arrow entity does not exist
end end
end end
end end
@ -2871,12 +2870,14 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
-- spawn mob half block higher than ground -- spawn mob half block higher than ground
pos.y = pos.y - 0.5 pos.y = pos.y - 0.5
local mob = minetest.add_entity(pos, name) if minetest.registered_entities[name] then
if mob and mob:get_luaentity() then minetest.add_entity(pos, name)
-- print ("[mobs] Spawned " .. name .. " at " --[[
-- .. minetest.pos_to_string(pos) .. " on " print ("[mobs] Spawned " .. name .. " at "
-- .. node.name .. " near " .. neighbors[1]) .. minetest.pos_to_string(pos) .. " on "
.. node.name .. " near " .. neighbors[1])
]]
if on_spawn and not on_spawn(mob, pos) then if on_spawn and not on_spawn(mob, pos) then
return return
end end
@ -2884,7 +2885,6 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
minetest.log("warning", string.format("[mobs] %s failed to spawn at %s", minetest.log("warning", string.format("[mobs] %s failed to spawn at %s",
name, minetest.pos_to_string(pos))) name, minetest.pos_to_string(pos)))
end end
end end
}) })
end end
@ -3112,19 +3112,18 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative)
and within_limits(pos, 0) and within_limits(pos, 0)
and not minetest.is_protected(pos, placer:get_player_name()) then and not minetest.is_protected(pos, placer:get_player_name()) then
if not minetest.registered_entities[mob] then
return
end
pos.y = pos.y + 1 pos.y = pos.y + 1
local data = itemstack:get_metadata() local data = itemstack:get_metadata()
local mob = minetest.add_entity(pos, mob, data) local mob = minetest.add_entity(pos, mob, data)
local ent = mob:get_luaentity() local ent = mob:get_luaentity()
if not ent then -- set owner if not a monster
mob:remove()
return
end
if ent.type ~= "monster" then if ent.type ~= "monster" then
-- set owner and tame if not monster
ent.owner = placer:get_player_name() ent.owner = placer:get_player_name()
ent.tamed = true ent.tamed = true
end end
@ -3160,19 +3159,18 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative)
and within_limits(pos, 0) and within_limits(pos, 0)
and not minetest.is_protected(pos, placer:get_player_name()) then and not minetest.is_protected(pos, placer:get_player_name()) then
if not minetest.registered_entities[mob] then
return
end
pos.y = pos.y + 1 pos.y = pos.y + 1
local mob = minetest.add_entity(pos, mob) local mob = minetest.add_entity(pos, mob)
local ent = mob:get_luaentity() local ent = mob:get_luaentity()
if not ent then -- don't set owner if monster or sneak pressed
mob:remove()
return
end
if ent.type ~= "monster" if ent.type ~= "monster"
and not placer:get_player_control().sneak then and not placer:get_player_control().sneak then
-- set owner and tame if not monster
ent.owner = placer:get_player_name() ent.owner = placer:get_player_name()
ent.tamed = true ent.tamed = true
end end
@ -3521,7 +3519,9 @@ function mobs:alias_mob(old_name, new_name)
local pos = self.object:getpos() local pos = self.object:getpos()
if minetest.registered_entities[new_name] then
minetest.add_entity(pos, new_name) minetest.add_entity(pos, new_name)
end
self.object:remove() self.object:remove()
end end

View File

@ -22,6 +22,7 @@ Lucky Blocks: 9
Changelog: Changelog:
- 1.38- Better entity checking, nametag setting and on_spawn function added to mob registry, tweaked light damage
- 1.37- Added support for Raymoo's CMI (common mob interface) mod: https://forum.minetest.net/viewtopic.php?f=9&t=15448 - 1.37- Added support for Raymoo's CMI (common mob interface) mod: https://forum.minetest.net/viewtopic.php?f=9&t=15448
- 1.36- Death check added, if mob dies in fire/lava/with lava pick then drops are cooked - 1.36- Death check added, if mob dies in fire/lava/with lava pick then drops are cooked
- 1.35- Added owner_loyal flag for owned mobs to attack player enemies, also fixed group_attack - 1.35- Added owner_loyal flag for owned mobs to attack player enemies, also fixed group_attack