Added feed/tame/breed function

master
TenPlus1 2015-08-09 11:31:35 +01:00
parent ffc01c35be
commit 0030a01685
9 changed files with 234 additions and 459 deletions

69
api.lua
View File

@ -1,4 +1,4 @@
-- Mobs Api (4th August 2015)
-- Mobs Api (9th August 2015)
mobs = {}
mobs.mod = "redo"
@ -508,13 +508,26 @@ function mobs:register_mob(name, def)
for i,obj in ipairs(ents) do
ent = obj:get_luaentity()
-- quick fix for racist sheep
if ent
and string.find(ent.name, "mobs:sheep_") then
ent.name = "mobs:sheep"
-- check for same animal with different colour
local canmate = false
if ent then
if ent.name == self.name then
canmate = true
else
local entname = string.split(ent.name,":")
local selfname = string.split(self.name,":")
if entname[1] == selfname[1] then
entname = string.split(entname[2],"_")
selfname = string.split(selfname[2],"_")
if entname[1] == selfname[1] then
canmate = true
end
end
end
end
if ent
and ent.name == self.name
and canmate == true
and ent.horny == true
and ent.hornytimer <= 40 then
num = num + 1
@ -1566,3 +1579,47 @@ function mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso,
end
end
end
-- feeding, taming and breeding (thanks blert2112)
function mobs:feed_tame(self, clicker, feed_count, breed)
local item = clicker:get_wielded_item()
if item:get_name() == self.follow then
-- take item
if not minetest.setting_getbool("creative_mode") then
item:take_item()
clicker:set_wielded_item(item)
end
-- make children grow quicker
if self.child == true then
self.hornytimer = self.hornytimer + 20
return true
end
-- feed and tame
self.food = (self.food or 0) + 1
if self.food == feed_count then
self.food = 0
if breed and self.hornytimer == 0 then
self.horny = true
end
self.gotten = false
self.tamed = true
if not self.owner or self.owner == "" then
self.owner = clicker:get_player_name()
end
-- make sound when fed so many times
if self.sounds.random then
minetest.sound_play(self.sounds.random, {
object = self.object,
max_hear_distance = self.sounds.distance
})
end
end
return true
else
return false
end
end

View File

@ -43,43 +43,22 @@ mobs:register_mob("mobs:bunny", {
replace_what = {"farming:carrot_7", "farming:carrot_8", "farming_plus:carrot"},
replace_with = "air",
on_rightclick = function(self, clicker)
local item = clicker:get_wielded_item()
local name = clicker:get_player_name()
if item:get_name() == "farming_plus:carrot_item"
or item:get_name() == "farming:carrot" then
-- take item
if not minetest.setting_getbool("creative_mode") then
item:take_item()
clicker:set_wielded_item(item)
end
-- feed and tame
self.food = (self.food or 0) + 1
if self.food > 3 then
self.food = 0
self.tamed = true
-- make owner
if self.owner == "" then
self.owner = name
if not mobs:feed_tame(self, clicker, 4, true) then
-- Monty Python tribute
local item = clicker:get_wielded_item()
if item:get_name() == "mobs:lava_orb" then
if not minetest.setting_getbool("creative_mode") then
item:take_item()
clicker:set_wielded_item(item)
end
self.object:set_properties({
textures = {"mobs_bunny_evil.png"},
})
self.type = "monster"
self.state = "attack"
self.object:set_hp(20)
return
end
return
end
-- Monty Python tribute
if item:get_name() == "mobs:lava_orb" then
-- take item
if not minetest.setting_getbool("creative_mode") then
item:take_item()
clicker:set_wielded_item(item)
end
self.object:set_properties({
textures = {"mobs_bunny_evil.png"},
})
self.type = "monster"
self.state = "attack"
self.object:set_hp(20)
return
end
mobs:capture_mob(self, clicker, 30, 50, 80, false, nil)

View File

@ -49,42 +49,7 @@ mobs:register_mob("mobs:chicken", {
replace_what = {"air"},
replace_with = "mobs:egg",
on_rightclick = function(self, clicker)
local tool = clicker:get_wielded_item()
local name = clicker:get_player_name()
if tool:get_name() == "farming:seed_wheat" then
-- take item
if not minetest.setting_getbool("creative_mode") then
tool:take_item(1)
clicker:set_wielded_item(tool)
end
-- make child grow quicker
if self.child == true then
self.hornytimer = self.hornytimer + 10
return
end
-- feed and tame
self.food = (self.food or 0) + 1
if self.food > 7 then
self.food = 0
if self.hornytimer == 0 then
self.horny = true
end
self.tamed = true
-- make owner
if self.owner == "" then
self.owner = name
end
minetest.sound_play("mobs_chicken", {
object = self.object,
gain = 1.0,
max_hear_distance = 15,
loop = false,
})
end
return
end
mobs:feed_tame(self, clicker, 8, true)
mobs:capture_mob(self, clicker, 30, 50, 80, false, nil)
end,
})

71
cow.lua
View File

@ -49,61 +49,28 @@ mobs:register_mob("mobs:cow", {
replace_what = {"default:grass_3", "default:grass_4", "default:grass_5", "farming:wheat_8"},
replace_with = "air",
on_rightclick = function(self, clicker)
local tool = clicker:get_wielded_item()
local name = clicker:get_player_name()
if not mobs:feed_tame(self, clicker, 8, true) then
local tool = clicker:get_wielded_item()
if tool:get_name() == "bucket:bucket_empty" then
if self.gotten == true
or self.child == true then
-- milk cow with empty bucket
if tool:get_name() == "bucket:bucket_empty" then
if self.gotten == true
or self.child == true then
return
end
local inv = clicker:get_inventory()
inv:remove_item("main", "bucket:bucket_empty")
if inv:room_for_item("main", {name = "mobs:bucket_milk"}) then
clicker:get_inventory():add_item("main", "mobs:bucket_milk")
else
local pos = self.object:getpos()
pos.y = pos.y + 0.5
minetest.add_item(pos, {name = "mobs:bucket_milk"})
end
self.gotten = true -- milked
return
end
local inv = clicker:get_inventory()
inv:remove_item("main", "bucket:bucket_empty")
if inv:room_for_item("main", {name = "mobs:bucket_milk"}) then
clicker:get_inventory():add_item("main", "mobs:bucket_milk")
else
local pos = self.object:getpos()
pos.y = pos.y + 0.5
minetest.add_item(pos, {name = "mobs:bucket_milk"})
end
self.gotten = true -- milked
return
end
if tool:get_name() == "farming:wheat" then
-- take item
if not minetest.setting_getbool("creative_mode") then
tool:take_item(1)
clicker:set_wielded_item(tool)
end
-- make child grow quicker
if self.child == true then
self.hornytimer = self.hornytimer + 10
return
end
-- feed and tame
self.food = (self.food or 0) + 1
if self.food > 7 then
self.food = 0
if self.hornytimer == 0 then
self.horny = true
end
self.gotten = false -- ready to be milked again
self.tamed = true
-- make owner
if self.owner == "" then
self.owner = name
end
minetest.sound_play("mobs_cow", {
object = self.object,
gain = 1.0,
max_hear_distance = 10,
loop = false,
})
end
return
end
end
mobs:capture_mob(self, clicker, 0, 5, 60, false, nil)
end,
})

View File

@ -48,4 +48,18 @@ minetest.register_craft({
{"default:stick", "", "default:stick"},
{"farming:string", "default:stick", "farming:string"},
}
})
-- shears (right click to shear animal)
minetest.register_tool("mobs:shears", {
description = "Steel Shears (right-click to shear)",
inventory_image = "mobs_shears.png",
})
minetest.register_craft({
output = 'mobs:shears',
recipe = {
{'', 'default:steel_ingot', ''},
{'', 'group:stick', 'default:steel_ingot'},
}
})

View File

@ -39,35 +39,7 @@ mobs:register_mob("mobs:kitten", {
follow = "mobs:rat",
view_range = 8,
on_rightclick = function(self, clicker)
local item = clicker:get_wielded_item()
local name = clicker:get_player_name()
if item:get_name() == "fishing:fish_raw"
or item:get_name() == "ethereal:fish_raw" then
-- take item
if not minetest.setting_getbool("creative_mode") then
item:take_item()
clicker:set_wielded_item(item)
end
-- feed and tame
self.food = (self.food or 0) + 1
if self.food > 3 then
self.food = 0
self.tamed = true
-- make owner
if self.owner == "" then
self.owner = name
end
minetest.sound_play("mobs_kitten", {
object = self.object,
gain = 1.0,
max_hear_distance = 10,
loop = false,
})
end
return
end
mobs:feed_tame(self, clicker, 4, true)
mobs:capture_mob(self, clicker, 50, 50, 90, false, nil)
end
})

386
sheep.lua
View File

@ -1,283 +1,139 @@
local all_colours = {
"grey", "black", "red", "yellow", "green", "cyan", "blue", "magenta",
"orange", "violet", "brown", "pink", "dark_grey", "dark_green"
"white", "orange", "violet", "brown", "pink", "dark_grey", "dark_green"
}
-- Sheep by PilzAdam
mobs:register_mob("mobs:sheep", {
type = "animal",
passive = true,
hp_min = 8,
hp_max = 10,
armor = 200,
collisionbox = {-0.4, -1, -0.4, 0.4, 0.3, 0.4},
visual = "mesh",
mesh = "mobs_sheep.b3d",
textures = {
{"mobs_sheep.png"},
},
gotten_texture = {"mobs_sheep_shaved.png"},
gotten_mesh = "mobs_sheep_shaved.b3d",
makes_footstep_sound = true,
sounds = {
random = "mobs_sheep",
},
walk_velocity = 1,
jump = true,
drops = {
{name = "mobs:meat_raw",
chance = 1, min = 2, max = 3},
{name = "wool:white",
chance = 1, min = 1, max = 1},
},
water_damage = 1,
lava_damage = 5,
light_damage = 0,
animation = {
speed_normal = 15,
speed_run = 15,
stand_start = 0,
stand_end = 80,
walk_start = 81,
walk_end = 100,
},
follow = "farming:wheat",
view_range = 5,
replace_rate = 50,
replace_what = {"default:grass_3", "default:grass_4", "default:grass_5", "farming:wheat_8"},
replace_with = "air",
replace_offset = -1,
on_rightclick = function(self, clicker)
local item = clicker:get_wielded_item()
local name = clicker:get_player_name()
if item:get_name() == "farming:wheat" then
-- take item
if not minetest.setting_getbool("creative_mode") then
item:take_item()
clicker:set_wielded_item(item)
end
-- make child grow quicker
if self.child == true then
self.hornytimer = self.hornytimer + 10
return
end
-- feed and tame
self.food = (self.food or 0) + 1
if self.food > 7 then
self.food = 0
if self.hornytimer == 0 then
self.horny = true
end
self.gotten = false -- can be shaved again
self.tamed = true
-- make owner
if self.owner == "" then
self.owner = name
end
self.object:set_properties({
textures = {"mobs_sheep.png"},
mesh = "mobs_sheep.b3d",
})
minetest.sound_play("mobs_sheep", {
object = self.object,
gain = 1.0,
max_hear_distance = 10,
loop = false,
})
end
return
end
if item:get_name() == "mobs:shears"
and self.gotten == false
and self.child == false then
self.gotten = true -- shaved
if minetest.registered_items["wool:white"] then
local pos = self.object:getpos()
pos.y = pos.y + 0.5
local obj = minetest.add_item(pos, ItemStack("wool:white "..math.random(2,3)))
if obj then
obj:setvelocity({
x = math.random(-1,1),
y = 5,
z = math.random(-1,1)
})
end
item:add_wear(650) -- 100 uses
clicker:set_wielded_item(item)
end
self.object:set_properties({
textures = {"mobs_sheep_shaved.png"},
mesh = "mobs_sheep_shaved.b3d",
})
return
end
for _, col in ipairs(all_colours) do
if item:get_name() == "dye:"..col
and self.gotten == false
and self.child == false
and self.tamed == true
and name == self.owner then
local pos = self.object:getpos()
self.object:remove()
local mob = minetest.add_entity(pos, "mobs:sheep_"..col)
local ent = mob:get_luaentity()
ent.owner = clicker:get_player_name()
ent.tamed = true
-- take item
if not minetest.setting_getbool("creative_mode") then
item:take_item()
clicker:set_wielded_item(item)
end
break
end
end
mobs:capture_mob(self, clicker, 0, 5, 60, false, nil)
end,
})
mobs:register_spawn("mobs:sheep", {"default:dirt_with_grass", "ethereal:green_dirt"}, 20, 10, 15000, 1, 31000)
mobs:register_egg("mobs:sheep", "Sheep", "wool_white.png", 1)
-- shears (right click sheep to shear wool)
minetest.register_tool("mobs:shears", {
description = "Steel Shears (right-click sheep to shear)",
inventory_image = "mobs_shears.png",
})
minetest.register_craft({
output = 'mobs:shears',
recipe = {
{'', 'default:steel_ingot', ''},
{'', 'group:stick', 'default:steel_ingot'},
}
})
-- Coloured sheep
for _, col in ipairs(all_colours) do
mobs:register_mob("mobs:sheep_"..col, {
type = "animal",
passive = true,
hp_min = 8,
hp_max = 10,
armor = 200,
collisionbox = {-0.4, -1, -0.4, 0.4, 0.3, 0.4},
visual = "mesh",
mesh = "mobs_sheep.b3d",
textures = {
{"mobs_sheep_"..col..".png"},
},
gotten_texture = {"mobs_sheep_shaved.png"},
gotten_mesh = "mobs_sheep_shaved.b3d",
makes_footstep_sound = true,
sounds = {
random = "mobs_sheep",
},
walk_velocity = 1,
jump = true,
drops = {
{name = "mobs:meat_raw",
chance = 1, min = 2, max = 3},
{name = "wool:"..col,
chance = 1, min = 1, max = 1},
},
water_damage = 1,
lava_damage = 5,
light_damage = 0,
animation = {
speed_normal = 15,
speed_run = 15,
stand_start = 0,
stand_end = 80,
walk_start = 81,
walk_end = 100,
},
follow = "farming:wheat",
view_range = 5,
replace_rate = 50,
replace_what = {"default:grass_3", "default:grass_4", "default:grass_5", "farming:wheat_8"},
replace_with = "air",
replace_offset = -1,
on_rightclick = function(self, clicker)
local item = clicker:get_wielded_item()
local name = clicker:get_player_name()
mobs:register_mob("mobs:sheep_"..col, {
type = "animal",
passive = true,
hp_min = 8,
hp_max = 10,
armor = 200,
collisionbox = {-0.4, -1, -0.4, 0.4, 0.3, 0.4},
visual = "mesh",
mesh = "mobs_sheep.b3d",
textures = {
{"mobs_sheep_"..col..".png"},
},
gotten_texture = {"mobs_sheep_shaved.png"},
gotten_mesh = "mobs_sheep_shaved.b3d",
makes_footstep_sound = true,
sounds = {
random = "mobs_sheep",
},
walk_velocity = 1,
jump = true,
drops = {
{name = "mobs:meat_raw",
chance = 1, min = 2, max = 3},
{name = "wool:"..col,
chance = 1, min = 1, max = 1},
},
water_damage = 1,
lava_damage = 5,
light_damage = 0,
animation = {
speed_normal = 15,
speed_run = 15,
stand_start = 0,
stand_end = 80,
walk_start = 81,
walk_end = 100,
},
follow = "farming:wheat",
view_range = 5,
replace_rate = 50,
replace_what = {"default:grass_3", "default:grass_4", "default:grass_5", "farming:wheat_8"},
replace_with = "air",
replace_offset = -1,
on_rightclick = function(self, clicker)
local shpcolor = string.split(self.name,"_")[2]
if shpcolor =="dark" then
shpcolor = shpcolor.."_"..string.split(self.name,"_")[3]
end
if item:get_name() == "farming:wheat" then
-- take item
if not minetest.setting_getbool("creative_mode") then
item:take_item()
clicker:set_wielded_item(item)
end
-- make child grow quicker
if self.child == true then
self.hornytimer = self.hornytimer + 10
return
end
-- feed and tame
self.food = (self.food or 0) + 1
if self.food > 7 then
self.food = 0
if self.hornytimer == 0 then
self.horny = true
end
self.gotten = false -- can be shaved again
self.tamed = true
-- make owner
if self.owner == "" then
self.owner = name
end
self.object:set_properties({
textures = {"mobs_sheep_"..col..".png"},
mesh = "mobs_sheep.b3d",
})
minetest.sound_play("mobs_sheep", {
object = self.object,
gain = 1.0,
max_hear_distance = 10,
loop = false,
})
end
return
end
if item:get_name() == "mobs:shears"
and self.gotten == false
and self.child == false then
self.gotten = true -- shaved
if minetest.registered_items["wool:"..col] then
local pos = self.object:getpos()
pos.y = pos.y + 0.5
local obj = minetest.add_item(pos, ItemStack("wool:"..col.." "..math.random(2,3)))
if obj then
obj:setvelocity({
x = math.random(-1,1),
y = 5,
z = math.random(-1,1)
--are we feeding?
if mobs:feed_tame(self, clicker, 8, true, "mobs_sheep", 1.0, 10) then
--if full grow fuzz
if self.gotten == false then
self.object:set_properties({
textures = {"mobs_sheep_"..shpcolor..".png"},
mesh = "mobs_sheep.b3d",
})
end
item:add_wear(650) -- 100 uses
clicker:set_wielded_item(item)
return
end
self.object:set_properties({
textures = {"mobs_sheep_shaved.png"},
mesh = "mobs_sheep_shaved.b3d",
})
return
local item = clicker:get_wielded_item()
local itemname = item:get_name()
--are we giving a haircut>
if itemname == "mobs:shears" then
if self.gotten == false and self.child == false then
self.gotten = true -- shaved
if minetest.get_modpath("wool") then
local pos = self.object:getpos()
pos.y = pos.y + 0.5
local obj = minetest.add_item(pos, ItemStack("wool:"..shpcolor.." "..math.random(2,3)))
if obj then
obj:setvelocity({
x = math.random(-1,1),
y = 5,
z = math.random(-1,1)
})
end
item:add_wear(650) -- 100 uses
clicker:set_wielded_item(item)
end
self.object:set_properties({
textures = {"mobs_sheep_shaved.png"},
mesh = "mobs_sheep_shaved.b3d",
})
end
return
end
local name = clicker:get_player_name()
--are we coloring?
if itemname:find("dye:") then
if self.gotten == false and self.child == false and self.tamed == true and name == self.owner then
local col = string.split(itemname,":")[2]
for _,c in pairs(all_colours) do
if c == col then
local pos = self.object:getpos()
self.object:remove()
local mob = minetest.add_entity(pos, "mobs:sheep_"..col)
local ent = mob:get_luaentity()
ent.owner = name
ent.tamed = true
-- take item
if not minetest.setting_getbool("creative_mode") then
item:take_item()
clicker:set_wielded_item(item)
end
break
end
end
end
return
end
--are we capturing?
mobs:capture_mob(self, clicker, 0, 5, 60, false, nil)
end
})
mobs:capture_mob(self, clicker, 0, 5, 60, false, nil)
mobs:register_egg("mobs:sheep_"..col, "Sheep ("..col..")", "wool_"..col..".png", 1)
end,
})
end
mobs:register_egg("mobs:sheep_"..col, "Sheep ("..col..")", "wool_"..col..".png", 1)
mobs:register_spawn("mobs:sheep_white", {"default:dirt_with_grass", "ethereal:green_dirt"}, 20, 10, 15000, 1, 31000)
end
-- compatibility
minetest.register_alias("mobs:sheep", "mobs:sheep_white")

Binary file not shown.

After

Width:  |  Height:  |  Size: 801 B

View File

@ -42,42 +42,7 @@ mobs:register_mob("mobs:pumba", {
punch_end = 100,
},
on_rightclick = function(self, clicker)
local item = clicker:get_wielded_item()
local name = clicker:get_player_name()
if item:get_name() == "default:apple" then
-- take item
if not minetest.setting_getbool("creative_mode") then
item:take_item()
clicker:set_wielded_item(item)
end
-- make child grow quicker
if self.child == true then
self.hornytimer = self.hornytimer + 10
return
end
-- feed and tame
self.food = (self.food or 0) + 1
if self.food > 7 then
self.food = 0
if self.hornytimer == 0 then
self.horny = true
end
self.tamed = true
-- make owner
if self.owner == "" then
self.owner = name
end
minetest.sound_play("mobs_pig", {
object = self.object,
gain = 1.0,
max_hear_distance = 10,
loop = false,
})
end
return
end
mobs:feed_tame(self, clicker, 8, true)
mobs:capture_mob(self, clicker, 0, 5, 50, false, nil)
end,
})