Advertisement
NeerdOner

Untitled

Aug 21st, 2019
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.72 KB | None | 0 0
  1. local spaceBetweenRows = 2
  2. local spaceBetweenTorches = 10
  3. local currentRow, currentLength, currentHeight, rows, length, height = 1, 1, 1, 1, 1
  4. local sunduk
  5. local turtle = require("robot");
  6.  
  7. local fuels = {
  8.         lava = "minecraft:lava_bucket",
  9.         coal = "minecraft:coal",
  10. }
  11.  
  12. local function text(x, y, text)
  13.         print(text)
  14. end
  15.  
  16. local function refuel()
  17.         local fuelLevel = turtle.getFuelLevel()
  18.         local bucketSlot
  19.  
  20.         if fuelLevel ~= "unlimited" or fuelLevel < 10 then
  21.                 for i = 1, 16 do
  22.                         local itemDetail = turtle.getItemDetail(i) or {name = "huy"}
  23.  
  24.                         if itemDetail.name == "minecraft:lava_bucket" then
  25.                                 local oldSlot = turtle.getSelectedSlot()
  26.                                 turtle.select(i)
  27.                                 turtle.refuel()
  28.                                 turtle.select(oldSlot)
  29.  
  30.                                 return true
  31.                         else
  32.                                 for key, value in pairs(fuels) do
  33.                                         if itemDetail.name == value then
  34.                                                 local oldSlot = turtle.getSelectedSlot()
  35.                                                 turtle.select(i)
  36.                                                 turtle.refuel()
  37.                                                 turtle.select(oldSlot)
  38.  
  39.                                                 return true
  40.                                         end
  41.                                 end
  42.                         end
  43.                 end
  44.  
  45.                 return false
  46.         end
  47. end
  48.  
  49. local function turnBack()
  50.         turtle.turnLeft()
  51.         turtle.turnLeft()
  52. end
  53.  
  54. local function placeSunduk()
  55.         for i = 1, 16 do
  56.                 local itemDetail = turtle.getItemDetail(i) or {name = "huy"}
  57.  
  58.                 if itemDetail.name == "minecraft:chest" then
  59.                         turnBack()
  60.                         sunduk = i
  61.                         local oldSlot = turtle.getSelectedSlot()
  62.                         turtle.select(i)
  63.                         turtle.dig()
  64.                         turtle.place()
  65.                         turtle.select(oldSlot)
  66.                         turnBack()
  67.  
  68.                         return 0
  69.                 end
  70.         end
  71. end
  72.  
  73. local function placeTorch()
  74.         for i = 1, 16 do
  75.                 local itemDetail = turtle.getItemDetail(i) or {name = "huy"}
  76.  
  77.                 if itemDetail.name == "minecraft:torch" then
  78.                         local oldSlot = turtle.getSelectedSlot()
  79.                         turtle.select(i)
  80.                         turtle.placeDown()
  81.                         turtle.select(oldSlot)
  82.  
  83.                         return 0
  84.                 end
  85.         end
  86. end
  87.  
  88.  
  89. local function kopat(direction)
  90.  
  91.         refuel()
  92.  
  93.         if turtle.getFuelLevel() == 0 then error("Out of fuel!") end
  94.  
  95.  
  96.         if direction == "forward" then
  97.                 turtle.dig()
  98.                 turtle.attack()
  99.                 if not turtle.forward() then kopat(direction) end
  100.         elseif direction == "up" then
  101.                 turtle.digUp()
  102.                 turtle.attackUp()
  103.                 if not turtle.up() then kopat(direction) end
  104.         elseif direction == "down" then
  105.                 turtle.digDown()
  106.                 turtle.attackDown()
  107.                 if not turtle.down() then kopat(direction) end
  108.         else
  109.                 turtle.dig()
  110.         end
  111. end
  112.  
  113. ------------------------------------------------------------------------------------------------------------------------
  114.  
  115. text(2, 2, "Skolko ryadov: ")
  116. rows = tonumber(io.read())
  117. text(2, 4, "Dlina ryada: ")
  118. length = tonumber(io.read())
  119. text(2, 6, "Visota ryada: ")
  120. height = tonumber(io.read())
  121.  
  122. placeSunduk()
  123.  
  124. kopat("up")
  125.  
  126. for r = 1, rows do
  127.         currentRow = r
  128.  
  129.         --Копать в высоту
  130.  
  131.         for h = 1, height do
  132.                 currentHeight = h
  133.  
  134.                 --Копать вперед
  135.                 for l = 1, length do
  136.                         currentLength = l
  137.  
  138.                         kopat("forward")
  139.                         turtle.digUp()
  140.                         turtle.digDown()
  141.  
  142.                         if h == 1 and l % (spaceBetweenTorches + 1) == 0 then
  143.                                 placeTorch()
  144.                         end
  145.                 end
  146.  
  147.                 --Возврат назад по длине
  148.                 turnBack()
  149.                 for l = 1, length do
  150.                         currentLength = length - l + 1
  151.  
  152.                         kopat("forward")
  153.                 end
  154.                 turnBack()
  155.  
  156.                 --Копать выше
  157.                 if h < height then
  158.                         for i = 1, 3 do
  159.                                 kopat("up")
  160.                         end
  161.                 end
  162.         end
  163.  
  164.         --Возврат назад по высоте
  165.         for i = 1, ((height - 1) * 3) do
  166.                 kopat("down")
  167.         end
  168.  
  169.         turtle.turnRight()
  170.  
  171.         if r < rows then
  172.                 for i = 1, (spaceBetweenRows + 1) do
  173.                         kopat("forward")
  174.                         turtle.digUp()
  175.                         turtle.digDown()
  176.                 end
  177.         end
  178.  
  179.         turtle.turnLeft()
  180.  
  181. end
  182.  
  183. turtle.turnLeft()
  184.  
  185. for i = 1, ((rows - 1) * (spaceBetweenRows + 1)) do
  186.         kopat("forward")
  187. end
  188.  
  189. kopat("down")
  190.  
  191. if sunduk then
  192.         turtle.turnLeft()
  193.         for i = 1, 16 do
  194.                 turtle.select(i)
  195.                 turtle.drop()
  196.         end
  197.         turtle.turnRight()
  198. end
  199.  
  200. turtle.turnRight()
  201.  
  202.  
  203. text(2, 2, "Done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement