]> git.lizzy.rs Git - Crafter.git/blob - mods/mob/api/data_handling.lua
Implement first prototype of pathfinding
[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                 return minetest.serialize({
5                         --range = self.range,
6                         hp = self.hp,
7                         hunger = self.hunger,
8                         hostile = self.hostile,
9                         hostile_timer = self.hostile_timer,
10                         death_animation_timer = self.death_animation_timer,
11                         dead = self.dead,
12                         tnt_timer = self.tnt_timer,
13                         tnt_tick_timer = self.tnt_tick_timer,
14                         tnt_mod_state = self.tnt_mod_state,
15                         punch_timer = self.punch_timer,
16                         projectile_timer = self.projectile_timer
17                 })
18         end
19
20
21         mob_register.on_activate = function(self, staticdata, dtime_s)
22                 global_mob_amount = global_mob_amount + 1
23                 print("Mobs Spawned. Current Mobs: "..global_mob_amount)
24                 self.object:set_armor_groups({immortal = 1})
25                 --self.object:set_velocity({x = math.random(-5,5), y = 5, z = math.random(-5,5)})
26                 self.object:set_acceleration(def.gravity)
27                 if string.sub(staticdata, 1, string.len("return")) == "return" then
28                         local data = minetest.deserialize(staticdata)
29                         if data and type(data) == "table" then
30                                 --self.range = data.range
31                                 self.hp = data.hp
32                                 self.hunger = data.hunger
33                                 self.hostile = data.hostile
34                                 self.hostile_timer = data.hostile_timer
35                                 self.death_animation_timer = data.death_animation_timer
36                                 self.dead = data.dead
37                                 self.tnt_timer = data.tnt_timer
38                                 self.tnt_tick_timer = data.tnt_tick_timer
39                                 self.tnt_mod_state = data.tnt_mod_state
40                                 self.punch_timer = data.punch_timer
41                                 self.projectile_timer = data.projectile_timer
42                         end
43                 end
44                 
45                 --set up mob
46                 self.object:set_animation(def.standing_frame, 0, 0, true)
47                 self.current_animation = 0
48                 self.object:set_hp(self.hp)
49                 self.direction = vector.new(math.random()*math.random(-1,1),0,math.random()*math.random(-1,1))
50                 
51                 
52                 --set the head up
53                 if self.head_bone then
54                         self.object:set_bone_position(self.head_bone, self.head_position_correction, vector.new(0,0,0))
55                 end
56                 self.is_mob = true
57                 self.object:set_armor_groups({immortal = 1})
58                 --self.object:set_yaw(math.pi*math.random(-1,1)*math.random())
59         end
60
61         --this is the info on the mob
62         mob_register.debug_nametag = function(self,dtime)
63                 --we're doing this to the child because the nametage breaks the
64                 --animation on the mob's body
65                 
66                 --we add in items we want to see in this list
67                 local debug_items = {"hostile","hostile_timer"}
68                 local text = ""
69                 for _,item in pairs(debug_items) do
70                         if self[item] ~= nil then
71                                 text = text..item..": "..tostring(self[item]).."\n"
72                         end
73                 end
74                 self.object:set_nametag_attributes({
75                 color = "white",
76                 text = text
77                 })
78         end
79         return(mob_register)
80 end