Karnel

builder_CC

May 4th, 2022 (edited)
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. local length = 40
  2. local height = 5
  3. local width = 5
  4.  
  5. local function select_block()
  6.     for slot=1,16 do
  7.         if turtle.getItemCount(slot) ~= 0 then
  8.             turtle.select(slot)
  9.             return true
  10.         end
  11.     end
  12.     return false
  13. end
  14.  
  15. local function build_step()
  16.     if select_block() then
  17.         turtle.placeDown()
  18.         return true
  19.     end
  20.     return false
  21. end
  22.  
  23. local function build_line()
  24.     for i=1, length-1 do
  25.         build_step()
  26.         turtle.forward()
  27.     end
  28.     build_step()
  29. end
  30.  
  31. local function build_flat()
  32.     for i=1, width -1 do
  33.         build_line()
  34.         if math.fmod(i, 2) == 1 then
  35.             turtle.turnRight()
  36.             turtle.forward()
  37.             turtle.turnRight()
  38.         else
  39.             turtle.turnLeft()
  40.             turtle.forward()
  41.             turtle.turnLeft()
  42.         end
  43.     end
  44.     build_line()
  45. end
  46.  
  47. local function build_volume()
  48.     for i=1, height-1 do
  49.         build_flat()
  50.         turtle.turnLeft()
  51.         turtle.turnLeft()
  52.         turtle.up()
  53.     end
  54.     build_flat()
  55.     if math.fmod(height, 2) == 1 then
  56.         turtle.turnLeft()
  57.         for i=1, width-1 do
  58.             turtle.forward()
  59.         end
  60.         turtle.turnLeft()
  61.         for i=1, length-1 do
  62.             turtle.forward()
  63.         end
  64.     end
  65.     turtle.forward()
  66.     for i=1, height do
  67.         turtle.down()
  68.     end
  69.     turtle.turnLeft()
  70.     turtle.turnLeft()
  71. end
  72.  
  73. need_fuel = height*width*length+length+width+height
  74. print("Fuel: "..turtle.getFuelLevel())
  75. print("Need: "..need_fuel)
  76. if turtle.getFuelLevel() > need_fuel then
  77.     turtle.up()
  78.     build_volume()
  79. else
  80.     print("not enough fuel!!!")
  81. end
  82. print("Fuel: "..turtle.getFuelLevel())
Add Comment
Please, Sign In to add comment