Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bookSlot = 1
- local enchantSlot = 16
- local emptySlotsStart = 2
- local emptySlotsEnd = 15
- local xpSide = "right"
- local grinderSide = "left"
- local manualSide = "back"
- local xp = peripheral.wrap(xpSide)
- local enchantLevel = 30
- local levelLow = 60
- local levelHigh = 120
- function getBook()
- if turtle.getItemCount(bookSlot) < 1 then
- turtle.select(bookSlot)
- turtle.suckUp()
- clearInv()
- if turtle.getItemCount(bookSlot) < 2 then
- return false
- end
- end
- return true
- end
- function setGrind(isGrind)
- redstone.setOutput(grinderSide, isGrind)
- end
- local lastLevel
- function checkXP()
- local level = xp.getLevels()
- if level ~= lastLevel then
- print("level " .. level)
- end
- lastLevel = level
- if level <= levelLow then
- setGrind(true)
- elseif level >= levelHigh then
- setGrind(false)
- end
- return level >= enchantLevel
- end
- function clearInv()
- for i = emptySlotsStart, emptySlotsEnd do
- turtle.select(i)
- turtle.dropDown()
- end
- if turtle.getItemCount(enchantSlot) > 0 then
- turtle.select(enchantSlot)
- if turtle.compareTo(bookSlot) then
- turtle.dropUp()
- else
- turtle.dropDown()
- end
- end
- turtle.select(bookSlot)
- end
- function enchant()
- turtle.select(bookSlot)
- turtle.transferTo(enchantSlot, 1)
- turtle.select(enchantSlot)
- local good = xp.enchant(enchantLevel)
- if good then
- print("Enchant successful")
- else
- print("Enchant failed")
- end
- 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 getBook() then
- enchant()
- else
- sleep(5)
- end
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment