Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.81 KB | None | 0 0
  1. local INVENTORY_SIZE = 16
  2. local FUEL_SLOT = 1
  3.  
  4. local function getNumberFromUser(message)
  5.     print(message)
  6.     local raw = io.read()
  7.     number = tonumber(raw)
  8.     return number
  9. end
  10.  
  11. local function getFirstSlotContainingBlocks()
  12.     for slot = 1, INVENTORY_SIZE do
  13.         local itemCount = turtle.getItemCount(slot)
  14.         if slot ~= FUEL_SLOT and itemCount > 0 then
  15.             return slot
  16.         end
  17.     end
  18.     return -1
  19. end
  20.  
  21. local function hasEnoughFuel()
  22.     return turtle.getFuelLevel() > 16
  23. end
  24.  
  25. local function refuel()
  26.     turtle.select(FUEL_SLOT)
  27.     turtle.refuel(1)
  28. end
  29.  
  30. local function checkFuel()
  31.     if not hasEnoughFuel() then
  32.         refuel()
  33.     end
  34. end
  35.  
  36. local function arcRight()
  37.     turtle.forward()
  38.     turtle.turnRight()
  39.     turtle.forward()
  40.     turtle.turnRight()
  41. end
  42.  
  43. local function arcLeft()
  44.     turtle.forward()
  45.     turtle.turnLeft()
  46.     turtle.forward()
  47.     turtle.turnLeft()
  48. end
  49.  
  50.  
  51. local function build(x, y)
  52.     for xProgress = 1, x do
  53.         for yProgress = 1, y do
  54.             checkFuel()
  55.             turtle.forward()
  56.             if (turtle.detectDown()) then
  57.                 -- clear the block so we can place a new one
  58.                 turtle.digDown()
  59.             end
  60.             local slot = getFirstSlotContainingBlocks()
  61.             if (slot == -1) then
  62.                 print("No buildable blocks")
  63.                 return
  64.             end
  65.             turtle.select(slot)
  66.             turtle.placeDown()
  67.         end
  68.         if xProgress % 2 == 0 then
  69.             arcLeft()
  70.         else
  71.             arcRight()
  72.         end
  73.     end
  74.     print("Done!")
  75. end
  76.  
  77. local function init()
  78.     local x = getNumberFromUser("How far straight should I build?")
  79.     local y = getNumberFromUser("How far right should I build?")
  80.     build(x, y)
  81. end
  82.  
  83. init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement