From 237e5a3215e6e8fe6cbd86f59aa67fb4e6b8d1be Mon Sep 17 00:00:00 2001 From: "Tai @ Flex" Date: Sat, 20 Aug 2016 12:00:21 +0100 Subject: [PATCH] add mobtamer tool --- init.lua | 1 + mobtamer.lua | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 mobtamer.lua diff --git a/init.lua b/init.lua index 3297298..93230ed 100644 --- a/init.lua +++ b/init.lua @@ -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") diff --git a/mobtamer.lua b/mobtamer.lua new file mode 100644 index 0000000..4c339f7 --- /dev/null +++ b/mobtamer.lua @@ -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"} + } +}) +