Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- enderchestbot.lua
- local enderChestName = "enderstorage:ender_chest" -- Adjust if your Ender Chest has a different ID
- -- e.g., "enderstorage:ender_chest" for EnderStorage mod
- local function log(message)
- print("[EnderBot] " .. message)
- end
- -- Function to find an Ender Chest in inventory and select it
- local function findAndSelectEnderChest()
- for i = 1, 16 do -- Turtles have 16 inventory slots
- local itemCount = turtle.getItemCount(i)
- if itemCount > 0 then
- local itemDetail = turtle.getItemDetail(i)
- if itemDetail and itemDetail.name == enderChestName then
- turtle.select(i)
- log("Selected Ender Chest from slot " .. i)
- return true -- Found and selected
- end
- end
- end
- log("No Ender Chests found in inventory!")
- return false -- Not found
- end
- log("EnderChestBot starting...")
- log("Will look for: " .. enderChestName)
- while true do
- log("Checking block below...")
- local success, data = turtle.inspectDown()
- if success and data.name == enderChestName then
- log("Ender Chest detected below. Moving forward.")
- while not turtle.forward() do
- log("Movement forward failed (obstructed). Retrying...")
- -- Optional: Add logic here to deal with obstructions, like digging
- -- For now, it will just keep trying to move forward.
- os.sleep(0.5) -- Wait a bit before retrying
- end
- log("Moved forward successfully.")
- else
- if success then
- log("Block below is '" .. data.name .. "', not an Ender Chest.")
- else
- log("No block detected below (air).")
- end
- log("Attempting to place Ender Chest...")
- if findAndSelectEnderChest() then
- if turtle.placeDown() then
- log("Placed Ender Chest successfully.")
- else
- log("Failed to place Ender Chest. Is the space occupied or invalid?")
- -- It might fail if there's already a non-solid block or entity
- -- The loop will continue, and it will try again next iteration.
- end
- else
- log("Cannot place Ender Chest: None in inventory. Waiting...")
- -- The bot will be stuck here until it gets more Ender Chests manually
- -- or the script is stopped.
- os.sleep(5) -- Wait 5 seconds before checking again if out of chests
- end
- end
- os.sleep(0.2) -- Short delay to prevent overwhelming the server and allow a tick for updates
- end
Add Comment
Please, Sign In to add comment