Advertisement
Guest User

autoQuarry.lua

a guest
Feb 22nd, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.37 KB | None | 0 0
  1. local tX, tY, tZ = 0,0,0 --start location of turtle
  2. local face = 1 --dirrection
  3. local errorType = 0
  4. local hitBottom = false
  5. local bedrock = false
  6. local sizeX, sizeY = 4,4
  7.  
  8. function coalNeeded()
  9.     local coalAmmount = math.ceil((100000 - turtle.getFuelLevel()) / 80)
  10.     return coalAmmount
  11. end
  12.  
  13. function fuel() --refuels the turtle to full
  14.     turtle.digUp()
  15.     if turtle.getFuelLevel() > 50000 then return true end
  16.     emptyInventory()
  17.     local coalTake = coalNeeded()
  18.     turtle.select(2)
  19.     turtle.placeUp()
  20.     while coalTake > 64 do
  21.         turtle.select(3)
  22.         turtle.suckUp(64)
  23.         turtle.refuel()
  24.         coalTake = coalNeeded()
  25.     end
  26.     if coalTake ~= 0 then
  27.         turtle.select(3)
  28.         turtle.suckUp(coalTake)
  29.         turtle.refuel()
  30.     end
  31.     turtle.select(2)
  32.     turtle.digUp()
  33. end
  34.  
  35. function turnR()
  36.     turtle.turnRight()
  37.     if face == 4 then
  38.         face = 1
  39.     else
  40.         face = face + 1
  41.     end
  42.     print("turnR face: ",  face)
  43. end
  44.  
  45. function turnL()
  46.     turtle.turnLeft()
  47.     if face == 1 then
  48.         face = 4
  49.     else
  50.         face = face - 1
  51.     end
  52.     print("----turnL face: ", face)
  53. end
  54.  
  55.  
  56. function move()
  57.     print("move")
  58.     turtle.dig()
  59.     if turtle.detect() then
  60.         sleep(0.10)
  61.         turtle.dig()
  62.     end
  63.    
  64.     if invFull() then
  65.         emptyInventory()
  66.     end
  67.    
  68.     fuel()
  69.    
  70.     if turtle.forward() == false then
  71.         print("turtle cant go forward")
  72.         while not turtle.forward() do
  73.            turtle.attack()
  74.         end
  75.     end
  76.      
  77.     turtle.digUp()
  78.     turtle.digDown()
  79.    
  80.     if face == 1 then
  81.         tX = tX + 1
  82.     elseif face == 2 then
  83.         tZ = tZ + 1
  84.     elseif face == 3 then
  85.         tX = tX - 1
  86.     elseif face == 4 then
  87.         tZ = tZ - 1
  88.     else
  89.         print("---face = ", face)
  90.     end
  91. end
  92.  
  93. function emptyInventory() --empties everything in inventory but chest
  94.     turtle.digUp()
  95.     turtle.select(1)
  96.     turtle.placeUp()
  97.     for i = 3, 16 do
  98.         turtle.select(i)
  99.         turtle.dropUp()
  100.     end
  101.     turtle.select(1)
  102.     turtle.digUp()    
  103. end
  104.  
  105. function invFull()
  106.     for i = 3, 16 do
  107.         if turtle.getItemCount(i) == 0 then
  108.             return false
  109.         end
  110.     end
  111.     return true
  112. end
  113.  
  114. function down()
  115.    
  116.         if turtle.digDown() == false then
  117.             if turtle.detectDown() == true then
  118.                 bedrock = true
  119.                 return
  120.             end
  121.         end
  122.         turtle.digDown()
  123.         turtle.down()
  124.         tZ = tZ + 1
  125.        
  126. end
  127.  
  128. function up()
  129.     turtle.up()
  130.     tZ = tZ - 1
  131. end
  132.  
  133.  
  134. function quarry()
  135.     hitBottom = false
  136.     bedrock = false
  137.     turtle.digDown()
  138.     turtle.down()
  139.     turtle.digDown()
  140.    
  141.     while not hitBottom do
  142.         for y = 1, sizeY do
  143.             for x = 1, sizeX do
  144.                if x ~= sizeX then
  145.                print("face: ", face, "x y: ", x, ":", y)
  146.                    move()
  147.                elseif y ~= sizeY then
  148.                    print("elseif face: ", face)
  149.                   -- if y == 2 then sleep(300) end
  150.                    if face == 1 then
  151.                        turnR()
  152.                        move()
  153.                        turnR()
  154.                    elseif face == 3 then
  155.                        print("this should print")
  156.                        turnR()
  157.                        turnR()
  158.                        turnR()                       turnL()
  159.                        --move()
  160.                        sleep(30)
  161.                        
  162.                       -- turnL()
  163.                    else
  164.                        print("ERROR FACING IN QUARRY FUNCTION")
  165.                    end
  166.                else
  167.                    if bedrock == true then
  168.                        print("made to bottom")
  169.                        --exit while loop
  170.                        -- add return back
  171.                    else
  172.                        turnR()
  173.                        turnR()
  174.                        down()
  175.                        down()
  176.                        down()
  177.                    end
  178.                 end
  179.             end
  180.         end
  181.     end
  182. end
  183.  
  184. function moveChunks()
  185. end
  186.  
  187. function setup()
  188.     local goodChest1 = false
  189.     local goodChest2 = false
  190.     local details = ""
  191.     turtle.select(1)
  192.     if turtle.getItemCount() ~= 0 then
  193.         details = turtle.getItemDetail()
  194.         if (details.nbtHash ~= "2140ff65135fd9bd2d814704d2926a0b") then
  195.             goodChest1 = false
  196.         else
  197.             goodChest1 = true
  198.         end
  199.     end
  200.     turtle.select(2)
  201.     if turtle.getItemCount() ~= 0 then
  202.         details = turtle.getItemDetail()
  203.         if (details.nbtHash ~= "7ca7d17d1bad27a13c95b6672880aabb") then
  204.            goodChest2 = false
  205.         else
  206.             goodChest2 = true
  207.         end  
  208.     end
  209.     if (goodChest1 == false) then
  210.         print("slot1 is not white,white,white chest")
  211.     end
  212.     if (goodChest2 == false) then
  213.         print("slot2 is not white,black,white chest")
  214.     end
  215.  
  216.     if ((goodChest1 and goodChest2) == false) then
  217.         print("press any key to retry")
  218.         os.pullEvent("key")
  219.         setup()
  220.     else
  221.         return true
  222.     end
  223. end
  224.  
  225. ---------------------------------
  226. print("place white,white,white enderchest in slot 1 and white,black,white enderchest in slot 2")
  227. print("press any key to continue")
  228. os.pullEvent("key")
  229. setup()
  230. quarry()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement