Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not turtle then
- printError("Requires a Turtle")
- return
- end
- local tArgs = { ... }
- if #tArgs ~= 3 then
- local programName = arg[0] or fs.getName(shell.getRunningProgram())
- print("Usage: " .. programName .. " <width> <length> <item to place>")
- return
- end
- local width = tonumber(tArgs[1])
- local length = tonumber(tArgs[2])
- local targetItem = tArgs[3]
- local function refuel(amount)
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel == "unlimited" then
- return true
- end
- turtle.select(16)
- while turtle.getItemCount(16) > 0 and turtle.getFuelLevel() < amount do
- if not turtle.refuel(1) then
- return false
- end
- end
- if turtle.getFuelLevel() < amount then
- return false
- else
- return true
- end
- end
- local function waitForFuel(amount)
- if not refuel(amount) then
- print("Please put fuel in slot 16")
- while not refuel(amount) do
- sleep(0.5)
- end
- print("Received sufficient fuel. Continuing...")
- end
- end
- local function selectItem(name)
- for i=15, 1, -1 do
- itemDetail = turtle.getItemDetail(i)
- if itemDetail and itemDetail.name == name then
- turtle.select(i)
- return true
- end
- end
- return false
- end
- local function countItem(name)
- num = 0
- for i=1, 15 do
- itemDetail = turtle.getItemDetail(i)
- if itemDetail and itemDetail.name == name then
- num = num + itemDetail.count
- end
- end
- return num
- end
- local function waitForItem(name, amount)
- if countItem(name) < amount then
- print("Please provide more " .. name)
- while countItem(name) < amount do
- sleep(0.5)
- end
- print("Received sufficient " .. name .. ". Continuing...")
- end
- selectItem(name)
- end
- local function waitForDrop()
- if turtle.getItemCount() > 0 and not turtle.drop() then
- print("Please make room for turtle to drop")
- while turtle.getItemCount() > 0 and not turtle.drop() do
- sleep(0.5)
- end
- print("Turtle successfully dropped. Continuing...")
- end
- end
- local function waitForDropDown()
- if turtle.getItemCount() > 0 and not turtle.dropDown() then
- print("Please make room for turtle to drop")
- while turtle.getItemCount() > 0 and not turtle.dropDown() do
- sleep(0.5)
- end
- print("Turtle successfully dropped. Continuing...")
- end
- end
- local function getBlock()
- local hasBlock, data = turtle.inspect()
- if hasBlock then
- return data.name
- else
- return "minecraft:air"
- end
- end
- local function getBlockDown()
- local hasBlock, data = turtle.inspectDown()
- if hasBlock then
- return data.name
- else
- return "minecraft:air"
- end
- end
- local function getBlockUp()
- local hasBlock, data = turtle.inspectUp()
- if hasBlock then
- return data.name
- else
- return "minecraft:air"
- end
- end
- local function tryForward()
- waitForFuel(1)
- if not turtle.forward() then
- exit()
- end
- end
- local function tryMakeCeiling()
- if turtle.detectUp() then
- turtle.digUp()
- end
- waitForItem(targetItem, 1)
- turtle.placeUp()
- end
- waitForFuel(2*width*length)
- waitForItem(targetItem, width*length)
- for i=1, width do
- for j=1, length-1 do
- tryMakeCeiling()
- tryForward()
- end
- tryMakeCeiling()
- if i < width then
- if i % 2 == 1 then
- turtle.turnRight()
- tryForward()
- turtle.turnRight()
- else
- turtle.turnLeft()
- tryForward()
- turtle.turnLeft()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment