Future_Crafter47

Sorting Turtle V1

Nov 21st, 2020
667
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. print("Row 1")
  2. turtle.select(1)
  3.  
  4. local listofvaluables = {'ore','iron','gold','diamond','refined','ingot','nugget','quartz','emerald','lapis','blaze','redstone','coal'}
  5. local listofbuilding = {'log','brick','wool','plank','door','factory','glass','bookshelf','ice','soul','chiseled','pillar','block','stair'}
  6. local witchery = {'witchery'}
  7. local ic2 = {'IC2'}
  8. local computercraft = {'computer','Computer','CC','disk'}
  9. local othertech = {'thermal','reactor','stargate','star','Thermal','BuildCraft','buildcraft'}
  10. local materials = {'flint','gunpower','ender'}
  11. local foodandplants = {'apple','raw','cooked','pam','sapling'}
  12. local thaumcraft = {'thaumcraft'}
  13. local decocraft = {'prop'}
  14.  
  15. local function has_value (tab, val)
  16.     for index, value in ipairs(tab) do
  17.         if string.find(val, value) then
  18.             return true
  19.         end
  20.     end
  21.     return false
  22. end
  23.  
  24.  
  25. local function returntosorter()
  26.     turtle.back()
  27.     turtle.back()
  28.     turtle.turnRight()
  29.     turtle.forward()
  30.     turtle.up()
  31.     turtle.forward()
  32. end
  33.  
  34. local function rtcfromsorter()
  35.     turtle.back()
  36.     turtle.down()
  37.     turtle.back()
  38.     turtle.turnLeft()
  39.     turtle.forward()
  40.     turtle.forward()
  41. end
  42.  
  43. local function checkitems(n)
  44.  
  45.     putintotl = {}
  46.  
  47.     for i=1,n do
  48.         print(i)
  49.         turtle.select(i)
  50.         turtle.suck()
  51.         data = turtle.getItemDetail(i)
  52.         if data.name == nil or data.name == '' then
  53.             print("...")
  54.         elseif(string.find(data.name, "coal")) then
  55.             print("found coal")
  56.             --userinput = read()
  57.             if(turtle.getFuelLevel() < 200) then
  58.                 print("Using coal to refuel")
  59.                 turtle.refuel()
  60.             end
  61.         elseif(has_value(listofvaluables, data.name)) then
  62.             print(data.name)
  63.         elseif(has_value(listofbuilding, data.name)) then
  64.             print(data.name)
  65.         elseif(has_value(witchery, data.name)) then
  66.             print(data.name)
  67.         elseif(has_value(ic2, data.name)) then
  68.             print(data.name)
  69.         elseif(has_value(computercraft, data.name)) then
  70.             print(data.name)
  71.         elseif(has_value(othertech, data.name)) then
  72.             print(data.name)
  73.         else
  74.             print("found trash")
  75.             print(data.name)
  76.             table.insert(putintotl, i)
  77.         end
  78.     end
  79.    
  80.     itemstotrash = putintotl
  81.    
  82. end
  83.  
  84. local function testitems()
  85.  
  86.     itemstotrash = {}
  87.  
  88.     turtle.select(1)
  89.    
  90.     checkitems(16)
  91.    
  92.     while true do
  93.         for i=1,table.getn(itemstotrash) do
  94.             print(textutils.serialize(itemstotrash))
  95.             turtle.select(itemstotrash[i])
  96.             turtle.dropDown()
  97.         end
  98.        
  99.         if(table.getn(itemstotrash) ~= nil) then
  100.             checkitems(table.getn(itemstotrash))
  101.             print("done checking another time...")
  102.         end
  103.        
  104.         if(itemstotrash[1] == nil) then
  105.             break
  106.         else
  107.             print(itemstotrash[1])
  108.         end
  109.        
  110.     end
  111. end
  112.  
  113. local function sortitems()
  114.     turtle.forward()
  115.     local slotswithvaluables = {}
  116.     local slotswithbuilding = {}
  117.     local slotswithwitchery = {}
  118.     local slotswithic2 = {}
  119.     local slotswithcomputercraft = {}
  120.     local slotswithothertech = {}
  121.     print("Sorting Items...")
  122.     for i=1,16 do
  123.         turtle.select(i)
  124.         data = turtle.getItemDetail(i)
  125.         print(data.name)
  126.         if(data.name == nil)then
  127.             print("...")
  128.         elseif(has_value(listofvaluables, data.name)) then
  129.             print("found valuable")
  130.             table.insert(slotswithvaluables, i)
  131.         elseif(has_value(listofbuilding, data.name)) then
  132.             print("found valuable")
  133.             table.insert(slotswithbuilding, i)
  134.         elseif(has_value(witchery, data.name)) then
  135.             print("found valuable")
  136.             table.insert(slotswithwitchery, i)
  137.         elseif(has_value(ic2, data.name)) then
  138.             print("found valuable")
  139.             table.insert(slotswithic2, i)
  140.         elseif(has_value(computercraft, data.name)) then
  141.             print("found valuable")
  142.             table.insert(slotswithcomputercraft, i)
  143.         elseif(has_value(othertech, data.name)) then
  144.             print("found valuable")
  145.             table.insert(slotswithothertech, i)
  146.         end
  147.     end
  148.    
  149.     turtle.turnLeft()
  150.    
  151.     for i=1,table.getn(slotswithvaluables) do
  152.         print(textutils.serialize(slotswithvaluables))
  153.         turtle.select(slotswithvaluables[i])
  154.         turtle.drop()
  155.     end
  156.    
  157.     turtle.turnRight()
  158.     turtle.turnRight()
  159.    
  160.     for i=1,table.getn(slotswithbuilding) do
  161.         print(textutils.serialize(slotswithbuilding))
  162.         turtle.select(slotswithbuilding[i])
  163.         turtle.drop()
  164.     end
  165.    
  166.     turtle.turnLeft()
  167.     turtle.forward()
  168.     turtle.turnRight()
  169.    
  170.     for i=1,table.getn(slotswithwitchery) do
  171.         print(textutils.serialize(slotswithwitchery))
  172.         turtle.select(slotswithwitchery[i])
  173.         turtle.drop()
  174.     end
  175.    
  176.     turtle.turnLeft()
  177.     turtle.turnLeft()
  178.    
  179.     for i=1,table.getn(slotswithcomputercraft) do
  180.         print(textutils.serialize(slotswithcomputercraft))
  181.         turtle.select(slotswithcomputercraft[i])
  182.         turtle.drop()
  183.     end
  184.    
  185.     turtle.turnRight()
  186.     turtle.forward()
  187.     turtle.turnRight()
  188.    
  189.     for i=1,table.getn(slotswithic2) do
  190.         print(textutils.serialize(slotswithic2))
  191.         turtle.select(slotswithic2[i])
  192.         turtle.drop()
  193.     end
  194.    
  195.     turtle.turnLeft()
  196.     turtle.turnLeft()
  197.  
  198.     for i=1,table.getn(slotswithothertech) do
  199.         print(textutils.serialize(slotswithothertech))
  200.         turtle.select(slotswithothertech[i])
  201.         turtle.drop()
  202.     end
  203.  
  204.     turtle.turnRight()
  205.  
  206.     turtle.back()
  207.     turtle.back()
  208.     turtle.back()
  209.    
  210. end
  211.  
  212. print("starting up...")
  213. while true do
  214.     sleep(2)
  215.     stuffinchest = redstone.getInput("right")
  216.     if(stuffinchest == true) then
  217.         print("Redstone signal detected...")
  218.         returntosorter()
  219.         testitems()
  220.         rtcfromsorter()
  221.         sortitems()
  222.         term.clear()
  223.     end
  224.  
  225. end
RAW Paste Data