]> git.lizzy.rs Git - Crafter.git/blob - mods/mob/api/api_hook.lua
1106defb9a463c64f95cbfe79327910f6e0d0eff
[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 mob_register.hurt_inside_timer = 0
40 mob_register.death_animation_timer = 0
41 mob_register.dead = false
42
43 mob_register.mob = true
44 mob_register.hostile = def.hostile
45
46 mob_register.hostile_timer = 0
47 mob_register.timer = 0
48
49 mob_register.state = def.state
50
51 mob_register.hunger = 200
52
53 mob_register.view_distance = def.view_distance
54
55 mob_register.punch_timer = 0
56 mob_register.punched_timer = 0
57
58 mob_register.death_rotation = def.death_rotation
59
60 mob_register.head_mount = def.head_mount
61
62 mob_register.hurt_sound = def.hurt_sound
63 mob_register.die_sound = def.die_sound
64
65 mob_register.attack_type = def.attack_type
66 mob_register.explosion_radius = def.explosion_radius
67 mob_register.explosion_power = def.explosion_power
68 mob_register.tnt_timer = nil
69 mob_register.explosion_time = def.explosion_time
70
71 mob_register.custom_function_begin = def.custom_function_begin
72 mob_register.custom_function_end = def.custom_function_end
73 mob_register.projectile_timer_cooldown = def.projectile_timer_cooldown
74
75 mob_register.projectile_timer = 0
76 mob_register.projectile_type = def.projectile_type
77
78
79 mob_register.item_drop = def.item_drop
80 mob_register.item_minimum = def.item_minimum or def.item_amount
81 mob_register.item_amount = def.item_amount
82
83 mob_register.die_in_light = def.die_in_light
84 mob_register.die_in_light_level = def.die_in_light_level
85
86
87 mobs.create_movement_functions(def,mob_register)
88 mobs.create_interaction_functions(def,mob_register)
89 mobs.create_data_handling_functions(def,mob_register)
90 mobs.create_animation_functions(def,mob_register)
91 mobs.create_timer_functions(def,mob_register)
92 --only creat internal head animation functions if has head
93 if def.has_head == true then
94     mobs.create_head_functions(def,mob_register)
95 end
96
97
98 mob_register.on_step = function(self, dtime)
99     if self.custom_function_begin then
100         self.custom_function_begin(self,dtime)
101     end
102         if self.dead == false and self.death_animation_timer == 0 then
103                 self.move(self,dtime)
104                 self.set_animation(self)
105         
106         if self.look_around then
107             self.look_around(self,dtime)
108         end
109         
110                 self.manage_punch_timer(self,dtime)
111                 --self.debug_nametag(self,dtime)
112         else
113                 self.manage_death_animation(self,dtime)
114         end
115         --fix zombie state again
116         if self.dead == true and self.death_animation_timer <= 0 then
117                 self.on_death(self)
118         end
119     
120     if self.tnt_timer then
121         self.manage_explode_timer(self,dtime)
122     end
123     
124     if self.projectile_timer then
125         self.manage_projectile_timer(self,dtime)
126     end
127     
128     if self.custom_function_end then
129         self.custom_function_end(self,dtime)
130     end
131 end
132
133 minetest.register_entity("mob:"..def.mobname, mob_register)
134
135
136 if def.has_head == true then
137     mob_register.head = {}
138     mob_register.head.initial_properties = {
139         hp_max = 1,
140         physical = false,
141         collide_with_objects = false,
142         collisionbox = {0, 0, 0, 0, 0, 0},
143         visual =  def.head_visual,
144         visual_size = def.head_visual_size,
145         mesh = def.head_mesh,
146         textures = def.head_textures,
147         is_visible = true,
148         pointable = false,
149         --automatic_face_movement_dir = 0.0,
150         --automatic_face_movement_max_rotation_per_sec = 600,
151     }
152
153     --remove the head if no body
154     mob_register.head.on_step = function(self, dtime)
155         if self.parent == nil then
156             self.object:remove()
157         end
158     end
159     minetest.register_entity("mob:head"..def.mobname, mob_register.head) 
160 end
161 ------------------------------------------------
162
163 end