Advertisement
Dima99

miner

Aug 25th, 2015
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.91 KB | None | 0 0
  1. --Russian version/Русская версия
  2. --Past version/Прошлая версия: http://pastebin.com/e46ZkmEm (ComputerCraft)
  3. --options/настройки
  4. VERSION = "3.0.1"
  5. NAME = "miner"
  6. TORCHSLOT = 1
  7. BLOCKSLOT = 2
  8. CHESTSLOT = 16
  9. TORCHDIST = 10
  10. CLEVERTORCHING = true
  11. CHESTS = false --не реализовано
  12.  
  13. --variables/переменные
  14. arg = { ... }
  15. version = "v3.0.1b"
  16. robot = require("robot")
  17. term = require("term")
  18. sides = require("sides")
  19.  
  20. --functions/функции
  21.  
  22. function cotorch(dist, tdist)
  23.  local col = math.floor(dist/tdist)
  24.  return col
  25. end
  26.  
  27. function torch()
  28.  if robot.count(TORCHSLOT) ~= 0 then
  29.   robot.back()
  30.   if CLEVERTORCHING == true then
  31.    robot.down()
  32.    os.sleep(0.1)
  33.    if not robot.detectDown() then
  34.     robot.select(BLOCKSLOT)
  35.     robot.placeDown()
  36.    end
  37.    robot.up()
  38.    robot.select(TORCHSLOT)
  39.    robot.placeDown()
  40.    else robot.select(TORCHSLOT)
  41.    robot.placeDown()
  42.   end
  43.   robot.forward()
  44.  end
  45. end
  46.  
  47. function testitems()
  48.  local relay = true
  49.  local relayone = true
  50.  while relay do
  51.   local torchcount = robot.count(TORCHSLOT)
  52.   if torchcount == 0 then
  53.    term.clear()
  54.    print("Положите несколько факелов в слот "..tostring(TORCHSLOT))
  55.    os.sleep(2)
  56.    else relay = false
  57.   end
  58.  end
  59.  if CHESTS == true then
  60.   while realyone do
  61.    local chestcount = robot.count(CHESTSLOT)
  62.    if chestcount == 0 then
  63.     term.clear()
  64.     print("Положите несколько сундуков в слот "..tostring(CHESTSLOT))
  65.     os.sleep(2)
  66.     else relayone = false
  67.    end
  68.   end
  69.  end
  70. end
  71.  
  72. function dig()
  73.  repeat robot.swing(sides.front)
  74.  os.sleep(0.1)
  75.  until not robot.detect()
  76. end
  77.  
  78. function digUp()
  79.  repeat robot.swingUp()
  80.  os.sleep(0.1)
  81.  until not robot.detectUp()
  82. end
  83.  
  84. function digDown()
  85.  robot.swingDown()
  86. end
  87.  
  88. --body/тело
  89.  
  90. if #arg < 1 then
  91.  print("Использование: "..NAME.." <distance>")
  92.  return
  93.  elseif tonumber(arg[1]) < 1 then
  94.  print("Дистанция должна быть больше нуля")
  95.  return
  96. end
  97. col = cotorch(arg[1], TORCHDIST)
  98. if col > 64 then
  99.  print("Нужно более стака факелов")
  100.  print("Часть пути будет не освещена")
  101.  print("Всё равно продолжить? y/n")
  102.  answ = read()
  103.  if ans == "n" then
  104.   return
  105.  end
  106. end
  107. testitems()
  108.  
  109. --main/главное
  110.  
  111. print("Нужно "..col.." факелов")
  112. print("Нажмите Enter для начала")
  113. print("Введите cancel для отмены")
  114. qwe = io.read()
  115. if qwe == "cancel" then
  116.  print("Отменено")
  117.  os.sleep(1)
  118.  term.clear()
  119.  return
  120. end
  121. light = 1
  122. dig()
  123. robot.forward()
  124. for i = 1, arg[1]-1 do
  125.  digUp()
  126.  digDown()
  127.  dig()
  128.  robot.forward()
  129.  if light == TORCHDIST then
  130.   torch()
  131.   light = 0
  132.   else light = light + 1
  133.  end
  134. end
  135. digUp()
  136. digDown()
  137. if light == TORCHDIST then
  138.  torch()
  139. end
  140. print("Сделано!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement