Created
April 23, 2013 02:02
-
-
Save NelsonMinar/5440251 to your computer and use it in GitHub Desktop.
Minecraft ComputerCraft turtle function that enchants books
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Minecraft turtle function to enchant books. Requires MiscPeripherals | |
-- Place books in lower right slot; this will enchant them and drop them | |
-- in a chest below | |
-- Plug this routine into a melee XP bot's script to automatically generate books | |
-- Get a reference to the XP Peripheral API | |
local xp = peripheral.wrap("right") | |
-- enchantBook takes what level you want, returns true if successful | |
function enchantBook(level) | |
-- Check we can do the enchantment | |
if xp.getLevels() < level then | |
return false | |
end | |
-- Clear slot 15 just in case | |
turtle.select(15) | |
turtle.dropDown() | |
-- Move a single book from 16 to 15. Must do this; can't enchant a stack of books | |
turtle.select(16) | |
if not turtle.transferTo(15, 1) then | |
return false | |
end | |
-- Enchant the book and put it in the chest | |
turtle.select(15) | |
if not xp.enchant(level) then | |
return false | |
end | |
turtle.dropDown() | |
return true | |
end | |
-- Demo program | |
print("Level " .. xp.getLevels()) | |
args = {...} | |
if #args < 1 then | |
print("Usage: enchant <level>") | |
return | |
end | |
local desiredLevel = tonumber(args[1]) | |
if enchantBook(desiredLevel) then | |
print "Success!" | |
else | |
print "Failed to enchant book" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment