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)
6 local hp = self.object:get_hp()
8 if (self.punched_timer <= 0 and hp > 1) or puncher == self.object then
10 self.hostile_timer = 20
11 self.punched_timer = 0.8
12 local hurt = tool_capabilities.damage_groups.fleshy
17 self.object:set_hp(hp-hurt)
19 minetest.sound_play("pig", {object=self.object, gain = 1.0, max_hear_distance = 60,pitch = math.random(80,100)/100})
25 self.direction = vector.multiply(dir,-1)
28 dir = vector.multiply(dir,10)
30 self.object:add_velocity(dir)
31 elseif self.punched_timer <= 0 and self.death_animation_timer == 0 then
32 self.death_animation_timer = 1
33 minetest.sound_play("pig_die", {object=self.object, gain = 1.0, max_hear_distance = 60,pitch = math.random(80,100)/100})
37 --this is what happens when a mob diese
38 pig.on_death = function(self, killer)
39 local pos = self.object:getpos()
41 minetest.sound_play("mob_die", {pos = pos, gain = 1.0})
42 minetest.add_particlespawner({
47 minvel = vector.new(-5,-5,-5),
48 maxvel = vector.new(5,5,5),
49 minacc = {x=0, y=0, z=0},
50 maxacc = {x=0, y=0, z=0},
55 collisiondetection = false,
57 texture = "smoke.png",
59 local obj = minetest.add_item(pos,"mob:raw_porkchop")
60 self.child:get_luaentity().parent = nil
63 --this makes the mob rotate and then die
64 pig.manage_death_animation = function(self,dtime)
65 if self.death_animation_timer > 0 then
66 self.death_animation_timer = self.death_animation_timer - dtime
68 local self_rotation = self.object:get_rotation()
70 if self_rotation.z < math.pi/2 then
71 self_rotation.z = self_rotation.z + (dtime*2)
72 self.object:set_rotation(self_rotation)
75 --print(self.death_animation_timer)
76 local currentvel = self.object:getvelocity()
77 local goal = vector.new(0,0,0)
78 local acceleration = vector.new(goal.x-currentvel.x,0,goal.z-currentvel.z)
79 acceleration = vector.multiply(acceleration, 0.05)
80 self.object:add_velocity(acceleration)
81 self.object:set_animation({x=0,y=0}, 15, 0, true)
82 self.return_head_to_origin(self,dtime)
84 if self.death_animation_timer < 0 then
86 self.object:punch(self.object, 2,
88 full_punch_interval=1.5,
89 damage_groups = {fleshy=2},
95 --the pig will look for and at players
96 pig.look_around = function(self,dtime)
97 local pos = self.object:get_pos()
99 --this is where the mob is actually looking
100 --local eye_ray = self.raycast_look(self,dtime)
101 --this is below where the mob is pointed, checks if ledge
102 --[[ --work on this later
103 local ledge_ray = self.look_below(self)
105 local is_a_drop = true
106 --check if there's a drop
108 for pointed_thing in ledge_ray do
109 if pointed_thing then
110 local pos2 = pointed_thing.under
111 local distance = math.floor(vector.subtract(pos2,pos).y-self.object:get_properties().collisionbox[2]+0.5+0.5)
112 if distance >= -3 then
119 if is_a_drop == true then
120 self.direction = vector.multiply(self.direction, -1)
121 print("turning around")
125 --a mob will check if it needs to jump
127 for pointed_thing in eye_ray do
128 local pos = self.object:get_pos()
129 local pos2 = pointed_thing.under
131 if minetest.registered_nodes[minetest.get_node(pos2).name] then
132 walkable = minetest.registered_nodes[minetest.get_node(pos2).name].walkable
135 if vector.distance(pos,pos2) < 1 then
146 self.following = false
147 local player_found = false
148 for _,object in ipairs(minetest.get_objects_inside_radius(pos, 6)) do
149 if object:is_player() and player_found == false and object:get_hp() > 0 then
150 --look at player's camera
151 local pos2 = object:get_pos()
152 pos2.y = pos2.y + 1.625
156 self.move_head(self,pos2,dtime)
158 if self.hostile == true then
159 self.direction = vector.direction(pos,pos2)
160 local distance = vector.distance(pos,pos2)-2
166 if distance < 1 and self.punch_timer <= 0 and object:get_hp() > 0 then
168 object:punch(self.object, 2,
170 full_punch_interval=1.5,
171 damage_groups = {fleshy=2},
172 },vector.direction(pos,pos2))
174 self.speed = distance * 3
175 self.following = true
177 --only look at one player
181 --stare straight if not found
182 if player_found == false then
183 self.move_head(self,nil,dtime)
184 self.manage_hostile_timer(self,dtime)