Advertisement
JJC15433

turtleScriptTesting

Nov 28th, 2020 (edited)
946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.04 KB | None | 0 0
  1. -- Constants and Variables--
  2. SLOT_COUNT = 16
  3.  
  4. unwantedItemsMenu = {   cobble="minecraft:cobblestone",
  5.                                             cobblestone="minecraft:cobblestone",
  6.                                             dirt="minecraft:dirt",
  7.                                             stone="minecraft:stone",
  8.                                             smoothstone="minecraft:stone",
  9.                                             andesite="minecraft:stone",
  10.                                             diorite="minecraft:stone",
  11.                                             granite="minecraft:stone",
  12.                                             marble="PLACEHOLDER",
  13.                                             slate=  {   "rustic:slate",
  14.                                                                 "quark:slate"
  15.                                                             }
  16.                                         }
  17.  
  18. list = {}
  19.  
  20. -- /Constants and Variables
  21.  
  22. -- Command Line Args
  23. targs = {...}
  24.  
  25. function elementIterator(collection)
  26.     local index = 0
  27.     local count = #collection
  28.     return function()
  29.         index = index + 1
  30.         if index <= count then
  31.             return collection[index]
  32.         end
  33.     end
  34. end
  35.  
  36. function join(src,dest)
  37.     if src == dest then
  38.         local temp = {}
  39.         join(src,temp)
  40.         join(temp,dest)
  41.     else
  42.         for k,v in pairs(src) do
  43.             -- print("src entry:",k,v)
  44.             -- if #dest > 0 then print("dest@len:", #dest,dest[#dest]) end
  45.             dest[#dest+1] = v
  46.             -- print("dest@new len:", #dest,dest[#dest])
  47.             -- os.sleep(5)
  48.         end
  49.     end
  50. end
  51.  
  52. function selectFromTable(input, reference, output)
  53.     local entries = {}
  54.     for k,v in pairs(input) do
  55.         if reference[input[k]]~=nil then
  56.             -- print("entry found in input: ", input[i], " = ", reference[input[i]]) -- TEST CODE
  57.             if type(reference[input[k]]) == "table" then
  58.                 -- print(#reference[input[k]]," entries found for",input[k]) -- TEST CODE
  59.                 join(reference[input[k]],entries)
  60.             else
  61.                 join({reference[input[k]]},entries) --should be equivalent to the below, but using join
  62.                 --entries[(#entries+1)] = reference[input[k]]
  63.             end
  64.         end
  65.         -- for k,v in ipairs(unwantedItems) do
  66.         --  if targs[i]==k then entries = entries + v end
  67.         -- end
  68.     end
  69.     join(entries,output)
  70.     --return output
  71. end
  72.  
  73. function listify(input, reference)
  74.     local entries = {}
  75.     for i=1,#input do
  76.         if reference[input[i]]~=nil then
  77.             -- print("entry found in input: ", input[i], " = ", reference[input[i]]) -- TEST CODE
  78.             if type(reference[input[i]]) == "table" then
  79.                 print(#reference[input[i]]," entries found for ", input[i]) -- TEST CODE
  80.             else
  81.                 entries[i] = reference[input[i]]
  82.             end
  83.         end
  84.         -- for k,v in ipairs(unwantedItems) do
  85.         --  if targs[i]==k then entries = entries + v end
  86.         -- end
  87.     end
  88.     list = entries
  89.     return list
  90. end
  91.  
  92. function printList(list)
  93.     for k,v in pairs(list) do
  94.         print(k,v)
  95.     end
  96. end
  97.  
  98. function dropUnwanted(list)
  99.     currSlot=turtle.getSelectedSlot()
  100.     for i=1,SLOT_COUNT do
  101.         for k,v in pairs(list) do
  102.             if turtle.getItemCount(i) ~= 0 and turtle.getItemDetail(i).name == v then
  103.                 if turtle.getItemSpace(i) == 0 then
  104.                     turtle.select(i)
  105.                     turtle.drop()
  106.                 end
  107.             end
  108.         end
  109.     end
  110.     turtle.select(currSlot)
  111. end
  112.  
  113.  
  114. --run scripts to test here
  115. -- printList(unwantedItems)
  116. -- printList(listify(targs,unwantedItems))
  117. selectFromTable(targs, unwantedItemsMenu, list)
  118. printList(list)
  119. dropUnwanted(list)
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement