Advertisement
o11o01

Scanning Strip Mine Advanced Peripherals

Nov 2nd, 2023 (edited)
1,557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.58 KB | Gaming | 0 0
  1. local X = 0
  2. local Y = 0
  3. local Z = 0
  4. local Rotation = 0
  5. local User_Tags = {}
  6. local temp = 0
  7.  
  8. print("This program uses a chunk loader, diamond pick, geoscanner, Water bucket, and fuel")
  9. print("The chunk loader should be equiped in the turtles left side prior to running")
  10. print("Fuel goes into the first inventory slot. Geoscanner in second, and bucket in third")
  11. print("Enter Desired Length")
  12. Length = tonumber(io.read())
  13. print("Enter Desired number of tunnels. Must be even")
  14. Tunnels = tonumber(io.read())
  15. Space = 16
  16. print("Enter the Block tags you'd like to scan for")
  17. print("Enter stop when done. Case sensitive")
  18. while temp ~= "stop"
  19.     do
  20.     temp = io.read()
  21.     User_Tags[temp] = true
  22.     print(User_Tags[temp])
  23.     end
  24. Fuel = ((Length*Tunnels+(2*Space))/100)
  25. print(Fuel .. "Coal Needed for program. y/n to continue")
  26. answer = io.read()
  27.  
  28. Location = vector.new(0,0,0)
  29. Ore_Location = vector.new(0,0,0)
  30. Scan_Location = vector.new(0,0,0)
  31.  
  32. function Scan()
  33.     print("scanning")
  34.  
  35.     local continue = true
  36.     Scan_Location.x = X
  37.     Scan_Location.y = Y
  38.     Scan_Location.z = Z
  39.     if turtle.getItemDetail(2).name == "advancedperipherals:geo_scanner"
  40.         then
  41.         turtle.select(2)
  42.         turtle.equipRight()
  43.         end
  44.  
  45.     Geoscan = peripheral.wrap('right')
  46.     local scan = Geoscan.scan(8)
  47.     for i, Scan_data in ipairs(scan) do
  48.         if Scan_data.tags and continue == true
  49.             then
  50.             for i, Tag_data in ipairs(Scan_data.tags) do
  51.                 if User_Tags[Tag_data] == true
  52.                     then
  53.                     Ore_Location.x = Scan_data.x * -1 + Scan_Location.x
  54.                     Ore_Location.y = Scan_data.z + Scan_Location.y
  55.                     Ore_Location.z = Scan_data.y + Scan_Location.z
  56.                     if Ore_Location.x ~= Scan_Location.x and Ore_Location.z < 3 and Ore_Location.z > -3 and Ore_Location.x > Location.x -8 and Ore_Location.x < Location.x + 8
  57.                     and Ore_Location.y < Location.y + 8 and Ore_Location.y > Location.y - 8
  58.                         then
  59.                         print("Found Ore")
  60.                         continue = false
  61.                         if turtle.getItemDetail(2).name == "minecraft:diamond_pickaxe"
  62.                             then
  63.                             turtle.select(2)
  64.                             turtle.equipRight()
  65.                             end
  66.                         FindOre()
  67.                         Scan()
  68.                         Return()
  69.                         end
  70.                     end
  71.                 end
  72.             end
  73.         end
  74.     if continue == false
  75.         then
  76.         Scan()
  77.         end
  78.     if turtle.getItemDetail(2).name == "minecraft:diamond_pickaxe"
  79.         then
  80.         turtle.select(2)
  81.         turtle.equipRight()
  82.         end
  83.     end
  84. function FindOre()
  85.     CheckInvOre()
  86.     while Ore_Location.x < X
  87.         do
  88.             ALeft()
  89.             Mine()
  90.         end
  91.     while Ore_Location.x > X
  92.         do
  93.             ARight()
  94.             Mine()
  95.         end
  96.     while Ore_Location.y < Y
  97.         do
  98.             ABack()
  99.             Mine()
  100.         end
  101.     while Ore_Location.y > Y
  102.         do
  103.         AForward()
  104.         Mine()
  105.         end
  106.     while Ore_Location.z < Z
  107.         do
  108.         Down()
  109.         end
  110.     while Ore_Location.z > Z
  111.         do
  112.         Up()
  113.         end
  114.     end
  115.  
  116. function SetReturn()
  117.     Location.x = X
  118.     Location.y = Y
  119.     Location.z = Z
  120.     end
  121. function Inspect()
  122.     local success, data = turtle.inspect()
  123.     if success then
  124.         if data.name == "forbidden_arcanus:stella_arcanum"
  125.             then
  126.             turtle.select(3)
  127.             Up()
  128.             turtle.digUp()
  129.             Down()
  130.             turtle.placeUp()
  131.             turtle.dig()
  132.             turtle.select(3)
  133.             turtle.placeUp()
  134.             return "false"
  135.         elseif data.state.level
  136.             then
  137.             print("Water")
  138.             return "false"
  139.         else
  140.             return success
  141.             end
  142.         end
  143.     end
  144. function InspectUp()
  145.     local success, data = turtle.inspectUp()
  146.     if success then
  147.         if data.name == "forbidden_arcanus:stella_arcanum"
  148.             then
  149.             turtle.select(3)
  150.             turtle.placeUp()
  151.             turtle.digUp()
  152.             turtle.select(3)
  153.             turtle.placeUp()
  154.             return "false"
  155.         elseif data.state.level
  156.             then
  157.             return "false"
  158.         else
  159.             return success
  160.             end
  161.         end
  162.     end
  163. function InspectDown()
  164.     local success, data = turtle.inspectDown()
  165.     if success then
  166.         if data.name == "forbidden_arcanus:stella_arcanum"
  167.             then
  168.             turtle.select(3)
  169.             Up()
  170.             turtle.digUp()
  171.             Down()
  172.             turtle.placeUp()
  173.             turtle.digDown()
  174.             turtle.select(3)
  175.             turtle.placeUp()
  176.             return "false"
  177.         elseif data.state.level
  178.             then
  179.             print("Water")
  180.             return "false"
  181.         else
  182.             return success
  183.             end
  184.         end
  185.     end
  186.    
  187.  
  188.        
  189. function Forward()
  190.     if turtle.getFuelLevel() == 0
  191.         then
  192.             turtle.select(1)
  193.             turtle.refuel(1)
  194.             end
  195.     while (Inspect() == true)
  196.         do
  197.             turtle.dig()
  198.         end
  199.             turtle.forward()
  200.             HorizontalPos()
  201.     end
  202. function Up()
  203.     if turtle.getFuelLevel() == 0
  204.         then
  205.             turtle.select(1)
  206.             turtle.refuel(1)
  207.             end
  208.     while (InspectUp() == true)
  209.         do
  210.             turtle.digUp()
  211.         end
  212.             turtle.up()
  213.             Z = Z + 1
  214.     end
  215. function Down()
  216.     if turtle.getFuelLevel() == 0
  217.         then
  218.             turtle.select(1)
  219.             turtle.refuel(1)
  220.             end
  221.     while (InspectDown() == true)
  222.         do
  223.             turtle.digDown()
  224.         end
  225.             turtle.down()
  226.             Z = Z - 1
  227.     end
  228. -- HorizontalPos Counts location variables according to Rotation. Can be used to record turtle position
  229. function HorizontalPos()
  230.     if Rotation == 0
  231.         then
  232.             Y = (Y+1)
  233.     elseif Rotation == 1
  234.         then
  235.             X = (X+1)
  236.     elseif Rotation == 2
  237.         then
  238.             Y = (Y-1)
  239.     elseif Rotation == 3
  240.         then X = (X-1)
  241.         end
  242.     end
  243. -- TurnRight & TurnLeft record direction turtle is facing while rotating
  244. function TurnRight()
  245.     turtle.turnRight()
  246.     if Rotation == 0
  247.         then
  248.             Rotation = 1
  249.     elseif Rotation == 1
  250.         then
  251.             Rotation = 2
  252.     elseif Rotation == 2
  253.         then
  254.             Rotation = 3
  255.     elseif Rotation == 3
  256.         then Rotation = 0
  257.         end
  258.     end
  259. function TurnLeft()
  260.     turtle.turnLeft()
  261.     if Rotation == 0
  262.         then
  263.             Rotation = 3
  264.     elseif Rotation == 3
  265.         then
  266.             Rotation = 2
  267.     elseif Rotation == 2
  268.         then
  269.             Rotation = 1
  270.     elseif Rotation == 1
  271.         then
  272.             Rotation = 0
  273.         end
  274.     end
  275. -- A Movement functions are absolute movement relative to the direction the turtle was placed in
  276. function ARight()
  277.     if Rotation == 0
  278.         then
  279.             TurnRight()
  280.             Forward()
  281.     elseif Rotation == 1
  282.         then
  283.             Forward()
  284.     elseif Rotation == 2
  285.         then
  286.             TurnLeft()
  287.             Forward()
  288.     elseif Rotation == 3
  289.         then
  290.             TurnRight()
  291.             TurnRight()
  292.             Forward()
  293.         end
  294.     end
  295. function ALeft()
  296.     if Rotation == 2
  297.         then
  298.             TurnRight()
  299.             Forward()
  300.     elseif Rotation == 3
  301.         then
  302.             Forward()
  303.     elseif Rotation == 0
  304.         then
  305.             TurnLeft()
  306.             Forward()
  307.     elseif Rotation == 1
  308.         then
  309.             TurnRight()
  310.             TurnRight()
  311.             Forward()
  312.         end
  313.     end
  314. function AForward()
  315.     if Rotation == 3
  316.         then
  317.             TurnRight()
  318.             Forward()
  319.     elseif Rotation == 0
  320.         then
  321.             Forward()
  322.     elseif Rotation == 1
  323.         then
  324.             TurnLeft()
  325.             Forward()
  326.     elseif Rotation == 2
  327.         then
  328.             TurnRight()
  329.             TurnRight()
  330.             Forward()
  331.         end
  332.     end
  333. function ABack()
  334.     if Rotation == 1
  335.         then
  336.             TurnRight()
  337.             Forward()
  338.     elseif Rotation == 2
  339.         then
  340.             Forward()
  341.     elseif Rotation == 3
  342.         then
  343.             TurnLeft()
  344.             Forward()
  345.     elseif Rotation == 0
  346.         then
  347.             TurnRight()
  348.             TurnRight()
  349.             Forward()
  350.         end
  351.     end
  352. function Home()
  353.     SetReturn()
  354.     while(X > 0)
  355.         do
  356.         ALeft()
  357.         end
  358.     while(Y>0)
  359.         do
  360.         ABack()
  361.         end
  362.     while Rotation ~= 3
  363.         do
  364.         TurnRight()
  365.         end
  366.     end
  367. function HomeOre()
  368.     while(Z>0)
  369.         do
  370.         Down()
  371.         end
  372.     while(Z<0)
  373.         do
  374.         Up()
  375.         end    
  376.     while(X < 0)
  377.         do
  378.         ARight()
  379.         end
  380.     while(Y < 0)
  381.         do
  382.         AForward()
  383.         end
  384.     while(X > 0)
  385.         do
  386.         ALeft()
  387.         Mine()
  388.         end
  389.     while(Y>0)
  390.         do
  391.         ABack()
  392.         end
  393.    
  394.     while Rotation ~= 3
  395.         do
  396.         TurnRight()
  397.         end
  398.     end
  399. function Return()
  400.     while(Z>0)
  401.         do
  402.         Down()
  403.         end
  404.     while(Z<0)
  405.         do
  406.         Up()
  407.         end
  408.  
  409.     while(X<Location.x)
  410.         do
  411.         ARight()
  412.         Mine()
  413.         end
  414.     while(X>Location.x)
  415.         do
  416.         ALeft()
  417.         Mine()
  418.         end
  419.     while(Y<Location.y)
  420.         do
  421.         AForward()
  422.         end
  423.     while(Y>Location.y)
  424.         do
  425.         ABack()
  426.         end
  427.     end
  428. function Mine()
  429.     if InspectUp() == true
  430.         then
  431.         turtle.digUp()
  432.         end
  433.     if InspectDown() == true
  434.         then
  435.         turtle.digDown()
  436.         end
  437.     end
  438. function CheckInv()
  439.     if turtle.getItemCount(16) > 0
  440.         then
  441.         Home()
  442.         Empty()
  443.         Return()
  444.         end
  445.     end
  446. function CheckInvOre()
  447.     if turtle.getItemCount(16) > 0
  448.         then
  449.         HomeOre()
  450.         Empty()
  451.         Return()
  452.         end
  453.     end
  454. -- Empties inventory except for 1st slot (reserved for fuel)
  455. function Empty()
  456.     for i =4, 16, 1
  457.         do
  458.     turtle.select(i)
  459.     turtle.drop()
  460.         end
  461.     turtle.select(1)
  462.     end
  463. function Strip()
  464.     local counter = 0
  465.     while X < Tunnels * Space
  466.         do
  467.         while Y < Length
  468.             do
  469.             AForward()
  470.             CheckInv()
  471.             counter = counter + 1
  472.             print(Y)
  473.             if counter == 8
  474.                 then
  475.                 SetReturn()
  476.                 Scan()
  477.                 counter = 0
  478.                 end
  479.             end
  480.         if X < Tunnels * Space
  481.             then
  482.             for i = 0, Space, 1
  483.                 do
  484.                 ARight()
  485.                 Mine()
  486.                 end
  487.             else
  488.             home()
  489.             os.shutdown()
  490.             end
  491.         while Y > 0
  492.             do
  493.             ABack()
  494.             CheckInv()
  495.             counter = counter + 1
  496.             if counter == 8
  497.                 then
  498.                 SetReturn()
  499.                 Scan()
  500.                 counter = 0
  501.                 end
  502.             end
  503.         for i = 0, Space, 1
  504.             do
  505.             ARight()
  506.             Mine()
  507.             end
  508.         end
  509.  
  510.     end
  511.  
  512.  
  513.  
  514.  
  515. if answer == "y"
  516. then
  517. Strip()
  518.     end
  519.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement