Advertisement
M0n5t3r

Find_ores

Jun 30th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.70 KB | None | 0 0
  1. local Length
  2. local Width
  3.  
  4. local Forward = 0
  5. local Right = 0
  6. local Slot_selected = 1
  7.  
  8. local turn = "left"
  9.  
  10. local dia = 0
  11. local iron = 0
  12. local copper = 0
  13. local gold = 0
  14. local silver = 0
  15. local coal = 0
  16. local tin = 0
  17. local lapis = 0
  18. local emerald = 0
  19. local ruby = 0
  20. local sapphire = 0
  21. local peridot = 0
  22. local redstone = 0
  23. local exploration = 0
  24.  
  25. term.write("Insert Length: ")
  26. Length = tonumber(read()) - 1
  27. print(" ")
  28.  
  29. term.write("Insert Width: ")
  30. Width = tonumber(read())
  31. print(" ")
  32.  
  33. function dig()
  34.     turtle.digDown()
  35.     if turtle.forward() == false then
  36.         while turtle.forward() == false do
  37.             turtle.dig()
  38.         end
  39.         Forward = Forward + 1
  40.     else
  41.         Forward = Forward + 1
  42.     end
  43.     check_ore()
  44.     throw_away()
  45.     turtle.digDown()
  46. end
  47. function digBack()
  48.     turtle.digDown()
  49.     if turtle.forward() == false then
  50.         while turtle.forward() == false do
  51.             turtle.dig()
  52.         end
  53.         Forward = Forward - 1
  54.     else
  55.         Forward = Forward - 1
  56.     end
  57.     check_ore()
  58.     throw_away()
  59.     turtle.digDown()
  60. end
  61.  
  62. function check_ore()
  63.     if turtle.getItemCount(Slot_selected) > 0 then
  64.         local x, y, z = gps.locate(5)
  65.         x = math.floor(x)
  66.         y = math.floor(y)
  67.  
  68.         local item_detail = turtle.getItemDetail(Slot_selected)
  69.         if string.find(item_detail.name, "diam") ~= nil then
  70.             dia = dia + 1
  71.             local h = fs.open("finder/finder_text", "a")
  72.             h.writeLine("diamond: " .. x .. " " .. y)
  73.             h.close()
  74.            
  75.         elseif string.find(item_detail.name, "iron") ~= nil then
  76.             iron = iron + 1
  77.             local h = fs.open("finder/finder_text", "a")
  78.             h.writeLine("iron: " .. x .. " " .. y)
  79.             h.close()
  80.            
  81.         elseif string.find(item_detail.name, "copper") ~= nil then
  82.             copper = copper + 1
  83.             local h = fs.open("finder/finder_text", "a")
  84.             h.writeLine("copper: " .. x .. " " .. y)
  85.             h.close()
  86.            
  87.         elseif string.find(item_detail.name, "gold") ~= nil then
  88.             gold = gold + 1
  89.             local h = fs.open("finder/finder_text", "a")
  90.             h.writeLine("gold: " .. x .. " " .. y)
  91.             h.close()
  92.            
  93.         elseif string.find(item_detail.name, "silver") ~= nil then
  94.             silver = silver + 1
  95.             local h = fs.open("finder/finder_text", "a")
  96.             h.writeLine("silver: " .. x .. " " .. y)
  97.             h.close()
  98.            
  99.         elseif string.find(item_detail.name, "tin") ~= nil then
  100.             tin = tin + 1
  101.             local h = fs.open("finder/finder_text", "a")
  102.             h.writeLine("tin: " .. x .. " " .. y)
  103.             h.close()
  104.            
  105.         elseif string.find(item_detail.name, "coal") ~= nil then
  106.             coal = coal + 1
  107.             local h = fs.open("finder/finder_text", "a")
  108.             h.writeLine("coal: " .. x .. " " .. y)
  109.             h.close()
  110.            
  111.         elseif string.find(item_detail.name, "lapis") ~= nil then
  112.             lapis = lapis + 1
  113.             local h = fs.open("finder/finder_text", "a")
  114.             h.writeLine("lapis: " .. x .. " " .. y)
  115.             h.close()
  116.            
  117.         elseif string.find(item_detail.name, "emerald") ~= nil then
  118.             emerald = emerald + 1
  119.             local h = fs.open("finder/finder_text", "a")
  120.             h.writeLine("emerald: " .. x .. " " .. y)
  121.             h.close()
  122.            
  123.         elseif string.find(item_detail.name, "ruby") ~= nil then
  124.             ruby = ruby + 1
  125.             local h = fs.open("finder/finder_text", "a")
  126.             h.writeLine("ruby: " .. x .. " " .. y)
  127.             h.close()
  128.            
  129.         elseif string.find(item_detail.name, "sapphire") ~= nil then
  130.             sapphire = sapphire + 1
  131.             local h = fs.open("finder/finder_text", "a")
  132.             h.writeLine("sapphire: " .. x .. " " .. y)
  133.             h.close()
  134.            
  135.         elseif string.find(item_detail.name, "peridot") ~= nil then
  136.             peridot = peridot + 1
  137.             local h = fs.open("finder/finder_text", "a")
  138.             h.writeLine("peridot: " .. x .. " " .. y)
  139.             h.close()
  140.            
  141.         elseif string.find(item_detail.name, "redstone") ~= nil then
  142.             redstone = redstone + 1
  143.             local h = fs.open("finder/finder_text", "a")
  144.             h.writeLine("redstone: " .. x .. " " .. y)
  145.             h.close()
  146.            
  147.         elseif string.find(item_detail.name, "exploration") ~= nil then
  148.             exploration = exploration + 1
  149.             local h = fs.open("finder/finder_text", "a")
  150.             h.writeLine("exploration: " .. x .. " " .. y)
  151.             h.close()
  152.            
  153.         end
  154.         if turtle.getItemCount(Slot_selected) == 64 then
  155.             Slot_selected = Slot_selected + 1
  156.         end
  157.        
  158.         turtle.select(Slot_selected)
  159.    
  160.     end    
  161. end
  162.  
  163. function throw_away()
  164.     if Slot_selected == 15 then
  165.         for q=1,15 do
  166.             turtle.select(q)
  167.             if turtle.getItemCount(q) > 0 then
  168.                 local item_detail = turtle.getItemDetail(q)
  169.                 if string.find(item_detail.name, "cobblestone") ~= nil then
  170.                     turtle.drop()
  171.                 elseif string.find(item_detail.name, "dirt") ~= nil then
  172.                     turtle.drop()
  173.                 elseif string.find(item_detail.name, "gravel") ~= nil then
  174.                     turtle.drop()
  175.                 end
  176.             end
  177.         end
  178.     end
  179. end
  180.        
  181. function makeLine()
  182.     if Forward ~= Length then
  183.         repeat
  184.             dig()
  185.         until Forward == Length
  186.     else
  187.         repeat
  188.             digBack()
  189.         until Forward == 0
  190.     end
  191. end
  192.  
  193.  
  194. function start()
  195.     local h = fs.open("finder/finder_text", "w")
  196.     h.writeLine(":D hey ")
  197.     h.close()
  198.  
  199.     if turtle.forward() == false then
  200.         while turtle.forward() == false do
  201.             turtle.dig()
  202.         end
  203.     end
  204.  
  205.     print("Starting")
  206.     repeat
  207.         makeLine()
  208.        
  209.         Right = Right + 1
  210.        
  211.         if Right ~= Width then
  212.             if turn == "left" then
  213.                 turtle.turnRight()
  214.                 if turtle.forward() == false then
  215.                     while turtle.forward() == false do
  216.                         turtle.dig()
  217.                     end
  218.                 end
  219.                 check_ore()
  220.                 throw_away()
  221.                 turtle.turnRight()
  222.                 turn = "right"
  223.             else
  224.                 turtle.turnLeft()
  225.                 if turtle.forward() == false then
  226.                     while turtle.forward() == false do
  227.                         turtle.dig()
  228.                     end
  229.                 end
  230.                 check_ore()
  231.                 throw_away()
  232.                 turtle.turnLeft()
  233.                 turn = "left"
  234.             end
  235.         end
  236.     until Right == Width
  237.     goBack()
  238. end
  239.  
  240. function goBack()
  241.     print(turn)
  242.     print(Width)
  243.     print(Length)
  244.     local move_1 = 0
  245.     local move_2 = 0
  246.     if turn == "right" then
  247.         turtle.turnRight()
  248.         repeat
  249.             turtle.forward()
  250.             move_1 = move_1 + 1
  251.         until move_1 == (Width - 1) or turtle.forward() == false
  252.     else
  253.         turtle.turnLeft()
  254.         turtle.turnLeft()
  255.         repeat
  256.             turtle.forward()
  257.             move_2 = move_2 + 1
  258.         until move_2 == (Length) or turtle.forward() == false
  259.         turtle.turnRight()
  260.         repeat
  261.             turtle.forward()
  262.             move_1 = move_1 + 1
  263.         until move_1 == (Width - 1) or turtle.forward() == false
  264.     end
  265.    
  266.     turtle.turnLeft()
  267.     turtle.forward()
  268.     readAll()
  269. end
  270.  
  271. function printAll()
  272.     if dia ~= 0 then
  273.         print("dia: " .. dia)
  274.     end
  275.     if iron ~= 0 then
  276.         print("iron: " .. iron)
  277.     end
  278.     if copper ~= 0 then
  279.         print("copper: " .. copper)
  280.     end
  281.     if gold ~= 0 then
  282.         print("gold: " .. gold)
  283.     end
  284.     if silver ~= 0 then
  285.         print("silver: " .. silver)
  286.     end
  287.     if coal ~= 0 then
  288.         print("coal: " .. coal)
  289.     end
  290.     if tin ~= 0 then
  291.         print("tin: " .. tin)
  292.     end
  293.     if lapis ~= 0 then
  294.         print("lapis: " .. lapis)
  295.     end
  296.     if emerald ~= 0 then
  297.         print("emerald: " .. emerald)
  298.     end
  299.     if ruby ~= 0 then
  300.         print("ruby: " .. ruby)
  301.     end
  302.     if sapphire ~= 0 then
  303.         print("sapphire: " .. sapphire)
  304.     end
  305.     if peridot ~= 0 then
  306.         print("peridot: " .. peridot)
  307.     end
  308.     if redstone ~= 0 then
  309.         print("redstone: " .. redstone)
  310.     end
  311.     if exploration ~= 0 then
  312.         print("exploration: " .. exploration)
  313.     end
  314. end
  315. function readAll()
  316.     printAll()
  317.     print(" ")
  318.     term.write("Type: 'r' to read, 'd' to delete or 'x' to exit")
  319.     print(" ")
  320.     answer = read()
  321.     if answer == "r" then
  322.         reader_go()
  323.     elseif answer == "d" then
  324.         deleteOrNot()
  325.     elseif answer == "x" then
  326.         print("Bye Bye :)")
  327.     else
  328.         print("No valid input")
  329.         readAll()
  330.     end
  331. end
  332.  
  333. function reader_go()
  334.     local h = fs.open("finder/finder_text", "r")
  335.     repeat
  336.         local line = h:readLine()
  337.         print(line)
  338.     until not line
  339.     h.close()
  340.     readAll()
  341. end
  342.  
  343. function deleteOrNot()
  344.     term.write("Delete all? y/n_  ")
  345.     Delete = read()
  346.     if Delete == "y" then
  347.         print("Deleting finder folder and startup file")
  348.         fs.delete("finder")
  349.         if fs.exists("finder") then
  350.             print("finder folder not deleted")
  351.         end
  352.     elseif Delete == "n" then
  353.         readAll()
  354.     else
  355.         print("not a valid input")
  356.         deleteOrNot()
  357.     end
  358. end
  359.  
  360. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement