Advertisement
bob558

dig3

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