]> git.lizzy.rs Git - Crafter.git/blob - mods/mob/api/data_handling.lua
Make mobs navigate even better
[Crafter.git] / mods / mob / api / data_handling.lua
1 local
2 vector,minetest,math,pairs
3 =
4 vector,minetest,math,pairs
5 --
6 mobs.create_data_handling_functions = function(def,mob_register)
7
8         --mob_register.get_staticdata = function(self)
9                 --[[
10                 return minetest.serialize({
11                         --range = self.range,
12                         hp = self.hp,
13                         hunger = self.hunger,
14                         hostile = self.hostile,
15                         hostile_timer = self.hostile_timer,
16                         death_animation_timer = self.death_animation_timer,
17                         dead = self.dead,
18                         tnt_timer = self.tnt_timer,
19                         tnt_tick_timer = self.tnt_tick_timer,
20                         tnt_mod_state = self.tnt_mod_state,
21                         punch_timer = self.punch_timer,
22                         projectile_timer = self.projectile_timer,
23                         scared = self.scared,
24                         scared_timer = self.scared_timer,
25                         c_mob_data = self.c_mob_data,
26                         on_fire = self.on_fire,
27                 })
28                 ]]--
29         --end
30
31         mob_register.on_activate = function(self)--, staticdata, dtime_s)
32                 --[[
33                 if string.sub(staticdata, 1, string.len("return")) == "return" then
34                         local data = minetest.deserialize(staticdata)
35                         if data and type(data) == "table" then
36                                 --self.range = data.range
37                                 self.hp = data.hp
38                                 self.hunger = data.hunger
39                                 self.hostile = data.hostile
40                                 self.hostile_timer = data.hostile_timer
41                                 self.death_animation_timer = data.death_animation_timer
42                                 self.dead = data.dead
43                                 self.tnt_timer = data.tnt_timer
44                                 self.tnt_tick_timer = data.tnt_tick_timer
45                                 self.tnt_mod_state = data.tnt_mod_state
46                                 self.punch_timer = data.punch_timer
47                                 self.projectile_timer = data.projectile_timer
48                                 self.scared = data.scared
49                                 self.scared_timer = data.scared_timer                           
50                                 self.c_mob_data = data.c_mob_data
51                                 self.on_fire = data.on_fire
52                         end
53                 end
54                 ]]--
55                 --set up mob
56                 self.object:set_armor_groups({immortal = 1})
57                 --self.object:set_velocity({x = math.random(-5,5), y = 5, z = math.random(-5,5)})
58                 self.object:set_acceleration(def.gravity)
59                 self.object:set_animation(def.standing_frame, 0, 0, true)
60                 self.current_animation = 0
61                 self.object:set_hp(self.hp)
62                 self.direction = vector.new(math.random()*math.random(-1,1),0,math.random()*math.random(-1,1))
63                 
64                 
65                 --set the head up
66                 if self.head_bone then
67                         self.object:set_bone_position(self.head_bone, self.head_position_correction, vector.new(0,0,0))
68                 end
69                 self.is_mob = true
70                 self.object:set_armor_groups({immortal = 1})
71
72                 if self.custom_on_activate then
73                         self.custom_on_activate(self)
74                 end
75
76                 if self.on_fire == true then
77                         start_fire(self.object)
78                 end
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