Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- 3x3
- By Coaster3000
- 3x3 is licensed under the Creative Commons Attribution-ShareAlike 3.0 United States License.
- To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/us/.
- Extra Permissions: You can freely extract the api for turtle movement tracking. Do note...
- You are required to follow iNav's Licensing. As this part of code is based off of it.
- This is simply a remake of it.
- -- Link: http://pastebin.com/3KHq3K2R
- -- Maker of iNav dd4235
- ]]
- local x,z,y = 0,0,0
- local dir = 0
- local count = 0
- local function dig()
- while turtle.dig() do
- count = count + 1
- sleep(0.5)
- end
- return true
- end
- local function digUp()
- while turtle.digUp() do
- count = count + 1
- sleep(0.5)
- end
- return true
- end
- local function digDown()
- while turtle.digDown() do
- count = count + 1
- sleep(0.5)
- end
- return true
- end
- local function hasFuel( ammount )
- ammount = ammount or 1
- return turtle.getFuelLevel() >= ammount
- end
- local function refuel( ammount )
- ammount = ammount or (turtle.getFuelLevel() + 1)
- if turtle.getFuelLevel() > ammount then
- return true
- end
- for i=1,16 do
- turtle.select(i)
- while turtle.getItemCount(i) > 0 do
- if not turtle.refuel(0) then
- break
- end
- if hasFuel(ammount) then
- turtle.select(1)
- return true
- else
- turtle.refuel(1)
- end
- end
- end
- turtle.select(1)
- return false
- end
- local function forward()
- local good = turtle.forward()
- if good then
- if dir % 4 == 0 then x = x + 1 end
- if dir % 4 == 1 then z = z + 1 end
- if dir % 4 == 2 then x = x - 1 end
- if dir % 4 == 3 then z = z - 1 end
- end
- return good
- end
- local function back()
- local good = turtle.back()
- if good then
- if dir % 4 == 0 then x = x - 1 end
- if dir % 4 == 1 then z = z - 1 end
- if dir % 4 == 2 then x = x + 1 end
- if dir % 4 == 3 then z = z + 1 end
- end
- return good
- end
- local function turnRight()
- local good = turtle.turnRight()
- if good then
- dir = dir + 1
- end
- return good
- end
- local function turnAround()
- turnRight()
- turnRight()
- end
- local function turnLeft()
- local good = turtle.turnLeft()
- if good then
- dir = dir - 1
- end
- return good
- end
- local function up()
- local good = turtle.up()
- if good then
- y = y + 1
- end
- return good
- end
- local function down()
- local good = turtle.down()
- if good then
- y = y - 1
- end
- return good
- end
- length = nil
- local args = {...}
- lastx = 0
- function resume()
- while (x < lastx) do
- if not forward() then
- break
- end
- end
- end
- if #args > 0 then
- length = tonumber(args[1]) or nil
- if #args > 1 then
- lastx = tonumber(args[2]) or 0
- resume()
- end
- end
- local function layer()
- turnLeft()
- dig()
- turnAround()
- dig()
- turnLeft()
- end
- fuelNeeded = 0
- function checkLength()
- while not length do
- term.clear()
- term.setCursorPos(1, 1)
- write("Enter Length: ")
- local d = tonumber(read())
- if (d) and (d > 0) then
- length = d
- else
- print("Invalid Input... Please type a number...")
- sleep(3)
- end
- end
- fuelNeeded = 2 + length * 2 + (length * 4) -- Formula is expanded to show those not soo good at math what calculation is
- if lastx then
- fuelNeeded = fuelNeeded + (lastx * 2)
- end
- while not refuel(fuelNeeded) do
- term.clear()
- term.setCursorPos(1, 1)
- print("Turtle needs more fuel.")
- print(turtle.getFuelLevel().."/"..fuelNeeded)
- print("Press any key to continue refueling")
- os.pullEvent("key")
- end
- end
- function run()
- checkLength()
- for i=1,length do
- up()
- up()
- dig()
- forward()
- layer()
- -- Bottom Layer
- digDown()
- down()
- layer()
- -- Mid Layer
- digDown()
- down()
- layer()
- end
- lastx = x
- while x > 0 do
- while dir % 4 ~= 0 do
- turnRight()
- end
- back()
- end
- endscreen()
- end
- function endscreen()
- term.clear()
- term.setCursorPos(1, 1)
- print("Total Blocks Dug: "..count)
- print("Current Fuel Level: "..turtle.getFuelLevel())
- write("Resume? (Y/N): ")
- length = nil
- local b = read()
- if (b == "y") or (b =="Y") then
- checkLength()
- resume()
- run()
- else
- term.clear()
- term.setCursorPos(1, 1)
- end
- end
- checkLength()
- if lastx then
- resume()
- end
- run()
Advertisement
Add Comment
Please, Sign In to add comment