1 --this is the file which houses the functions that control how mobs interact with the world
3 --this controls how fast the mob punches
4 mob.manage_punch_timer = function(self,dtime)
5 if self.punch_timer > 0 then
6 self.punch_timer = self.punch_timer - dtime
8 --this controls how fast you can punch the mob (punched timer reset)
9 if self.punched_timer > 0 then
10 --print(self.punched_timer)
11 self.punched_timer = self.punched_timer - dtime
16 --this controls what happens when the mob gets punched
17 mob.on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
18 local hp = self.object:get_hp()
20 if (self.punched_timer <= 0 and hp > 1) or puncher == self.object then
21 self.punched_timer = 0.8
22 local hurt = tool_capabilities.damage_groups.fleshy
27 self.object:set_hp(hp-hurt)
29 minetest.sound_play("pig", {object=self.object, gain = 1.0, max_hear_distance = 60,pitch = math.random(80,100)/100})
35 self.direction = vector.multiply(dir,-1)
38 dir = vector.multiply(dir,10)
40 self.object:add_velocity(dir)
41 elseif self.punched_timer <= 0 and self.death_animation_timer == 0 then
42 self.death_animation_timer = 1
43 minetest.sound_play("pig_die", {object=self.object, gain = 1.0, max_hear_distance = 60,pitch = math.random(80,100)/100})
47 --this is what happens when a mob diese
48 mob.on_death = function(self, killer)
49 local pos = self.object:getpos()
51 minetest.sound_play("mob_die", {pos = pos, gain = 1.0})
52 minetest.add_particlespawner({
57 minvel = vector.new(-5,-5,-5),
58 maxvel = vector.new(5,5,5),
59 minacc = {x=0, y=0, z=0},
60 maxacc = {x=0, y=0, z=0},
65 collisiondetection = false,
67 texture = "smoke.png",
69 local obj = minetest.add_item(pos,"mob:raw_porkchop")
70 self.child:get_luaentity().parent = nil
73 --this makes the mob rotate and then die
74 mob.manage_death_animation = function(self,dtime)
75 if self.death_animation_timer > 0 then
76 self.death_animation_timer = self.death_animation_timer - dtime
78 local self_rotation = self.object:get_rotation()
80 if self_rotation.x < math.pi/2 then
81 self_rotation.x = self_rotation.x + (dtime*2)
82 self.object:set_rotation(self_rotation)
85 --print(self.death_animation_timer)
86 local currentvel = self.object:getvelocity()
87 local goal = vector.new(0,0,0)
88 local acceleration = vector.new(goal.x-currentvel.x,0,goal.z-currentvel.z)
89 acceleration = vector.multiply(acceleration, 0.05)
90 self.object:add_velocity(acceleration)
91 self.object:set_animation({x=0,y=0}, 15, 0, true)
92 self.return_head_to_origin(self)
94 if self.death_animation_timer < 0 then
96 self.object:punch(self.object, 2,
98 full_punch_interval=1.5,
99 damage_groups = {fleshy=2},