From 6253ffd78b336fe12a0ffe336e2ecd1a9f8f70f2 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sun, 6 Aug 2017 12:49:13 +0200 Subject: [PATCH] Update Mobs Redo --- mods/ENTITIES/mobs/api.lua | 54 +++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/mods/ENTITIES/mobs/api.lua b/mods/ENTITIES/mobs/api.lua index 206aed7274..4352fd037f 100644 --- a/mods/ENTITIES/mobs/api.lua +++ b/mods/ENTITIES/mobs/api.lua @@ -1,9 +1,9 @@ --- Mobs Api (26th July 2017) +-- Mobs Api (4th August 2017) mobs = {} mobs.mod = "redo" -mobs.version = "20170726" +mobs.version = "20170804" -- Intllib @@ -139,7 +139,8 @@ end -- set defined animation 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 "" @@ -439,6 +440,10 @@ local check_for_death = function(self, cause, cmi_cause) and self.animation.die_start 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.v_start = false self.timer = 0 @@ -448,7 +453,7 @@ local check_for_death = function(self, cause, cmi_cause) set_velocity(self, 0) set_animation(self, "die") - minetest.after(2, function(self) + minetest.after(length, function(self) if use_cmi then cmi.notify_die(self.object, cmi_cause) @@ -523,7 +528,7 @@ local node_ok = function(pos, fallback) return node end - return {name = fallback} + return minetest.registered_nodes[fallback] -- {name = fallback} end @@ -582,7 +587,6 @@ local do_env_damage = function(self) -- don't fall when on ignore, just stand still if self.standing_in == "ignore" then self.object:setvelocity({x = 0, y = 0, z = 0}) - --print ("--- stopping on ignore") end local nodef = minetest.registered_nodes[self.standing_in] @@ -702,7 +706,7 @@ local do_jump = function(self) local v = self.object:getvelocity() - v.y = self.jump_height -- + 1 + v.y = self.jump_height 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 -- also adjust height for player models! 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) 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 ndef1 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.add_item(s, ItemStack(node1)) @@ -1105,7 +1110,8 @@ local smart_mobs = function(self, s, p, dist, dtime) and node1 ~= "ignore" and ndef1 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.set_node(p1, {name = "air"}) @@ -1119,7 +1125,8 @@ local smart_mobs = function(self, s, p, dist, dtime) and node1 ~= "ignore" and ndef1 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.set_node(p1, {name = "air"}) @@ -1251,9 +1258,9 @@ local npc_attack = function(self) return end + local p, sp, obj, min_player local s = self.object:getpos() local min_dist = self.view_range + 1 - local obj, min_player = nil, nil local objs = minetest.get_objects_inside_radius(s, self.view_range) for n = 1, #objs do @@ -1262,7 +1269,7 @@ local npc_attack = function(self) if obj and obj.type == "monster" then - local p = obj.object:getpos() + p = obj.object:getpos() dist = get_distance(p, s) @@ -1428,7 +1435,7 @@ end -- execute current state (stand, walk, run, attacks) local do_states = function(self, dtime) - local yaw = 0 + local yaw = self.object:get_yaw() or 0 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 else - yaw = (random(0, 360) - 180) / 180 * pi +-- yaw = (random(0, 360) - 180) / 180 * pi + + yaw = yaw + random(-0.5, 0.5) end yaw = set_yaw(self.object, yaw) @@ -1538,7 +1547,9 @@ local do_states = function(self, dtime) do_jump(self) set_velocity(self, self.walk_velocity) else - yaw = (random(0, 360) - 180) / 180 * pi +-- yaw = (random(0, 360) - 180) / 180 * pi + + yaw = yaw + random(-0.5, 0.5) end else @@ -1559,7 +1570,9 @@ local do_states = function(self, dtime) elseif random(1, 100) <= 30 then --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) end @@ -3049,7 +3062,6 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative) inventory_image = invimg, groups = grp, - -- FIXME: Provide a function to place a mob without the on_place thingie on_place = function(itemstack, placer, pointed_thing) 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? local under = minetest.get_node(pointed_thing.under) 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) end if pos 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 @@ -3076,7 +3088,7 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative) end 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 ent.owner = placer:get_player_name() ent.tamed = true