1 local minetest = minetest
5 local path = minetest.get_modpath(minetest.get_current_modname()).."/api/"
6 dofile(path.."movement.lua")
7 dofile(path.."interaction.lua")
8 dofile(path.."data_handling.lua")
9 dofile(path.."head_code.lua")
10 dofile(path.."animation.lua")
11 dofile(path.."timers.lua")
13 mobs.register_mob = function(def)
17 local mob_register = {}
19 register_mob_spawner(def.mobname,def.textures,def.mesh)
21 ------------------------------------------------
22 mob_register.initial_properties = {
23 physical = def.physical,
24 collide_with_objects = def.collide_with_objects,
25 collisionbox = def.collisionbox,
27 visual_size = def.visual_size,
29 textures = def.textures,
30 is_visible = def.is_visible,
31 pointable = def.pointable,
32 automatic_face_movement_dir = def.automatic_face_movement_dir,
33 automatic_face_movement_max_rotation_per_sec = def.automatic_face_movement_max_rotation_per_sec,
34 makes_footstep_sound = def.makes_footstep_sound,
39 mob_register.hp = def.hp
40 mob_register.max_speed = def.max_speed
41 mob_register.jump_timer = 0
45 mob_register.head_bone = def.head_bone
46 mobs.create_head_functions(def,mob_register)
47 mob_register.debug_head_pos = def.debug_head_pos
48 mob_register.head_directional_offset = def.head_directional_offset
49 mob_register.head_height_offset = def.head_height_offset
50 mob_register.head_rotation_offset = def.head_rotation_offset
51 mob_register.head_position_correction = def.head_position_correction
52 mob_register.head_coord = def.head_coord
53 mob_register.flip_pitch = def.flip_pitch
55 --print("create some other functions to turn mob " .. def.mobname)
58 mob_register.hurt_inside_timer = 0
59 mob_register.death_animation_timer = 0
60 mob_register.dead = false
62 mob_register.mob = true
63 mob_register.mobname = def.mobname
65 mob_register.hostile = def.hostile
66 if def.friendly_in_daylight == true then
67 mob_register.friendly_in_daylight = def.friendly_in_daylight
68 mob_register.friendly_in_daylight_timer = 0
71 mob_register.hostile_cooldown = def.hostile_cooldown
73 mob_register.hostile_timer = 0
74 mob_register.timer = 0
76 mob_register.state = def.state
78 mob_register.hunger = 200
80 mob_register.view_distance = def.view_distance
82 mob_register.punch_timer = 0
83 mob_register.punched_timer = 0
84 mob_register.group_attack = def.group_attack
86 mob_register.death_rotation = def.death_rotation
88 mob_register.head_mount = def.head_mount
89 mob_register.rotational_correction = def.rotational_correction or 0
91 mob_register.hurt_sound = def.hurt_sound
92 mob_register.die_sound = def.die_sound
94 mob_register.attack_type = def.attack_type
95 if def.attack_type == "explode" then
96 mob_register.tnt_tick_timer = 0
97 mob_register.explosion_type = def.explosion_type
99 mob_register.explosion_radius = def.explosion_radius
100 mob_register.explosion_power = def.explosion_power
101 mob_register.tnt_timer = nil
102 mob_register.explosion_time = def.explosion_time
103 mob_register.explosion_blink_color = def.explosion_blink_color or "white"
104 mob_register.explosion_blink_timer = def.explosion_blink_timer or 0.2
106 mob_register.custom_function_begin = def.custom_function_begin
107 mob_register.custom_function = def.custom_function
108 mob_register.custom_function_end = def.custom_function_end
110 mob_register.projectile_timer_cooldown = def.projectile_timer_cooldown
111 mob_register.attacked_hostile = def.attacked_hostile
112 if not def.hostile and not def.attacked_hostile then
113 mob_register.scared = false
114 mob_register.scared_timer = 0
116 mob_register.attack_damage = def.attack_damage
118 mob_register.projectile_timer = 0
119 mob_register.projectile_type = def.projectile_type
121 mob_register.takes_fall_damage = def.takes_fall_damage or true
122 mob_register.make_jump_noise = def.make_jump_noise
123 mob_register.jump_animation = def.jump_animation
124 mob_register.jumping_frame = def.jumping_frame
126 mob_register.item_drop = def.item_drop
127 mob_register.item_minimum = def.item_minimum or 1
128 mob_register.item_max = def.item_max
130 mob_register.die_in_light = def.die_in_light
131 mob_register.die_in_light_level = def.die_in_light_level
133 mob_register.current_animation = 0
134 mob_register.hurt_color_timer = 0
135 mob_register.damage_color = def.damage_color or "red"
136 mob_register.custom_on_death = def.custom_on_death
138 mob_register.custom_on_activate = def.custom_on_activate
140 mob_register.custom_on_punch = def.custom_on_punch
142 mob_register.c_mob_data = def.c_mob_data
144 mob_register.deactivating = false
146 mob_register.on_fire = false
148 mob_register.fire_table = def.fire_table
150 mob_register.sound_pitch_mod_min = def.sound_pitch_mod_min
151 mob_register.sound_pitch_mod_max = def.sound_pitch_mod_max
153 mob_register.sound_pitch_mod_min_die = def.sound_pitch_mod_min_die
154 mob_register.sound_pitch_mod_max_die = def.sound_pitch_mod_max_die
157 if def.pathfinds then
158 --mob_register.path = {}
159 mob_register.pathfinding_timer = 0
162 if def.custom_timer then
163 mob_register.c_timer = 0
164 mob_register.custom_timer = def.custom_timer
165 mob_register.custom_timer_function = def.custom_timer_function
168 mobs.create_movement_functions(def,mob_register)
169 mobs.create_interaction_functions(def,mob_register)
170 mobs.create_data_handling_functions(def,mob_register)
171 mobs.create_animation_functions(def,mob_register)
172 mobs.create_timer_functions(def,mob_register)
175 mob_register.on_step = function(self, dtime,moveresult)
176 if self.custom_function_begin then
177 self.custom_function_begin(self,dtime)
180 self.collision_detection(self)
181 if self.fall_damage then
182 self.fall_damage(self)
185 if self.dead == false and self.death_animation_timer == 0 then
186 if self.do_custom_timer then
187 self.do_custom_timer(self,dtime)
190 if self.custom_function then
191 self.custom_function(self,dtime,moveresult)
194 self.move(self,dtime,moveresult)
197 --self.debug_nametag(self,dtime)
199 self.manage_hurt_color_timer(self,dtime)
201 if self.manage_scared_timer then
202 self.manage_scared_timer(self,dtime)
205 if self.set_animation then
206 self.set_animation(self)
209 if self.look_around then
210 self.look_around(self,dtime)
213 if self.pathfinding then
214 self.pathfinding(self,dtime)
217 if self.handle_friendly_in_daylight_timer then
218 self.handle_friendly_in_daylight_timer(self,dtime)
221 self.manage_punch_timer(self,dtime)
223 self.manage_death_animation(self,dtime)
224 if self.move_head then
225 self.move_head(self,nil,dtime)
229 --fix zombie state again
230 if self.dead == true and self.death_animation_timer <= 0 then
234 if self.tnt_timer then
235 self.manage_explode_timer(self,dtime)
238 if self.projectile_timer then
239 self.manage_projectile_timer(self,dtime)
242 if self.custom_function_end then
243 self.custom_function_end(self,dtime)
247 minetest.register_entity("mob:"..def.mobname, mob_register)
248 ------------------------------------------------