]> git.lizzy.rs Git - Crafter.git/blob - mods/mob/api/data_handling.lua
Add in capes
[Crafter.git] / mods / mob / api / data_handling.lua
1 --
2 mobs.create_data_handling_functions = function(def,mob_register)
3         mob_register.get_staticdata = function(self)
4                 if self.deactivating == false then
5                         global_mob_amount = global_mob_amount + 1
6                         --print("Mob Spawned. Current Mobs: "..global_mob_amount)
7                 elseif self.deactivating == true then
8                         minetest.after(0, function()
9                                 if not self.object:get_luaentity() then
10                                         global_mob_amount = global_mob_amount - 1
11                                         --print("Mob Deactivated. Current Mobs: "..global_mob_amount)
12                                 end
13                         end)
14                 end
15
16                 return minetest.serialize({
17                         --range = self.range,
18                         hp = self.hp,
19                         hunger = self.hunger,
20                         hostile = self.hostile,
21                         hostile_timer = self.hostile_timer,
22                         death_animation_timer = self.death_animation_timer,
23                         dead = self.dead,
24                         tnt_timer = self.tnt_timer,
25                         tnt_tick_timer = self.tnt_tick_timer,
26                         tnt_mod_state = self.tnt_mod_state,
27                         punch_timer = self.punch_timer,
28                         projectile_timer = self.projectile_timer,
29                         scared = self.scared,
30                         scared_timer = self.scared_timer,
31                         c_mob_data = self.c_mob_data,
32                 })
33         end
34
35
36         mob_register.on_activate = function(self, staticdata, dtime_s)
37                 self.object:set_armor_groups({immortal = 1})
38                 --self.object:set_velocity({x = math.random(-5,5), y = 5, z = math.random(-5,5)})
39                 self.object:set_acceleration(def.gravity)
40                 if string.sub(staticdata, 1, string.len("return")) == "return" then
41                         local data = minetest.deserialize(staticdata)
42                         if data and type(data) == "table" then
43                                 --self.range = data.range
44                                 self.hp = data.hp
45                                 self.hunger = data.hunger
46                                 self.hostile = data.hostile
47                                 self.hostile_timer = data.hostile_timer
48                                 self.death_animation_timer = data.death_animation_timer
49                                 self.dead = data.dead
50                                 self.tnt_timer = data.tnt_timer
51                                 self.tnt_tick_timer = data.tnt_tick_timer
52                                 self.tnt_mod_state = data.tnt_mod_state
53                                 self.punch_timer = data.punch_timer
54                                 self.projectile_timer = data.projectile_timer
55                                 self.scared = data.scared
56                                 self.scared_timer = data.scared_timer                           
57                                 self.c_mob_data = data.c_mob_data
58                         end
59                 end
60                 
61                 --set up mob
62                 self.object:set_animation(def.standing_frame, 0, 0, true)
63                 self.current_animation = 0
64                 self.object:set_hp(self.hp)
65                 self.direction = vector.new(math.random()*math.random(-1,1),0,math.random()*math.random(-1,1))
66                 
67                 
68                 --set the head up
69                 if self.head_bone then
70                         self.object:set_bone_position(self.head_bone, self.head_position_correction, vector.new(0,0,0))
71                 end
72                 self.is_mob = true
73                 self.object:set_armor_groups({immortal = 1})
74
75                 if self.custom_on_activate then
76                         self.custom_on_activate(self)
77                 end
78                 --self.object:set_yaw(math.pi*math.random(-1,1)*math.random())
79
80                 --use this to handle the global mob table
81                 minetest.after(0,function()
82                         self.deactivating = true
83                 end)
84         end
85
86         --this is the info on the mob
87         mob_register.debug_nametag = function(self,dtime)
88                 --we're doing this to the child because the nametage breaks the
89                 --animation on the mob's body
90                 
91                 --we add in items we want to see in this list
92                 local debug_items = {"hostile","hostile_timer"}
93                 local text = ""
94                 for _,item in pairs(debug_items) do
95                         if self[item] ~= nil then
96                                 text = text..item..": "..tostring(self[item]).."\n"
97                         end
98                 end
99                 self.object:set_nametag_attributes({
100                 color = "white",
101                 text = text
102                 })
103         end
104         return(mob_register)
105 end