Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pastebin run FuQ3WvPs VW70dBq0 miningTurtle
- local torches = turtle.getItemCount(1)
- local fuel = turtle.getItemCount(2)
- local buildingMaterial = turtle.getItemCount(3)
- local maxFuel = fuel
- local placeTorchAt = 8 -- place torch on every N. block
- local errorLv = 0
- local distance = 0
- local mainPathLength = 0
- local mainPath = true
- local subLength = 32
- function checkInventory ()
- print ("Checking inventory...\n")
- torches = turtle.getItemCount(1)
- fuel = turtle.getItemCount(2)
- buildingMaterial = turtle.getItemCount(3)
- print ("Torches: " .. tostring(torches) .. "\nFuel: " .. tostring(fuel) .. "\nBuilding Material: " .. tostring(buildingMaterial) .. "\n")
- if torches <= 1 then errorLv = 1 end
- if fuel <= maxFuel / 2 and turtle.getFuelLevel() < mainPathLength then errorLv = 1 end
- if buildingMaterial <= 1 then errorLv = 1 end
- print ("Error Level: " .. tostring(errorLv) .. "\n")
- end
- function home ()
- print ("Returning Home..\n")
- if mainPath then
- print ("On Main Path\n")
- turtle.turnRight()
- turtle.turnRight()
- for i = 1, mainPathLength, 1 do
- turtle.forward()
- end
- print ("I am home! Or am I?\n")
- else
- print ("Not on Main Path\n")
- turtle.turnRight()
- turtle.turnRight()
- for i = 1, distance, 1 do
- turtle.forward()
- end
- turtle.turnRight()
- mainPath = true
- home()
- end
- end
- function moveBit (pTorch)
- print ("Moving forward...\n")
- -- Move forward, if not possible -> dig
- while not turtle.forward() do
- turtle.dig()
- end
- -- Build floor
- turtle.select(3)
- turtle.placeDown()
- -- Build lower left wall
- turtle.turnLeft()
- turtle.place()
- -- Move Up
- while not turtle.up() do
- turtle.digUp()
- end
- -- Build ceiling
- turtle.placeUp()
- -- Build upper left wall
- turtle.place()
- -- Build upper right wall
- turtle.turnRight()
- turtle.turnRight()
- turtle.place()
- -- Move down
- turtle.down()
- -- Build lower right wall
- turtle.place()
- -- Place Torch
- if pTorch then
- print ("Placing Torch\n")
- turtle.select(1)
- turtle.placeUp()
- turtle.select(3)
- end
- -- Turn back to path
- turtle.turnLeft()
- distance = distance + 1
- if mainPath then mainPathLength = mainPathLength + 1 end
- end
- function run ()
- print ("Starting Program...\n")
- while (true) do
- checkInventory ()
- if errorLv ~= 0 then
- home()
- return
- end
- -- Refuel
- if turtle.getFuelLevel() == 0 then
- turtle.select(2)
- turtle.refuel()
- end
- -- Strip Mine Thing
- if mainPath and distance >= 3 then
- print ("Leaving Main Path...\n")
- mainPath = false
- distance = 0
- turtle.turnRight()
- elseif not mainPath and distance >= subLength then
- print ("Going back to Main Path...\n")
- turtle.turnRight()
- turtle.turnRight()
- distance = 0
- for i = 1, subLength, 1 do
- print (tostring(i) .. " of " .. tostring(subLength) .. "\n")
- turtle.forward()
- end
- turtle.turnRight()
- mainPath = true
- end
- -- Move, Dig, Build and place Torch
- moveBit((not mainPath and (((distance + 1) % placeTorchAt == 0) or (distance + 1) == 1)))
- end
- end
- run()
Add Comment
Please, Sign In to add comment