Advertisement
Romanok2805

Untitled

May 20th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.33 KB | None | 0 0
  1. local component = require("component")
  2. local c = component.crafting
  3. local ic = component.inventory_controller
  4. local r = require("robot")
  5.  
  6. numslot = ic.getInventorySize(1)
  7. hotslotchest = 0
  8. if numslot == nil then
  9.     print("Сундук над роботом не найден!")
  10. else
  11.     print("Всего слотов в сундуке:"..numslot)
  12. end
  13. if(ic.getStackInSlot(1,1) ~= nil) then
  14.     if(ic.getStackInSlot(1,1)["label"] == "Diamond Hoe") then
  15.         print("Путь:"..os.getenv("PWD"))
  16.         file = io.open(os.getenv("PWD") .."/curentcraft.txt","w")
  17.         for j = 2, 10 do
  18.             if ic.getStackInSlot(1,j) == nil then
  19.                 item = "<empty>"
  20.             else
  21.                 item = ic.getStackInSlot(1,j)["label"]
  22.             end
  23.             file:write(item.."\n")
  24.         end
  25.         file:close()
  26.         print("Крафт успешно записан!")
  27.         os.exit()
  28.     end
  29. end
  30. file = io.open(os.getenv("PWD") .."/curentcraft.txt","r")
  31. if file == nil then
  32.     print("Файл крафта не найден!")
  33.     os.exit()
  34. end
  35. local arr = {}
  36. for line in file:lines() do
  37.     table.insert (arr, line);
  38. end
  39. file:close()
  40. setkacrafta = {1,2,3,5,6,7,9,10,11}
  41. itemforcraft = {arr[1], arr[2], arr[3],arr[4],arr[5],arr[6],arr[7],arr[8],arr[9]}
  42. r.select(4)
  43.  
  44. local function craftthis(counts)
  45.     i = 0
  46.     while i < counts do
  47.         c.craft(64)
  48.         r.dropUp(64)
  49.         i = i + 1
  50.     end
  51. end
  52.  
  53. function loadItem(robotslot, chestslot)
  54.     if chestslot == 0 then
  55.         print("В сундуке не найден нужный предмет!")
  56.         unloadallitem()
  57.     else
  58.         ic.suckFromSlot(1,chestslot,64)
  59.         r.transferTo(robotslot,64)
  60.     end
  61. end
  62.  
  63. function unloadallitem()
  64. for j = 1, 16 do
  65. r.select(j)
  66. r.dropUp(64)
  67. end
  68. r.select(4)
  69. end
  70.  
  71. function finditem(nameitem)
  72. onlyfirst = 0
  73. Cnumslot = numslot
  74. i = hotslotchest
  75. ::startfind::
  76. while i < Cnumslot do
  77. i = i + 1
  78. ItemStack = ic.getStackInSlot(1,i)
  79.  if ItemStack ~= nil then
  80.  if ic.getStackInSlot(1,i)["label"] == nameitem then
  81.  hotslotchest = i
  82.  return i
  83.  end
  84.  end
  85. end
  86. i = 0
  87. Cnumslot = hotslotchest
  88. onlyfirst = onlyfirst + 1
  89. if onlyfirst == 1 then goto startfind end
  90. return 0
  91. end
  92.  
  93. while true do
  94. craftthis(1)
  95.     for j = 1, 9 do
  96.         if itemforcraft[j] ~= "<empty>" then
  97.             if r.count(setkacrafta[j]) < 1 then
  98.                 print("Кончилось "..itemforcraft[j].." в слоте "..setkacrafta[j].."...")
  99.                 loadItem(setkacrafta[j],finditem(itemforcraft[j]))
  100.             end
  101.         end
  102.     end
  103. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement