CelticCoder

simpleQuarry

Sep 24th, 2023 (edited)
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.28 KB | Gaming | 0 0
  1. os.loadAPI("turtleForward.lua")
  2.  
  3. -- Quarry Dimension Input and Mining Program
  4.  
  5. -- Get the dimensions
  6. function input(newWidth, newLength, newDepth)
  7.     width = newWidth
  8.     length = newLength
  9.     depth = newDepth
  10.     fuelcost = 0
  11. end
  12.  
  13. function setWidth(newWidth)
  14.     width = newWidth
  15. end
  16.  
  17. function setLength(newLength)
  18.     length = newLength
  19. end
  20.  
  21. function setDepth(newDepth)
  22.     depth = newDepth
  23. end
  24.  
  25. -- Function to Mine to Depth
  26. function mineDepth()
  27.   for i = 1, depth do
  28.     turtle.digDown()
  29.     turtle.down()
  30.   end
  31. end
  32.  
  33. function mineHeight()
  34.     for j = 1, depth do
  35.         turtle.digUp()
  36.         turtle.up()
  37.     end
  38. end
  39.  
  40. -- Function to mine a layer
  41. function mine(width, length)
  42.   down = true
  43.   for i = 1, length do
  44.     for j = 1, width do
  45.       if down then
  46.         mineDepth()
  47.         down = false
  48.       else
  49.         mineHeight()
  50.         down = true
  51.       end
  52.       turtleForward.moveForward()
  53.     end
  54.     if i < length then
  55.       if i % 2 == 1 then
  56.         if down then
  57.             mineDepth()
  58.             down = false
  59.         else
  60.             mineHeight()
  61.             down = true
  62.         end
  63.         turtle.turnRight()
  64.         turtleForward.moveForward()
  65.         turtle.turnRight()
  66.       else
  67.         if down then
  68.             mineDepth()
  69.             down = false
  70.         else
  71.             mineHeight()
  72.             down = true
  73.         end
  74.         turtle.turnLeft()
  75.         turtleForward.moveForward()
  76.         turtle.turnLeft()
  77.       end
  78.     end
  79.   end
  80. end
  81.  
  82. function toStart()
  83.     if length % 2 == 1 then
  84.         turtle.turnLeft()
  85.         turtle.turnLeft()
  86.         for i = 1, width do
  87.             turtle.forward()
  88.         end
  89.     end
  90.     turtle.turnRight()
  91.     for j = 2, length do
  92.         turtle.forward()
  93.     end
  94.     turtle.turnLeft()
  95.     turtle.forward()
  96.     turtle.turnLeft()
  97.     turtle.turnLeft()
  98. end
  99.  
  100. function isBlockBelow(blockName)
  101.     if turtle.detectDown() then
  102.         local success, blockInfo = turtle.inspectDown()
  103.         if success and blockInfo.name == blockName then
  104.             return true
  105.         else
  106.             return false
  107.         end
  108.     else
  109.         return false
  110.     end
  111. end
  112.  
  113. -- Function to Mine to Depth
  114. function smartMineDepth(blockname)
  115.   i = 1
  116.   while i ~= depth do
  117.     if turtle.down() then
  118.         i = i + 1
  119.     else
  120.         if isBlockBelow(blockname) then
  121.             turtle.digDown()
  122.         else
  123.             break
  124.         end
  125.     end
  126.   end
  127.   i = i - 1
  128.   for j = 1, i do
  129.     turtle.up()
  130.   end
  131. end
  132.  
  133. -- Function to mine a layer
  134. function smartMine(blockname)
  135.   for i = 1, length do
  136.     for j = 1, width do
  137.       smartMineDepth(blockname)
  138.       turtleForward.moveForward()
  139.     end
  140.     if i < length then
  141.       if i % 2 == 1 then
  142.         smartMineDepth(blockname)
  143.         turtle.turnRight()
  144.         turtleForward.moveForward()
  145.         turtle.turnRight()
  146.       else
  147.         smartMineDepth(blockname)
  148.         turtle.turnLeft()
  149.         turtleForward.moveForward()
  150.         turtle.turnLeft()
  151.       end
  152.     end
  153.   end
  154. end
  155.  
  156. function quarry(newWidth, newLength, newDepth)
  157.     input(newWidth, newLength, newDepth)
  158.     turtleForward.moveForward()
  159.     mine(width, length)
  160.     if down then
  161.         mineDepth()
  162.         mineHeight()
  163.         down = false
  164.     else
  165.         mineHeight()
  166.         down = true
  167.     end
  168.     toStart()
  169. end
  170.  
  171. function smartQuarry(newWidth, newLength, newDepth, blockname)
  172.     input(newWidth, newLength, newDepth)
  173.     turtleForward.moveForward()
  174.     smartMine(blockname)
  175.     smartMineDepth(blockname)
  176.     toStart()
  177. end
  178.  
  179. function remoteMine(width, length, depth)
  180.    
  181.     invalid = true
  182.     while invalid do
  183.         if width == nil then
  184.             return "width error"
  185.         elseif length == nil then
  186.             return "length error"
  187.         elseif depth == nil then
  188.             return "depth error"
  189.         else
  190.             invalid = false
  191.         end
  192.     end
  193.     tw = width
  194.     tl = length
  195.     td = depth
  196.     if tw == 0 then
  197.         tw = 1
  198.     end
  199.     if tl == 0 then
  200.         tl = 1
  201.     end
  202.     if td == 0 then
  203.         td = 1
  204.     end
  205.     volume = tw * tl * td
  206.     width = width - 1
  207.     print("Volume: " .. volume .. " blocks")
  208.  
  209.     max = volume > 9000
  210.     if not max then
  211.         predictSimpleQuarry.predict(width, length, depth)
  212.         fuelcost = predictSimpleQuarry.getFuelCost()
  213.         if fuelcost > turtle.getFuelLevel() then
  214.             return "fuel error"
  215.         else
  216.             simpleQuarry.quarry(width, length, depth)
  217.             return "true"
  218.         end
  219.     else
  220.         return "volume error"
  221.     end
  222. end
Advertisement
Add Comment
Please, Sign In to add comment