]> git.lizzy.rs Git - Crafter.git/blob - mods/mob/init.lua
Turn off mob footsteps
[Crafter.git] / mods / mob / init.lua
1 --this is where mobs are defined
2
3 --this is going to be used to set an active mob limit
4 global_mob_table = {}
5
6
7 local path = minetest.get_modpath(minetest.get_current_modname())
8
9 dofile(path.."/spawning.lua")
10 dofile(path.."/items.lua")
11
12
13 --these are helpers to create entities
14 pig = {}
15
16
17
18 pig.initial_properties = {
19         hp_max = 1,
20         physical = true,
21         collide_with_objects = false,
22         collisionbox = {-0.37, -0.4, -0.37, 0.37, 0.5, 0.37},
23         visual = "mesh",
24         visual_size = {x = 3, y = 3},
25         mesh = "pig.x",
26         textures = {
27                 "body.png","leg.png","leg.png","leg.png","leg.png"
28         },
29         is_visible = true,
30         pointable = true,
31         automatic_face_movement_dir = -90.0,
32         automatic_face_movement_max_rotation_per_sec = 300,
33         --makes_footstep_sound = true,
34 }
35
36 pig.hp = 5
37 pig.speed = 5
38 pig.jump_timer = 0
39
40 pig.death_animation_timer = 0
41
42 pig.mob = true
43 pig.hostile = false
44 pig.hostile_timer = 0
45 pig.timer = 0
46
47 pig.state = 0
48 pig.hunger = 200
49 pig.view_distance = 20
50
51 pig.punch_timer = 0
52 pig.punched_timer = 0
53
54
55 --head stuff
56 pig.head_mount = vector.new(0,1.2,1.9)
57
58 dofile(path.."/chatcommands.lua")
59 dofile(path.."/timers.lua")
60 dofile(path.."/head_code.lua")
61 dofile(path.."/movement_code.lua")
62 dofile(path.."/data_handling_code.lua")
63 dofile(path.."/interaction_code.lua")
64
65
66 ----------------------------------
67
68
69 --repel from players
70 pig.push = function(self)
71         local pos = self.object:getpos()
72         local radius = 1
73         for _,object in ipairs(minetest.get_objects_inside_radius(pos, radius)) do
74                 if object:is_player() or object:get_luaentity().mob == true then
75                         local player_pos = object:getpos()
76                         pos.y = 0
77                         player_pos.y = 0
78                         
79                         local currentvel = self.object:getvelocity()
80                         local vel = vector.subtract(pos, player_pos)
81                         vel = vector.normalize(vel)
82                         local distance = vector.distance(pos,player_pos)
83                         distance = (radius-distance)*10
84                         vel = vector.multiply(vel,distance)
85                         local acceleration = vector.new(vel.x-currentvel.x,0,vel.z-currentvel.z)
86                         
87                         
88                         self.object:add_velocity(acceleration)
89                         
90                         acceleration = vector.multiply(acceleration, 5)
91                         object:add_player_velocity(acceleration)
92                 end
93         end
94 end
95
96 --sets the mob animation and speed
97 pig.set_animation = function(self)
98         if self.speed == 0 or vector.equals(self.direction,vector.new(0,0,0)) then
99                 self.object:set_animation({x=0,y=0}, 1, 0, true)
100         else
101                 self.object:set_animation({x=5,y=15}, 1, 0, true)
102                 local speed = self.object:get_velocity()
103                 speed.y = 0
104                 self.object:set_animation_frame_speed(vector.distance(vector.new(0,0,0),speed)*5)
105         end
106 end
107
108 --this depletes the mobs hunger
109 pig.do_hunger = function(self,dtime)
110         self.hunger = self.hunger - dtime
111 end
112
113 --this sets the state of the mob
114 pig.set_state = function(self,dtime)
115         self.do_hunger(self,dtime)
116 end
117
118 pig.on_step = function(self, dtime)
119         self.manage_death_animation(self,dtime)
120         if self.death_animation_timer == 0 then
121                 self.set_state(self,dtime)
122                 self.move(self,dtime)
123                 self.set_animation(self)
124                 self.look_around(self,dtime)
125                 self.manage_punch_timer(self,dtime)
126                 pig.debug_nametag(self,dtime)
127         end
128 end
129
130 minetest.register_entity("mob:pig", pig)
131
132
133
134
135
136 ------------------------------------------------------------------------the head
137
138 pig.head = {}
139 pig.head.initial_properties = {
140         hp_max = 1,
141         physical = false,
142         collide_with_objects = false,
143         collisionbox = {0, 0, 0, 0, 0, 0},
144         visual = "mesh",
145         visual_size = {x = 1.1, y = 1.1},
146         mesh = "pig_head.x",
147         textures = {
148                 "head.png","nose.png"
149         },
150         is_visible = true,
151         pointable = false,
152         --automatic_face_movement_dir = 0.0,
153         --automatic_face_movement_max_rotation_per_sec = 600,
154 }
155
156 --remove the head if no body
157 pig.head.on_step = function(self, dtime)
158         if self.parent == nil then
159                 self.object:remove()
160         end
161 end
162 minetest.register_entity("mob:head", pig.head)