Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- xpos = 0
- ypos = 0
- zpos = 0
- direction = 0
- origXpos = xpos
- origYpos = ypos
- origZpos = zpos
- origDirection = direction
- print("How many slots do you want to reserve")
- print("for blocks you want the turtle to")
- print("ingore? (NOTE: Now's a good time to")
- print("check if you put your 'ingore blocks'")
- print("into the turtle). Enter 'q' to abort")
- write("Enter> ")
- numIgnoreSlots = tonumber(io.read())
- if type(numIgnoreSlots) ~= "number" then
- error("Invalid number of slots specified")
- elseif numIgnoreSlots > 8 or numIgnoreSlots < 0 then
- error("Please enter a number between 0 and 8")
- end
- print("How large an area do you want to mine?")
- write("Enter> ")
- gridSize = tonumber(io.read())
- if type(gridSize) ~= "number" then
- gridSize = 10
- elseif gridSize < 1 then
- error("Grid size must be a positive integer greater than 1")
- end
- print("Setting grid size to "..gridSize.." by "..gridSize.." blocks")
- function turnLeft()
- direction = (direction - 1) % 4
- turtle.turnLeft()
- end
- function turnRight()
- direction = (direction + 1) % 4
- turtle.turnRight()
- end
- function forward()
- local isNotMoved = true
- while isNotMoved do
- if turtle.forward() then
- isNotMoved = false
- else
- sleep(1)
- end
- end
- if direction == 0 then
- xpos = xpos + 1
- elseif direction == 1 then
- zpos = zpos + 1
- elseif direction == 2 then
- xpos = xpos - 1
- else
- zpos = zpos - 1
- end
- end
- function down()
- local isNotMoved = true
- while isNotMoved do
- if turtle.down() then
- isNotMoved = false
- else
- sleep(1)
- end
- end
- ypos = ypos - 1
- end
- function up()
- local isNotMoved = true
- while isNotMoved do
- if turtle.up() then
- isNotMoved = false
- else
- sleep(1)
- end
- end
- ypos = ypos + 1
- end
- function isInventoryFull()
- local retval = true
- local inventorySlot = 0
- for inventorySlot = numIgnoreSlots + 1, 16 do
- if turtle.getItemCount(inventorySlot) == 0 then
- retval = false
- end
- end
- return retval
- end
- function dropoff(doReturn)
- -- Remember where we were
- local returnXpos = xpos
- local returnYpos = ypos
- local returnZpos = zpos
- local returnDirection = direction
- -- This returns us to the chest
- for i = ypos, origYpos - 1 do
- if turtle.detectUp() then
- turtle.digUp()
- end
- up()
- end
- while direction ~= 3 do
- turnRight()
- end
- for i = origZpos, zpos - 1 do
- if turtle.detect() then
- turtle.dig()
- end
- forward()
- end
- turnLeft()
- for i = origXpos, xpos - 1 do
- if turtle.detect() then
- turtle.dig()
- end
- forward()
- end
- -- Clean out the first 8 slots of all except one item
- for i = 1, numIgnoreSlots do
- turtle.select(i)
- turtle.drop(turtle.getItemCount(i) - 1)
- end
- -- Drop off everything in slots 9-16 into the chest
- for i = numIgnoreSlots + 1, 16 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- -- Head back to where we were before
- turnRight()
- turnRight()
- if doReturn then
- for i = xpos, returnXpos - 1 do
- if turtle.detect() then
- turtle.dig()
- end
- forward()
- end
- turnRight()
- for i = zpos, returnZpos - 1 do
- if turtle.detect() then
- turtle.dig()
- end
- forward()
- end
- for i = returnYpos, ypos - 1 do
- if turtle.detectDown() then
- turtle.digDown()
- end
- down()
- end
- while direction ~= returnDirection do
- turnRight()
- end
- end
- end
- function dropoffIfInventoryFull()
- if isInventoryFull() then
- dropoff(true)
- end
- end
- function digDown()
- local isNotImpenetrable = true
- if turtle.detectDown() and not turtle.digDown() then
- isNotImpenetrable = false
- end
- dropoffIfInventoryFull()
- return isNotImpenetrable
- end
- function digUp()
- local isNotImpenetrable = true
- if turtle.detectUp() and not turtle.digUp() then
- isNotImpenetrable = false
- end
- dropoffIfInventoryFull()
- return isNotImpenetrable
- end
- function digForward()
- local isNotImpenetrable = true
- if turtle.detect() and not turtle.dig() then
- isNotImpenetrable = false
- end
- dropoffIfInventoryFull()
- return isNotImpenetrable
- end
- function digForwardConditionally()
- local isDiggable = true
- local inventorySlot = 0
- for inventorySlot = 1, numIgnoreSlots do
- turtle.select(inventorySlot)
- if turtle.compare() then
- isDiggable = false
- end
- end
- turtle.select(1)
- if isDiggable then
- turtle.dig()
- end
- dropoffIfInventoryFull()
- end
- function doProcessCoord()
- local retval = false
- if (xpos + 2 * zpos - 1) % 5 == 0 then
- retval = true
- end
- return retval
- end
- function mineCoord()
- while digDown() do
- down()
- for i = 1, 4 do
- turnRight()
- digForwardConditionally()
- end
- end
- for i = ypos, origYpos - 1 do
- if turtle.detectUp() then
- turtle.digUp()
- end
- up()
- end
- end
- function chompForward()
- digForward()
- forward()
- digUp()
- end
- function testerFunc()
- turtle.placeUp()
- end
- function mainLoop()
- local isNotCompleted = true
- while isNotCompleted do
- if doProcessCoord() then
- mineCoord()
- -- testerFunc()
- dropoff(true)
- end
- -- Now we process our move to the next block and start again
- if zpos % 2 == 0 then
- if xpos == gridSize - 1 then
- if zpos == gridSize - 1 then
- isNotCompleted = false
- else
- turnRight()
- chompForward()
- turnRight()
- end
- else
- chompForward()
- end
- else
- if xpos == 0 then
- if zpos == gridSize - 1 then
- isNotCompleted = false
- else
- turnLeft()
- chompForward()
- turnLeft()
- end
- else
- chompForward()
- end
- end
- end
- dropoff(false)
- end
- mainLoop()
Advertisement
Add Comment
Please, Sign In to add comment