1 --these are helpers to create entities
4 flying_pig.initial_properties = {
6 collide_with_objects = false,
7 collisionbox = {-0.37, -0.4, -0.37, 0.37, 0.5, 0.37},
9 visual_size = {x = 3, y = 3},
12 "flying_pig_body.png","flying_pig_leg.png","flying_pig_leg.png","flying_pig_leg.png","flying_pig_leg.png"
16 automatic_face_movement_dir = -90.0,
17 automatic_face_movement_max_rotation_per_sec = 300,
18 --makes_footstep_sound = true,
23 flying_pig.jump_timer = 0
25 flying_pig.death_animation_timer = 0
26 flying_pig.dead = false
29 flying_pig.hostile = false
30 flying_pig.hostile_timer = 0
34 flying_pig.hunger = 200
35 flying_pig.view_distance = 20
37 flying_pig.punch_timer = 0
38 flying_pig.punched_timer = 0
42 flying_pig.head_mount = vector.new(0,1.2,1.9)
43 local path = minetest.get_modpath(minetest.get_current_modname()).."/flying_pig"
44 dofile(path.."/timers.lua")
45 dofile(path.."/head_code.lua")
46 dofile(path.."/movement_code.lua")
47 dofile(path.."/data_handling_code.lua")
48 dofile(path.."/interaction_code.lua")
51 ----------------------------------
55 flying_pig.push = function(self)
56 local pos = self.object:getpos()
58 for _,object in ipairs(minetest.get_objects_inside_radius(pos, radius)) do
59 if object:is_player() or object:get_luaentity().mob == true then
60 local player_pos = object:getpos()
64 local currentvel = self.object:getvelocity()
65 local vel = vector.subtract(pos, player_pos)
66 vel = vector.normalize(vel)
67 local distance = vector.distance(pos,player_pos)
68 distance = (radius-distance)*10
69 vel = vector.multiply(vel,distance)
70 local acceleration = vector.new(vel.x-currentvel.x,0,vel.z-currentvel.z)
73 self.object:add_velocity(acceleration)
75 acceleration = vector.multiply(acceleration, 5)
76 object:add_player_velocity(acceleration)
81 --sets the mob animation and speed
82 flying_pig.set_animation = function(self)
83 if self.speed == 0 or vector.equals(self.direction,vector.new(0,0,0)) then
84 self.object:set_animation({x=0,y=0}, 1, 0, true)
86 self.object:set_animation({x=5,y=15}, 1, 0, true)
87 local speed = self.object:get_velocity()
89 self.object:set_animation_frame_speed(vector.distance(vector.new(0,0,0),speed)*5)
93 --this depletes the mobs hunger
94 flying_pig.do_hunger = function(self,dtime)
95 self.hunger = self.hunger - dtime
98 --this sets the state of the mob
99 flying_pig.set_state = function(self,dtime)
100 self.do_hunger(self,dtime)
103 flying_pig.on_step = function(self, dtime)
104 if self.dead == false and self.death_animation_timer == 0 then
105 self.set_state(self,dtime)
106 self.move(self,dtime)
107 self.set_animation(self)
108 self.look_around(self,dtime)
109 self.manage_punch_timer(self,dtime)
110 --self.debug_nametag(self,dtime)
112 self.manage_death_animation(self,dtime)
114 --fix zombie state again
115 if self.dead == true and self.death_animation_timer <= 0 then
120 minetest.register_entity("mob:flying_pig", flying_pig)
126 ------------------------------------------------------------------------the head
129 flying_pig.head.initial_properties = {
132 collide_with_objects = false,
133 collisionbox = {0, 0, 0, 0, 0, 0},
135 visual_size = {x = 1.1, y = 1.1},
138 "flying_pig_head.png","flying_pig_nose.png"
142 --automatic_face_movement_dir = 0.0,
143 --automatic_face_movement_max_rotation_per_sec = 600,
146 --remove the head if no body
147 flying_pig.head.on_step = function(self, dtime)
148 if self.parent == nil then
152 minetest.register_entity("mob:flying_pig_head", flying_pig.head)