Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Enchanting Turtle V0.1 by QQII
- --Badly attempt to find an optimum times to attack before enchanting
- --Wrap peripherals
- local xp = peripheral.wrap("right")
- --Declerations
- local attacks = 165 --The number of attacks it performs before attempting to enchant
- local enchantLevel = 0 --The level the turtle initially attemps to perform an enchant at
- local enchants = 0 --The number of enchants performed by the turtle
- local levels = 0 --The amount of levels collected for the number of attacks performed
- local slot = 1 --The slot number that the items to be enchanted are in
- xp.setAutoCollect(true) --Sets the turtle to automatically collect xp
- --User Inputs
- print("Make sure that the mobs fall ontop of the turtle.")
- print("Make sure that there is an inventory infront containing books or other items for enchating.")
- print("Make sure that there is an inventory below the turtle for it to place the items it has encanted.")
- print("Enter the level you want the turtle to enchant at:")
- while enchantLevel <= 0
- enchantLevel = tonumber(read())
- end
- --Functions
- local function clearSlot(slotNumber) --Attemps to clear the slot slotNumber
- turtle.select(slotNumber)
- if turtle.getItemCount(slotNumber) ~= 0 then
- if not turtle.dropDown() then
- print("ERROR: failure to clear slot number " .. slotNumber)
- end
- end
- end
- local function clearSlots() --Places all the items into the chest under the turtle
- for i = 1,16 do
- clearSlot(i)
- end
- end
- local function getItem() --Attemps to take something from the chest above the turtle
- clearSlots()
- turtle.select(slot)
- if not turtle.suck() then
- print("ERROR: failure to obtain item to enchant")
- end
- if turtle.getItemCount(slot) ~= 1 then
- if not turtle.drop(turtle.getItemCount(slot) - 1) then
- print("ERROR: failure to reduce slot number " .. slot .. " to one item")
- end
- end
- end
- local function enchant() --Attemps to enchant the item
- turtle.select(slot)
- if xp.enchant(enchantLevel) then
- enchants = enchants + 1
- print("Number of enchants performed by the turtle: " .. enchants)
- else
- turtle.drop() --Replaces the items if it doesn't have enough levels
- end
- clearSlots()
- end
- --Main Script
- while true do
- levels = xp.getLevels()
- for i = 1,attacks do
- while not turtle.attackUp() do end
- end
- xp.collect()
- levels = xp.getLevels() - levels
- print("Gained " .. levels .. " for " .. attacks .. " attacks.")
- if levels >= enchantLevel then --Assumes all mobs that drop xp (for fine tuning)
- attacks = attacks - 1
- elseif levels < enchantLevel then --Assumes a constant flow of 1 hit kill mobs that drop 5 xp each
- attacks = attacks + 5 * (enchantLevel - levels)
- end
- print("Turtle will now attack " .. attacks .. " times before attempting to enchant")
- getItem()
- enchant()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement