Advertisement
BlueMarble

Lua CC BuilderAPI

Sep 2nd, 2015
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.65 KB | None | 0 0
  1. local builder = {}
  2.  
  3.  
  4. function builder.clearDig()
  5.    while turtle.detect() do
  6.       turtle.dig()
  7.       sleep(1.5)
  8.    end
  9. end
  10. function builder.clearCurs()
  11.     term.clear()
  12.     term.setCursorPos(1,1)
  13. end
  14. function builder.blockCheck()
  15.     turtle.select(1)
  16.     for exa1 = 1, 16, 1 do
  17.         turtle.select(exa1)
  18.         sp = turtle.getItemSpace()
  19.         print(sp)
  20.         if sp > 0 and sp < 64 and compareTo(desSlot) then
  21.             for exa2 = 16, exa1, -1 do
  22.                 turtle.select(exa2)
  23.                 co = turtle.getItemCount()
  24.                 if co < sp then
  25.                     if turtle.compareTo(exa1) then
  26.                         turtle.transferTo(exa1, co)
  27.                     end
  28.                 else
  29.                     if turtle.compareTo(exa1) then
  30.                         turtle.transferTo(exa1, sp)
  31.                     end
  32.                 end
  33.             end
  34.         end
  35.     end
  36.     local s = 0
  37.     for i = 1, 16, 1 do
  38.         turtle.select(i)
  39.         if turtle.compareTo(1) then
  40.             s = s + turtle.getItemCount()
  41.         end
  42.     end
  43.     if not (s%64 == 0) then
  44.         ss = (math.floor(s/64).. " stacks and "..s-(math.floor(s/64)*64).." blocks.")
  45.     else
  46.         ss = (math.floor(s/64).. " stacks.")
  47.     end
  48.     print("Amount of blocks left for building: \n"..s.." blocks, or "..ss)
  49. end
  50. function builder.fuelCheck()
  51.     clearCurs()
  52.     fuell = turtle.getFuelLevel()
  53.     print("Total fuel: "..fuell)
  54.     if (fuell < 120) then
  55.         print("That's not enough! Refueling...")
  56.         for i = 2, 16, 1 do
  57.             turtle.select(i)
  58.             if not turtle.compareTo(1) then
  59.                 turtle.refuel()
  60.             end
  61.         end
  62.         print("Refueled; the total fuel now is: "..turtle.getFuelLevel())
  63.     end
  64.     clearCurs()
  65.     sfuell = turtle.getFuelLevel()
  66.     if sfuell < 120 then
  67.         print("There wasn't enough fuel to refuel with, enter 'OK' when you put fuel inside the inventory")
  68.         refuelOK = read()
  69.         print("I lied, I can't read, I'll just assume you entered 'OK'")
  70.         sleep(1)
  71.     end
  72.     turtle.select(1)
  73. end
  74. function builder.doubleCheck()
  75.     blockCheck()
  76.     fuelCheck()
  77. end
  78. function builder.platform(platformz, platformx, digdown)
  79.     if not (digdown == true) or not (digdown == false) or (platformz == null) or (platformx == null) then
  80.         clearCurs()
  81.         print("You did it wrong, maggot!")
  82.         print("Usage:")
  83.         print("platform(<length>, <width>, <true or false>)")
  84.         shell.exit()
  85.     end
  86.     --[[builds a basic platform of variable size,
  87.     USAGE: platform(length, width, boolean);
  88.     (if you set the boolean to 'true', you will give the order to replace every block underneath)]]
  89.     local x = platformz
  90.     local z = platformx
  91.     for i = 2, z, 1 do
  92.         row(x, digdown)
  93.         turtle.turnRight()
  94.         while turtle.detect() do
  95.             turtle.dig()
  96.             sleep(2)
  97.         end
  98.         turtle.forward()
  99.         turtle.turnLeft()
  100.     end
  101.     row(x)
  102. end
  103. function builder.row(rowx, rowdigdown)
  104.     --[[builds a basic row of variable length
  105.     USAGE: platform(length, boolean);
  106.     (if you set the boolean to 'true', you will give the order to replace every block underneath)]]
  107.     local x = rowx
  108.     local pdown = rowdigdown
  109.     for i = 2, x, 1 do
  110.         while turtle.detect() do
  111.             turtle.dig()
  112.             sleep(1.5)
  113.         end
  114.         if (pdown == true) then
  115.             turtle.digDown()
  116.             turtle.placeDown()
  117.         end
  118.         turtle.forward()
  119.     end
  120.     turtle.digDown()
  121.     while turtle.detect() do
  122.         turtle.dig()
  123.         sleep(2)
  124.     end
  125.     turtle.placeDown()
  126.     for i = 2, z, 1 do
  127.         turtle.back()
  128.     end
  129. end
  130. function builder.wall(wallx, wallz)
  131.     --[[builds a basic wall of variable size,
  132.     USAGE: wall(length, width)]]
  133.     local z = wallz
  134.     local x = wallx
  135.     for i = 0, 1, 1 do
  136.         for u = 2, x, 1 do
  137.             turtle.forward()
  138.             turtle.placeDown()
  139.             if (y % x/3 == 0) or (y % 6 == 0)  then
  140.                 doubleCheck()
  141.             end
  142.         end
  143.         turtle.turnRight()
  144.     end
  145. end
  146. function builder.reltogr()
  147.     print("Enter where you'd like the building to be, relative to the ground")
  148.     yg = tonumber(read())
  149.     clearCurs()
  150.     if yg > 0 then
  151.         for i = 1, yg, 1 do
  152.             while turtle.detectUp() do
  153.                 turtle.digUp()
  154.                 sleep(1.5)
  155.             end
  156.             turtle.up()
  157.         end
  158.     else
  159.         for i = 1, math.abs(yg), 1 do
  160.             turtle.digDown()
  161.             turtle.down()
  162.         end
  163.     end
  164. end
  165. function builder.turtleName()
  166.     if shell.run("label", "get") == "No Computer label" then
  167.     shell.run("label", "set ", "Builder")
  168.     end
  169. end
  170. function builder.box(width, length, height)
  171.     local x = width
  172.     local z = length
  173.     local y = height
  174.     function wallUp(y)
  175.         doubleCheck()
  176.         for local i = 2, y, 1 do
  177.             if turtle.detectUp() then
  178.                 turtle.digUp()
  179.             end
  180.             turtle.up()
  181.             turtle.placeDown()
  182.         end
  183.     end
  184.     function forwDecline(y)
  185.         doubleCheck()
  186.         turtle.dig()
  187.         turtle.forward()
  188.         for local i = 2, y, 1 do
  189.             if turtle.detectDown() then
  190.                 turtle.digDown()
  191.             end
  192.             turtle.down()
  193.         end
  194.        for i = 2, y, 1 do
  195.           turtle.placeDown()
  196.           turtle.up()
  197.        end
  198.     end
  199.     function floof(y)
  200.        for i = 2, y, 1 do
  201.           if turtle.detectDown() then
  202.              turtle.digDown()
  203.           end
  204.           turtle.down()
  205.        end
  206.        turtle.placeDown()
  207.        for i = 2, y, 1 do
  208.           turtle.up()
  209.        end
  210.        turtle.placeDown()
  211.     end
  212.     function row(y, z)
  213.        floof(y)
  214.        for i = 4, z, 1 do
  215.           clearDig()
  216.           turtle.forward()
  217.           floof(y)
  218.        end
  219.        for i = 4, z, 1 do
  220.           turtle.back()
  221.        end
  222.     end
  223.     for i = 0, 1, 1 do
  224.         for i = 2, z, 1 do
  225.             wallUp(y)
  226.             clearDig()
  227.             turtle.forward()
  228.         end
  229.         turtle.turnRight()
  230.         for i = 2, x, 1 do
  231.             wallUp(y)
  232.             clearDig()
  233.             turtle.forward()
  234.         end
  235.     end
  236.     clearDig()
  237.     turtle.forward()
  238.     turtle.turnRight()
  239.     clearDig()
  240.     turtle.forward()
  241.     turtle.turnLeft()
  242.     clearDig()
  243.     row(y, z)
  244.     for i = 4, x, 1 do
  245.        turtle.turnRight()
  246.        clearDig()
  247.        turtle.forward()
  248.        turtle.turnLeft()
  249.        row(y, z)
  250.     end
  251.     turtle.turnLeft()
  252.     for i = 3, x, 1 do
  253.        turtle.forward()
  254.     end
  255. end
  256.  
  257. return builder
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement