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 ~= 1 then
- local programName = arg[0] or fs.getName(shell.getRunningProgram())
- print("Usage: " .. programName .. " <num units>")
- return
- end
- local numUnits = tonumber(tArgs[1])
- local function fastFail(success)
- if not success then
- print("An unexpected error has occured! Aborting.")
- exit()
- end
- end
- 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=1, 15 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()
- hasBlock, data = turtle.inspect()
- if hasBlock then
- return data.name
- else
- return "minecraft:air"
- end
- end
- local function getBlockDown()
- hasBlock, data = turtle.inspectDown()
- if hasBlock then
- return data.name
- else
- return "minecraft:air"
- end
- end
- local function getBlockUp()
- hasBlock, data = turtle.inspectUp()
- if hasBlock then
- return data.name
- else
- return "minecraft:air"
- end
- end
- local function tryForwards()
- waitForFuel(1)
- while not turtle.forward() do
- if turtle.detect() then
- if not turtle.dig() then
- return false
- end
- elseif not turtle.attack() then
- sleep(0.5)
- end
- end
- return true
- end
- local function tryDown()
- waitForFuel(1)
- while not turtle.down() do
- if turtle.detectDown() then
- if not turtle.digDown() then
- return false
- end
- elseif not turtle.attackDown() then
- sleep(0.5)
- end
- end
- return true
- end
- local function tryUp()
- waitForFuel(1)
- while not turtle.up() do
- if turtle.detectUp() then
- if not turtle.digUp() then
- return false
- end
- elseif not turtle.attackUp() then
- sleep(0.5)
- end
- end
- return true
- end
- local function repeatForwards(amount)
- for i=1, amount do
- fastFail(tryForwards())
- end
- end
- local function repeatDown(amount)
- for i=1, amount do
- fastFail(tryDown())
- end
- end
- local function repeatUp(amount)
- for i=1, amount do
- fastFail(tryUp())
- end
- end
- local function stripForwards(amount)
- for i=1, amount do
- fastFail(tryForwards())
- turtle.digDown()
- end
- end
- local function stripForwardsWithFloor(amount)
- for i=1, amount do
- fastFail(tryForwards())
- turtle.digDown()
- waitForItem("minecraft:cobblestone", 1)
- turtle.placeDown()
- end
- end
- waitForFuel(512*numUnits)
- waitForItem("minecraft:cobblestone", 18*numUnits)
- waitForItem("minecraft:crimson_planks", 12*numUnits)
- waitForItem("minecraft:stone_brick_slab", 12*numUnits)
- waitForItem("minecraft:stone_brick_stairs", 2*numUnits)
- waitForItem("minecraft:lantern", 2*numUnits)
- waitForItem("minecraft:crimson_trapdoor", 2*numUnits)
- for unit=1, numUnits do
- fastFail(tryForwards())
- repeatUp(4)
- turtle.turnRight()
- for i=1, 2 do
- stripForwards(8)
- turtle.turnLeft()
- stripForwards(1)
- turtle.turnLeft()
- stripForwards(8)
- turtle.turnLeft()
- stripForwards(1)
- turtle.turnLeft()
- repeatDown(2)
- end
- stripForwardsWithFloor(8)
- turtle.turnLeft()
- stripForwardsWithFloor(1)
- turtle.turnLeft()
- stripForwardsWithFloor(8)
- turtle.turnLeft()
- stripForwardsWithFloor(1)
- turtle.turnLeft()
- fastFail(tryUp())
- waitForItem("minecraft:crimson_planks", 1)
- turtle.placeDown()
- fastFail(tryForwards())
- waitForItem("minecraft:crimson_planks", 1)
- turtle.placeDown()
- fastFail(tryForwards())
- turtle.turnLeft()
- turtle.turnLeft()
- waitForItem("minecraft:stone_brick_stairs", 1)
- turtle.placeDown()
- turtle.turnLeft()
- fastFail(tryForwards())
- turtle.turnRight()
- fastFail(tryDown())
- waitForItem("minecraft:crimson_trapdoor", 1)
- turtle.placeUp()
- fastFail(tryForwards())
- fastFail(tryForwards())
- fastFail(tryUp())
- waitForItem("minecraft:crimson_planks", 1)
- turtle.placeDown()
- fastFail(tryUp())
- waitForItem("minecraft:crimson_planks", 1)
- turtle.placeDown()
- turtle.turnRight()
- fastFail(tryForwards())
- waitForItem("minecraft:crimson_planks", 1)
- turtle.placeDown()
- turtle.turnRight()
- fastFail(tryForwards())
- waitForItem("minecraft:crimson_planks", 1)
- turtle.placeDown()
- fastFail(tryForwards())
- waitForItem("minecraft:lantern", 1)
- turtle.placeDown()
- fastFail(tryUp())
- waitForItem("minecraft:stone_brick_slab", 1)
- turtle.placeDown()
- turtle.turnRight()
- fastFail(tryForwards())
- waitForItem("minecraft:stone_brick_slab", 1)
- turtle.placeDown()
- turtle.turnRight()
- fastFail(tryForwards())
- waitForItem("minecraft:stone_brick_slab", 1)
- turtle.placeDown()
- fastFail(tryForwards())
- waitForItem("minecraft:stone_brick_slab", 1)
- turtle.placeDown()
- turtle.turnRight()
- fastFail(tryForwards())
- waitForItem("minecraft:stone_brick_slab", 1)
- turtle.placeDown()
- turtle.turnRight()
- fastFail(tryForwards())
- waitForItem("minecraft:stone_brick_slab", 1)
- turtle.placeDown()
- repeatForwards(7)
- repeatDown(2)
- turtle.turnRight()
- turtle.turnRight()
- waitForItem("minecraft:crimson_planks", 1)
- turtle.placeDown()
- fastFail(tryForwards())
- waitForItem("minecraft:crimson_planks", 1)
- turtle.placeDown()
- fastFail(tryForwards())
- turtle.turnRight()
- turtle.turnRight()
- waitForItem("minecraft:stone_brick_stairs", 1)
- turtle.placeDown()
- turtle.turnRight()
- fastFail(tryForwards())
- turtle.turnLeft()
- fastFail(tryDown())
- waitForItem("minecraft:crimson_trapdoor", 1)
- turtle.placeUp()
- fastFail(tryForwards())
- fastFail(tryForwards())
- fastFail(tryUp())
- waitForItem("minecraft:crimson_planks", 1)
- turtle.placeDown()
- fastFail(tryUp())
- waitForItem("minecraft:crimson_planks", 1)
- turtle.placeDown()
- turtle.turnLeft()
- fastFail(tryForwards())
- waitForItem("minecraft:crimson_planks", 1)
- turtle.placeDown()
- turtle.turnLeft()
- fastFail(tryForwards())
- waitForItem("minecraft:crimson_planks", 1)
- turtle.placeDown()
- fastFail(tryForwards())
- waitForItem("minecraft:lantern", 1)
- turtle.placeDown()
- fastFail(tryUp())
- waitForItem("minecraft:stone_brick_slab", 1)
- turtle.placeDown()
- turtle.turnLeft()
- fastFail(tryForwards())
- waitForItem("minecraft:stone_brick_slab", 1)
- turtle.placeDown()
- turtle.turnLeft()
- fastFail(tryForwards())
- waitForItem("minecraft:stone_brick_slab", 1)
- turtle.placeDown()
- fastFail(tryForwards())
- waitForItem("minecraft:stone_brick_slab", 1)
- turtle.placeDown()
- turtle.turnLeft()
- fastFail(tryForwards())
- waitForItem("minecraft:stone_brick_slab", 1)
- turtle.placeDown()
- turtle.turnLeft()
- fastFail(tryForwards())
- waitForItem("minecraft:stone_brick_slab", 1)
- turtle.placeDown()
- repeatForwards(7)
- turtle.turnRight()
- fastFail(tryForwards())
- repeatDown(3)
- end
- for i=1, 15 do
- itemDetail = turtle.getItemDetail(i)
- if itemDetail and itemDetail.name ~= "minecraft:cobblestone" and itemDetail.name ~= "minecraft:crimson_planks" and itemDetail.name ~= "minecraft:stone_brick_slab" and itemDetail.name ~= "minecraft:stone_brick_stairs" and itemDetail.name ~= "minecraft:lantern" and itemDetail.name ~= "minecraft:crimson_trapdoor" then
- turtle.select(i)
- turtle.dropUp()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment