]> git.lizzy.rs Git - Crafter.git/blob - mods/mob/api/api_hook.lua
0376f11d7f9e40cf56ece3bfbdb7147640523f9f
[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 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 else
49         print("create some other functions to turn mob " .. def.mobname)
50 end
51
52 mob_register.hurt_inside_timer = 0
53 mob_register.death_animation_timer = 0
54 mob_register.dead = false
55
56 mob_register.mob = true
57 mob_register.hostile = def.hostile
58
59 mob_register.hostile_timer = 0
60 mob_register.timer = 0
61
62 mob_register.state = def.state
63
64 mob_register.hunger = 200
65
66 mob_register.view_distance = def.view_distance
67
68 mob_register.punch_timer = 0
69 mob_register.punched_timer = 0
70 mob_register.group_attack = def.group_attack
71
72 mob_register.death_rotation = def.death_rotation
73
74 mob_register.head_mount = def.head_mount
75
76 mob_register.hurt_sound = def.hurt_sound
77 mob_register.die_sound = def.die_sound
78
79 mob_register.attack_type = def.attack_type
80 mob_register.explosion_radius = def.explosion_radius
81 mob_register.explosion_power = def.explosion_power
82 mob_register.tnt_timer = nil
83 mob_register.explosion_time = def.explosion_time
84
85 mob_register.custom_function_begin = def.custom_function_begin
86 mob_register.custom_function_end = def.custom_function_end
87 mob_register.projectile_timer_cooldown = def.projectile_timer_cooldown
88 mob_register.attacked_hostile = def.attacked_hostile
89
90
91 mob_register.projectile_timer = 0
92 mob_register.projectile_type = def.projectile_type
93
94
95 mob_register.item_drop = def.item_drop
96 mob_register.item_minimum = def.item_minimum or def.item_amount
97 mob_register.item_amount = def.item_amount
98
99 mob_register.die_in_light = def.die_in_light
100 mob_register.die_in_light_level = def.die_in_light_level
101
102 mob_register.current_animation = 0
103
104 mob_register.mob = true
105
106 mob_register.collision_boundary = def.collision_boundary or 1
107
108
109 mobs.create_movement_functions(def,mob_register)
110 mobs.create_interaction_functions(def,mob_register)
111 mobs.create_data_handling_functions(def,mob_register)
112 mobs.create_animation_functions(def,mob_register)
113 mobs.create_timer_functions(def,mob_register)
114
115
116 mob_register.on_step = function(self, dtime)
117         if self.custom_function_begin then
118                 self.custom_function_begin(self,dtime)
119         end
120         
121         self.collision_detection(self)
122         self.fall_damage(self)
123         
124         if self.dead == false and self.death_animation_timer == 0 then
125                 self.move(self,dtime)
126                 self.set_animation(self)
127                 
128                 if self.look_around then
129                         self.look_around(self,dtime)
130                 end
131                 
132                 self.manage_punch_timer(self,dtime)
133                 --self.debug_nametag(self,dtime)
134         else
135                 self.manage_death_animation(self,dtime)
136                 self.move_head(self,nil,dtime)
137         end
138         --fix zombie state again
139         if self.dead == true and self.death_animation_timer <= 0 then
140                 self.on_death(self)
141         end
142         
143         if self.tnt_timer then
144                 self.manage_explode_timer(self,dtime)
145         end
146         
147         if self.projectile_timer then
148                 self.manage_projectile_timer(self,dtime)
149         end
150         
151         if self.custom_function_end then
152                 self.custom_function_end(self,dtime)
153         end
154 end
155
156 minetest.register_entity("mob:"..def.mobname, mob_register)
157 ------------------------------------------------
158
159 end