Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Turtle Block Replacer
- -- Breaks block below and replaces with dirt in a defined area
- -- Uses dirt from all available slots
- -- Get area dimensions from user
- print("Enter area width (x):")
- local width = tonumber(read())
- print("Enter area length (z):")
- local length = tonumber(read())
- -- Calculate total dirt across all slots
- local totalDirt = 0
- for slot = 1, 16 do
- local item = turtle.getItemDetail(slot)
- if item and item.name:find("dirt") then
- totalDirt = totalDirt + item.count
- end
- end
- -- Calculate required dirt and check inventory
- local requiredDirt = width * length
- print("Total dirt available: "..totalDirt)
- print("Dirt needed: "..requiredDirt)
- if totalDirt < requiredDirt then
- print("Not enough dirt! Need "..requiredDirt..", have "..totalDirt)
- return
- end
- -- Check fuel requirements (1 fuel per move + 1 per dig/place)
- local requiredFuel = (width * length * 3) + (width + length)
- local currentFuel = turtle.getFuelLevel()
- if currentFuel < requiredFuel then
- print("Warning: Low fuel! Need "..requiredFuel..", have "..currentFuel)
- print("Place fuel in any slot to continue or type 'cancel'")
- local input = read()
- if input:lower() == "cancel" then return end
- -- Refuel from all slots that contain fuel
- for slot = 1, 16 do
- turtle.select(slot)
- if turtle.refuel(0) then -- Check if item is fuel
- turtle.refuel()
- end
- end
- currentFuel = turtle.getFuelLevel()
- if currentFuel < requiredFuel then
- print("Still not enough fuel! Canceling operation.")
- return
- end
- end
- -- Main operation function
- local function findDirtSlot()
- for slot = 1, 16 do
- local item = turtle.getItemDetail(slot)
- if item and item.name:find("dirt") and item.count > 0 then
- return slot
- end
- end
- return nil
- end
- -- Begin replacement pattern
- for z = 1, length do
- for x = 1, width do
- -- Break block below
- while not turtle.digDown() do
- sleep(0.5)
- end
- -- Find and select dirt
- local dirtSlot = findDirtSlot()
- if not dirtSlot then
- print("Ran out of dirt unexpectedly!")
- return
- end
- turtle.select(dirtSlot)
- -- Place dirt block
- turtle.placeDown()
- -- Move forward if not at end of row
- if x < width then
- while not turtle.forward() do
- turtle.dig()
- sleep(0.5)
- end
- end
- end
- -- Return to start of row if not on last row
- if z < length then
- if z % 2 == 0 then
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- else
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- end
- end
- end
- print("Area processed successfully!")
- print("Blocks replaced: "..(width * length))
- print("Fuel remaining: "..turtle.getFuelLevel())
Add Comment
Please, Sign In to add comment