Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- turtleShell API
- -- fuelUp()
- -- distance - int - if it is necessary for the turtle to return to a specific
- -- location - int - pass the distance from that location to the function.
- -- verbose - bool - provides information to the screen
- -- broadcast - bool - broadcasts messages to listening computers
- function fuelUp(distance,verbose,broadcast)
- distance = distance or 0
- verbose = verbose or true
- broadcast = broadcast or false
- previousFuelLevel = turtle.getFuelLevel()
- currentFuelLevel = previousFuelLevel
- success = false
- slot = 1
- messageOne = ""
- messageTwo = ""
- if currentFuelLevel <= distance then
- if verbose or broadcast then
- messageOne = "Attempting to refuel..."
- end
- if verbose then
- print(messageOne)
- end
- if broadcast then
- rednet.open("right")
- rednet.broadcast(messageOne)
- rednet.close("right")
- end
- while not(success) and slot < 17 do
- turtle.select(slot)
- if turtle.refuel(slot) then
- success = true
- currentFuelLevel = turtle.getFuelLevel()
- else
- slot = slot + 1
- end
- end
- if success and (verbose or broadcast) then
- messageOne = "Refueling successful."
- messageTwo = "Increased fuel by " .. currentFuelLevel - previousFuelLevel .. " from slot " .. slot .. "."
- elseif verbose or broadcast then
- messageOne = "No fuel source found."
- end
- if success and verbose then
- print(messageOne)
- print(messageTwo)
- elseif verbose then
- print(messageOne)
- end
- if broadcast then
- rednet.open("right")
- if success then
- rednet.broadcast(messageOne)
- rednet.broadcast(messageTwo)
- else
- rednet.broadcast(messageOne)
- end
- end
- else
- success = true
- end
- return success
- end
- function betterDig()
- success = false
- while turtle.detect() do
- if turtle.dig() then
- success = true
- elseif turtle.attack() then
- else
- return success
- end
- -- waits for falling blocks
- sleep(.5)
- end
- return success
- end
- function betterDigUp()
- success = false
- while turtle.detectUp() do
- if turtle.digUp() then
- success = true
- elseif turtle.attackUp() then
- else
- return success
- end
- -- waits for falling blocks
- sleep(.5)
- end
- return success
- end
- function betterDigDown()
- success = false
- while turtle.detectDown() do
- if turtle.digDown() then
- success = true
- elseif turtle.attackDown() then
- else
- return success
- end
- end
- return success
- end
- function checkInventory()
- full = true
- for i = 1,16 do
- if turtle.getItemCount(i) == 0 then
- full = false
- end
- end
- return full
- end
Advertisement
Add Comment
Please, Sign In to add comment