Andronio12

GeoMiner

Mar 20th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.02 KB | None | 0 0
  1. -- GeoMiner by Andronio and Orlin c помощью Fingercomp
  2. local fs = require("filesystem")
  3. local cmp = require("component")
  4. local comp = require("computer")
  5. local term = require("term")
  6. local event = require("event")
  7. local genIsOn = false
  8. local iscompatlib = false -- поставьте на true, если хотите убрать проверку на доработанную версию библиотеки robot.lua
  9. local gotnewdrivers = false
  10. if not iscompatlib then
  11.   io.write('Вы используете апгрейднутую версию либы robot.lua? [y/n] ')
  12.   local z = io.read()
  13.   if z == "N" or z == "n" then
  14.     if cmp.isAvailable('internet') then
  15.       print('Удаляю старую либу...')
  16.       os.execute('rm /lib/robot.lua')
  17.       print('Скачиваю апгрейднутую версию...')
  18.       os.execute('pastebin get vq8nVTRy /lib/robot.lua')
  19.       gotnewdrivers = true
  20.     else
  21.       print('Подключите интернет карту!')
  22.       os.exit()
  23.     end
  24.   end
  25.   if z ~= "Y" and z ~= "y" and z ~= "n" and z ~= "N" then
  26.     print('Введено неверное значение!')
  27.     os.exit()
  28.   end
  29. end
  30. if not fs.exists("/lib/rl.lua") then
  31.   print('Отсутствуют библиотека rl.lua!')
  32.   if cmp.isAvailable('internet') then
  33.     print('Начинаю скачивание...')
  34.     os.execute('pastebin get 6Nge8Lji /lib/rl.lua')
  35.     gotnewdrivers = true
  36.   else
  37.     print('Подключите интернет карту!')
  38.     os.exit()
  39.   end
  40.   io.write('Для стабильной работы требуется перезагрузка! Перезагрузить сейчас? [y/n] ')
  41.   local i = io.read()
  42.   if i == "N" or i == "n" then
  43.     print('Перезагрузка отменена!')
  44.     os.sleep(0.5)
  45.     term.clear()
  46.     os.exit()
  47.   end
  48.   if i == "Y" or i == "y" then
  49.     os.execute('reboot')
  50.   end
  51.   if i ~= "Y" and i ~= "y" and i ~= "n" and i ~= "N" then
  52.     print('Перезагрузка отменена!')
  53.     os.sleep(0.5)
  54.     term.clear()
  55.     os.exit()
  56.   end
  57. end
  58. if gotnewdrivers then
  59.   io.write('Для стабильной работы требуется перезагрузка! Перезагрузить сейчас? [y/n] ')
  60.   local i = io.read()
  61.   if i == "N" or i == "n" then
  62.     print('Перезагрузка отменена!')
  63.     os.sleep(0.5)
  64.     term.clear()
  65.     os.exit()
  66.   end
  67.   if i == "Y" or i == "y" then
  68.     os.execute('reboot')
  69.   end
  70.   if i ~= "Y" and i ~= "y" and i ~= "n" and i ~= "N" then
  71.     print('Перезагрузка отменена!')
  72.     os.sleep(0.5)
  73.     term.clear()
  74.     os.exit()
  75.   end
  76. end
  77. local rl = require("rl")
  78. local r = require("robot")
  79.  
  80. local ic = cmp.inventory_controller
  81. local gl = cmp.geolyzer
  82.  
  83. local wasteList = {
  84.   'minecraft:cobblestone',
  85.   'minecraft:sandstone',
  86.   'minecraft:stone',
  87.   'minecraft:dirt',
  88.   'minecraft:grass',
  89.   'minecraft:sand',
  90.   'minecraft:end_stone',
  91.   'minecraft:hardened_clay',
  92.   'minecraft:mossy_cobblestone',
  93.   'minecraft:torch',
  94.   'minecraft:nether_brick',
  95.   'minecraft:nether_brick_fence',
  96.   'minecraft:nether_brick_stairs',
  97.   'minecraft:netherrack',
  98.   'minecraft:soul_sand',
  99.   'chisel:diorite',
  100.   'chisel:andesite',
  101.   'chisel:marble',
  102.   'chisel:woolen_clay'
  103. }
  104. local fuelList = {
  105.   'minecraft:planks',
  106.   'minecraft:coal',
  107.   'Railcraft:fuel.coke',
  108.   'minecraft:fence',
  109.   'minecraft:stick'
  110. }
  111. term.clear()
  112. r.logPath(true)
  113. local invSize = r.inventorySize()
  114.  
  115. function ExtGen()
  116.   if cmp.isAvailable('generator') then
  117.     if cmp.generator.count() == 0 and genIsOn == true then
  118.       genIsOn = false
  119.     end
  120.     if genIsOn == false then
  121.       if (comp.energy()/comp.maxEnergy() < 0.33) then
  122.         local foundFuel = false
  123.         for slot = 1, invSize do
  124.           local stack = ic.getStackInInternalSlot(slot)
  125.           if stack then
  126.             if rl.tblChk(stack.name, fuelList) then
  127.               r.select(slot)
  128.               foundFuel = true
  129.               if cmp.generator.insert(stack.size) then
  130.                 rl.report('Заряд упал ниже 33%. Генератор был активирован')
  131.               end
  132.               genIsOn = true
  133.               break
  134.             end
  135.           end
  136.         end
  137.         if not foundFuel then
  138.           r.select(1)
  139.         end
  140.       end
  141.     end
  142.     if comp.energy()/comp.maxEnergy() > 0.5 and genIsOn == true then
  143.       cmp.generator.remove(cmp.generator.count())
  144.       genIsOn = false
  145.       rl.report('Достигнуто 50%. Выключение генератора')
  146.     end
  147.   else
  148.     event.cancel(genTimer)
  149.   end
  150. end
  151. function GenOn(bool)
  152.   if bool == true then
  153.     local genTimer = event.timer(5, ExtGen, math.huge)
  154.   else
  155.     print("Генератор выключен!")
  156.   end
  157. end
  158. function dropWaste()
  159.   for slt = 1, invSize do
  160.     local stck = ic.getStackInInternalSlot(slt)
  161.     if stck then
  162.       if rl.tblChk(stck.name, wasteList) then
  163.         r.select(slt)
  164.         r.drop()
  165.       end
  166.     end
  167.   end
  168.   r.select(1)
  169. end
  170.  
  171.  
  172. rl.CL(true)
  173. GenOn(true)
  174.  
  175. while true do
  176.   os.sleep()
  177. end
Add Comment
Please, Sign In to add comment