add mobtamer tool

This commit is contained in:
Tai @ Flex 2016-08-20 12:00:21 +01:00
parent f586737971
commit 237e5a3215
2 changed files with 52 additions and 0 deletions

View File

@ -4,3 +4,4 @@
dofile(minetest.get_modpath("vivarium") .. "/falling_light.lua")
dofile(minetest.get_modpath("vivarium") .. "/staves.lua")
dofile(minetest.get_modpath("vivarium") .. "/capturing.lua")
dofile(minetest.get_modpath("vivarium") .. "/mobtamer.lua")

51
mobtamer.lua Normal file
View File

@ -0,0 +1,51 @@
minetest.register_tool("vivarium:mobtamer", {
description = "Mob Tamer",
inventory_image = "mobs_nametag.png^[colorize:blue:90",
wield_image = "mobs_nametag.png^[colorize:blue:90",
range = 5,
stack_max = 1,
on_use = function(itemstack, user, pointed_thing)
local maxuses = 30
local pos = user:getpos()
pos = {x=pos.x+math.random(1,2),y=pos.y+1,z=pos.z+math.random(1,2)}
-- here get the mob to the left
local inventory = user:get_inventory()
local eggname = ''
for idx,x in pairs(inventory:get_list("main") ) do
if x:get_name() == "vivarium:mobtamer" then
break
end
eggname = x:get_name()
end
local luaobj = minetest.add_entity(pos,eggname )
local luae = luaobj:get_luaentity()
if luae then
inventory:remove_item("main", eggname)
luae.type="npc"
luae.attacks_monsters=true
luae.state="walk"
bomf(pos,2 )
else
luaobj:remove()
minetest.chat_send_player(user:get_player_name(),"Not a mob!")
end
itemstack:add_wear(math.ceil(65536/maxuses))
return itemstack
end,
})
minetest.register_craft({
output = "vivarium:mobtamer",
recipe = {
{"mobs:leather","mobs:magic_lasso","mobs:leather"},
{"mobs:nametag","mobs:nametag","mobs:nametag"}
}
})