Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- A program to make turtle computercraft dig a 25x25x25 hole
- -- The turtle should start at the top left corner of the hole
- -- The turtle should have enough fuel and a chest in slot 1
- local length = 25 -- The length of the hole
- local width = 25 -- The width of the hole
- local depth = 25 -- The depth of the hole
- -- A function to check if the turtle has enough fuel
- local function checkFuel()
- if turtle.getFuelLevel() < 10 then -- If the fuel level is less than 10
- print("Low fuel. Refueling...") -- Print a message
- turtle.select(16) -- Select the last slot
- if turtle.refuel(1) then -- Try to refuel with one item
- print("Refueled.") -- Print a message
- else -- If refueling failed
- print("No fuel. Please insert fuel in slot 16.") -- Print a message
- while not turtle.refuel(1) do -- Wait until refueling succeeds
- os.sleep(1) -- Sleep for one second
- end
- print("Refueled.") -- Print a message
- end
- end
- end
- -- A function to dig forward and move forward
- local function digForward()
- checkFuel() -- Check the fuel level
- while turtle.detect() do -- While there is a block in front
- turtle.dig() -- Dig the block
- end
- turtle.forward() -- Move forward
- end
- -- A function to dig down and move down
- local function digDown()
- checkFuel() -- Check the fuel level
- while turtle.detectDown() do -- While there is a block below
- turtle.digDown() -- Dig the block
- end
- turtle.down() -- Move down
- end
- -- A function to dig up and move up
- local function digUp()
- checkFuel() -- Check the fuel level
- while turtle.detectUp() do -- While there is a block above
- turtle.digUp() -- Dig the block
- end
- turtle.up() -- Move up
- end
- -- A function to turn around
- local function turnAround()
- turtle.turnLeft() -- Turn left
- turtle.turnLeft() -- Turn left again
- end
- -- A function to place a chest and empty the inventory
- local function emptyInventory()
- print("Inventory full. Emptying...") -- Print a message
- turtle.select(1) -- Select the first slot (chest)
- while not turtle.placeDown() do -- While placing the chest fails
- digDown() -- Dig down and move down
- end
- for i = 2, 16 do -- For each slot except the first one (chest)
- turtle.select(i) -- Select the slot
- turtle.dropDown() -- Drop the item into the chest
- end
- turtle.select(1) -- Select the first slot (chest)
- digUp() -- Dig up and move up (back to original position)
- end
- -- A function to check if the inventory is full
- local function checkInventory()
- if turtle.getItemCount(16) > 0 then -- If the last slot is not empty
- emptyInventory() -- Empty the inventory into a chest below
- end
- end
- -- Start digging the hole
- print("Starting to dig...") -- Print a message
- for i = 1, depth do -- For each layer of depth
- for j = 1, width do -- For each row of width
- for k = 1, length - 1 do -- For each column of length except the last one
- digForward() -- Dig forward and move forward
- checkInventory() -- Check if the inventory is full
- end
- if j < width then -- If this is not the last row
- if j % 2 == 0 then -- If this is an even row
- turtle.turnLeft() -- Turn left
- digForward() -- Dig forward and move forward
- checkInventory() -- Check if the inventory is full
- turtle.turnLeft() -- Turn left
- else -- If this is an odd row
- turtle.turnRight() -- Turn right
- digForward() -- Dig forward and move forward
- checkInventory() -- Check if the inventory is full
- turtle.turnRight() -- Turn right
- end
- elseif i < depth then -- If this is the last row but not the last layer
- turnAround() -- Turn around
- for l = 1, length -1 do -- For each column of length except the first one
- digForward() -- Dig forward and move forward
- checkInventory() -- Check if the inventory is full
- end
- digDown() -- Dig down and move down
- checkInventory() -- Check if the inventory is full
- end
- end
- end
- print("Finished digging.") -- Print a message
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement