Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --ELTRUT 0.1.0
- --Fixxed by AxxiD
- -- PRINT
- OSwidth, OSheight = term.getSize()
- -- SCREEN
- function clearScreen()
- term.clear()
- term.setCursorPos(1,1)
- end
- function cS() -- shortcut for clearScreen()
- clearScreen()
- end
- function clearLine(line)
- printCentered(string.rep(" ", OSwidth), line)
- end
- function clearColumn(column)
- for i=1, OSheight, 1 do
- term.setCursorPos(column,i)
- term.write(" ")
- end
- end
- function clearColumnFromTo(column, start, last)
- for i=start, last do
- term.setCursorPos(column,i)
- term.write(" ")
- end
- end
- function centerCursor(line)
- term.setCursorPos(OSwidth/2,line)
- end
- function leftCursor(line)
- term.setCursorPos(1,line)
- end
- function rightCursor(line)
- term.setCursorPos(OSwidth,line)
- end
- -- PRINT
- function print(text, line, column)
- term.setCursorPos(column,line)
- term.write(text)
- end
- function printCentered(text, line)
- term.setCursorPos(OSwidth/2,line)
- term.write(text)
- end
- function printCenteredR(text,line)
- clearLine(line)
- printCentered(text,line)
- end
- function printRight(text, line)
- term.setCursorPos(OSwidth-#text,line)
- term.write(text)
- end
- function printRightR(text, line)
- clearLine(line)
- printRight(text,line)
- end
- function printLeft(text, line)
- term.setCursorPos(1,line)
- term.write(text)
- end
- function printLeftR(text, line)
- clearLine(line)
- printLeft(text, line)
- end
- function printVertical(text, column)
- for i=1, #text do
- term.setCursorPos(column,i)
- term.write(string.sub(text,i,i))
- end
- end
- function printVerticalR(text, column)
- clearColumn(column)
- printVertical(text, column)
- end
- function printHeader(text,line)
- printCentered(text, line)
- printCentered(string.rep("-", OSwidth), line+1)
- end
- -- FUEL
- function refuel(slot ,level)
- turtle.select(slot)
- while turtle.getFuelLevel() <= level do
- if turtle.refuel(0) then
- turtle.refuel(1)
- else
- sleep(1)
- end
- end
- end
- --INVENTORY
- function countSlots(first, last)
- local amount = 0
- for i=first, last do
- local slotAmount = turtle.getItemCount(i)
- if slotAmount > 0 then
- amount = amount + slotAmount
- end
- end
- return amount
- end
- function countInventory()
- return countSlots(1,16)
- end
- function compareToSlot(first, second)
- turtle.select(first)
- return turtle.compareTo(second)
- end
- function compareToSlots(selected, first, last)
- local same = true
- turtle.select(selected)
- for i=first, last do
- local check = turtle.compareTo(i)
- if not check then same = false end
- end
- return same
- end
- function transferTo(first, second, quantity)
- quantity = quantity or 64
- turtle.select(first)
- turtle.transferTo(second,quantity)
- end
- function transferToSlots(start, last, startTo)
- for i=0, last-start-1 do
- local startSlot = start + i
- if startSlot > 16 then
- startSlot = startSlot - 16
- end
- if turtle.getItemCount(startSlot) > 0 then
- local slot = startTo + i
- if slot > 16 then
- slot = slot - 16
- end
- transferTo(startSlot, slot)
- end
- end
- if countSlots(start, last) > 0 then
- return false
- end
- return true
- end
- -- DROP
- function drop(slot,quantity)
- quantitiy = quantity or 64
- turtle.select(slot)
- return turtle.drop(quantity)
- end
- function dropUp(slot, quantity)
- quantitiy = quantity or 64
- turtle.select(slot)
- return turtle.dropUp(quantity)
- end
- function dropDown(slot, quantity)
- quantity = quantity or 64
- turtle.select(slot)
- return turtle.dropDown(quantity)
- end
- function dropSlots(dStart, dEnd)
- local success = true
- for i=dStart, dEnd do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- local var = turtle.drop()
- if not var then success = false end
- end
- end
- return success
- end
- function dropUpSlots(dStart, dEnd)
- local success = true
- for i=dStart, dEnd do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- local var = turtle.dropUp()
- if not var then success = false end
- end
- end
- return success
- end
- function dropDownSlots(dStart, dEnd)
- local success = true
- for i=dStart, dEnd do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- local var = turtle.dropDown()
- if not var then success = false end
- end
- end
- return success
- end
- function dropSameTo(slot)
- local amount = 0
- turtle.select(slot)
- for i=1, 16 do
- if turtle.getItemCount(i) > 0 and turtle.compareTo(i) and not slot == i then
- turtle.select(i)
- amount = amount + turtle.getItemCount(i)
- turtle.drop()
- end
- end
- return amount
- end
- function dropUpSameTo(slot)
- local amount = 0
- turtle.select(slot)
- for i=1, 16 do
- if turtle.getItemCount(i) > 0 and turtle.compareTo(i) and not slot == i then
- turtle.select(i)
- amount = amount + turtle.getItemCount(i)
- turtle.dropUp()
- end
- end
- return amount
- end
- function dropDownSameTo(slot)
- local amount = 0
- turtle.select(slot)
- for i=1, 16 do
- if turtle.getItemCount(i) > 0 and turtle.compareTo(i) and not slot == i then
- turtle.select(i)
- amount = amount + turtle.getItemCount(i)
- turtle.dropDown()
- end
- end
- return amount
- end
- -- SUCK
- function suck(slot)
- turtle.select(slot)
- turtle.suck()
- return turtle.getItemCount(slot)
- end
- function suckUp(slot)
- turtle.select(slot)
- turtle.suckUp()
- return turtle.getItemCount(slot)
- end
- function suckDown(slot)
- turtle.select(slot)
- turtle.suckDown()
- return turtle.getItemCount(slot)
- end
- function suckSlots(sStart, sEnd)
- local amount = countSlots(sStart, sEnd)
- for i=sStart, sEnd do
- if turtle.getItemCount(i) == 0 then
- turtle.select(i)
- turtle.suck()
- end
- end
- return countSlots(sStart, sEnd) - amount
- end
- function suckUpSlots(sStart, sEnd)
- local amount = countSlots(sStart, sEnd)
- for i=sStart, sEnd do
- if turtle.getItemCount(i) == 0 then
- turtle.select(i)
- turtle.suckUp()
- end
- end
- return countSlots(sStart, sEnd) - amount
- end
- function suckDownSlots(sStart, sEnd)
- local amount = countSlots(sStart, sEnd)
- for i=sStart, sEnd do
- if turtle.getItemCount(i) == 0 then
- turtle.select(i)
- turtle.suckDown()
- end
- end
- return countSlots(sStart, sEnd) - amount
- end
- -- DIG
- function dig()
- while turtle.detect() do
- turtle.dig()
- sleep(0.4)
- end
- end
- function digUp()
- while turtle.detectUp() do
- turtle.digUp()
- if turtle.detectUp() then
- sleep(0.4)
- end
- end
- end
- function digDown()
- while turtle.detectDown() do
- turtle.digDown()
- if turtle.detectDown() then
- sleep(0.4)
- end
- end
- end
- -- MOVEMENT
- function turnAround()
- if math.ceil(math.random()*2) == 1 then
- turtle.turnLeft()
- turtle.turnLeft()
- else
- turtle.turnRight()
- turtle.turnRight()
- end
- end
- function forward(length)
- for i=1,length do
- while not turtle.forward() do sleep(1) end
- end
- end
- function forwardDig(length)
- length = length or 1
- for i=1,length do
- while not turtle.forward() do turtle.dig() end
- end
- end
- function forwardExtreme(length)
- length = length or 1
- for i=1,length do
- while not turtle.forward() do
- if turtle.detect() then
- dig()
- else
- turtle.attack()
- end
- end
- end
- end
- function back(length)
- length = length or 1
- for i=1,length do
- while not turtle.back() do sleep(1) end
- end
- end
- function backDig(length)
- length = length or 1
- for i=1,length do
- while not turtle.back() do
- turnAround()
- dig()
- turnAround()
- end
- end
- end
- function backExtreme(length)
- length = length or 1
- for i=1,length do
- while not turtle.back() do
- turnAround()
- if turtle.detect() then
- turtle.dig()
- else
- turtle.attack()
- end
- turnAround()
- end
- end
- end
- function up(length)
- length = length or 1
- for i=1,length do
- while not turtle.up() do sleep(1) end
- end
- end
- function upDig(length)
- length = length or 1
- for i=1,length do
- while not turtle.up() do turtle.digUp() end
- end
- end
- function upExtreme(length)
- length = length or 1
- for i=1,length do
- while not turtle.up() do
- if turtle.detectUp() then
- digUp()
- else
- turtle.attackUp()
- end
- end
- end
- end
- function down(length)
- length = length or 1
- for i=1,length do
- while not turtle.down() do sleep(1) end
- end
- end
- function downDig(length)
- length = length or 1
- for i=1,length do
- while not turtle.down() do turtle.digDown() end
- end
- end
- function downExtreme(length)
- length = length or 1
- for i=1,length do
- while not turtle.down() do
- if turtle.detectDown() then
- turtle.digDown()
- else
- turtle.attackDown()
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment