Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- width = 16 -- Grid width (can be smaller for testing)
- local fuelThreshold = 500 -- Refuel when below this level
- -- Helper function to refuel using coal or charcoal in inventory
- local function refuelFromInventory()
- if turtle.getFuelLevel() >= fuelThreshold then
- return false -- No need to refuel
- end
- for i = 1, 14 do -- Skip slot 15 (patching blocks) and 16 (ender chest)
- turtle.select(i)
- local item = turtle.getItemDetail()
- if item and (item.name == "minecraft:coal" or item.name == "minecraft:charcoal") then
- turtle.refuel()
- if turtle.getFuelLevel() >= fuelThreshold then
- return true -- Refueled enough
- end
- end
- end
- return false -- Couldn't refuel enough
- end
- -- Function to dump inventory into ender chest
- local function dumpToEnderChest()
- -- Verify slot 16 has ender chest
- turtle.select(16)
- local item = turtle.getItemDetail()
- if not item or item.name ~= "enderstorage:ender_chest" then
- print("Error: No ender chest in slot 16!")
- error("Missing enderstorage:ender_chest")
- end
- -- Place ender chest below
- while not turtle.placeDown() do
- turtle.digDown() -- Clear any block preventing placement
- end
- -- Dump items from slots 1-14 (slot 15 is for patching blocks)
- for i = 1, 14 do
- turtle.select(i)
- if turtle.getItemCount(i) > 0 then
- if not turtle.dropDown() then
- print("Warning: Ender chest full!")
- turtle.digDown() -- Retrieve ender chest
- error("Ender chest full")
- end
- end
- end
- -- Pick up ender chest
- turtle.select(16)
- turtle.digDown() -- Retrieve ender chest
- end
- -- Modified digger function with fluid patching
- local function digger()
- -- Attempt to move forward, handle fluids
- local moved = false
- while not moved do
- if turtle.forward() then
- moved = true
- else
- turtle.dig() -- Try digging (e.g., gravel, sand)
- if not turtle.forward() then
- -- Assume fluid (e.g., water); patch with block from slot 15
- turtle.select(15)
- local item = turtle.getItemDetail()
- if item and (item.name == "minecraft:dirt" or item.name == "minecraft:cobblestone") then
- turtle.place() -- Place block to patch fluid
- if turtle.forward() then
- moved = true
- end
- else
- print("Warning: No patching blocks in slot 15!")
- -- Try to continue without patching
- if turtle.forward() then
- moved = true
- else
- error("Cannot move forward; check for obstacles or fluids")
- end
- end
- else
- moved = true
- end
- end
- end
- turtle.digUp()
- turtle.digDown()
- -- Refuel if needed
- refuelFromInventory()
- -- Check if slots 1-14 are full (use slot 14 as indicator)
- if turtle.getItemCount(14) > 0 then
- dumpToEnderChest()
- end
- end
- -- Flip function for serpentine pattern
- local function flip(flipper)
- if flipper == 0 then
- turtle.turnRight()
- digger()
- turtle.turnRight()
- else
- turtle.turnLeft()
- digger()
- turtle.turnLeft()
- end
- end
- -- Main loop
- while turtle.digDown() do
- while not turtle.down() do
- turtle.digDown()
- end
- while not turtle.down() do
- turtle.digDown()
- end
- while not turtle.down() do
- turtle.digDown()
- end
- while not turtle.down() do
- turtle.digDown()
- end
- local flop = 0
- for y = 1, width do
- for x = 1, width - 1 do
- digger()
- end
- print(y)
- if y ~= width then
- flip(flop)
- flop = 1 - flop
- end
- end
- turtle.digDown()
- if flop == 1 then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- end
Add Comment
Please, Sign In to add comment