1 --this is the file which houses the functions that control how mobs interact with the world
4 --this controls what happens when the mob gets punched
5 pig.on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
8 local hurt = tool_capabilities.damage_groups.damage
16 if (self.punched_timer <= 0 and hp > 1) or puncher == self.object then
18 self.hostile_timer = 20
19 self.punched_timer = 0.8
22 minetest.sound_play("pig", {object=self.object, gain = 1.0, max_hear_distance = 60,pitch = math.random(80,100)/100})
28 self.direction = vector.multiply(dir,-1)
31 dir = vector.multiply(dir,10)
33 self.object:add_velocity(dir)
34 elseif self.punched_timer <= 0 and self.death_animation_timer == 0 then
35 self.death_animation_timer = 1
37 minetest.sound_play("pig_die", {object=self.object, gain = 1.0, max_hear_distance = 60,pitch = math.random(80,100)/100})
38 --self.object:set_texture_mod("^[colorize:red:90")
39 --self.child:set_texture_mod("^[colorize:red:90")
43 --this is what happens when a mob diese
44 pig.on_death = function(self, killer)
45 local pos = self.object:getpos()
47 minetest.sound_play("mob_die", {pos = pos, gain = 1.0})
48 minetest.add_particlespawner({
53 minvel = vector.new(-5,-5,-5),
54 maxvel = vector.new(5,5,5),
55 minacc = {x=0, y=0, z=0},
56 maxacc = {x=0, y=0, z=0},
61 collisiondetection = false,
63 texture = "smoke.png",
65 local obj = minetest.add_item(pos,"mob:raw_porkchop")
66 self.child:get_luaentity().parent = nil
70 --this makes the mob rotate and then die
71 pig.manage_death_animation = function(self,dtime)
72 if self.death_animation_timer >= 0 and self.dead == true then
73 self.death_animation_timer = self.death_animation_timer - dtime
75 local self_rotation = self.object:get_rotation()
77 if self_rotation.z < math.pi/2 then
78 self_rotation.z = self_rotation.z + (dtime*2)
79 self.object:set_rotation(self_rotation)
82 --print(self.death_animation_timer)
83 local currentvel = self.object:getvelocity()
84 local goal = vector.new(0,0,0)
85 local acceleration = vector.new(goal.x-currentvel.x,0,goal.z-currentvel.z)
86 acceleration = vector.multiply(acceleration, 0.05)
87 self.object:add_velocity(acceleration)
88 self.object:set_animation({x=0,y=0}, 15, 0, true)
89 self.return_head_to_origin(self,dtime)
91 if self.death_animation_timer <= 0 then
97 --the pig will look for and at players
98 pig.look_around = function(self,dtime)
99 local pos = self.object:get_pos()
103 self.following = false
104 local player_found = false
105 for _,object in ipairs(minetest.get_objects_inside_radius(pos, 6)) do
106 if object:is_player() and player_found == false and object:get_hp() > 0 then
107 --look at player's camera
108 local pos2 = object:get_pos()
109 pos2.y = pos2.y + 1.625
113 self.move_head(self,pos2,dtime)
115 if self.hostile == true then
116 self.direction = vector.direction(pos,pos2)
117 local distance = vector.distance(pos,pos2)-2
123 if distance < 1 and self.punch_timer <= 0 and object:get_hp() > 0 then
125 object:punch(self.object, 2,
127 full_punch_interval=1.5,
128 damage_groups = {fleshy=2},
129 },vector.direction(pos,pos2))
131 self.speed = distance * 3
132 self.following = true
134 --only look at one player
138 --stare straight if not found
139 if player_found == false then
140 self.move_head(self,nil,dtime)
141 self.manage_hostile_timer(self,dtime)