Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Digs a rectangular hole down to bedrock, or where water meets lava
- -- creating a blocking layer of cobblestone. Dimensions are specified directly
- -- below. Width starts at current block and extends rightward. Length starts
- -- at the current block and extends forward.
- length = 2
- width = 2
- x = 0
- y = 0
- z = 0
- workx = 0
- worky = 0
- workz = 0
- orientation = 0
- function moveForward()
- -- Moves forward keeping track of location
- turtle.forward()
- if (orientation == 0) then
- z = z + 1
- elseif (orientation == 1) then
- x = x + 1
- elseif (orientation == 2) then
- z = z - 1
- elseif (orientation == 3) then
- x = x - 1
- else
- print("Error, invalid orientation.")
- end
- end
- function goDown()
- -- Moves down keeping track of location
- turtle.down()
- y = y - 1
- end
- function goUp()
- -- Moves up keeping track of location
- turtle.up()
- y = y + 1
- end
- function turnRight()
- -- Turns turtle to the right keeping track of location
- turtle.turnRight()
- orientation = (orientation + 1) % 4
- end
- function turnLeft()
- -- Turns turtle to the left keeping track of location
- turtle.turnLeft()
- orientation = orientation - 1
- if (orientation == -1) then
- orientation = 3
- end
- end
- function safeUp()
- if (not turtle.detectUp()) then
- goUp()
- return true
- end
- return false
- end
- function safeDown()
- if (not turtle.detectDown()) then
- goDown()
- return true
- end
- return false
- end
- function tryDown()
- turtle.digDown()
- return safeDown()
- end
- function progressUp()
- while not safeUp() do
- turtle.digUp()
- end
- end
- function progressDown()
- while not safeDown() do
- turtle.digDown()
- end
- end
- function safeForward()
- if (not turtle.detect()) then
- moveForward()
- return true
- end
- return false
- end
- function progressForward()
- while not safeForward() do
- turtle.dig()
- end
- end
- function comebackDirection()
- if (orientation == 0) then
- while z < 0 do
- progressForward()
- end
- elseif (orientation == 1) then
- while x < 0 do
- progressForward()
- end
- elseif (orientation == 2) then
- while (z > 0) do
- progressForward()
- end
- else
- while (x > 0) do
- progressForward()
- end
- end
- end
- function goToHeightZero()
- while (y < 0) do
- progressUp()
- end
- while (y > 0) do
- progressDown()
- end
- end
- function comeBack()
- workx = x
- worky = y
- workz = z
- for i=1, 4 do
- comebackDirection()
- turnLeft()
- end
- goToHeightZero()
- end
- function comeback()
- comeBack()
- end
- function backToWork()
- x = -workx
- y = -worky
- z = -workz
- for i=1, 4 do
- comebackDirection()
- turnRight()
- end
- goToHeightZero()
- x = workx
- y = worky
- z = workz
- end
- function unload()
- for i=1, 16 do
- turtle.select(i)
- turtle.drop(64)
- end
- end
- function dropOff()
- comeBack()
- turnRight()
- turnRight()
- unload()
- turnRight()
- turnRight()
- backToWork()
- end
- function unloadAndBackToStart()
- comeback()
- turnRight()
- turnRight()
- unload()
- turnRight()
- turnRight()
- end
- function goToDigCoreLocation(xlocation, zlocation)
- -- Go to digging location on x z grid
- for zmoveCounter=1, zlocation do
- progressForward()
- end
- turnRight()
- for xmoveCounter=1, xlocation do
- progressForward()
- end
- turnLeft()
- end
- function digCore()
- while (tryDown()) do
- end
- end
- function digCoreAtAndBackToStart(xlocation, zlocation)
- goToDigCoreLocation(xlocation, zlocation)
- digCore()
- unloadAndBackToStart()
- end
- function runJob()
- adjustedWidth = width - 1
- adjustedLength = length - 1
- for currentX=0, adjustedWidth do
- for currentZ=0, adjustedLength do
- digCoreAtAndBackToStart(currentX, currentZ)
- end
- end
- end
- runJob()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement