Advertisement
Guest User

newnuc.lua

a guest
Oct 19th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.61 KB | None | 0 0
  1. local lzhs = {1, 5, 8, 12, 17, 19, 24, 31, 36, 38, 43, 47, 50, 54}
  2.  
  3. local component = require("component")
  4. local event = require("event")
  5. -- local m = component.modem -- get primary modem component
  6. -- m.open(1488)
  7. -- print(m.isOpen(1488)) -- true
  8. -- Send some message.
  9. -- m.broadcast(1488, "Started.")
  10.  
  11. local robot = component.robot
  12. local sides = require("sides")
  13. robot.select(2)
  14.  
  15. local ic = component.inventory_controller
  16.  
  17. -- checking for lapis
  18. function CheckLapis()
  19. local slot = 2
  20. robot.select(2)
  21. local lapisPassed = false
  22.  
  23. while lapisPassed == false do
  24. local item = ic.getStackInInternalSlot(slot)
  25. if item then
  26.   if item.size < 64 then
  27.     ic.suckFromSlot(sides.up, 1, 64 - item.size)
  28.   end
  29. else
  30.   ic.suckFromSlot(sides.up, 1)
  31. end
  32. item = ic.getStackInInternalSlot(slot)
  33. lapisPassed = item.size == 64
  34. if lapisPassed == false then
  35.   print("Too low amount of lapis!")
  36.   os.sleep(2)
  37. end
  38. end
  39. end
  40.  
  41. function wPrint(mes)
  42.   print(mes)
  43. --  m.broadcast(1488, mes)  
  44. end
  45.  
  46. function has_value (tab, val)
  47.     for index, value in ipairs(tab) do
  48.         if value == val then
  49.             return true
  50.         end
  51.     end
  52.  
  53.     return false
  54. end
  55.  
  56. function CheckLZH(slot)
  57.   local lzhitem = ic.getStackInSlot(sides.forward, slot)
  58.   if lzhitem then
  59.     if lzhitem.damage > 40000 then
  60.       wPrint("LZH at slot ".. tostring(slot).. " is damaged.")
  61.     turnOff()
  62.       RepairLZH(slot)
  63.     turnOn()
  64.     end
  65.   end
  66. end
  67.  
  68. function RepairLZH(slot)
  69.   CheckLapis()
  70.   robot.select(1)
  71.   ic.suckFromSlot(sides.forward, slot)
  72.   component.crafting.craft(1)
  73.   PutLZH(slot)
  74. end  
  75.  
  76. function PutLZH(slot)
  77.   ic.dropIntoSlot(sides.forward, slot)
  78. end
  79.  
  80. function GlobalCheckLZHs()
  81.   for i=1, #lzhs do
  82.     CheckLZH(lzhs[i])
  83.   end
  84. end
  85. --RepairLZH(1)
  86. --CheckLZH(1)
  87. --GlobalCheckLZHs()
  88.  
  89. function turnOn()
  90.   component.redstone.setOutput(sides.forward, 15)
  91.   component.redstone.setOutput(sides.back, 15)
  92. end
  93.  
  94. function turnOff()
  95.   component.redstone.setOutput(sides.forward, 0)
  96.   component.redstone.setOutput(sides.back, 0)
  97. end
  98.  
  99. function CheckFuel(slot)
  100.   local fitem = ic.getStackInSlot(sides.forward, slot)
  101.   if fitem then
  102.     if fitem.label == "Quad Fuel Rod (Depleted MOX)" then
  103.     wPrint("Fuel at slot"..tostring(slot).." is depleted.")
  104.     turnOff()
  105.     r.select(1)
  106.     ic.suckFromSlot(sides.forward, slot)
  107.     r.drop(sides.left)
  108.     local item = ic.getStackInSlot(sides.down, 1)
  109.       if item then
  110.     ic.suckFromSlot(sides.down, 1, 1)
  111.     ic.dropIntoSlot(sides.forward, slot)
  112.     end
  113.     end
  114.   end
  115. end
  116.  
  117. function GlobalCheckFuel()
  118.   for i = 1, 54 do
  119.     CheckFuel(i)
  120.   end
  121. end  
  122.  
  123.  
  124. component.redstone.setOutput(sides.right, 15)
  125. while true do
  126.   turnOn()
  127.   GlobalCheckLZHs()
  128. --  GlobalCheckFuel()
  129. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement