Advertisement
CelticCoder

simpleQuarry

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