1 --these are helpers to create entities
4 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 "body.png","leg.png","leg.png","leg.png","leg.png"
16 automatic_face_movement_dir = -90.0,
17 automatic_face_movement_max_rotation_per_sec = 300,
18 --makes_footstep_sound = true,
25 pig.hurt_inside_timer = 0
26 pig.death_animation_timer = 0
36 pig.view_distance = 20
43 pig.head_mount = vector.new(0,1.2,1.9)
44 local path = minetest.get_modpath(minetest.get_current_modname()).."/pig"
45 dofile(path.."/timers.lua")
46 dofile(path.."/head_code.lua")
47 dofile(path.."/movement_code.lua")
48 dofile(path.."/data_handling_code.lua")
49 dofile(path.."/interaction_code.lua")
52 ----------------------------------
56 pig.push = function(self)
57 local pos = self.object:getpos()
59 for _,object in ipairs(minetest.get_objects_inside_radius(pos, radius)) do
60 if object:is_player() or object:get_luaentity().mob == true then
61 local player_pos = object:getpos()
65 local currentvel = self.object:getvelocity()
66 local vel = vector.subtract(pos, player_pos)
67 vel = vector.normalize(vel)
68 local distance = vector.distance(pos,player_pos)
69 distance = (radius-distance)*10
70 vel = vector.multiply(vel,distance)
71 local acceleration = vector.new(vel.x-currentvel.x,0,vel.z-currentvel.z)
74 self.object:add_velocity(acceleration)
76 acceleration = vector.multiply(acceleration, 5)
77 object:add_player_velocity(acceleration)
82 --sets the mob animation and speed
83 pig.set_animation = function(self)
84 if self.speed == 0 or vector.equals(self.direction,vector.new(0,0,0)) then
85 self.object:set_animation({x=0,y=0}, 1, 0, true)
87 self.object:set_animation({x=5,y=15}, 1, 0, true)
88 local speed = self.object:get_velocity()
90 self.object:set_animation_frame_speed(vector.distance(vector.new(0,0,0),speed)*5)
94 --this depletes the mobs hunger
95 pig.do_hunger = function(self,dtime)
96 self.hunger = self.hunger - dtime
99 --this sets the state of the mob
100 pig.set_state = function(self,dtime)
101 self.do_hunger(self,dtime)
104 pig.on_step = function(self, dtime)
105 if self.dead == false and self.death_animation_timer == 0 then
106 self.set_state(self,dtime)
107 self.move(self,dtime)
108 self.set_animation(self)
109 self.look_around(self,dtime)
110 self.manage_punch_timer(self,dtime)
111 --self.debug_nametag(self,dtime)
113 self.manage_death_animation(self,dtime)
115 --fix zombie state again
116 if self.dead == true and self.death_animation_timer <= 0 then
121 minetest.register_entity("mob:pig", pig)
127 ------------------------------------------------------------------------the head
130 pig.head.initial_properties = {
133 collide_with_objects = false,
134 collisionbox = {0, 0, 0, 0, 0, 0},
136 visual_size = {x = 1.1, y = 1.1},
139 "head.png","nose.png"
143 --automatic_face_movement_dir = 0.0,
144 --automatic_face_movement_max_rotation_per_sec = 600,
147 --remove the head if no body
148 pig.head.on_step = function(self, dtime)
149 if self.parent == nil then
153 minetest.register_entity("mob:head", pig.head)