Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Bridge Building Program for CC:Tweaked Turtle
- -- Function to count building blocks in inventory
- local function countBuildingBlocks()
- local total = 0
- for i = 1, 16 do
- local item = turtle.getItemDetail(i)
- if item then
- total = total + item.count
- end
- end
- return total
- end
- -- Function to check and refuel if necessary
- local function refuel(neededFuel)
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel == "unlimited" then return true end
- for i = 1, 16 do
- turtle.select(i)
- if turtle.refuel(0) then
- local needed = neededFuel - fuelLevel
- if needed > 0 then
- turtle.refuel(needed)
- end
- return true
- end
- end
- return false
- end
- -- Function to find and select a block for placement
- local function selectBlock()
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- return true
- end
- end
- return false
- end
- -- Main program
- print("Bridge Building Program")
- print("Enter the length of the bridge:")
- local length = tonumber(read())
- if not length or length < 1 then
- print("Invalid length. Please enter a positive number.")
- return
- end
- local blocksNeeded = length
- local blocksAvailable = countBuildingBlocks()
- print("Blocks needed: " .. blocksNeeded)
- print("Blocks available: " .. blocksAvailable)
- if blocksAvailable < blocksNeeded then
- print("Not enough blocks to complete the bridge.")
- return
- end
- local fuelNeeded = length * 2 -- Move forward and back
- local currentFuel = turtle.getFuelLevel()
- if currentFuel ~= "unlimited" and currentFuel < fuelNeeded then
- print("Attempting to refuel...")
- if not refuel(fuelNeeded) then
- print("Not enough fuel to complete the bridge.")
- return
- end
- end
- print("Starting bridge construction...")
- -- Build the bridge
- for i = 1, length do
- if not selectBlock() then
- print("Ran out of blocks unexpectedly.")
- break
- end
- turtle.placeDown()
- if i < length then
- turtle.forward()
- end
- end
- -- Return to start
- turtle.turnRight()
- turtle.turnRight()
- for i = 1, length - 1 do
- turtle.forward()
- end
- print("Bridge construction complete!")
Advertisement
Add Comment
Please, Sign In to add comment