1 --this is where mobs are defined
3 --this is going to be used to set an active mob limit
7 local path = minetest.get_modpath(minetest.get_current_modname())
9 dofile(path.."/spawning.lua")
10 dofile(path.."/items.lua")
13 --these are helpers to create entities
18 pig.initial_properties = {
21 collide_with_objects = false,
22 collisionbox = {-0.37, -0.4, -0.37, 0.37, 0.5, 0.37},
24 visual_size = {x = 3, y = 3},
27 "body.png","leg.png","leg.png","leg.png","leg.png"
31 automatic_face_movement_dir = -90.0,
32 automatic_face_movement_max_rotation_per_sec = 300,
33 --makes_footstep_sound = true,
40 pig.death_animation_timer = 0
49 pig.view_distance = 20
56 pig.head_mount = vector.new(0,1.2,1.9)
58 dofile(path.."/chatcommands.lua")
59 dofile(path.."/timers.lua")
60 dofile(path.."/head_code.lua")
61 dofile(path.."/movement_code.lua")
62 dofile(path.."/data_handling_code.lua")
63 dofile(path.."/interaction_code.lua")
66 ----------------------------------
70 pig.push = function(self)
71 local pos = self.object:getpos()
73 for _,object in ipairs(minetest.get_objects_inside_radius(pos, radius)) do
74 if object:is_player() or object:get_luaentity().mob == true then
75 local player_pos = object:getpos()
79 local currentvel = self.object:getvelocity()
80 local vel = vector.subtract(pos, player_pos)
81 vel = vector.normalize(vel)
82 local distance = vector.distance(pos,player_pos)
83 distance = (radius-distance)*10
84 vel = vector.multiply(vel,distance)
85 local acceleration = vector.new(vel.x-currentvel.x,0,vel.z-currentvel.z)
88 self.object:add_velocity(acceleration)
90 acceleration = vector.multiply(acceleration, 5)
91 object:add_player_velocity(acceleration)
96 --sets the mob animation and speed
97 pig.set_animation = function(self)
98 if self.speed == 0 or vector.equals(self.direction,vector.new(0,0,0)) then
99 self.object:set_animation({x=0,y=0}, 1, 0, true)
101 self.object:set_animation({x=5,y=15}, 1, 0, true)
102 local speed = self.object:get_velocity()
104 self.object:set_animation_frame_speed(vector.distance(vector.new(0,0,0),speed)*5)
108 --this depletes the mobs hunger
109 pig.do_hunger = function(self,dtime)
110 self.hunger = self.hunger - dtime
113 --this sets the state of the mob
114 pig.set_state = function(self,dtime)
115 self.do_hunger(self,dtime)
118 pig.on_step = function(self, dtime)
119 self.manage_death_animation(self,dtime)
120 if self.death_animation_timer == 0 then
121 self.set_state(self,dtime)
122 self.move(self,dtime)
123 self.set_animation(self)
124 self.look_around(self,dtime)
125 self.manage_punch_timer(self,dtime)
126 --self.debug_nametag(self,dtime)
130 minetest.register_entity("mob:pig", pig)
136 ------------------------------------------------------------------------the head
139 pig.head.initial_properties = {
142 collide_with_objects = false,
143 collisionbox = {0, 0, 0, 0, 0, 0},
145 visual_size = {x = 1.1, y = 1.1},
148 "head.png","nose.png"
152 --automatic_face_movement_dir = 0.0,
153 --automatic_face_movement_max_rotation_per_sec = 600,
156 --remove the head if no body
157 pig.head.on_step = function(self, dtime)
158 if self.parent == nil then
162 minetest.register_entity("mob:head", pig.head)