diff --git a/mods/mobs/api.lua b/mods/mobs/api.lua index 91bd1f60..42f8dfdf 100644 --- a/mods/mobs/api.lua +++ b/mods/mobs/api.lua @@ -92,7 +92,7 @@ function mobs:register_mob(name, def) self.attack.dist = dist end end, - + set_velocity = function(self, v) if not v then v = 0 end if def.drawtype and def.drawtype == "side" then self.rotate = 1.5 end @@ -101,7 +101,7 @@ function mobs:register_mob(name, def) local z = math.cos(yaw) * v self.object:setvelocity({x=x, y=self.object:getvelocity().y, z=z}) end, - + get_velocity = function(self) local v = self.object:getvelocity() return (v.x^2 + v.z^2)^(0.5) @@ -116,11 +116,11 @@ function mobs:register_mob(name, def) local ps = math.sqrt(pos.x^2 + pos.z^2) local d = { x = vx / ds, z = vz / ds } local p = { x = pos.x / ps, z = pos.z / ps } - + local an = ( d.x * p.x ) + ( d.z * p.z ) - + a = math.deg( math.acos( an ) ) - + if a > ( self.fov / 2 ) then return false else @@ -161,7 +161,7 @@ function mobs:register_mob(name, def) end end end, - + on_step = function(self, dtime) local yaw = 0 @@ -229,7 +229,7 @@ function mobs:register_mob(name, def) self.old_y = self.object:getpos().y end end - + -- knockback timer if self.pause_timer > 0 then self.pause_timer = self.pause_timer - dtime @@ -238,7 +238,7 @@ function mobs:register_mob(name, def) end return end - + -- attack timer self.timer = self.timer + dtime if self.state ~= "attack" then @@ -251,7 +251,7 @@ function mobs:register_mob(name, def) if self.sounds.random and math.random(1, 100) <= 1 then minetest.sound_play(self.sounds.random, {object = self.object}) end - + local do_env_damage = function(self) local pos = self.object:getpos() @@ -272,7 +272,7 @@ function mobs:register_mob(name, def) self.object:set_hp(self.object:get_hp()-self.water_damage) effect(pos, 5, "bubble.png") end - + if self.lava_damage and self.lava_damage ~= 0 and minetest.get_item_group(n.name, "lava") ~= 0 then self.object:set_hp(self.object:get_hp()-self.lava_damage) @@ -281,7 +281,7 @@ function mobs:register_mob(name, def) check_for_death(self) end - + local do_jump = function(self) if self.fly then return end @@ -315,7 +315,7 @@ function mobs:register_mob(name, def) self.jumptimer = 0 end end - + -- environmental damage timer self.env_damage_timer = self.env_damage_timer + dtime if self.state == "attack" and self.env_damage_timer > 1 then @@ -324,7 +324,7 @@ function mobs:register_mob(name, def) elseif self.state ~= "attack" then do_env_damage(self) end - + -- find someone to attack if self.type == "monster" and damage_enabled and self.state ~= "attack" then @@ -348,7 +348,7 @@ function mobs:register_mob(name, def) type = obj.type end end - + if type == "player" or type == "npc" then s = self.object:getpos() p = player:getpos() @@ -371,7 +371,7 @@ function mobs:register_mob(name, def) self.do_attack(self, min_player, min_dist) end end - + -- npc, find closest monster to attack local min_dist = self.view_range + 1 local min_player = nil @@ -534,7 +534,7 @@ function mobs:register_mob(name, def) if self.type == "npc" then local o = minetest.get_objects_inside_radius(self.object:getpos(), 3) - + local yaw = 0 for _,o in ipairs(o) do if o:is_player() then @@ -550,7 +550,7 @@ function mobs:register_mob(name, def) if lp.x > s.x then yaw = yaw+math.pi end - else + else yaw = self.object:getyaw()+((math.random(0,360)-180)/180*math.pi) end self.object:setyaw(yaw) @@ -583,7 +583,7 @@ function mobs:register_mob(name, def) local s = self.object:getpos() -- if there is water nearby, try to avoid it local lp = minetest.find_node_near(s, 2, {"group:water"}) - + if lp ~= nil then local vec = {x=lp.x-s.x, y=lp.y-s.y, z=lp.z-s.z} yaw = math.atan(vec.z/vec.x) + 3*math.pi / 2 + self.rotate @@ -610,7 +610,7 @@ function mobs:register_mob(name, def) end -- exploding mobs - elseif self.state == "attack" and self.attack_type == "explode" then + elseif self.state == "attack" and self.attack_type == "explode" then if not self.attack.player or not self.attack.player:is_player() then self.state = "stand" self:set_animation("stand") @@ -634,7 +634,7 @@ function mobs:register_mob(name, def) self:set_animation("walk") self.attack.dist = dist end - + local vec = {x = p.x -s.x, y = p.y -s.y, z = p.z -s.z} local yaw = math.atan(vec.z/vec.x)+math.pi/2 + self.rotate if p.x > s.x then @@ -735,7 +735,7 @@ end else self.attack.dist = dist end - + local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z} local yaw = (math.atan(vec.z/vec.x)+math.pi/2) + self.rotate if p.x > s.x then @@ -800,7 +800,7 @@ end else self.attack.dist = dist end - + local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z} local yaw = (math.atan(vec.z/vec.x)+math.pi/2) + self.rotate if p.x > s.x then @@ -808,7 +808,7 @@ end end self.object:setyaw(yaw) self.set_velocity(self, 0) - + if self.shoot_interval and self.timer > self.shoot_interval and math.random(1, 100) <= 60 then self.timer = 0 @@ -959,7 +959,7 @@ end kb = kb * ( tflp / tool_capabilities.full_punch_interval ) r = r * ( tflp / tool_capabilities.full_punch_interval ) end - if v.y ~= 0 then ykb = 0 end + if v.y ~= 0 then ykb = 0 end self.object:setvelocity({x=dir.x*kb,y=ykb,z=dir.z*kb}) self.pause_timer = r @@ -995,7 +995,7 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, inter action = function(pos, node, _, active_object_count_wider) -- do not spawn if too many active in area if active_object_count_wider > active_object_count - or not mobs.spawning_mobs[name] + or not mobs.spawning_mobs[name] or not pos then return end @@ -1130,14 +1130,13 @@ function mobs:explosion(pos, radius, fire, smoke, sound) elseif n.name == "doors:door_wood_t_1" then minetest.remove_node({x=np.x,y=np.y-1,z=np.z}) end - if fire > 0 and (minetest.registered_nodes[n].groups.flammable or math.random(1, 100) <= 30) then - minetest.set_node(p, {name="fire:basic_flame"}) - else - minetest.remove_node(p) - end - if smoke > 0 then - effect(p, 2, "tnt_smoke.png", 5) - end + if fire > 0 and (minetest.registered_nodes[n].groups.flammable or math.random(1, 100) <= 30) then + minetest.set_node(p, {name="fire:basic_flame"}) + else + minetest.remove_node(p) + end + if smoke > 0 then + effect(p, 2, "tnt_smoke.png", 5) end end vi = vi + 1 diff --git a/mods/mobs/npc.lua b/mods/mobs/npc.lua index 21d913de..ce8f1b94 100755 --- a/mods/mobs/npc.lua +++ b/mods/mobs/npc.lua @@ -1,9 +1,9 @@ -- Npc by TenPlus1 -mobs.npc_drops = { "farming:meat", "farming:donut", "farming:bread", "default:apple", "default:sapling", "default:junglesapling", - "shields:shield_enhanced_wood", "3d_armor:chestplate_cactus", "3d_armor:boots_bronze", - "default:sword_steel", "default:sword_gold", "default:pick_steel", "default:shovel_steel", +mobs.npc_drops = { "farming:meat", "farming:donut", "farming:bread", "default:apple", "default:sapling", "default:junglesapling", + "shields:shield_enhanced_wood", "3d_armor:chestplate_cactus", "3d_armor:boots_bronze", + "default:sword_steel", "default:sword_gold", "default:pick_steel", "default:shovel_steel", "default:bronze_ingot", "bucket:bucket_water" } mobs.npc_max_hp = 20 @@ -94,6 +94,7 @@ mobs:register_mob("mobs:npc", { self.diamond_count = (self.diamond_count or 0) + 1 if not minetest.setting_getbool("creative_mode") then item:take_item() + end -- pick up npc elseif item:get_name() == "mobs:magic_lasso" and clicker:is_player() @@ -120,7 +121,6 @@ mobs:register_mob("mobs:npc", { -- if owner switch between follow and stand if self.owner and self.owner == clicker:get_player_name() then self.damages = 4 - else if self.order == "follow" then self.order = "stand" else