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