Advertisement
bob558

Авоткрафт

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