Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Local
- local bedrockLayer = 5
- local startingX = 0
- local startingY
- local startingZ = 0
- local startingD = 0
- local currentX = 0
- local currentY = 0
- local currentZ = 0
- local currentD = 0
- local squareSize
- local done = true
- local currentSlot
- local data
- local succes
- local horizontalState = 0
- local i
- direction = {NORTH=0, EAST=1, SOUTH=2, WEST=3}
- -- Movement functions
- function printAllData()
- print("startingX" .. startingX)
- print("startingY" .. startingY)
- print("startingZ" .. startingZ)
- print("startingD" .. startingD)
- print("currentX" .. currentX)
- print("currentY" .. currentY)
- print("currentZ" .. currentZ)
- print("currentD" .. currentD)
- print("squareSize" .. squareSize)
- end
- function goUp()
- currentY = currentY + 1
- turtle.digUp()
- turtle.up()
- checkFuelLevel()
- end
- function goDown()
- currentY = currentY - 1
- turtle.digDown()
- turtle.down()
- checkFuelLevel()
- end
- function goNorth()
- if(currentD == 3) then
- turtle.turnRight()
- end
- if(currentD == 2) then
- turtle.turnRight()
- turtle.turnRight()
- end
- if(currentD == 1) then
- turtle.turnLeft()
- end
- currentX = currentX + 1
- currentD = 0
- turtle.dig()
- turtle.forward()
- checkFuelLevel()
- end
- function goSouth()
- if(currentD == 1) then
- turtle.turnRight()
- end
- if(currentD == 0) then
- turtle.turnRight()
- turtle.turnRight()
- end
- if(currentD == 3) then
- turtle.turnLeft()
- end
- currentX = currentX - 1
- currentD = 2
- turtle.dig()
- turtle.forward()
- checkFuelLevel()
- end
- function goEast()
- if(currentD == 0) then
- turtle.turnRight()
- end
- if(currentD == 3) then
- turtle.turnRight()
- turtle.turnRight()
- end
- if(currentD == 2) then
- turtle.turnLeft()
- end
- currentZ = currentZ + 1
- currentD = 1
- turtle.dig()
- turtle.forward()
- checkFuelLevel()
- end
- function goWest()
- if(currentD == 2) then
- turtle.turnRight()
- end
- if(currentD == 1) then
- turtle.turnRight()
- turtle.turnRight()
- end
- if(currentD == 0) then
- turtle.turnLeft()
- end
- currentZ = currentZ - 1
- currentD = 3
- turtle.dig()
- turtle.forward()
- checkFuelLevel()
- end
- function goToMiningStart()
- print("goToMiningStart")
- while(currentY > (bedrockLayer)) do
- goDown()
- print("should go down")
- end
- end
- function goToZero()
- print("goToZero")
- if(currentX < 0) then
- while (currentX < 0) do
- goNorth()
- end
- elseif(currentX > 0) then
- while (currentX > 0) do
- goSouth()
- end
- end
- if(currentZ < 0) then
- while (currentZ < 0) do
- goEast()
- end
- elseif(currentZ > 0) then
- while (currentZ > 0) do
- goWest()
- end
- end
- end
- function goToNextSlice()
- print("goToNextSlice")
- goToZero()
- faceNorth()
- goUp()
- goUp()
- end
- function returnToStartPoint()
- print("returnToStartPoint")
- goToZero()
- if(currentY <= startingY) then
- while(currentY < startingY) do
- goUp()
- end
- else
- while(currentY > startingY) do
- goDown()
- end
- end
- end
- function faceNorth()
- if(currentD == 3) then
- turtle.turnRight()
- end
- if(currentD == 2) then
- turtle.turnRight()
- turtle.turnRight()
- end
- if(currentD == 1) then
- turtle.turnLeft()
- end
- currentD = 0
- end
- -- Check functions
- function checkFuelLevel()
- if(turtle.getFuelLevel() < 80) then
- refuelFromEnderChest()
- end
- end
- function refuelFromEnderChest()
- print("refuelFromEnderChest")
- dumpIntoEnderChest()
- turtle.select(16)
- turtle.place()
- turtle.select(1)
- turtle.suck(32)
- turtle.refuel(32)
- if(turtle.getItemCount(1) ~= 0) then
- turtle.drop()
- end
- turtle.dig()
- turtle.transferTo(16)
- end
- function isBlockUseful(data)
- if(data.name == "minecraft:stone" or data.name == "minecraft:dirt") then
- return false
- else
- return true
- end
- end
- function checkAvailableInventory()
- for i = 1, 14 do
- if(turtle.getItemCount(i) == 0) then
- return i
- end
- end
- return -1
- end
- function dumpIntoEnderChest()
- print("dumpIntoEnderChest")
- turtle.dig()
- turtle.select(15)
- turtle.place()
- for i = 1,14 do
- turtle.select(i)
- if(turtle.getItemCount(i) ~= 0) then
- done = turtle.drop()
- end
- while(done == false) do
- print("enter while")
- sleep(10)
- done = turtle.drop()
- end
- done = true
- end
- turtle.select(1)
- turtle.dig()
- turtle.transferTo(15)
- end
- function changeHorizontalState()
- if(horizontalState == 0) then
- horizontalState = 1
- else
- horizontalState = 0
- end
- end
- -- Mining function
- -- Direction code : Front = 0, Under = 1, Above = 2
- function mineDirection(direc)
- if(direc == 0 ) then
- succes, data = turtle.inspect()
- if(succes == true and isBlockUseful(data) == true) then
- if(checkAvailableInventory() == -1) then
- dumpIntoEnderChest()
- end
- turtle.dig()
- end
- end
- if(direc == 1 ) then
- succes, data = turtle.inspectDown()
- if(succes == true and isBlockUseful(data) == true) then
- if(checkAvailableInventory() == -1) then
- dumpIntoEnderChest()
- end
- turtle.digDown()
- end
- end
- if(direc == 2 ) then
- succes, data = turtle.inspectUp()
- if(succes == true and isBlockUseful(data) == true) then
- if(checkAvailableInventory() == -1) then
- dumpIntoEnderChest()
- end
- turtle.digUp()
- end
- end
- end
- function mine()
- turtle.turnLeft()
- mineDirection(0)
- turtle.turnRight()
- mineDirection(0)
- turtle.turnRight()
- mineDirection(0)
- turtle.turnLeft()
- mineDirection(2)
- end
- function doVerticalLine()
- if(currentD == 0) then
- print("toto")
- while(currentX < squareSize) do
- mine()
- goNorth()
- end
- mine()
- goEast()
- end
- if (currentD == 2) then
- while(currentX > 0) do
- mine()
- goSouth()
- end
- mine()
- goEast()
- end
- end
- function doHorizontalLine()
- if (currentD == 1) then
- for i = 0, 1 do
- mine()
- goEast()
- end
- mine()
- if(horizontalState == 0 ) then
- goSouth()
- changeHorizontalState()
- else
- goNorth()
- changeHorizontalState()
- end
- end
- end
- function doSlice()
- print("doSlice")
- printAllData()
- while(currentX <= squareSize and currentZ <= squareSize) do
- doVerticalLine()
- doHorizontalLine()
- end
- end
- function mineAll()
- goToMiningStart()
- doSlice()
- print("before while")
- while(currentY < 30) do
- print("entered while")
- goToNextSlice()
- doSlice()
- end
- dumpIntoEnderChest()
- returnToStartPoint()
- end
- -- Main
- local args = { ... }
- local canRun = false
- print("Please input two argument, square size and current turtle height ")
- if (#args <= 1 or #args > 2) then
- print("Please input two argument, square size, current turtle height and turtle facing direction")
- elseif(#args == 2) then
- print("Detected 2 arguments")
- squareSize = tonumber(args[1])
- startingY = tonumber(args[2])
- currentY = startingY
- canRun = true
- end
- if (canRun == true) then
- print("Mining started")
- mineAll()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement