Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Turtle Helper Api "ascoTurtleApi"
- --Load other apis
- --APIs are loaded in the downloader
- -- Turtle Detection
- function detectRight()
- turtle.turnRight()
- local blocked = turtle.detect()
- turtle.turnLeft()
- return blocked
- end
- function detectLeft()
- turtle.turnLeft()
- local blocked = turtle.detect()
- turtle.turnRight()
- return blocked
- end
- -- Turtle Movements
- function moveForward()
- checkFuel()
- return turtle.forward()
- end
- function moveBackward()
- checkFuel()
- turnAround()
- local moved = turtle.forward()
- turnAround()
- return moved
- end
- function moveRight()
- turtle.turnRight()
- local moved = moveForward()
- turtle.turnLeft()
- return moved
- end
- function moveLeft()
- turtle.turnLeft()
- local moved = moveForward()
- turtle.turnRight()
- return moved
- end
- function turnAround()
- turtle.turnLeft()
- turtle.turnLeft()
- return true
- end
- -- Fuel Helper
- fuelSlot = 16
- function setFuelSlot(slot)
- fuelSlot = slot
- end
- function getFuelSlot()
- return fuelSlot
- end
- function checkFuel()
- turtle.select(getFuelSlot())
- while (turtle.getFuelLevel() < 1) do
- if ((turtle.getItemCount(getFuelSlot()) == 0) or (not turtle.refuel(0))) then
- print("Please put fuel in slot " .. getFuelSlot() .. ". Thank you.")
- waitForInput()
- end
- turtle.refuel(1)
- end
- end
- function printFuelStatus()
- print("Fuel left: " .. turtle.getFuelLevel())
- end
- -- Inventory Helper
- function makeMaxStack(slot)
- turtle.select(slot)
- for s = 1, 16 do
- if(turtle.getItemSpace(slot) > 0) then
- if (slot ~= s) then
- if (turtle.getItemCount(slot) == 0) then
- turtle.select(s)
- turtle.transferTo(slot)
- turtle.select(slot)
- elseif (turtle.compareTo(s)) then
- turtle.select(s)
- turtle.transferTo(slot)
- end
- end
- end
- end
- return (turtle.getItemSpace(slot) == 0)
- end
- function emptyInventory(side)
- if(side == "back") then
- turtle.turnRight()
- turtle.turnRight()
- dropSlots(side)
- turtle.turnLeft()
- turtle.turnLeft()
- elseif(side == "left") then
- turtle.turnLeft()
- dropSlots(side)
- turtle.turnRight()
- elseif(side == "right") then
- turtle.turnRight()
- dropSlots(side)
- turtle.turnLeft()
- else
- dropSlots(side)
- end
- end
- function dropSlots(side)
- for s = 1, 16 do
- turtle.select(s)
- local itemsToDrop = turtle.getItemCount(s)
- if (s == getFuelSlot()) then
- -- Fuel will be ignored
- if(turtle.refuel(0)) then
- itemsToDrop = 0
- end
- end
- if(s == ascoFarmingApi.getSeedSlot()) then
- -- Keep atleast one seed, as "template"
- itemsToDrop = itemsToDrop - 1
- end
- if(itemsToDrop > 0) then
- if (side == "top") then
- turtle.dropUp(itemsToDrop)
- elseif (side == "bottom") then
- turtle.dropDown(itemsToDrop)
- else
- turtle.drop(itemsToDrop)
- end
- end
- end
- end
- --Wait for Key-Input, Exit program when F1 is pressed
- function waitForInput()
- local event, scancode = os.pullEvent("key")
- input = false
- -- F1 == 59
- if (scancode == 59) then
- error()
- end
- end
- -- Debug function
- local function ListRedstoneSides()
- for k,v in pairs(redstone.getSides()) do
- print(v)
- end
- end
- local function CursorPosition()
- local x1, y1 = term.getCursorPos()
- print ("New text line")
- local x2, y2 = term.getCursorPos()
- print ("Before: x=" .. x1 .. " y=" .. y1)
- local x3, y3 = term.getCursorPos()
- print ("After: x=" .. x2 .. " y=" .. y2)
- local x4, y4 = term.getCursorPos()
- print ("After: x=" .. x3 .. " y=" .. y3)
- print ("After: x=" .. x4 .. " y=" .. y4)
- local s = "Waiting "
- print(s)
- for i = 1, 10 do
- local x,y = term.getCursorPos()
- term.setCursorPos(x, y-1)
- term.clearLine()
- s = s .. "."
- print(s)
- os.sleep(2)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement