1
0
Fork 0

Update Mobs Redo

This commit is contained in:
Wuzzy 2017-08-06 12:49:13 +02:00
parent 0f70bd740d
commit 6253ffd78b
1 changed files with 33 additions and 21 deletions

View File

@ -1,9 +1,9 @@
-- Mobs Api (26th July 2017) -- Mobs Api (4th August 2017)
mobs = {} mobs = {}
mobs.mod = "redo" mobs.mod = "redo"
mobs.version = "20170726" mobs.version = "20170804"
-- Intllib -- Intllib
@ -139,7 +139,8 @@ end
-- set defined animation -- set defined animation
local set_animation = function(self, anim) local set_animation = function(self, anim)
if not self.animation then return end if not self.animation
or not anim then return end
self.animation.current = self.animation.current or "" self.animation.current = self.animation.current or ""
@ -439,6 +440,10 @@ local check_for_death = function(self, cause, cmi_cause)
and self.animation.die_start and self.animation.die_start
and self.animation.die_end then and self.animation.die_end then
local frames = self.animation.die_end - self.animation.die_start
local speed = self.animation.die_speed or 15
local length = max(frames / speed, 0)
self.attack = nil self.attack = nil
self.v_start = false self.v_start = false
self.timer = 0 self.timer = 0
@ -448,7 +453,7 @@ local check_for_death = function(self, cause, cmi_cause)
set_velocity(self, 0) set_velocity(self, 0)
set_animation(self, "die") set_animation(self, "die")
minetest.after(2, function(self) minetest.after(length, function(self)
if use_cmi then if use_cmi then
cmi.notify_die(self.object, cmi_cause) cmi.notify_die(self.object, cmi_cause)
@ -523,7 +528,7 @@ local node_ok = function(pos, fallback)
return node return node
end end
return {name = fallback} return minetest.registered_nodes[fallback] -- {name = fallback}
end end
@ -582,7 +587,6 @@ local do_env_damage = function(self)
-- don't fall when on ignore, just stand still -- don't fall when on ignore, just stand still
if self.standing_in == "ignore" then if self.standing_in == "ignore" then
self.object:setvelocity({x = 0, y = 0, z = 0}) self.object:setvelocity({x = 0, y = 0, z = 0})
--print ("--- stopping on ignore")
end end
local nodef = minetest.registered_nodes[self.standing_in] local nodef = minetest.registered_nodes[self.standing_in]
@ -702,7 +706,7 @@ local do_jump = function(self)
local v = self.object:getvelocity() local v = self.object:getvelocity()
v.y = self.jump_height -- + 1 v.y = self.jump_height
set_animation(self, "jump") -- only when defined set_animation(self, "jump") -- only when defined
@ -1006,7 +1010,7 @@ local smart_mobs = function(self, s, p, dist, dtime)
-- round position to center of node to avoid stuck in walls -- round position to center of node to avoid stuck in walls
-- also adjust height for player models! -- also adjust height for player models!
s.x = floor(s.x + 0.5) s.x = floor(s.x + 0.5)
s.y = floor(s.y + 0.5) - sheight -- s.y = floor(s.y + 0.5) - sheight
s.z = floor(s.z + 0.5) s.z = floor(s.z + 0.5)
local ssight, sground = minetest.line_of_sight(s, { local ssight, sground = minetest.line_of_sight(s, {
@ -1076,7 +1080,8 @@ local smart_mobs = function(self, s, p, dist, dtime)
and node1 ~= "ignore" and node1 ~= "ignore"
and ndef1 and ndef1
and not ndef1.groups.level and not ndef1.groups.level
and not ndef1.groups.unbreakable then and not ndef1.groups.unbreakable
and not ndef1.groups.liquid then
minetest.set_node(s, {name = "air"}) minetest.set_node(s, {name = "air"})
minetest.add_item(s, ItemStack(node1)) minetest.add_item(s, ItemStack(node1))
@ -1105,7 +1110,8 @@ local smart_mobs = function(self, s, p, dist, dtime)
and node1 ~= "ignore" and node1 ~= "ignore"
and ndef1 and ndef1
and not ndef1.groups.level and not ndef1.groups.level
and not ndef1.groups.unbreakable then and not ndef1.groups.unbreakable
and not ndef1.groups.liquid then
minetest.add_item(p1, ItemStack(node1)) minetest.add_item(p1, ItemStack(node1))
minetest.set_node(p1, {name = "air"}) minetest.set_node(p1, {name = "air"})
@ -1119,7 +1125,8 @@ local smart_mobs = function(self, s, p, dist, dtime)
and node1 ~= "ignore" and node1 ~= "ignore"
and ndef1 and ndef1
and not ndef1.groups.level and not ndef1.groups.level
and not ndef1.groups.unbreakable then and not ndef1.groups.unbreakable
and not ndef1.groups.liquid then
minetest.add_item(p1, ItemStack(node1)) minetest.add_item(p1, ItemStack(node1))
minetest.set_node(p1, {name = "air"}) minetest.set_node(p1, {name = "air"})
@ -1251,9 +1258,9 @@ local npc_attack = function(self)
return return
end end
local p, sp, obj, min_player
local s = self.object:getpos() local s = self.object:getpos()
local min_dist = self.view_range + 1 local min_dist = self.view_range + 1
local obj, min_player = nil, nil
local objs = minetest.get_objects_inside_radius(s, self.view_range) local objs = minetest.get_objects_inside_radius(s, self.view_range)
for n = 1, #objs do for n = 1, #objs do
@ -1262,7 +1269,7 @@ local npc_attack = function(self)
if obj and obj.type == "monster" then if obj and obj.type == "monster" then
local p = obj.object:getpos() p = obj.object:getpos()
dist = get_distance(p, s) dist = get_distance(p, s)
@ -1428,7 +1435,7 @@ end
-- execute current state (stand, walk, run, attacks) -- execute current state (stand, walk, run, attacks)
local do_states = function(self, dtime) local do_states = function(self, dtime)
local yaw = 0 local yaw = self.object:get_yaw() or 0
if self.state == "stand" then if self.state == "stand" then
@ -1458,7 +1465,9 @@ local do_states = function(self, dtime)
if lp.x > s.x then yaw = yaw + pi end if lp.x > s.x then yaw = yaw + pi end
else else
yaw = (random(0, 360) - 180) / 180 * pi -- yaw = (random(0, 360) - 180) / 180 * pi
yaw = yaw + random(-0.5, 0.5)
end end
yaw = set_yaw(self.object, yaw) yaw = set_yaw(self.object, yaw)
@ -1538,7 +1547,9 @@ local do_states = function(self, dtime)
do_jump(self) do_jump(self)
set_velocity(self, self.walk_velocity) set_velocity(self, self.walk_velocity)
else else
yaw = (random(0, 360) - 180) / 180 * pi -- yaw = (random(0, 360) - 180) / 180 * pi
yaw = yaw + random(-0.5, 0.5)
end end
else else
@ -1559,7 +1570,9 @@ local do_states = function(self, dtime)
elseif random(1, 100) <= 30 then elseif random(1, 100) <= 30 then
--yaw = random() * 2 * pi --yaw = random() * 2 * pi
yaw = (random(0, 360) - 180) / 180 * pi -- yaw = (random(0, 360) - 180) / 180 * pi
yaw = yaw + random(-0.5, 0.5)
yaw = set_yaw(self.object, yaw) yaw = set_yaw(self.object, yaw)
end end
@ -3049,7 +3062,6 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative)
inventory_image = invimg, inventory_image = invimg,
groups = grp, groups = grp,
-- FIXME: Provide a function to place a mob without the on_place thingie
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.above local pos = pointed_thing.above
@ -3057,13 +3069,13 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative)
-- am I clicking on something with existing on_rightclick function? -- am I clicking on something with existing on_rightclick function?
local under = minetest.get_node(pointed_thing.under) local under = minetest.get_node(pointed_thing.under)
local def = minetest.registered_nodes[under.name] local def = minetest.registered_nodes[under.name]
if def and def.on_rightclick and placer then if def and def.on_rightclick then
return def.on_rightclick(pointed_thing.under, under, placer, itemstack) return def.on_rightclick(pointed_thing.under, under, placer, itemstack)
end end
if pos if pos
and within_limits(pos, 0) and within_limits(pos, 0)
and ((not placer or not minetest.is_protected(pos, placer:get_player_name()))) then and not minetest.is_protected(pos, placer:get_player_name()) then
pos.y = pos.y + 1 pos.y = pos.y + 1
@ -3076,7 +3088,7 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative)
end end
if ent.type ~= "monster" if ent.type ~= "monster"
and (placer and not placer:get_player_control().sneak) then and not placer:get_player_control().sneak then
-- set owner and tame if not monster -- 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