VlaD00m

CycleBlockBreaker

Dec 8th, 2020 (edited)
733
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --CycleBlockBreaker for EEPROM
  2. --Original OpenOS version by Asior (Asioron)
  3. --Expanded EEPROM version by Bs()Dd
  4.  
  5. --[[Minimum requirements:
  6.     *Robot - 1 tier
  7.     In robot:
  8.         *CPU - 1 tier
  9.         *1x Memory - 1 tier
  10.         *Inventory Upgrade
  11.         *EEPROM with flash this code
  12.         *Mining tool
  13.     *Computer with OpenOS for flashing EEPROM
  14.    
  15.     Place the chest on top and put blocks there
  16.     Place the chest at the bottom, there will be loot from blocks
  17. ]]
  18. r = component.proxy(component.list("robot")())
  19. c = component.proxy(component.list("inventory_controller")())
  20. inv = r.inventorySize()
  21.  
  22. speaker = false --Set true for using speaker when something is gone wrong
  23. lowcharge = 0.005 --Set there number maximal working charge in durability() format
  24.  
  25. --Needs Inventory Controller
  26. autocharge = false --Set there number of turns right to charger (for charging tools)
  27. chargesleep = 15 --Set there number of sleep duration while tool is charging
  28.  
  29. function turnNcharge()
  30.   for i = 1, autocharge do
  31.     r.turn(true)
  32.   end
  33.   c.equip()
  34.   r.drop(3, 1)
  35.   local ws = computer.uptime() + chargesleep
  36.   repeat
  37.     computer.pullSignal(ws - computer.uptime())
  38.   until computer.uptime() >= ws
  39.   r.suck(3, 1)
  40.   c.equip()
  41.   for i = 1, autocharge do
  42.     r.turn(false)
  43.   end
  44. end
  45.  
  46. while true do
  47.   local rep = r.suck(1, 64)
  48.   if rep then
  49.     for i = 1, rep do
  50.       while not r.place(3) do
  51.         if speaker then
  52.           computer.beep(1100, 0.5)
  53.         else
  54.           computer.pullSignal(0)
  55.         end
  56.       end
  57.       while not r.swing(3) do
  58.         if speaker then
  59.           computer.beep(1000, 0.5)
  60.         else
  61.           computer.pullSignal(0)
  62.         end
  63.       end
  64.       if r.durability() then
  65.         while r.durability() < lowcharge do
  66.           if autocharge then
  67.             turnNcharge()
  68.           else
  69.             if speaker then
  70.               for i = 1, 10 do
  71.                 computer.beep(700, 0.5)
  72.               end
  73.             else
  74.               local ws = computer.uptime() + 5 --Wating 5 sec, then trying to drop blocks again
  75.               repeat
  76.                 computer.pullSignal(ws - computer.uptime())
  77.               until computer.uptime() >= ws
  78.             end
  79.           end
  80.         end
  81.       end
  82.     end
  83.     for i = 1, inv do
  84.       if r.count(i) > 0 then
  85.         r.select(i)
  86.         while not r.drop(0, 64) or r.count(i) > 0 do
  87.           if speaker then
  88.             for i = 1, 10 do
  89.               computer.beep(700, 0.5)
  90.             end
  91.           else
  92.             local ws = computer.uptime() + 5 --Wating 5 sec, then trying to drop blocks again
  93.             repeat
  94.               computer.pullSignal(ws - computer.uptime())
  95.             until computer.uptime() >= ws
  96.           end
  97.         end
  98.       end
  99.     end
  100.   else
  101.     if speaker then
  102.       for i = 1, 10 do
  103.         computer.beep(500, 0.5)
  104.       end
  105.     else
  106.       local ws = computer.uptime() + 5 --Wating 5 sec, then trying to get blocks again
  107.       repeat
  108.         computer.pullSignal(ws - computer.uptime())
  109.       until computer.uptime() >= ws
  110.     end
  111.   end
  112. end
RAW Paste Data