Update Mobs Redo

This commit is contained in:
Wuzzy 2018-01-08 02:03:31 +01:00
parent a818995d2a
commit a89b9e9c45
4 changed files with 77 additions and 50 deletions

View file

@ -3,7 +3,7 @@
mobs = {}
mobs.mod = "redo"
mobs.version = "20171018"
mobs.version = "20180104"
-- Intllib
@ -61,6 +61,7 @@ local remove_far = minetest.settings:get_bool("remove_far_mobs")
local difficulty = tonumber(minetest.settings:get("mob_difficulty")) or 1.0
local show_health = false
local max_per_block = tonumber(minetest.settings:get("max_objects_per_block") or 99)
local mob_chance_multiplier = tonumber(minetest.settings:get("mob_chance_multiplier") or 1)
-- Peaceful mode message so players will know there are no monsters
if peaceful_only then
@ -88,6 +89,7 @@ local node_snowblock = "mcl_core:snowblock"
local node_snow = "mcl_core:snow"
mobs.fallback_node = minetest.registered_aliases["mapgen_dirt"] or "mcl_core:dirt"
-- play sound
local mob_sound = function(self, sound)
@ -425,7 +427,8 @@ local check_for_death = function(self, cause, cmi_cause)
self.nametag2 = self.nametag or ""
end
if show_health then
if show_health
and (cmi_cause and cmi_cause.type == "punch") then
self.htimer = 2
self.nametag = "" .. self.health .. " / " .. self.hp_max
@ -828,6 +831,7 @@ local breed = function(self)
mesh = self.base_mesh,
visual_size = self.base_size,
collisionbox = self.base_colbox,
selectionbox = self.base_selbox,
})
-- custom function when child grows up
@ -948,6 +952,14 @@ local breed = function(self)
self.base_colbox[5] * .5,
self.base_colbox[6] * .5,
},
selectionbox = {
self.base_selbox[1] * .5,
self.base_selbox[2] * .5,
self.base_selbox[3] * .5,
self.base_selbox[4] * .5,
self.base_selbox[5] * .5,
self.base_selbox[6] * .5,
},
})
-- tamed and owned by parents' owner
ent2.child = true
@ -1078,10 +1090,10 @@ local smart_mobs = function(self, s, p, dist, dtime)
p1.y = floor(p1.y + 0.5)
p1.z = floor(p1.z + 0.5)
local dropheight = 10
local dropheight = 6
if self.fear_height ~= 0 then dropheight = self.fear_height end
-- self.path.way = minetest.find_path(s, p1, 16, 2, 6, "Dijkstra") -- "A*_noprefetch"
-- self.path.way = minetest.find_path(s, p1, 16, 2, 6, "Dijkstra")
self.path.way = minetest.find_path(s, p1, 16, self.stepheight, dropheight, "A*_noprefetch")
-- attempt to unstick mob that is "daydreaming"
@ -2423,6 +2435,7 @@ local mob_activate = function(self, staticdata, def, dtime)
self.base_mesh = def.mesh
self.base_size = self.visual_size
self.base_colbox = self.collisionbox
self.base_selbox = self.selectionbox
end
-- set texture, model and size
@ -2430,6 +2443,7 @@ local mob_activate = function(self, staticdata, def, dtime)
local mesh = self.base_mesh
local vis_size = self.base_size
local colbox = self.base_colbox
local selbox = self.base_selbox
-- specific texture if gotten
if self.gotten == true
@ -2463,6 +2477,14 @@ local mob_activate = function(self, staticdata, def, dtime)
self.base_colbox[5] * .5,
self.base_colbox[6] * .5
}
selbox = {
self.base_selbox[1] * .5,
self.base_selbox[2] * .5,
self.base_selbox[3] * .5,
self.base_selbox[4] * .5,
self.base_selbox[5] * .5,
self.base_selbox[6] * .5
}
end
if self.health == 0 then
@ -2485,6 +2507,7 @@ local mob_activate = function(self, staticdata, def, dtime)
self.textures = textures
self.mesh = mesh
self.collisionbox = colbox
self.selectionbox = selbox
self.visual_size = vis_size
self.standing_in = ""
@ -2674,6 +2697,7 @@ minetest.register_entity(name, {
hp_max = max(1, (def.hp_max or 10) * difficulty),
physical = true,
collisionbox = def.collisionbox,
selectionbox = def.selectionbox or def.collisionbox,
visual = def.visual,
visual_size = def.visual_size or {x = 1, y = 1},
mesh = def.mesh,
@ -2832,13 +2856,14 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
nodenames = nodes,
neighbors = neighbors,
interval = interval,
chance = chance,
chance = max(1, (chance * mob_chance_multiplier)),
catch_up = false,
action = function(pos, node, active_object_count, active_object_count_wider)
-- is mob actually registered?
if not mobs.spawning_mobs[name] then
if not mobs.spawning_mobs[name]
or not minetest.registered_entities[name] then
--print ("--- mob doesn't exist", name)
return
end
@ -2907,39 +2932,34 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
return
end
-- are we spawning inside solid nodes?
if minetest.registered_nodes[node_ok(pos).name].walkable == true then
--print ("--- feet in block", name, node_ok(pos).name)
return
end
-- do we have enough height clearance to spawn mob?
local ent = minetest.registered_entities[name]
local height = max(0, math.ceil(ent.collisionbox[5] - ent.collisionbox[2]) - 1)
pos.y = pos.y + 1
for n = 0, height do
if minetest.registered_nodes[node_ok(pos).name].walkable == true then
--print ("--- head in block", name, node_ok(pos).name)
return
local pos2 = {x = pos.x, y = pos.y + n, z = pos.z}
if minetest.registered_nodes[node_ok(pos2).name].walkable == true then
--print ("--- inside block", name, node_ok(pos2).name)
return
end
end
-- spawn mob half block higher than ground
pos.y = pos.y - 0.5
pos.y = pos.y + 0.5
if minetest.registered_entities[name] then
local mob = minetest.add_entity(pos, name)
local mob = minetest.add_entity(pos, name)
--[[
print ("[mobs] Spawned " .. name .. " at "
.. minetest.pos_to_string(pos) .. " on "
.. node.name .. " near " .. neighbors[1])
print ("[mobs] Spawned " .. name .. " at "
.. minetest.pos_to_string(pos) .. " on "
.. node.name .. " near " .. neighbors[1])
]]
if on_spawn then
if on_spawn then
local ent = mob:get_luaentity()
local ent = mob:get_luaentity()
on_spawn(ent, pos)
end
else
minetest.log("warning", string.format("[mobs] %s failed to spawn at %s",
name, minetest.pos_to_string(pos)))
on_spawn(ent, pos)
end
end
})