]> git.lizzy.rs Git - Crafter.git/blob - mods/mob/api/timers.lua
Fix mob count handling
[Crafter.git] / mods / mob / api / timers.lua
1 mobs.create_timer_functions = function(def,mob_register)
2         --this controls how fast the mob punches
3         mob_register.manage_punch_timer = function(self,dtime)
4                 if self.punch_timer > 0 then
5                         self.punch_timer = self.punch_timer - dtime
6                 end
7                 --this controls how fast you can punch the mob (punched timer reset)
8                 if self.punched_timer > 0 then
9                         --print(self.punched_timer)
10                         self.punched_timer = self.punched_timer - dtime
11                 end
12         end
13
14         --this controls the hostile state
15         if def.hostile == true or def.attacked_hostile == true then
16                 if def.hostile_cooldown == true then
17                         mob_register.manage_hostile_timer = function(self,dtime)
18                                 if self.hostile_timer > 0 then
19                                         self.hostile_timer = self.hostile_timer - dtime
20                                 end
21                                 if self.hostile_timer <= 0 then
22                                         self.hostile = false
23                                 end
24                         end
25                 end
26         else
27                 mob_register.manage_scared_timer = function(self,dtime)
28                         if self.scared_timer > 0 then
29                                 self.scared_timer = self.scared_timer - dtime
30                         end
31                         if self.scared_timer <= 0 then
32                                 self.scared = false
33                         end
34                 end
35         end
36
37         mob_register.manage_hurt_color_timer = function(self,dtime)
38                 if self.hurt_color_timer > 0 then
39                         self.hurt_color_timer = self.hurt_color_timer - dtime
40                         if self.hurt_color_timer  <= 0 then
41                                 self.hurt_color_timer = 0
42                                 self.object:set_texture_mod("")
43                         end
44                 end
45         end
46
47         mob_register.manage_explode_timer = function(self,dtime)
48                 self.tnt_timer = self.tnt_timer - dtime
49                 self.tnt_tick_timer = self.tnt_tick_timer  - dtime
50                 if self.tnt_tick_timer <= 0 and not self.dead then
51                         self.tnt_tick_timer = self.explosion_blink_timer
52                         self.tnt_mod_state = math.abs(self.tnt_mod_state-1)
53                         if self.tnt_mod_state == 0 then
54                                 self.object:set_texture_mod("")
55                         else
56                                 self.object:set_texture_mod("^[colorize:"..self.explosion_blink_color..":130")
57                         end
58                         --print(self.object:get_texture_mod())
59                         --self.object:set_texture_mod("^[colorize:red:130")
60                 end
61                 if self.tnt_timer <= 0 and not self.dead then
62                         
63                         self.object:set_texture_mod("^[colorize:red:130")
64                         
65                         local pos = self.object:get_pos()
66                         self.object:remove()
67                         tnt(pos,self.explosion_power)
68                 end
69         end
70
71         if def.custom_timer then
72                 mob_register.do_custom_timer = function(self,dtime)
73                         self.c_timer = self.c_timer + dtime
74                         if self.c_timer >= self.custom_timer then
75                                 self.c_timer = 0 
76                                 self.custom_timer_function(self,dtime)
77                         end
78                 end
79         end
80
81         mob_register.manage_projectile_timer = function(self,dtime)
82                 self.projectile_timer = self.projectile_timer - dtime
83         end
84
85         if def.friendly_in_daylight then
86                 mob_register.handle_friendly_in_daylight_timer = function(self,dtime)
87                         self.friendly_in_daylight_timer = self.friendly_in_daylight_timer + dtime
88                         if self.friendly_in_daylight_timer >= 2 then
89                                 self.friendly_in_daylight_timer = 0
90                                 local pos = self.object:get_pos()
91                                 local light = minetest.get_node_light(pos)
92                                 if pos and light and light >= 13 then --1 greater than torch light
93                                         if self.following == false then
94                                                 self.hostile = false
95                                         end
96                                 else
97                                         self.hostile = true
98                                 end
99                         end
100                 end
101         end
102
103         --this stops the pig from flying into the air
104         mob_register.manage_jump_timer = function(self,dtime)
105                 if self.jump_timer > 0 then
106                         self.jump_timer = self.jump_timer - dtime
107                 end
108         end
109         return(mob_register)
110 end