Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bookSlot = 1
- local lootSlotStart = 2
- local lootSlotEnd = 16
- local xpSide = "right"
- local grinderSide = "left"
- local manualSide = "back"
- local xp = peripheral.wrap(xpSide)
- local enchantLevel = 30
- local levelLow = 60
- local levelHigh = 120
- main()
- function checkBooks()
- if turtle.getItemCount(bookSlot) < 2 then
- turtle.select(bookSlot)
- turtle.suckUp()
- if turtle.getItemCount(bookSlot) < 2 then
- return false
- end
- end
- return true
- end
- function setGrind(isGrind)
- redstone.setOutput(grinderSide, isGrind)
- end
- function checkXP()
- local level = xp.getLevels()
- if level <= levelLow then
- setGrind(true)
- elseif level >= levelHigh then
- setGrind(false)
- end
- return level >= enchantLevel
- end
- function clearInv()
- for i = lootSlotStart, lootSlotEnd do
- turtle.select(i)
- turtle.dropDown()
- end
- turtle.select(bookSlot)
- end
- function enchant()
- turtle.select(bookSlot)
- xp.enchant(enchantLevel)
- clearInv()
- end
- function setManual(isManual)
- if isManual then
- setGrind(false)
- xp.setAutoCollect(false)
- else
- xp.setAutoCollect(true)
- end
- end
- function isManualSignal()
- return redstone.getInput(manualSide)
- end
- function main()
- clearInv()
- while true do
- if isManualSignal() then
- setManual(true)
- sleep(1)
- else
- setManual(false)
- if checkXP() and checkBooks() then
- enchant()
- else
- sleep(5)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment