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.death_animation_timer = 0
35 pig.view_distance = 20
42 pig.head_mount = vector.new(0,1.2,1.9)
43 local path = minetest.get_modpath(minetest.get_current_modname()).."/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 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 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 pig.do_hunger = function(self,dtime)
95 self.hunger = self.hunger - dtime
98 --this sets the state of the mob
99 pig.set_state = function(self,dtime)
100 self.do_hunger(self,dtime)
103 pig.on_step = function(self, dtime)
104 self.manage_death_animation(self,dtime)
105 if 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)
115 minetest.register_entity("mob:pig", pig)
121 ------------------------------------------------------------------------the head
124 pig.head.initial_properties = {
127 collide_with_objects = false,
128 collisionbox = {0, 0, 0, 0, 0, 0},
130 visual_size = {x = 1.1, y = 1.1},
133 "head.png","nose.png"
137 --automatic_face_movement_dir = 0.0,
138 --automatic_face_movement_max_rotation_per_sec = 600,
141 --remove the head if no body
142 pig.head.on_step = function(self, dtime)
143 if self.parent == nil then
147 minetest.register_entity("mob:head", pig.head)