1
0
Fork 0

Add mobs:spawn_child

This commit is contained in:
Wuzzy 2018-05-30 12:56:39 +02:00
parent 940b3748fb
commit b2d9c119ac
4 changed files with 72 additions and 100 deletions

View File

@ -969,52 +969,25 @@ local breed = function(self)
-- custom breed function
if self.on_breed then
-- when false skip going any further
if self.on_breed(self, ent) == false then
return
end
else
effect(pos, 15, "tnt_smoke.png", 1, 2, 2, 15, 5)
end
local mob = minetest.add_entity(pos, self.name)
local ent2 = mob:get_luaentity()
local child = mobs:spawn_child(pos, self.name)
local ent_c = child:get_luaentity()
-- Use parent's texture
local textures = self.base_texture
-- using specific child texture (if found)
if self.child_texture then
textures = self.child_texture[1]
end
-- and resize to half height
mob:set_properties({
child:set_properties({
textures = textures,
visual_size = {
x = self.base_size.x * .5,
y = self.base_size.y * .5,
},
collisionbox = {
self.base_colbox[1] * .5,
self.base_colbox[2] * .5,
self.base_colbox[3] * .5,
self.base_colbox[4] * .5,
self.base_colbox[5] * .5,
self.base_colbox[6] * .5,
},
selectionbox = {
self.base_selbox[1] * .5,
self.base_selbox[2] * .5,
self.base_selbox[3] * .5,
self.base_selbox[4] * .5,
self.base_selbox[5] * .5,
self.base_selbox[6] * .5,
},
})
-- tamed and owned by parents' owner
ent2.child = true
ent2.tamed = true
ent2.owner = self.owner
ent_c.tamed = true
ent_c.owner = self.owner
end)
num = 0
@ -3907,6 +3880,52 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame)
return false
end
-- Spawn a child
function mobs:spawn_child(pos, mob_type)
local child = minetest.add_entity(pos, mob_type)
if not child then
return
end
local ent = child:get_luaentity()
effect(pos, 15, "tnt_smoke.png", 1, 2, 2, 15, 5)
ent.child = true
local textures
-- using specific child texture (if found)
if ent.child_texture then
textures = ent.child_texture[1]
end
-- and resize to half height
child:set_properties({
textures = textures,
visual_size = {
x = ent.base_size.x * .5,
y = ent.base_size.y * .5,
},
collisionbox = {
ent.base_colbox[1] * .5,
ent.base_colbox[2] * .5,
ent.base_colbox[3] * .5,
ent.base_colbox[4] * .5,
ent.base_colbox[5] * .5,
ent.base_colbox[6] * .5,
},
selectionbox = {
ent.base_selbox[1] * .5,
ent.base_selbox[2] * .5,
ent.base_selbox[3] * .5,
ent.base_selbox[4] * .5,
ent.base_selbox[5] * .5,
ent.base_selbox[6] * .5,
},
})
return child
end
-- DISABLED IN MCL2
--[=[

View File

@ -361,6 +361,16 @@ true the mob will not spawn.
'name' is the name of the animal/monster
MineClone 2 extensions
----------------------
mobs:spawn_child(pos, mob_type)
This function spawns a mob as a child. The parameter mob_type is the
entitystring of the new mob.
This function returns the mob on success and nil otherwise.
Making Arrows
-------------

View File

@ -253,37 +253,9 @@ local horse = {
on_breed = function(parent1, parent2)
local pos = parent1.object:get_pos()
local mob = minetest.add_entity(pos, parent1.name)
-- resize to half height
mob:set_properties({
visual_size = {
x = parent1.base_size.x * .5,
y = parent1.base_size.y * .5,
},
collisionbox = {
parent1.base_colbox[1] * .5,
parent1.base_colbox[2] * .5,
parent1.base_colbox[3] * .5,
parent1.base_colbox[4] * .5,
parent1.base_colbox[5] * .5,
parent1.base_colbox[6] * .5,
},
selectionbox = {
parent1.base_selbox[1] * .5,
parent1.base_selbox[2] * .5,
parent1.base_selbox[3] * .5,
parent1.base_selbox[4] * .5,
parent1.base_selbox[5] * .5,
parent1.base_selbox[6] * .5,
},
})
local ent = mob:get_luaentity()
-- tamed and owned by parents' owner
ent.child = true
ent.tamed = true
ent.owner = parent1.owner
if mobs:spawn_child(pos, parent1.name) then
return false
end
end,
}

View File

@ -171,38 +171,9 @@ mobs:register_mob("mobs_mc:pig", {
on_breed = function(parent1, parent2)
local pos = parent1.object:get_pos()
local mob = minetest.add_entity(pos, parent1.name)
-- resize to half height
mob:set_properties({
visual_size = {
x = parent1.base_size.x * .5,
y = parent1.base_size.y * .5,
},
collisionbox = {
parent1.base_colbox[1] * .5,
parent1.base_colbox[2] * .5,
parent1.base_colbox[3] * .5,
parent1.base_colbox[4] * .5,
parent1.base_colbox[5] * .5,
parent1.base_colbox[6] * .5,
},
selectionbox = {
parent1.base_selbox[1] * .5,
parent1.base_selbox[2] * .5,
parent1.base_selbox[3] * .5,
parent1.base_selbox[4] * .5,
parent1.base_selbox[5] * .5,
parent1.base_selbox[6] * .5,
},
})
local ent = mob:get_luaentity()
-- tamed and owned by parents' owner
ent.child = true
ent.tamed = true
ent.owner = parent1.owner
if mobs:spawn_child(pos, parent1.name) then
return false
end
end,
})