Advertisement
Guest User

Untitled

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