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")
12 mobs.register_mob = function(def)
18 ------------------------------------------------
19 mob_register.initial_properties = {
20 physical = def.physical,
21 collide_with_objects = def.collide_with_objects,
22 collisionbox = def.collisionbox,
24 visual_size = def.visual_size,
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,
35 mob_register.hp = def.hp
36 mob_register.max_speed = def.max_speed
37 mob_register.jump_timer = 0
39 mob_register.hurt_inside_timer = 0
40 mob_register.death_animation_timer = 0
41 mob_register.dead = false
43 mob_register.mob = true
44 mob_register.hostile = def.hostile
46 mob_register.hostile_timer = 0
47 mob_register.timer = 0
49 mob_register.state = def.state
51 mob_register.hunger = 200
53 mob_register.view_distance = def.view_distance
55 mob_register.punch_timer = 0
56 mob_register.punched_timer = 0
58 mob_register.death_rotation = def.death_rotation
60 mob_register.head_mount = def.head_mount
62 mob_register.hurt_sound = def.hurt_sound
63 mob_register.die_sound = def.die_sound
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
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
75 mob_register.projectile_timer = 0
76 mob_register.projectile_type = def.projectile_type
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
83 mob_register.die_in_light = def.die_in_light
84 mob_register.die_in_light_level = def.die_in_light_level
86 mob_register.mob = true
88 mob_register.collision_boundary = def.collision_boundary or 1
91 mobs.create_movement_functions(def,mob_register)
92 mobs.create_interaction_functions(def,mob_register)
93 mobs.create_data_handling_functions(def,mob_register)
94 mobs.create_animation_functions(def,mob_register)
95 mobs.create_timer_functions(def,mob_register)
96 --only creat internal head animation functions if has head
97 if def.has_head == true then
98 mobs.create_head_functions(def,mob_register)
102 mob_register.on_step = function(self, dtime)
103 if self.custom_function_begin then
104 self.custom_function_begin(self,dtime)
107 self.collision_detection(self)
109 if self.dead == false and self.death_animation_timer == 0 then
110 self.move(self,dtime)
111 self.set_animation(self)
113 if self.look_around then
114 self.look_around(self,dtime)
117 self.manage_punch_timer(self,dtime)
118 --self.debug_nametag(self,dtime)
120 self.manage_death_animation(self,dtime)
122 --fix zombie state again
123 if self.dead == true and self.death_animation_timer <= 0 then
127 if self.tnt_timer then
128 self.manage_explode_timer(self,dtime)
131 if self.projectile_timer then
132 self.manage_projectile_timer(self,dtime)
135 if self.custom_function_end then
136 self.custom_function_end(self,dtime)
140 minetest.register_entity("mob:"..def.mobname, mob_register)
143 if def.has_head == true then
144 mob_register.head = {}
145 mob_register.head.initial_properties = {
148 collide_with_objects = false,
149 collisionbox = {0, 0, 0, 0, 0, 0},
150 visual = def.head_visual,
151 visual_size = def.head_visual_size,
152 mesh = def.head_mesh,
153 textures = def.head_textures,
156 --automatic_face_movement_dir = 0.0,
157 --automatic_face_movement_max_rotation_per_sec = 600,
160 --remove the head if no body
161 mob_register.head.on_step = function(self, dtime)
162 if self.parent == nil then
166 minetest.register_entity("mob:head"..def.mobname, mob_register.head)
168 ------------------------------------------------