Myros27

enderchest

May 25th, 2025 (edited)
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. -- enderchestbot.lua
  2.  
  3. local enderChestName = "enderstorage:ender_chest" -- Adjust if your Ender Chest has a different ID
  4. -- e.g., "enderstorage:ender_chest" for EnderStorage mod
  5.  
  6. local function log(message)
  7. print("[EnderBot] " .. message)
  8. end
  9.  
  10. -- Function to find an Ender Chest in inventory and select it
  11. local function findAndSelectEnderChest()
  12. for i = 1, 16 do -- Turtles have 16 inventory slots
  13. local itemCount = turtle.getItemCount(i)
  14. if itemCount > 0 then
  15. local itemDetail = turtle.getItemDetail(i)
  16. if itemDetail and itemDetail.name == enderChestName then
  17. turtle.select(i)
  18. log("Selected Ender Chest from slot " .. i)
  19. return true -- Found and selected
  20. end
  21. end
  22. end
  23. log("No Ender Chests found in inventory!")
  24. return false -- Not found
  25. end
  26.  
  27. log("EnderChestBot starting...")
  28. log("Will look for: " .. enderChestName)
  29.  
  30. while true do
  31. log("Checking block below...")
  32. local success, data = turtle.inspectDown()
  33.  
  34. if success and data.name == enderChestName then
  35. log("Ender Chest detected below. Moving forward.")
  36. while not turtle.forward() do
  37. log("Movement forward failed (obstructed). Retrying...")
  38. -- Optional: Add logic here to deal with obstructions, like digging
  39. -- For now, it will just keep trying to move forward.
  40. os.sleep(0.5) -- Wait a bit before retrying
  41. end
  42. log("Moved forward successfully.")
  43. else
  44. if success then
  45. log("Block below is '" .. data.name .. "', not an Ender Chest.")
  46. else
  47. log("No block detected below (air).")
  48. end
  49.  
  50. log("Attempting to place Ender Chest...")
  51. if findAndSelectEnderChest() then
  52. if turtle.placeDown() then
  53. log("Placed Ender Chest successfully.")
  54. else
  55. log("Failed to place Ender Chest. Is the space occupied or invalid?")
  56. -- It might fail if there's already a non-solid block or entity
  57. -- The loop will continue, and it will try again next iteration.
  58. end
  59. else
  60. log("Cannot place Ender Chest: None in inventory. Waiting...")
  61. -- The bot will be stuck here until it gets more Ender Chests manually
  62. -- or the script is stopped.
  63. os.sleep(5) -- Wait 5 seconds before checking again if out of chests
  64. end
  65. end
  66.  
  67. os.sleep(0.2) -- Short delay to prevent overwhelming the server and allow a tick for updates
  68. end
Add Comment
Please, Sign In to add comment