Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Mining a series of pluses all the way to bedrock, then come back and leave the items in chests.
- --To start, Have a chest one in front and one up from the turtle, then a row going back from there. You'll want a lot.
- --Make sure the turtle is fueled. Put buckets in slot one and stone in slot 2
- --declare the global variables
- width = 9 --width of the area to mine. (Actually 2 * width +1
- theta = 50*6.28 --sweep of the spiral
- step = 0.001 --change in theta each step
- b = 0.14 --growth factor for spiral
- columnList = " " --list of columns visited
- maxradius = 200 --don't grow out past this point
- buildWall = 0 --set to 1 to build a wall on the outside
- lavaSum = 200 --sum of the YY locations for finding lava
- lavaCount = 0 --number of lava blocks collected
- cobbleCountMax = 600 --give up if you check this many columns and they're all already done
- curX = 0 --current X position relative to the start
- curY = 0 --current Y position relative to the start
- curZ = 0 --current Z position relative to the start
- facing = 0 --what direction is the turtle facing (0,1,2,3)
- --0 is toward positive Z
- function fuel(direction)
- --called periodically, and also when lava is detected.
- --print("refueling ", direction)
- turtle.select(1)
- --Now let's pickup the lava
- if direction == 1 then
- --its in front
- turtle.place()
- elseif direction == 2 then
- turtle.placeDown()
- lavaSum = lavaSum + curY
- lavaCount = lavaCount + 1
- elseif direction == 3 then
- turtle.placeUp()
- lavaSum = lavaSum + curY
- lavaCount = lavaCount + 1
- end
- if turtle.getFuelLevel() < 19000 then
- for slot = 5,16,1 do
- turtle.select(slot)
- turtle.refuel()
- if turtle.compareTo(1) then
- turtle.transferTo(1)
- end
- if turtle.getFuelLevel() > 19000 then
- break
- end
- end
- if curY >=0 or turtle.getFuelLevel() < 500 then
- repeat
- --Time to refuel
- for slot = 5,16,1 do
- turtle.select(slot)
- turtle.refuel()
- if turtle.compareTo(1) then
- turtle.transferTo(1)
- end
- end
- until (turtle.getFuelLevel() > 1000) --don't stop trying if the level is too low
- end
- end
- turtle.select(1)
- print(turtle.getFuelLevel())
- end
- function SlotItems(slot)
- turtle.select(slot)
- if turtle.getItemCount() == 0 then
- return "nothing"
- else
- local data = turtle.getItemDetail()
- return data.name
- end
- end
- function TRight()
- --Turn the turtle to the right
- turtle.turnRight()
- facing = facing +1
- if facing > 3 then
- facing = facing - 4
- end
- end
- function TLeft()
- --Turn the turtle to the right
- turtle.turnLeft()
- facing = facing - 1
- if facing < 0 then
- facing = facing + 4
- end
- end
- function Forward()
- local success, data = turtle.inspect()
- if success then
- while string.find(data.name, "urtle") do
- print("Turtle detected: No TVT!")
- success, data = turtle.inspect()
- end
- if string.find(data.name, "lava") then
- fuel(1)
- end
- end
- while not turtle.forward() do
- turtle.dig()
- end
- if facing == 0 then
- curZ = curZ + 1
- elseif facing == 1 then
- curX = curX +1
- elseif facing == 2 then
- curZ = curZ - 1
- else
- curX = curX - 1
- end
- end
- function Up()
- local success, data = turtle.inspectUp()
- if success then
- while string.find(data.name, "urtle") do
- print("Turtle detected: No TVT!")
- success, data = turtle.inspectUp()
- sleep(10)
- end
- if string.find(data.name, "lava") then
- fuel(3)
- end
- end
- while not turtle.up() do
- turtle.digUp()
- end
- curY = curY + 1
- end
- function Down()
- local success, data = turtle.inspectDown()
- if success then
- while string.find(data.name, "urtle") do
- print("Turtle detected: No TVT!")
- success, data = turtle.inspectDown()
- sleep(10)
- end
- if string.find(data.name, "lava") then
- fuel(2)
- end
- end
- while not turtle.down() do
- turtle.digDown()
- end
- curY = curY - 1
- end
- function TurnTo(face)
- while (facing ~= face) do
- TLeft()
- end
- end
- function MoveTo (MoveToX, MoveToY, MoveToZ)
- --Move the turtle to the desired position
- --first X
- --print(MoveToX, " " , MoveToY, " " ,MoveToZ)
- if MoveToX < curX then
- TurnTo(3)
- while MoveToX < curX do
- Forward()
- end
- elseif MoveToX > curX then
- TurnTo(1)
- while MoveToX > curX do
- Forward()
- end
- end
- --Now Z
- if MoveToZ < curZ then
- TurnTo(2)
- while MoveToZ < curZ do
- Forward()
- end
- elseif MoveToZ > curZ then
- TurnTo(0)
- while MoveToZ > curZ do
- Forward()
- end
- end
- --Now Y
- if MoveToY < curY then
- while MoveToY < curY do
- Down()
- end
- end
- while MoveToY > curY do
- Up()
- end
- end --MoveTo
- function cobbleBelow()
- local success, data = turtle.inspectDown()
- if success then
- if string.find(data.name, "cobble") then
- return 1
- end
- end
- return nil
- end
- function setCobble(direction)
- for slot = 2,3,1 do
- turtle.select(slot)
- if turtle.getItemCount() > 1 then
- if direction < 0 then
- turtle.placeDown()
- elseif direction > 0 then
- turtle.placeUp()
- else
- turtle.place()
- end
- for s=4,16,1 do
- turtle.select(s)
- if turtle.compareTo(slot) then
- turtle.transferTo(slot,1)
- return(1)
- end
- end
- return(1)
- end
- end
- return 0
- end
- --Start the program
- columnX = 0 --location to dig out a column
- columnY = 0
- fuel()
- oldXX = 1 --previous XX and ZZ positions
- oldZZ = 1
- XX = 1
- ZZ = 1
- while math.abs(theta) < maxradius*6.28 do
- --find the next (XX,ZZ)
- --first change theta until we get to a new column
- --print("new column")
- while (XX == oldXX) and (ZZ == oldZZ) do
- theta = theta + step
- XX = math.floor((b*theta) * math.cos(theta))
- ZZ = math.floor((b*theta) * math.sin(theta))
- end
- --now the column has changed, but is it really one we've never done before?
- MoveTo(XX,curY,ZZ)
- MoveTo(XX,0,ZZ)
- --print("Checking for cobble")
- cobbleCount = 0
- while cobbleBelow() or ((ZZ - XX*2) % 5) ~= 0 do
- --print(XX, "," ZZ, "," , (ZZ-XX*2) % 5)
- oldXX = XX
- oldZZ = ZZ
- while (XX == oldXX) and (ZZ == oldZZ) do
- theta = theta + step
- XX = math.floor((b*theta) * math.cos(theta))
- ZZ = math.floor((b*theta) * math.sin(theta))
- end
- MoveTo(XX,curY,ZZ)
- cobbleCount = cobbleCount + 1
- if cobbleCount > cobbleCountMax then
- --Looks like we've run into an area already processed by another turtle.
- print("Couldn't find a new column. Finishing!")
- MoveTo(0,0,0)
- os.exit()
- end
- end
- oldXX = XX
- oldZZ = ZZ
- --dig down
- turtle.digDown()
- while not turtle.detectDown() do
- Down()
- --Remove the blocks in the four directions
- for i=1,4,1 do
- local success, data = turtle.inspect()
- if success then
- if string.find(data.name, "lava") then
- fuel(1)
- end
- end
- turtle.dig()
- TRight()
- end
- if curY == -2 then
- setCobble(1)
- elseif curY == -1 then
- turtle.select(2)
- for i=1,4,1 do
- TRight()
- setCobble(0)
- end
- end
- --check for lava
- local success, data = turtle.inspectDown()
- if success then
- if string.find(data.name, "lava") then
- fuel(2)
- end
- end
- turtle.digDown()
- end
- --return up
- --print("atan=" , math.floor(2*math.atan2(curX+0.1,curZ+0.1)))
- while curY < -1 do
- turtle.select(2)
- Up()
- if (curY + math.floor(2*math.atan2(curX,curZ))) % 12 == 0 then
- setCobble(-1)
- elseif (curY + math.floor(2*math.atan2(curX,curZ))) % 12 == 11 then
- for i=1,4,1 do
- TRight()
- setCobble(0)
- end
- elseif buildWall > 0 and theta > maxradius*6.28 - 9 then
- --If we're on the last circuit and below the lava level
- setCobble(0)
- end
- end
- --place the cobbles at the top (YY=-1)
- for i=1,4,1 do
- TRight()
- setCobble(0)
- end
- Up()
- turtle.placeDown() --place a cobblestone in this location to mark it as done
- MoveTo(0,2,0)
- TurnTo(0)
- fuel()
- --Now empty all the slots into chests except leave the stones in the first one.
- Forward() --Move to above the chest.
- --first chest is just for picking up more empty buckets
- turtle.select(1) --the empty bucket slot
- turtle.suckDown(turtle.getItemSpace())
- --Second chest is to make sure we have cobblestone
- Forward()
- turtle.select(2) -- The cobblestone slot
- turtle.suckDown(turtle.getItemSpace())
- turtle.select(3) -- The cobblestone slot
- turtle.suckDown(turtle.getItemSpace())
- --now empty into the subsequent chests
- Forward()
- local done = 0
- local count = 20
- while done == 0 do
- done = 1
- for slot = 4,16,1 do
- turtle.select(slot)
- turtle.dropDown()
- if turtle.getItemCount(slot) >= 1 then
- done = 0
- end
- end
- if done == 0 then
- count = count + 1
- --print( 2*math.floor(count/10) ," ", curY," ", count % 10 +1 )
- MoveTo(2*math.floor(count/10) ,curY, count % 10 + 1)
- end
- end
- MoveTo(0,curY,0)
- turtle.select(2)
- end
Add Comment
Please, Sign In to add comment