]> git.lizzy.rs Git - Crafter.git/blob - mods/mob/api/api_hook.lua
Fix mob count handling
[Crafter.git] / mods / mob / api / api_hook.lua
1 --class 
2 mobs = {}
3
4 local path = minetest.get_modpath(minetest.get_current_modname()).."/api/"
5 dofile(path.."movement.lua")
6 dofile(path.."interaction.lua")
7 dofile(path.."data_handling.lua")
8 dofile(path.."head_code.lua")
9 dofile(path.."animation.lua")
10 dofile(path.."timers.lua")
11
12 mobs.register_mob = function(def)
13
14
15
16 local mob_register = {}
17
18 ------------------------------------------------
19 mob_register.initial_properties = {
20         physical = def.physical,
21         collide_with_objects = def.collide_with_objects,
22         collisionbox = def.collisionbox,
23         visual = def.visual,
24         visual_size = def.visual_size,
25         mesh = def.mesh,
26         textures = def.textures,
27         is_visible = def.is_visible,
28         pointable = def.pointable,
29         automatic_face_movement_dir = def.automatic_face_movement_dir,
30         automatic_face_movement_max_rotation_per_sec = def.automatic_face_movement_max_rotation_per_sec,
31         makes_footstep_sound = def.makes_footstep_sound,
32 }
33
34
35 mob_register.hp = def.hp
36 mob_register.max_speed = def.max_speed
37 mob_register.jump_timer = 0
38
39
40 if def.head_bone then
41         mob_register.head_bone = def.head_bone
42         mobs.create_head_functions(def,mob_register)
43         mob_register.debug_head_pos = def.debug_head_pos
44         mob_register.head_directional_offset = def.head_directional_offset
45         mob_register.head_height_offset = def.head_height_offset
46         mob_register.head_rotation_offset = def.head_rotation_offset
47         mob_register.head_position_correction = def.head_position_correction
48         mob_register.head_coord = def.head_coord
49         mob_register.flip_pitch = def.flip_pitch
50 else
51         --print("create some other functions to turn mob " .. def.mobname)
52 end
53
54 mob_register.hurt_inside_timer = 0
55 mob_register.death_animation_timer = 0
56 mob_register.dead = false
57
58 mob_register.mob = true
59 mob_register.mobname = def.mobname
60
61 mob_register.hostile = def.hostile
62 if def.friendly_in_daylight == true then
63         mob_register.friendly_in_daylight = def.friendly_in_daylight
64         mob_register.friendly_in_daylight_timer = 0
65 end
66
67 mob_register.hostile_cooldown = def.hostile_cooldown
68
69 mob_register.hostile_timer = 0
70 mob_register.timer = 0
71
72 mob_register.state = def.state
73
74 mob_register.hunger = 200
75
76 mob_register.view_distance = def.view_distance
77
78 mob_register.punch_timer = 0
79 mob_register.punched_timer = 0
80 mob_register.group_attack = def.group_attack
81
82 mob_register.death_rotation = def.death_rotation
83
84 mob_register.head_mount = def.head_mount
85 mob_register.rotational_correction = def.rotational_correction or 0
86
87 mob_register.hurt_sound = def.hurt_sound
88 mob_register.die_sound = def.die_sound
89
90 mob_register.attack_type = def.attack_type
91 if def.attack_type == "explode" then
92         mob_register.tnt_tick_timer = 0
93 end
94 mob_register.explosion_radius = def.explosion_radius
95 mob_register.explosion_power = def.explosion_power
96 mob_register.tnt_timer = nil
97 mob_register.explosion_time = def.explosion_time
98 mob_register.explosion_blink_color = def.explosion_blink_color or "white"
99 mob_register.explosion_blink_timer = def.explosion_blink_timer or 0.2
100
101 mob_register.custom_function_begin = def.custom_function_begin
102 mob_register.custom_function = def.custom_function
103 mob_register.custom_function_end = def.custom_function_end
104
105 mob_register.projectile_timer_cooldown = def.projectile_timer_cooldown
106 mob_register.attacked_hostile = def.attacked_hostile
107 if not def.hostile and not def.attacked_hostile then
108         mob_register.scared = false
109         mob_register.scared_timer = 0
110 end
111 mob_register.attack_damage = def.attack_damage
112
113 mob_register.projectile_timer = 0
114 mob_register.projectile_type = def.projectile_type
115
116 mob_register.takes_fall_damage = def.takes_fall_damage or true
117 mob_register.make_jump_noise = def.make_jump_noise
118 mob_register.jump_animation = def.jump_animation
119 mob_register.jumping_frame = def.jumping_frame
120
121 mob_register.item_drop = def.item_drop
122 mob_register.item_minimum = def.item_minimum or 1
123 mob_register.item_max = def.item_max
124
125 mob_register.die_in_light = def.die_in_light
126 mob_register.die_in_light_level = def.die_in_light_level
127
128 mob_register.current_animation = 0
129 mob_register.hurt_color_timer = 0
130 mob_register.damage_color = def.damage_color or "red"
131 mob_register.custom_on_death = def.custom_on_death
132
133 mob_register.custom_on_activate = def.custom_on_activate
134
135 mob_register.custom_on_punch = def.custom_on_punch
136
137 mob_register.c_mob_data = def.c_mob_data
138
139 mob_register.deactivating = false
140
141 if def.pathfinds then
142         --mob_register.path = {}
143         mob_register.pathfinding_timer = 0
144 end
145
146 if def.custom_timer then
147         mob_register.c_timer = 0
148         mob_register.custom_timer = def.custom_timer
149         mob_register.custom_timer_function = def.custom_timer_function
150 end
151
152 mobs.create_movement_functions(def,mob_register)
153 mobs.create_interaction_functions(def,mob_register)
154 mobs.create_data_handling_functions(def,mob_register)
155 mobs.create_animation_functions(def,mob_register)
156 mobs.create_timer_functions(def,mob_register)
157
158
159 mob_register.on_step = function(self, dtime,moveresult)
160         if self.custom_function_begin then
161                 self.custom_function_begin(self,dtime)
162         end
163         
164         self.collision_detection(self)
165         if self.fall_damage then
166                 self.fall_damage(self)
167         end
168         
169         if self.dead == false and self.death_animation_timer == 0 then
170                 if self.do_custom_timer then
171                         self.do_custom_timer(self,dtime)
172                 end
173
174                 if self.custom_function then
175                         self.custom_function(self,dtime,moveresult)
176                 end
177
178                 self.move(self,dtime,moveresult)
179                 
180                 --self.debug_nametag(self,dtime)
181
182                 self.manage_hurt_color_timer(self,dtime)
183
184                 if self.manage_scared_timer then
185                         self.manage_scared_timer(self,dtime)
186                 end
187
188                 if self.set_animation then
189                         self.set_animation(self)
190                 end
191                 
192                 if self.look_around then
193                         self.look_around(self,dtime)
194                 end
195                 
196                 if self.pathfinding then
197                         self.pathfinding(self,dtime)
198                 end
199
200                 if self.handle_friendly_in_daylight_timer then
201                         self.handle_friendly_in_daylight_timer(self,dtime)
202                 end
203
204                 self.manage_punch_timer(self,dtime)
205         else
206                 self.manage_death_animation(self,dtime)
207                 if self.move_head then
208                         self.move_head(self,nil,dtime)
209                 end
210         end
211
212         --fix zombie state again
213         if self.dead == true and self.death_animation_timer <= 0 then
214                 self.on_death(self)
215         end
216         
217         if self.tnt_timer then
218                 self.manage_explode_timer(self,dtime)
219         end
220         
221         if self.projectile_timer then
222                 self.manage_projectile_timer(self,dtime)
223         end
224         
225         if self.custom_function_end then
226                 self.custom_function_end(self,dtime)
227         end
228 end
229
230 minetest.register_entity("mob:"..def.mobname, mob_register)
231 ------------------------------------------------
232
233 end