Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local INVENTORY_SIZE = 16
- local FUEL_SLOT = 1
- local function getNumberFromUser(message)
- print(message)
- local raw = io.read()
- number = tonumber(raw)
- return number
- end
- local function init()
- local x = getNumberFromUser("How far straight should I build?")
- local y = getNumberFromUser("How far right should I build?")
- build(x, y)
- end
- local function build(x, y)
- for xProgress = 1, x do
- for yProgress = 1, y do
- checkFuel()
- turtle.forward()
- if (turtle.detectDown()) then
- -- clear the block so we can place a new one
- turtle.digDown()
- end
- local slot = getFirstSlotContainingBlocks()
- if (slot == -1) then
- print("No buildable blocks")
- return
- end
- turtle.select(slot)
- turtle.placeDown()
- end
- turtle.forward()
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- end
- print("Done!")
- end
- local function getFirstSlotContainingBlocks()
- for slot = 1, INVENTORY_SIZE do
- local itemCount = turtle.getItemCount(slot)
- if slot ~= FUEL_SLOT and itemCount > 0 then
- return slot
- end
- end
- return -1
- end
- local function checkFuel()
- if not hasEnoughFuel() then
- refuel()
- end
- end
- local function hasEnoughFuel()
- return turtle.getFuelLevel() > 16
- end
- local function refuel()
- turtle.select(FUEL_SLOT)
- turtle.refuel(1)
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement