Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 1.75 KB | None | 0 0
  1. rIronName = "IC2:item.itemIngotAdvIron"
  2. cCableName = "IC2:item.ic2cable"
  3. glassName = "minecraft:glass"
  4. coalDustName = "IC2:item.itemDustCoal"
  5. redstoneName = "minecraft:redstone"
  6. tinName = "IC2:item.itemIngotTin"
  7. cobbleName = "minecraft:cobblestone"
  8. circuitName = "IC2:item.itemPartCircuit"
  9. generatorName = "IC2:blockGenerator"
  10. furnaceName = "minecraft:furnace"
  11. casingName = "IC2:blockMachine"
  12. batteryName = "IC2:item.itemBatRE"
  13.  
  14. items = {}
  15.  
  16. function findNextEmptySlot()
  17.     for x=1,16 do
  18.         if turtle.getItemCount(x) == 0 then
  19.             return x
  20.         end
  21.     end
  22. end
  23.  
  24. function listenForRequest()
  25.     print("Waiting on item to be requested from my buddy...")
  26.     sID, msg, prot = rednet.receive("solar")
  27.     print("My buddy requested: " .. msg[2] .. " " .. msg[1])
  28.     return msg
  29. end
  30.  
  31. function findItem(itemName)
  32.     for k,v in ipairs(items) do
  33.         if v.name == itemName then
  34.             return k
  35.         end
  36.     end
  37.     return 0
  38. end
  39.  
  40. function giveItems(slotNum, count)
  41.     turtle.select(slotNum)
  42.     turtle.dropDown(count)
  43.     print("Gave my buddy " .. count .. " " .. items[slotNum].name)
  44.     rednet.send(11,"Sent",solar")
  45.     items[slotNum].count = items[slotNum].count - count
  46.     if items[slotNum].count == 0 then
  47.         items[slotNum] = nil
  48.     end
  49. end
  50.  
  51. function rescanInv()
  52.     for x=1,16 do
  53.         tmp = turtle.getItemDetail(x)
  54.         if tmp ~= nil then
  55.             items[x] = tmp
  56.         end
  57.     end
  58. end
  59.  
  60. function getAll()
  61.     rescanInv()
  62.     for x=1,16 do
  63.         slot = findNextEmptySlot()
  64.         if slot == 0 then
  65.             return
  66.         end
  67.         turtle.select(slot)
  68.         turtle.suck()
  69.         items[slot] = turtle.getItemDetail(x)
  70.     end
  71. end
  72.  
  73. rednet.open("right")
  74. running = true
  75. while running do
  76.     getAll()
  77.     item = listenForRequest()
  78.     i = findItem(item[1])
  79.     if i ~= 0 and turtle.getItemDetail(i).count >= item[2] then
  80.         giveItems(i, item[2])
  81.     end
  82. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement