Advertisement
bob558

dig3.01

Dec 18th, 2016 (edited)
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.43 KB | None | 0 0
  1. --Если бур надо заряжать, в первый слот кладем
  2. --энергохранилище во второй ключ, ставим
  3. --на игнор 2 слота и подключаем апгрейд
  4. --контроллера инвентаря
  5. ------------Настройки---------------
  6. incont=false;--заряжать кирку?
  7. slots=32;--количество слотов у робота?
  8. propusk=1;--игнорировать первые N слотов
  9. slotstocheck=2;--выгрузка если заполнены последние N слотов
  10. cobblestone=1
  11. ------------Переменные---------------
  12. local computer = require('computer')
  13. local component = require("component")
  14. if require("component").isAvailable("generator") then
  15.   generator=require("component").generator
  16. end
  17. if require("component").isAvailable("inventory_controller") then
  18.   incontrol=require("component").inventory_controller
  19. end
  20. if require("component").isAvailable("chunkloader") then
  21.   component.chunkloader.setActive(true)
  22.   loader=require("component").chunkloader
  23. end
  24. robot=require("robot")
  25.  
  26. withg=(generator~=nil)
  27. propusk=propusk+1;
  28. coords={x=0,y=0,z=0,side=1}
  29. extcoords={x=0,y=0,z=0,side=1}
  30. sx={0,1,0,-1}
  31. sy={1,0,-1,0}
  32. -------------Функции-----------------
  33. function go() while not robot.forward() do robot.swing()end coords.x=coords.x + sx[coords.side];coords.y = coords.y + sy[coords.side] end
  34. function godown() while not robot.down() do robot.swingDown()end coords.z = coords.z - 1 end
  35. function goup() while not robot.up() do robot.swingUp()end coords.z = coords.z + 1 end
  36. function check() return robot.count(slots-(slotstocheck-1)) > 0 end
  37. function energy() return computer.energy()<((computer.maxEnergy()*10)/100) end
  38. function energy2() return computer.energy()<((computer.maxEnergy()*70)/100) end
  39. function turnLeft() robot.turnLeft(); coords.side = (coords.side + 3)%4;if coords.side == 0 then coords.side =4 end; end
  40. function turnRight() robot.turnRight(); coords.side = (coords.side + 1)%4; if coords.side == 0 then coords.side =4 end; end
  41.  
  42. function tosurf()
  43.     extcoords.x=coords.x
  44.     extcoords.y=coords.y
  45.     extcoords.z=coords.z
  46.     extcoords.side=coords.side
  47.     while coords.z ~= 0 do goup() end
  48.     while coords.side ~= 3 do turnRight() end
  49.     while coords.y ~= 0 do go() end
  50.     turnRight();
  51.     while coords.x ~= 0 do go() end
  52.     turnLeft();
  53. end
  54.  
  55. function back()
  56.     while coords.z ~= extcoords.z do godown() end
  57.     while coords.side~= 1 do turnRight() end
  58.     while coords.y ~= extcoords.y do go() end
  59.     turnRight();
  60.     while coords.x ~= extcoords.x do go() end
  61.     while coords.side ~= extcoords.side do turnRight() end
  62. end
  63.  
  64. function clearinv()
  65.   alreadyhave=false
  66.   for invcounter=propusk,slots do
  67.     robot.select(invcounter)
  68.     if withg then
  69.       suc,error=generator.insert()
  70.       if (error=="selected slot does not contain fuel" or alreadyhave) then
  71.         robot.drop()
  72.       else
  73.         alreadyhave=true
  74.       end
  75.     else
  76.       robot.drop()
  77.     end
  78.   end
  79. robot.select(1)
  80. end
  81.  
  82. function cobbleDel()
  83.   if incontrol.getStackInInternalSlot(cobblestone).name=='minecraft:cobblestone' or 'Mars Cobblestone' then
  84.     if robot.count(cobblestone)>1 then
  85.       robot.select(cobblestone)
  86.       if robot.count()==1 then
  87.         robot.select(1)
  88.       else
  89.         robot.dropDown(robot.count()-1)
  90.         robot.select(1)
  91.       end
  92.     end
  93.   end
  94. end
  95.  
  96. function charg()
  97.   print("Уровень энергии." ,computer.energy())
  98.   if (energy2()) then
  99.     refuel()
  100.   end
  101.   if (computer.energy())<((computer.maxEnergy()*30)/100) then
  102.     print("меньше 30 %")
  103.     while energy() do
  104.       for i=1, 10 do
  105.         os.sleep(20)
  106.         print("Ожидаю ",(10*i)..'%')
  107.       end
  108.     end
  109.   end
  110. end
  111.  
  112. function refuel() -- Заправка генератора
  113.     for invfuel=1,slots do
  114.         robot.select(invfuel)
  115.         generator.insert(33)
  116.         if generator.count() >= 32 then
  117.           print("заправка зевершена")
  118.           print("топлива в генераторе = "..generator.count())
  119.           do break end
  120.         end
  121.     end
  122. end
  123.  
  124. function prevent()
  125. print (("полный? -"),(check()),("энергия -"),(energy())) --,("кирка -"),(robot.durability()>0.01))
  126.     if ((check()) or (energy()))  then
  127.       tosurf()
  128.       clearinv()
  129.       charg()
  130.       back()
  131.     end
  132. end
  133.  
  134. function digrow(n)
  135.   prevent()
  136.   robot.swingUp()
  137.   robot.swingDown()
  138.   for k=1,n do
  139.     go()
  140.     robot.swingUp()
  141.     robot.swingDown()
  142.     cobbleDel()
  143.     prevent()
  144.   end
  145. end
  146. function digdim(x,y)
  147.   godown()
  148.   godown()
  149.   for n=1,y do
  150.     if tl then turnLeft() else turnRight() end
  151.     digrow(ex)
  152.     if tl then turnRight() else turnLeft() end
  153.     tl = not tl
  154.     if n==y then print("ok") else go() end
  155.   end
  156.   turnRight();
  157.   turnRight();
  158.   tl= not tl
  159. end
  160. ------------Глав прог-----------------
  161. x,y,z=...
  162. tl=false
  163. x=x+0
  164. y=y+0
  165. z=z+0
  166. ex=x-1
  167. fullz=(z-z%3)/3
  168. print("Fullz = " .. fullz)
  169. refuel()
  170. do
  171. if incont==true then
  172.   if (incontrol~=nil)==false then
  173.     print("!!!ОШИБКА!!!")
  174.     print("Вы забыли установить контроллер инвентаря, зарядка невозможна без него")
  175.     print("Продолжить работать без него?(1-продолжить, 0-выйти)")
  176.     a=io.read(1)
  177.     if a=='1' then
  178.       print('Продолжаем работать, зарядка отключена')
  179.       incont=false;
  180.     else
  181.       print('Инициализация выхода...')
  182.       os.sleep(3)
  183.       computer.shutdown()
  184.     end
  185.   else
  186.     print('Контроллер инвентаря подключен, бур будет заряжаться, не забудьте положить энергохранилище и ключ')
  187.   end
  188. else
  189.   print('Зарядка рабочего инструмента отключена')
  190. end
  191. end
  192. print('Запуск генератора... ',generator~=nil)
  193. print('Запуск чанклодера... ',loader~=nil)
  194. print('Объем рабочей зоны - ',x*y*z,' м^3, будет добыто ~',math.ceil((x*y*z)/64))
  195. print('Проверка завершена, запуск...')
  196. for i=1,fullz do
  197.   digdim(x,y)
  198.   godown()
  199. end
  200. if fullz*3==z then
  201.   elseif fullz*3+1==z then
  202.     goup();
  203.     goup();
  204.     digdim(tl,x,y)
  205. else
  206.   goup();
  207.   digdim(tl,x,y)
  208. end
  209. tosurf()
  210. clearinv()
  211. computer.shutdown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement