1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2025-07-06 01:50:21 +02:00

Update mobs

add bunny, changed api.lua, other smalls changes
This commit is contained in:
Ombridride
2015-03-19 00:10:30 +01:00
parent 2c9927dfbf
commit 3be8905b12
49 changed files with 126 additions and 33 deletions

View File

@ -59,7 +59,7 @@ function mobs:register_mob(name, def)
replace_what = def.replace_what,
replace_with = def.replace_with,
replace_offset = def.replace_offset or 0,
stimer = 0,
timer = 0,
env_damage_timer = 0, -- only if state = "attack"
@ -74,6 +74,7 @@ function mobs:register_mob(name, def)
horny = false,
hornytimer = 0,
child = false,
gotten = false,
do_attack = function(self, player, dist)
if self.state ~= "attack" then
@ -184,7 +185,7 @@ function mobs:register_mob(name, def)
end
-- check for mob drop/replace (used for chicken egg and sheep eating grass/wheat)
if self.replace_rate and math.random(1,self.replace_rate) == 1 then
if self.replace_rate and math.random(1,self.replace_rate) == 1 and self.child == false then
local pos = self.object:getpos() ; pos.y = pos.y + self.replace_offset
if #minetest.find_nodes_in_area(pos,pos,self.replace_what) > 0
and self.object:getvelocity().y == 0 and self.state == "stand" then
@ -413,6 +414,8 @@ function mobs:register_mob(name, def)
self.child = false
self.hornytimer = 0
self.object:set_properties({
textures = self.base_texture,
mesh = self.base_mesh,
visual_size = {x=self.visual_size.x,y=self.visual_size.y},
})
end
@ -443,8 +446,13 @@ function mobs:register_mob(name, def)
--print ("spawned baby:",self.name)
local mob = minetest.add_entity(pos, self.name)
local ent2 = mob:get_luaentity()
local texture = self.base_texture
if def.child_texture then
print ("child texture detected")
textures = def.child_texture[1]
end
mob:set_properties({
textures = textures,
visual_size = {x=self.visual_size.x/2,y=self.visual_size.y/2},
})
ent2.child = true
@ -772,7 +780,7 @@ function mobs:register_mob(name, def)
if tmp.tamed then
self.tamed = tmp.tamed
end
if tmp.gotten then -- using this variable for obtaining something from mob (milk/wool)
if tmp.gotten then
self.gotten = tmp.gotten
end
if tmp.child then
@ -784,6 +792,18 @@ function mobs:register_mob(name, def)
if tmp.hornytimer then
self.hornytimer = tmp.hornytimer
end
if tmp.textures then
self.textures = tmp.textures
end
if tmp.mesh then
self.mesh = tmp.mesh
end
if tmp.base_texture then
self.base_texture = tmp.base_texture
end
if tmp.base_mesh then
self.base_mesh = tmp.base_mesh
end
end
end
@ -797,20 +817,31 @@ function mobs:register_mob(name, def)
end,
get_staticdata = function(self)
-- set mob texture and model
local textures = def.available_textures["texture_"..math.random(1,def.available_textures["total"])]
local mesh = self.mesh
-- select random texture, set model
if not self.base_texture then
self.base_texture = def.textures[math.random(1,#def.textures)]
self.base_mesh = def.mesh
end
-- set texture, model and size
local textures = self.base_texture
local mesh = self.base_mesh
local vis_size = self.visual_size
-- if object is a sheared sheep then set texture and model
if self.name == "mobs:sheep" and self.gotten == true then
textures = {"mobs_sheep_shaved.png"}
mesh = "mobs_sheep_shaved.x"
-- specific texture if gotten
if self.gotten == true and def.gotten_texture then
textures = def.gotten_texture
end
-- specific mesh if gotten
if self.gotten == true and def.gotten_mesh then
mesh = def.gotten_mesh
end
-- if object is child then set half size
if self.child == true then
vis_size = {x=self.visual_size.x/2,y=self.visual_size.y/2}
if def.child_texture then
textures = def.child_texture[1]
end
end
-- remember settings
local tmp = {
lifetimer = self.lifetimer,
tamed = self.tamed,
@ -821,6 +852,7 @@ function mobs:register_mob(name, def)
mesh = mesh,
textures = textures,
visual_size = vis_size,
base_texture = self.base_texture,
}
self.object:set_properties(tmp)
return minetest.serialize(tmp)
@ -927,11 +959,6 @@ function mobs:register_spawn(name, nodes, max_light, min_light, chance, active_o
pos.y = pos.y - 0.5
minetest.add_entity(pos, name)
-- set mob health (randomly between min and max)
if mob then
mob = mob:get_luaentity()
mob.object:set_hp( math.random(mob.hp_min, mob.hp_max) )
end
end
})
end