Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --stripMine
- --Dustin Luhmann
- --Version 1.3.1
- --3/3/2015
- --http://pastebin.com/pLCS9ENG
- --[[TO RUN: pastebin get pLCS9ENG <filename>; <filename>]]
- --Example > pastebin get pLCS9ENG test
- -- > test
- STRIP_DISTANCE = 50 --Blocks
- STRIP_GAP_DISTANCE = 2 --Blocks
- NUMBER_OF_RUNS = 16
- TORCH_IDX = 2
- TORCH_SPACING = 10 -- 10 --Blocks
- TORCH_HEIGHT = 0 --Blocks
- DIRECTION_OF_CHEST_FROM_HOME = "west"
- INVENTORY_SPACE = 16
- HOME_POSITION = {0,0,0} --{X,Y,Z}
- HEADINGS = {"north","east","south","west"}
- X_IDX = 1
- Y_IDX = 2
- Z_IDX = 3
- currentPosition = {0,0,0}
- heading = 1
- isFull = false
- function mine()
- turtle.dig()
- end
- function mineUp()
- turtle.digUp()
- end
- function mineDown()
- turtle.digDown()
- end
- function forward()
- if HEADINGS[heading] == "north" then
- currentPosition[Y_IDX] = currentPosition[Y_IDX] + 1
- elseif HEADINGS[heading] == "south" then
- currentPosition[Y_IDX] = currentPosition[Y_IDX] - 1
- elseif HEADINGS[heading] == "east" then
- currentPosition[X_IDX] = currentPosition[X_IDX] + 1
- elseif HEADINGS[heading] == "west" then
- currentPosition[X_IDX] = currentPosition[X_IDX] - 1
- end
- turtle.forward()
- end
- function turnLeft()
- if HEADINGS[heading] == "north" then
- heading = 4
- else
- heading = heading - 1
- end
- turtle.turnLeft()
- end
- function turnRight()
- if HEADINGS[heading] == "west" then
- heading = 1
- else
- heading = heading + 1
- end
- turtle.turnRight()
- end
- function up()
- currentPosition[Z_IDX] = currentPosition[Z_IDX] + 1
- turtle.digUp()
- turtle.up()
- end
- function down()
- currentPosition[Z_IDX] = currentPosition[Z_IDX] - 1
- turtle.digDown()
- turtle.down()
- end
- function checkSpace()
- for i = 1, INVENTORY_SPACE do
- if turtle.getItemCount(i) == 0 then
- return true
- end
- end
- isFull = true
- return false
- end
- function mineThreeHigh()
- up()
- up()
- mine()
- down()
- mine()
- down()
- mine()
- wait()
- while turtle.detect() do
- mine()
- wait()
- end
- forward()
- end
- function mineAStrip()
- local distanceTraveled = 0
- while distanceTraveled < STRIP_DISTANCE and turtle.detect() and checkSpace() do
- mineThreeHigh()
- distanceTraveled = distanceTraveled + 1
- end
- turnLeft()
- turnLeft()
- distanceBack = distanceTraveled
- for i = 1, distanceTraveled do
- if (distanceBack % TORCH_SPACING == 0) then
- placeTorch()
- end
- distanceBack = distanceBack - 1
- while turtle.detect() do
- mine()
- wait()
- end
- forward()
- end
- turnRight()
- turnRight()
- end
- function moveToStripInDirectionOf(direction)
- if direction == "right" then
- turnRight()
- elseif direction == "left" then
- turnLeft()
- else
- print("ERROR: moveToStripInDirectionOf was not given left or right")
- return
- end
- for i = 0, STRIP_GAP_DISTANCE do
- mineThreeHigh()
- end
- if direction == "right" then
- turnLeft()
- else
- turnRight()
- end
- end
- function wait()
- turnLeft()
- turnRight()
- end
- function returnHome()
- if currentPosition[Z_IDX] > 0 then
- while turtle.detectDown() do
- mineDown()
- wait()
- end
- down()
- elseif currentPosition[Z_IDX] < 0 then
- while turtle.detectUp() do
- mineUp()
- wait()
- end
- up()
- end
- if currentPosition[Y_IDX] > 0 then
- while currentPosition[Y_IDX] > 0 do
- while HEADINGS[heading] ~= "south" do
- turnLeft()
- end
- while turtle.detect() do
- mine()
- wait()
- end
- forward()
- end
- elseif currentPosition[Y_IDX] < 0 then
- while currentPosition[Y_IDX] < 0 do
- while HEADINGS[heading] ~= "north" do
- turnLeft()
- end
- while turtle.detect() do
- mine()
- wait()
- end
- forward()
- end
- end
- if currentPosition[X_IDX] > 0 then
- while currentPosition[X_IDX] > 0 do
- while HEADINGS[heading] ~= "west" do
- turnLeft()
- end
- while turtle.detect() do
- mine()
- wait()
- end
- forward()
- end
- elseif currentPosition[X_IDX] < 0 then
- while currentPosition[X_IDX] < 0 do
- while HEADINGS[heading] ~= "east" do
- turnLeft()
- end
- while turtle.detect() do
- mine()
- wait()
- end
- forward()
- end
- end
- while HEADINGS[heading] ~= "north" do
- turnLeft()
- end
- end
- function go(x,y,x)
- if x >= 0 then
- while HEADINGS[heading] ~= "east" do
- turnLeft()
- end
- for i = 0, (x - 1) do
- forward()
- end
- elseif x < 0 then
- while HEADINGS[heading] ~= "west" do
- turnLeft()
- end
- for i = 0, (x - 1) * -1 do
- forward()
- end
- end
- if y >= 0 then
- while HEADINGS[heading] ~= "north" do
- turnLeft()
- end
- for i = 0, (y - 1) do
- forward()
- end
- elseif y < 0 then
- while HEADINGS[heading] ~= "south" do
- turnLeft()
- end
- for i = 0, (y - 1) * -1 do
- forward()
- end
- if z > 0 then
- for i = 0, (z - 1) do
- up()
- end
- end
- elseif z < 0 then
- for i = 0, (z - 1) * -1 do
- down()
- end
- end
- end
- function placeTorch()
- oldHeading = heading
- oldHeight = currentPosition[Z_IDX]
- while HEADINGS[heading] ~= "west" do
- turnLeft()
- end
- if currentPosition[Z_IDX] > TORCH_HEIGHT then
- while currentPosition[Z_IDX] > TORCH_HEIGHT do
- down()
- end
- elseif currentPosition[Z_IDX] < TORCH_HEIGHT then
- while currentPosition[Z_IDX] < TORCH_HEIGHT do
- up()
- end
- end
- -- mine()
- turtle.select(TORCH_IDX)
- turtle.placeUp()
- while heading ~= oldHeading do
- turnRight()
- end
- if oldHeight < currentPosition[Z_IDX] then
- while currentPosition[Z_IDX] > oldHeight do
- down()
- end
- elseif oldHeight > currentPosition[Z_IDX] then
- while currentPosition[Z_IDX] < oldHeight do
- up()
- end
- end
- end
- function emptyInventory()
- oldHeading = heading
- while HEADINGS[heading] ~= DIRECTION_OF_CHEST_FROM_HOME do
- turnLeft()
- end
- for i = 1, INVENTORY_SPACE do
- if i ~= TORCH_IDX then
- turtle.select(i)
- turtle.drop()
- end
- end
- while heading ~= oldHeading do
- turnRight()
- end
- isFull = false
- turtle.select(1)
- end
- function run()
- runs = 0
- go(0,0,0)
- while checkSpace() and runs ~= NUMBER_OF_RUNS do
- runs = 0
- while runs < NUMBER_OF_RUNS and not isFull do
- mineAStrip()
- if runs + 1 ~= NUMBER_OF_RUNS and not isFull then
- moveToStripInDirectionOf("right")
- end
- runs = runs + 1
- end
- returnHome()
- emptyInventory()
- end
- print("Program Over")
- end
- run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement