Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Flatten Turtle Program
- os.loadAPI("t")
- local args = {...}
- local versionNumber = "1.5"
- local programName = "StarDustFlattener "
- local digWidth = 0
- local digLength = 0
- local currentLine = 0
- local lastLine = false
- term.clear()
- term.setCursorPos(1,1)
- print(programName..versionNumber.." Coded by MrHG")
- print("")
- print("Slot 1: Fuel")
- print("Slot 2: Materials")
- if #args == 1 then
- digLength = args[1]
- digWidth = args[1]
- elseif #args == 2 then
- digLength = args[1]
- digWidth = args[2]
- else
- print ("Usage: Flatten (Length) [Width]")
- return
- end
- function digUpUntilEmpty()
- local emptyBlocks = 0
- local blocksFromFloor = 0
- while emptyBlocks < 2 do
- t.up()
- blocksFromFloor = blocksFromFloor + 1
- if turtle.detectUp() then
- emptyBlocks = 0
- else
- emptyBlocks = emptyBlocks + 1
- end
- end
- t.down(blocksFromFloor)
- end
- function placeBelow()
- local blocksBelowFloor = 0
- while not turtle.detectDown() do
- t.down()
- blocksBelowFloor = blocksBelowFloor + 1
- end
- t.up()
- if turtle.getItemCount(2) < blocksBelowFloor+1 then
- if t.restock(2,3,true) then
- -- keep going
- else
- t.restock(2,3,false)
- end
- end
- t.placeRow("down",2,"up",blocksBelowFloor-1)
- t.placeDown(2)
- end
- function digLine()
- local blocksDug = 0
- while blocksDug < digLength-1 do
- t.forward()
- blocksDug = blocksDug + 1
- if turtle.detectUp() then
- digUpUntilEmpty()
- end
- if not turtle.detectDown() then
- placeBelow()
- end
- end
- if lastLine then
- return
- end
- if currentLine % 2 == 0 then
- t.right()
- t.forward()
- t.right()
- else
- t.left()
- t.forward()
- t.left()
- end
- if turtle.detectUp() then
- digUpUntilEmpty()
- end
- if not turtle.detectDown() then
- placeBelow()
- end
- end
- -- Main Program loop
- fuelRequired = (digLength*digWidth)*3
- print("Fuel required: ~"..fuelRequired)
- t.refuel(fuelRequired,2)
- for i=1,digWidth do
- digLine()
- if i == digWidth - 1 then
- lastLine = true
- end
- currentLine = currentLine + 1
- end
- if digWidth % 2 == 0 then
- t.strafeRight(digWidth-1)
- else
- t.turnAround()
- t.forward(digLength-1)
- t.strafeRight(digWidth-1)
- end
- t.turnAround()
- print("")
- print("Done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement