Advertisement
Wassaa

Item sorting

Nov 27th, 2016
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.75 KB | None | 0 0
  1. args ={...}
  2. sides = {"front", "back", "left", "right", "top", "bottom"}
  3. directions = {"north", "south", "east", "west", "up", "down"}
  4. drops = {"dropup", "dropdown,", "drop"}
  5.  
  6. function settings()
  7.     if #args==3 then
  8.         for i = 1, 6 do
  9.             if string.lower(args[1]) == sides[i] then
  10.                 p=peripheral.wrap(args[1])
  11.                 print("peripheral side: "..tostring(args[1]))
  12.                 break
  13.             end
  14.         end
  15.         for i = 1, 6 do
  16.             if string.lower(args[2]) == directions[i] then
  17.                 turtleDir = args[2]
  18.                 print("chest to turtle direction: "..tostring(args[2]))
  19.                 break
  20.             end
  21.         end
  22.         for i = 1, 3 do
  23.             if string.lower(args[3]) == drops[i] then
  24.                 dropWay(args[3])
  25.                 print("dropping way: "..tostring(drop))
  26.                 break
  27.             end
  28.         end
  29.        
  30.        
  31.         if p ~= nil and turtleDir ~= nil and drop ~= nil then
  32.             main()
  33.         else
  34.             print("something went wrong, try again")
  35.             L2U()
  36.         end
  37.     else
  38.         L2U()
  39.     end
  40. end
  41.  
  42. function dropWay(s)
  43.     if string.find(s, "up") ~= nil then
  44.         drop = turtle.dropUp
  45.         return
  46.     elseif string.find(s, "down") ~= nil then
  47.         drop = turtle.dropDown
  48.         return
  49.     else
  50.         drop = turtle.drop
  51.         return
  52.     end
  53. end
  54.  
  55. function L2U()
  56.     print('L2 Use my turtles, \nARGS #1 <peripheral side> \n#2 <Chest to Turtle direction> \n#3 <drop Up/down/nothing>' )
  57.     --print('viable sides: "front", "back", "left", "right", "top", "bottom"')
  58.     --print ('viable directions: "north", "south", "east", "west", "up", "down"')
  59. end
  60. --p = peripheral.wrap("front")
  61. --turtleDir = ("West")
  62.  
  63. function cleanUp()
  64.     print("sweep sweep sweep WIP")
  65.     for i=1, 16 do
  66.         if turtle.getItemCount(i) > 0 then
  67.             size = p.getInventorySize()
  68.             while p.pullItem(turtleDir, i, 64, size) == 0 do
  69.                 size = size - 1
  70.             end
  71.         end
  72.     end
  73. end
  74.  
  75. function getStacks()
  76.     for i=1, p.getInventorySize() do
  77.         if p.getStackInSlot(i) ~= nil then
  78.             quantity = p.getStackInSlot(i).qty
  79.             --if quantity >= 9 then
  80.             if quantity >= 4 then
  81.                 doCrafting(i, quantity)
  82.                 print("crafting")
  83.             end
  84.         end
  85.     end
  86. end
  87.  
  88. function doCrafting(slot, n)
  89.     --craftNr = math.floor(n / 9)
  90.     craftNr = math.floor(n / 4)
  91.     p.pushItemIntoSlot(turtleDir,slot,craftNr, 1)
  92.     p.pushItemIntoSlot(turtleDir,slot,craftNr, 2)
  93.     p.pushItemIntoSlot(turtleDir,slot,craftNr, 5)
  94.     p.pushItemIntoSlot(turtleDir,slot,craftNr, 6)
  95.     --p.pushItemIntoSlot(turtleDir,slot,craftNr, 3)
  96.     --p.pushItemIntoSlot(turtleDir,slot,craftNr, 7)
  97.     --p.pushItemIntoSlot(turtleDir,slot,craftNr, 9)
  98.     --p.pushItemIntoSlot(turtleDir,slot,craftNr, 10)
  99.     --p.pushItemIntoSlot(turtleDir,slot,craftNr, 11)
  100.     if turtle.craft() then
  101.         pcall(drop)
  102.     else
  103.         pcall(cleanUp)
  104.         os.sleep(2)
  105.     end
  106. end
  107.  
  108.  
  109. function main()
  110.     quantity = 0
  111.     p.condenseItems()
  112.     while true do
  113.         cleanUp()
  114.         getStacks()
  115.         p.condenseItems()
  116.         print("waiting 1")
  117.         os.sleep(0.4)
  118.     end
  119. end
  120.  
  121. settings()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement