arismoko

basic strip miner

Jun 8th, 2023 (edited)
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.62 KB | None | 0 0
  1. bedrockDetected = false
  2. d=0
  3. n=0
  4. facingNorth=true
  5. e=0
  6. facingEast=false
  7. s=0
  8. facingSouth=false
  9. w=0
  10. facingWest=false
  11. stripNDone=false
  12. stripEDone=false
  13. stripSDone=false
  14. stripWDone=false
  15. chestDistanceFromHome=0
  16. itemsDelivered = true
  17. while bedrockDetected == false do
  18.  
  19.     --detecting bedrock
  20.     local success, data = turtle.inspectDown()
  21.     if data.name == "minecraft:bedrock" then
  22.         bedrockDetected = true
  23.     end
  24. --
  25.     --checking fuel level and refueling with coal in inventory
  26.     if turtle.getFuelLevel()<=50 then
  27.         for i = 1, 16 do -- loop through the slots
  28.             turtle.select(i) -- change to the slot
  29.             if turtle.refuel(0) then -- if it's valid fuel
  30.             local halfStack = math.ceil(turtle.getItemCount(i)/2) -- work out half of the amount of fuel in the slot
  31.             turtle.refuel(halfStack) -- consume half the stack as fuel
  32.             end
  33.         end
  34.     end
  35.     if chestDistanceFromHome > 0 and d==0 and itemsDelivered == false then
  36.         for i = 1, chestDistanceFromHome do
  37.             turtle.up()
  38.         end
  39.         for i = 1, 16 do -- loop through the slots
  40.             if turtle.refuel(0) == false then
  41.                 turtle.select(i) -- change to the slot
  42.                 turtle.drop()
  43.             end
  44.         end
  45.         itemsDelivered=true
  46.     end
  47.     if chestDistanceFromHome > 0 and d==0 and itemsDelivered == true then
  48.         for i = 1, chestDistanceFromHome do
  49.             turtle.down()
  50.         end
  51.         itemsDelivered=false
  52.     end    
  53. --
  54.     --digging down and keeping count of depth
  55.     if turtle.detectDown() and d<2 then
  56.         turtle.digDown()
  57.         print("block detected, digging down")
  58.         print("current distance to next strip =", 2-d)
  59.     end
  60.     --moving down and keeping count of depth
  61.     if turtle.detectDown() == false and d<2 then
  62.         chestDistanceFromHome=chestDistanceFromHome+1
  63.         d=d+1
  64.         turtle.down()
  65.         print("block not detected, moving down")
  66.         print("current distance to next strip =", 2-d)
  67.     end
  68. --
  69.     --mining forward
  70.     if turtle.detect() and d==2 and facingNorth ==true and stripNDone==false then
  71.         turtle.dig()
  72.         print("mining forward")
  73.         print("current distance to next strip =", 50-n)
  74.     end
  75.     --moving forward and keeping count of depth
  76.     if turtle.detect() == false and d==2 and facingNorth == true and stripNDone==false then
  77.         turtle.forward()
  78.         n=n+1
  79.         if n==50 then
  80.             stripNDone=true
  81.         end
  82.     end
  83. --
  84.     --going home after finishing strip
  85.     if facingNorth==true and n>=0 and stripNDone == true then
  86.         turtle.back()
  87.         n=n-1
  88.         if n==0 then
  89.         facingNorth=false
  90.         facingEast=true
  91.         turtle.turnRight()
  92.         end
  93.     end
  94. --
  95.     --mining east
  96.     if turtle.detect() and d==2 and facingEast == true and stripEDone==false then
  97.         turtle.dig()
  98.         print("mining east")
  99.         print("current distance to next strip =", 50-e)
  100.     end
  101.     --moving east and keeping count of depth
  102.     if turtle.detect() == false and d==2 and facingEast == true and stripEDone==false then
  103.         turtle.forward()
  104.         e=e+1
  105.         if e==50 then
  106.             stripEDone=true
  107.         end    
  108.     end
  109. --
  110.     --going home after finishing strip
  111.     if facingEast==true and e>=0 and stripEDone == true then
  112.         turtle.back()
  113.         e=e-1
  114.         if e==0 then
  115.         facingEast=false
  116.         facingSouth=true
  117.         turtle.turnRight()
  118.         end
  119.     end
  120. --
  121.     --mining south
  122.     if turtle.detect() and d==2 and facingSouth == true and stripSDone==false then
  123.         turtle.dig()
  124.         print("mining south")
  125.         print("current distance to next strip =", 50-s)
  126.     end
  127.     --moving east and keeping count of depth
  128.     if turtle.detect() == false and d==2 and facingSouth == true and stripSDone==false then
  129.         turtle.forward()
  130.         s=s+1
  131.         if s==50 then
  132.             stripSDone=true
  133.         end    
  134.     end
  135. --
  136.     --going home after finishing strip
  137.     if facingSouth==true and e>=0 and stripSDone == true then
  138.         turtle.back()
  139.         s=s-1
  140.         if s==0 then
  141.         facingSouth=false
  142.         facingWest=true
  143.         turtle.turnRight()
  144.         end
  145.     end
  146. --
  147.     --mining West
  148.     if turtle.detect() and d==2 and facingWest == true and stripWDone==false then
  149.         turtle.dig()
  150.         print("mining west")
  151.         print("current distance to next strip =", 50-s)
  152.     end
  153.     --moving east and keeping count of depth
  154.     if turtle.detect() == false and d==2 and facingWest == true and stripWDone==false then
  155.         turtle.forward()
  156.         w=w+1
  157.         if w==50 then
  158.             stripWDone=true
  159.         end    
  160.     end
  161. --
  162.     --going home after finishing strip
  163.     if facingWest==true and e>=0 and stripWDone == true then
  164.         turtle.back()
  165.         w=w-1
  166.         if w==0 then
  167.         facingWest=false
  168.         facingNorth=true
  169.         turtle.turnRight()
  170.         d=0
  171.         stripNDone=false
  172.         stripEDone=false
  173.         stripSDone=false
  174.         stripWDone=false
  175.         itemsDelivered=false
  176.         end
  177.     end
  178. --
  179. end
Add Comment
Please, Sign In to add comment