Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("fabdrain: Rev 1.0")
- beltSlot = 1
- currentSlot = beltSlot
- goForward = 0
- goBackward = 1
- direction = goForward
- holeWidth = 3
- -- The following 'face' directions are relative to the starting position of the turtle in this program
- north = 0
- west = 1
- south = 2
- east = 3
- x = 0
- y = 0
- z = 0
- currentFace = north
- function setFace(f)
- if f == 0 then
- if face == 0 then return end
- if face == 1 then right() return end
- if face == 2 then right() right() return end
- if face == 3 then left() return end
- end
- if f == 1 then
- if face == 0 then left() return end
- if face == 1 then return end
- if face == 2 then right() return end
- if face == 3 then right() right() return end
- end
- if f == 2 then
- if face == 0 then left() left() return end
- if face == 1 then left() return end
- if face == 2 then return end
- if face == 3 then right() return end
- end
- if f == 3 then
- if face == 0 then right() return end
- if face == 1 then left() left() return end
- if face == 2 then left() return end
- if face == 3 then return end
- end
- end
- function left()
- if face == 0 then face = 1 turtle.turnLeft() return end
- if face == 1 then face = 2 turtle.turnLeft() return end
- if face == 2 then face = 3 turtle.turnLeft() return end
- if face == 3 then face = 0 turtle.turnLeft() return end
- print("function left\(\): Bad face value: ", face)
- end
- function right()
- if face == 0 then face = 3 turtle.turnRight() return end
- if face == 1 then face = 0 turtle.turnRight() return end
- if face == 2 then face = 1 turtle.turnRight() return end
- if face == 3 then face = 2 turtle.turnRight() return end
- print("function right\(\): Bad face value: ", face)
- end
- function aboutFace()
- if face == north then setFace(south) return end
- if face == south then setFace(north) return end
- if face == east then setFace(west) return end
- if face == west then setFace(east) return end
- end
- function reverseDirection()
- if direction == goForward then
- direction = goBackward
- else
- direction = goForward
- end
- end
- function moveForward(nBlocks)
- for i = 1, nBlocks do
- turtle.forward()
- if face == north then
- z = z + 1
- elseif face == south then
- z = z - 1
- elseif face == east then
- x = x + 1
- elseif face == west then
- x = x - 1
- end
- end
- end
- function moveBackward(nBlocks)
- for i = 1, nBlocks do
- turtle.back()
- if face == north then
- z = z - 1
- elseif face == south then
- z = z + 1
- elseif face == east then
- x = x - 1
- elseif face == west then
- x = x + 1
- end
- end
- end
- function home()
- end
- function xzHome()
- local X = gX
- local Z = gZ
- if x ~= X then
- if x < X then
- setFace(east)
- while x < X do
- turtle.forward()
- x = x + 1
- end
- else
- setFace(west)
- while x > X do
- turtle.forward()
- x = x - 1
- end
- end
- end
- if z ~= Z then
- if z < Z then
- setFace(north)
- while z < Z do
- turtle.forward()
- z = z + 1
- end
- else
- setFace(south)
- while z > Z do
- turtle.forward()
- z = z - 1
- end
- end
- end
- end
- function layBeltRow(direction, length)
- for j=1,5 do
- if turtle.getItemCount(currentSlot) < 1 then
- currentSlot = currentSlot + 1
- if turtle.getItemCount(currentSlot) < 1 then
- abort("No more belts in inventory.")
- end
- turtle.select(currentSlot)
- end
- turtle.placeDown()
- if j < 5 then
- if direction == goForward then
- moveForward(1)
- else
- moveBackward(1)
- end
- end
- end
- end
- rowHeading = west
- function goToNextRow()
- currentFace = face
- if face == north or face == south then
- setFace(rowHeading)
- moveForward(1)
- setFace(currentFace)
- else
- setFace(rowHeading)
- moveForward(1)
- setFace(currentFace)
- end
- end
- function layBeltSection(length, width)
- moveBackward(length - 1)
- for i = 1,width do
- direction = goForward
- layBeltRow(direction, length)
- moveForward(holeWidth+1)
- aboutFace()
- direction = goBackward
- layBeltRow(direction, length)
- goToNextRow()
- end
- setFace(east)
- rowHeading = south
- direction = goBackwards
- segLength = length + 3 + length
- for i = 1, segLength do
- layBeltRow(direction, length)
- if i < segLength then
- goToNextRow()
- reverseDirection()
- end
- end
- setFace(east)
- moveForward(length + holeWidth)
- aboutFace()
- rowHeading = north
- direction = goBackwards
- for i = 1, segLength do
- layBeltRow(direction, length)
- if i < segLength then
- goToNextRow()
- reverseDirection()
- end
- end
- end
- function abort(message)
- print(message)
- error()
- end
- -- Main Program
- turtle.up()
- y = y + 1
- turtle.select(1)
- layBeltSection(5, holeWidth)
- xzHome()
- yHome()
- setFace(north)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement