TrademarkThis

Quarry

Jan 8th, 2024 (edited)
1,086
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.08 KB | None | 0 0
  1. --Version 5 (WIP)
  2.  
  3. local nLimit = 1
  4. local badItems = {}
  5. badItems[1] = "minecraft:cobblestone"
  6. badItems[2] = "minecraft:andesite"
  7. badItems[3] = "minecraft:dirt"
  8. badItems[4] = "minecraft:diorite"
  9. badItems[5] = "minecraft:granite"
  10. badItems[6] = "minecraft:gravel"
  11. badItems[7] = "extractinator:silt"
  12. badItems[8] = "minecraft:cobbled_deepslate"
  13. badItems[9] = "minecraft:sand"
  14. badItems[10] = "minecraft:sandstone"
  15. badItems[11] = "minecraft:tuff"
  16. badItems[12] = "minecraft:calcite"
  17. badItems[13] = "minecraft:dripstone_block"
  18. badItems[14] = "minecraft:pointed_dripstone"
  19. badItems[15] = "minecraft:mossy_cobblestone"
  20. badItems[16] = "minecraft:flint"
  21.  
  22. function localRefuel()
  23.     if turtle.getFuelLevel() ~= "unlimited" then
  24.         for n=1,16 do
  25.             local nCount = turtle.getItemCount(n)
  26.             if nLimit > 0 and nCount > 0 and turtle.getFuelLevel() < turtle.getFuelLimit() then
  27.                 local nBurn = math.min( nLimit, nCount )
  28.                 turtle.select( n )
  29.                 if turtle.refuel( nBurn ) then
  30.                     local nNewCount = turtle.getItemCount(n)
  31.                     nLimit = nLimit - (nCount - nNewCount)
  32.                 end
  33.             end
  34.         end
  35.     end
  36.     turtle.select(1)
  37. end
  38.  
  39. function fakeInventory()
  40.     fakeSlots = {}
  41.     for i = 1,16 do
  42.         if turtle.getItemDetail(i) ~= nil then
  43.             fakeSlots[i] = turtle.getItemDetail(i).name
  44.         end
  45.     end
  46.     return fakeSlots
  47. end
  48.  
  49. function sortInventory()
  50.     for i = 1,16 do
  51.         fakeSlots = fakeInventory()
  52.         if turtle.getItemDetail(i) ~= nil then
  53.             containsItem = 0
  54.             for j = 1,16 do
  55.                 if fakeSlots[j] == turtle.getItemDetail(i).name then
  56.                     if containsItem == 0 then
  57.                         if turtle.getItemCount(j) < 64 then
  58.                             containsItem = j
  59.                         end
  60.                     end
  61.                 end
  62.             end
  63.             if containsItem ~= 0 then
  64.                 if containsItem ~= i then
  65.                     if turtle.getItemCount(i) < 64 then
  66.                         turtle.select(i)
  67.                         turtle.transferTo(containsItem)
  68.                     end
  69.                 end
  70.             end
  71.         end
  72.     end
  73.     for i = -16,-1 do
  74.         emptySlot = 0
  75.         for j = 1,16 do
  76.             if turtle.getItemDetail(j) == nil then
  77.                 emptySlot = j
  78.                 break
  79.             end
  80.         end
  81.         if emptySlot ~= 0 then
  82.             if emptySlot < i*-1 then
  83.                 if turtle.getItemDetail(i*-1) ~= nil then
  84.                     turtle.select(i*-1)
  85.                     turtle.transferTo(emptySlot)
  86.                 end
  87.             end
  88.         end
  89.     end
  90.     turtle.select(1)
  91. end
  92.  
  93. function checkInventory()
  94.     for i = 1,16 do
  95.         for j = 1,16 do
  96.             if turtle.getItemDetail(i) ~= nil then
  97.                 if turtle.getItemDetail(i).name == badItems[j] then
  98.                     turtle.select(i)
  99.                     turtle.drop(64)
  100.                 end
  101.             end
  102.         end
  103.     end
  104.     sortInventory()
  105. end
  106.  
  107. function clearScreen()
  108.     term.clear()
  109.     term.setCursorPos(1,1)
  110. end
  111.  
  112. function setup()
  113.     posX = 0
  114.     posY = 0
  115.     posZ = 0
  116.     rotation = 0
  117.     layerType = 0
  118.     clearScreen()
  119.     io.write("Quarry or bore? ")
  120.     mineType = io.read()
  121.     clearScreen()
  122.     io.write("Rows: ")
  123.     rows = io.read()
  124.     io.write("Columns: ")
  125.     columns = io.read()
  126.     clearScreen()
  127.     if mineType == "quarry" then
  128.         io.write("Current 'y' level: ")
  129.         iniY = io.read()
  130.         iniY = tonumber (iniY)
  131.         clearScreen()
  132.     end
  133.     start()
  134. end
  135.  
  136. function info()
  137.     clearScreen()
  138.     print("Creating a " .. rows .. "x" .. columns .. " " .. mineType)
  139.     print("Total distance: " .. posX + posY + posZ)
  140.     print("X: " .. posX)
  141.     print("Y: " .. posY)
  142.     print("Z: " .. posZ)
  143.     print("Rotation: " .. rotation)
  144.     print("Layer Type: " .. layerType)
  145.     print("Fuel level: " .. turtle.getFuelLevel())
  146. end
  147.  
  148. function orientate()
  149.     if rotation == 0 then
  150.         turtle.turnLeft()
  151.         rotation = 3
  152.         info()
  153.     elseif rotation == 1 then
  154.         turtle.turnLeft()
  155.         rotation = 0
  156.         info()
  157.         turtle.turnLeft()
  158.         rotation = 3
  159.         info()
  160.     elseif rotation == 2 then
  161.         turtle.turnRight()
  162.         rotation = 3
  163.         info()
  164.     end
  165. end
  166.  
  167. function recover()
  168.     orientate()
  169.     stepY = posY
  170.     stepX = posX
  171.     stepZ = posZ
  172.     for posY = stepY - 1, 0, -1 do
  173.         turtle.up()
  174.         info()
  175.     end
  176.     for posX = stepX - 1, 0, -1 do
  177.         turtle.forward()
  178.         info()
  179.     end
  180.     turtle.turnLeft()
  181.     for posZ = stepZ - 1, 0, -1 do
  182.         turtle.forward()
  183.         info()
  184.     end
  185. end
  186.  
  187. function digStraight()
  188.     turtle.digDown()
  189.     turtle.dig()
  190.     turtle.dig()
  191.     turtle.forward()
  192.     if rotation == 0 then
  193.         posZ = posZ + 1
  194.     elseif rotation == 1 then
  195.         posX = posX + 1
  196.     elseif rotation == 2 then
  197.         posZ = posZ - 1
  198.     elseif rotation == 3 then
  199.         posX = posX - 1
  200.     end
  201.     turtle.digUp()
  202.     sortInventory()
  203.     info()
  204. end
  205.  
  206. function nextRow()
  207.     if layerType == 0 then
  208.         if rotation == 0 then
  209.             turtle.turnRight()
  210.             rotation = 1
  211.             info()
  212.             digStraight()
  213.             turtle.turnRight()
  214.             rotation = 2
  215.             info()
  216.         elseif rotation == 2 then
  217.             turtle.turnLeft()
  218.             rotation = 1
  219.             info()
  220.             digStraight()
  221.             turtle.turnLeft()
  222.             rotation = 0
  223.             info()
  224.         end
  225.     elseif layerType == 1 then
  226.         if rotation == 0 then
  227.             turtle.turnLeft()
  228.             rotation = 3
  229.             info()
  230.             digStraight()
  231.             turtle.turnLeft()
  232.             rotation = 2
  233.             info()
  234.         elseif rotation == 2 then
  235.             turtle.turnRight()
  236.             rotation = 3
  237.             info()
  238.             digStraight()
  239.             turtle.turnRight()
  240.             rotation = 0
  241.             info()
  242.         end
  243.     end
  244. end
  245.  
  246. function nextLayer()
  247.     turtle.turnRight()
  248.     if rotation == 0 then
  249.         rotation = 1
  250.         info()
  251.     elseif rotation == 2 then
  252.         rotation = 3
  253.         info()
  254.     end
  255.     turtle.turnRight()
  256.     if rotation == 1 then
  257.         rotation = 2
  258.         info()
  259.     elseif rotation == 3 then
  260.         rotation = 0
  261.         info()
  262.     end
  263.     turtle.down()
  264.     posY = posY + 1
  265.     info()
  266.     turtle.digDown()
  267.     turtle.down()
  268.     posY = posY + 1
  269.     info()
  270.     turtle.digDown()
  271.     turtle.down()
  272.     posY = posY + 1
  273.     info()
  274.     if layerType == 0 then
  275.         layerType = 1
  276.     elseif layerType == 1 then
  277.         layerType = 0
  278.     end
  279. end
  280.  
  281. function layerMove()
  282.     for c = columns, 1, -1 do
  283.         for r = rows, 2, -1 do
  284.             if turtle.getFuelLevel() < 1 then
  285.                 localRefuel()
  286.             end
  287.             digStraight()
  288.         end
  289.         if c > 1 then
  290.             checkInventory()
  291.             nextRow()
  292.         else
  293.             turtle.digDown()
  294.         end
  295.     end
  296. end
  297.  
  298. function quarry()
  299.     turtle.digDown()
  300.     turtle.down()
  301.     posY = posY + 1
  302.     info()
  303.     turtle.digDown()
  304.     turtle.down()
  305.     posY = posY + 1
  306.     info()
  307.     while posY < iniY - 2 do
  308.         layerMove()
  309.         nextLayer()
  310.     end
  311.     recover()
  312. end
  313.  
  314. function bore()
  315.     turtle.up()
  316.     posY = posY + 1
  317.     info()
  318.     turtle.dig()
  319.     turtle.forward()
  320.     posZ = posZ + 1
  321.     info()
  322.     turtle.digUp()
  323.     layerMove()
  324.     recover()
  325. end
  326.  
  327. function start()
  328.     if mineType == "quarry" then
  329.         quarry()
  330.     elseif mineType == "bore" then
  331.         bore()
  332.     else
  333.         setup()
  334.     end
  335. end
  336.  
  337. setup()
Advertisement
Add Comment
Please, Sign In to add comment