Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- do_sugar
- -----------------------------------------------------------------------
- term.clear()
- term.setCursorPos(1, 1)
- minerID = os.getComputerID()
- turtleName = nil
- consoleID = 0
- version = "1.0"
- function getConsoleID()
- local fname = "ConsoleID"
- if fs.exists(fname) then
- file = fs.open(fname, "r")
- consoleID = tonumber(file.readAll())
- file.close()
- print("Monitor Console ID: "..consoleID)
- else
- updateStatus("Waiting for Console ID...",true)
- term.write("Monitor Console ID: ")
- consoleID = io.read()
- file = fs.open(fname, "w")
- file.write(consoleID)
- file.close()
- consoleID = tonumber(consoleID)
- end
- end
- function updateStatus(msg, silent)
- if not rednet.isOpen("right") then rednet.open("right") end
- if rednet.isOpen("right") then
- if turtleName == nil then return end
- networkmsg = "MM:"..turtleName..": "..msg
- if consoleID == 0 then
- rednet.broadcast(networkmsg)
- else
- rednet.send(consoleID,networkmsg)
- end
- end
- if not silent then print(msg) end
- end
- function getTurtleName()
- local fname = "TurtleName"
- if fs.exists(fname) then
- file = fs.open(fname, "r")
- turtleName = file.readAll()
- file.close()
- else
- term.write("Turtle Name: ")
- turtleName = io.read()
- file = fs.open(fname, "w")
- file.write(turtleName)
- file.close()
- end
- end
- -- Main Program
- updateStatus("Starting")
- term.clear()
- term.setCursorPos(1,1)
- getTurtleName()
- getConsoleID()
- function update()
- end
- function fuelItUp()
- updateStatus("...Working")
- --Finds out if the turtle needs to refuel and if it has fuel to run
- needsFuel = turtle.getFuelLevel()
- minimumFuelLevel = 10
- hasFuel = turtle.getItemCount(16)
- useFuel = turtle.refuel()
- if needsFuel == "unlimited" then
- else
- if tonumber(needsFuel) < tonumber(minimumFuelLevel) then
- if hasFuel > 0 then
- turtle.select(16)
- turtle.refuel(1)
- turtle.select(1)
- else
- updateStatus("Please insert fuel into slot 16")
- repeat os.sleep(1)
- until tonumber(turtle.getItemCount(16)) > 0
- fuelItUp()
- end
- end
- end
- end
- function questions()
- print("How many blocks long?")
- length = io.read()
- print("How many rows wide?")
- rows = io.read()
- declarations()
- end
- function declarations()
- currentPos = 0
- currentRow = 1
- startBlock = 1
- startRow = 1
- det = turtle.detect()
- detDown = turtle.detectDown()
- prime()
- end
- function prime()
- fuelItUp()
- turtle.up()
- turtle.up()
- farmDown()
- end
- function farmDown()
- while tonumber(currentPos) ~= tonumber(length) do
- fuelItUp()
- if det == true then
- turtle.dig()
- turtle.suck()
- turtle.forward()
- currentPos = currentPos + 1
- if detDown == true then
- turtle.digDown()
- turtle.suckDown()
- end
- else
- if detDown == true then
- turtle.digDown()
- turtle.suckDown()
- end
- end
- end
- if tonumber(currentRow) ~= tonumber(rows) then
- if tonumber(currentRow) % 2 == 0 then
- rightTurn()
- else
- leftTurn()
- end
- else
- ending()
- end
- end
- function leftTurn()
- turtle.turnLeft()
- turtle.forward()
- if det == true then
- turtle.dig()
- turtle.suck()
- turtle.forward()
- end
- turtle.turnLeft()
- if detDown == true then
- turtle.digDown()
- turtle.suckDown()
- end
- currentRow = currentRow + 1
- farmBack()
- end
- function rightTurn()
- turtle.turnRight()
- turtle.forward()
- if det == true then
- turtle.dig()
- turtle.suck()
- turtle.forward()
- end
- turtle.turnRight()
- if detDown == true then
- turtle.digDown()
- turtle.suckDown()
- end
- currentRow = currentRow + 1
- farmDown()
- end
- function farmBack()
- while tonumber(currentPos) ~= tonumber(startBlock) do
- fuelItUp()
- if det == true then
- turtle.dig()
- turtle.suck()
- turtle.forward()
- currentPos = currentPos - 1
- if detDown == true then
- turtle.digDown()
- turtle.suckDown()
- end
- else
- if detDown == true then
- turtle.digDown()
- turtle.suckDown()
- end
- end
- end
- if tonumber(currentRow) ~= tonumber(rows) then
- if tonumber(currentRow) % 2 == 0 then
- rightTurn()
- else
- leftTurn()
- end
- else
- ending()
- end
- end
- function ending()
- updateStatus("Finished")
- if tonumber(currentRow) % 2 == 0 then
- turtle.forward()
- turtle.turnLeft()
- turtle.down()
- turtle.down()
- else
- turtle.turnLeft()
- turtle.turnLeft()
- while tonumber(currentPos) ~= tonumber(startBlock - 1) do
- turtle.forward()
- currentPos = currentPos - 1
- end
- turtle.turnLeft()
- turtle.down()
- turtle.down()
- end
- while tonumber(currentRow) ~= tonumber(startRow) do
- fuelItUp()
- turtle.forward()
- turtle.forward()
- currentRow = currentRow - 1
- end
- dropoff()
- end
- function dropoff()
- s = 1
- total = 0
- while s < 16 do
- items = turtle.getItemCount(s)
- total = items + total
- if items > 0 then
- turtle.select(s)
- turtle.drop()
- end
- s = s + 1
- end
- turtle.turnLeft()
- print("Total Items Deposited:")
- print(total)
- updateStatus("Total Items Deposited " ..total)
- end
- questions()
- print("Press Enter to Continue")
- io.read()
- os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement