Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Honeycomb Centrifuge Automation Turtle Script
- -- For All The Mods 10 - Productive Bees
- -- Configuration
- local HONEYCOMB_ID = "productivebees:configurable_honeycomb"
- local CYCLE_DELAY = 60 -- seconds between cycles
- local MIN_FUEL_LEVEL = 500
- -- Position tracking for recovery
- local pos = {x = 0, y = 0, z = 0}
- local facing = "west"
- local START_FILE = "honeycomb_start_pos.txt"
- -- Direction mappings
- local directions = {
- north = 0,
- east = 1,
- south = 2,
- west = 3
- }
- -- Helper functions
- local function savePosition()
- local file = fs.open(START_FILE, "w")
- file.writeLine(pos.x)
- file.writeLine(pos.y)
- file.writeLine(pos.z)
- file.writeLine(facing)
- file.close()
- end
- local function loadPosition()
- if fs.exists(START_FILE) then
- local file = fs.open(START_FILE, "r")
- pos.x = tonumber(file.readLine()) or 0
- pos.y = tonumber(file.readLine()) or 0
- pos.z = tonumber(file.readLine()) or 0
- facing = file.readLine() or "west"
- file.close()
- return true
- end
- return false
- end
- local function checkFuel()
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel == "unlimited" then
- return true
- end
- if fuelLevel < MIN_FUEL_LEVEL then
- print("Low fuel! Attempting to refuel...")
- for slot = 1, 16 do
- turtle.select(slot)
- if turtle.refuel(0) then
- turtle.refuel()
- print("Refueled! New level: " .. turtle.getFuelLevel())
- turtle.select(1)
- return true
- end
- end
- turtle.select(1)
- print("ERROR: No fuel available!")
- return false
- end
- return true
- end
- local function turnRight()
- turtle.turnRight()
- local currentDir = directions[facing]
- currentDir = (currentDir + 1) % 4
- for dir, num in pairs(directions) do
- if num == currentDir then
- facing = dir
- break
- end
- end
- end
- local function turnLeft()
- turtle.turnLeft()
- local currentDir = directions[facing]
- currentDir = (currentDir - 1) % 4
- if currentDir < 0 then currentDir = currentDir + 4 end
- for dir, num in pairs(directions) do
- if num == currentDir then
- facing = dir
- break
- end
- end
- end
- local function forward(blocks)
- blocks = blocks or 1
- for i = 1, blocks do
- if not checkFuel() then return false end
- if turtle.forward() then
- if facing == "north" then pos.z = pos.z - 1
- elseif facing == "south" then pos.z = pos.z + 1
- elseif facing == "east" then pos.x = pos.x + 1
- elseif facing == "west" then pos.x = pos.x - 1
- end
- savePosition()
- else
- print("Cannot move forward - obstacle detected!")
- return false
- end
- end
- return true
- end
- local function up()
- if not checkFuel() then return false end
- if turtle.up() then
- pos.y = pos.y + 1
- savePosition()
- return true
- end
- return false
- end
- local function down()
- if not checkFuel() then return false end
- if turtle.down() then
- pos.y = pos.y - 1
- savePosition()
- return true
- end
- return false
- end
- local function pullHoneycombs()
- print("Pulling all items from chest below...")
- local pulledCount = 0
- -- Pull everything we can from the chest
- local itemsPulled = 0
- while turtle.suckDown() do
- itemsPulled = itemsPulled + 1
- end
- print("Pulled " .. itemsPulled .. " stacks, now sorting...")
- -- Go through our inventory and return non-honeycombs
- for slot = 1, 16 do
- local item = turtle.getItemDetail(slot)
- if item then
- print("Slot " .. slot .. ": " .. item.name)
- if item.name == HONEYCOMB_ID then
- pulledCount = pulledCount + 1
- print("Keeping configurable honeycomb in slot " .. slot)
- else
- print("Returning " .. item.name .. " to chest")
- turtle.select(slot)
- turtle.dropDown()
- end
- end
- end
- turtle.select(1)
- print("Kept " .. pulledCount .. " stacks of honeycombs")
- return true
- end
- local function depositHoneycomb()
- -- Try to deposit honeycomb into the centrifuge below
- local centrifuge = peripheral.wrap("bottom")
- if not centrifuge then
- print("No centrifuge found below")
- return false
- end
- -- Find a honeycomb in our inventory
- for slot = 1, 16 do
- local item = turtle.getItemDetail(slot)
- if item and item.name == HONEYCOMB_ID then
- turtle.select(slot)
- -- Try to drop entire stack into the centrifuge
- if turtle.dropDown() then
- print("Deposited " .. item.count .. " honeycombs into centrifuge")
- turtle.select(1)
- return true
- else
- print("Centrifuge appears to be full")
- turtle.select(1)
- return false
- end
- end
- end
- -- No honeycombs found
- return false
- end
- local function returnUnusedItems()
- -- Return any non-honeycomb items to the chest
- print("Returning non-honeycomb items...")
- -- Move back to chest position (we're currently at position 0,1,5 facing south)
- turnRight() -- Face west
- turnRight() -- Face north (180 turn from south)
- forward(5) -- Move back to 0,1,0
- -- Wait for clear path
- local waitCount = 0
- while turtle.detectDown() do
- waitCount = waitCount + 1
- print("Turtle detected below. Waiting... (" .. waitCount .. ")")
- os.sleep(2)
- if waitCount > 30 then
- print("Waited too long. Proceeding anyway...")
- break
- end
- end
- down() -- Go to 0,0,0
- turnRight() -- Face east
- turnRight() -- Face south
- turnRight() -- Face west (back to original orientation)
- -- Deposit non-honeycomb items
- for slot = 1, 16 do
- local item = turtle.getItemDetail(slot)
- if item and item.name ~= HONEYCOMB_ID then
- turtle.select(slot)
- turtle.dropDown()
- end
- end
- turtle.select(1)
- end
- local function processCycle()
- print("\n=== Starting honeycomb processing cycle ===")
- -- Pull honeycombs from chest
- pullHoneycombs()
- -- Move to centrifuge area
- up()
- turnLeft() -- Face south
- -- Try to deposit in 5 centrifuges
- for i = 1, 5 do
- forward(1)
- print("Checking centrifuge " .. i .. "...")
- depositHoneycomb()
- end
- -- Return to start
- returnUnusedItems()
- print("Cycle complete!")
- end
- -- Main program
- local function main()
- print("Honeycomb Centrifuge Automation")
- print("================================")
- -- Check fuel
- if not checkFuel() then
- print("Please add fuel to any slot!")
- while not checkFuel() do
- os.sleep(5)
- end
- end
- -- Load or save position
- if not loadPosition() then
- print("Setting current position as start...")
- savePosition()
- end
- print("Starting in 3 seconds...")
- print("Press Ctrl+T to stop")
- os.sleep(3)
- -- Main loop
- while true do
- processCycle()
- print("\nWaiting " .. CYCLE_DELAY .. " seconds...")
- os.sleep(CYCLE_DELAY)
- end
- end
- -- Error handling
- local ok, err = pcall(main)
- if not ok then
- print("Error: " .. err)
- print("Turtle stopped.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement