Advertisement
hornedcommando

Minecraft_Computercraft_Turtle_Butler

Apr 9th, 2024
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. --Requires Specific Building Setup to understand how to organize
  2. --TODO: write script to have the butler build the depot that it wants to live in (to avoid human error)
  3.  
  4. --Import Relative Location Libraries
  5. local tTurtle = require("TrackingTurtle")
  6.  
  7. local myTurtle = tTurtle.create()
  8.  
  9. local function checkJunkChest()
  10. myTurtle.turnLeft()
  11. for _ = 1, 3 do
  12. myTurtle.up()
  13. end
  14. for _ = 1, 6 do
  15. myTurtle.forward()
  16. end
  17. myTurtle.turnRight()
  18. for _ = 1, 2 do
  19. myTurtle.forward()
  20. end
  21. myTurtle.turnLeft()
  22. for _ = 1, 2 do
  23. myTurtle.forward()
  24. end
  25. myTurtle.turnRight()
  26. for _ = 1, 2 do
  27. myTurtle.drop()
  28. end
  29. end
  30.  
  31. local function fillInventory()
  32. -- Check if the turtle is adjacent to a chest
  33. if not turtle.detect() then
  34. print("No chest detected.")
  35. return
  36. end
  37.  
  38. -- Pull items from the chest until the inventory is full
  39. for slot = 1, 16 do
  40. if turtle.getItemCount(slot) == 0 then
  41. -- Select the current slot to store items from the chest
  42. turtle.select(slot)
  43. -- Attempt to pull items from the chest
  44. if turtle.suck() then
  45. print("Pulled items from the chest.")
  46. else
  47. -- If no items are left in the chest, stop pulling
  48. print("No more items in the chest.")
  49. break
  50. end
  51. end
  52. end
  53. end
  54.  
  55. local function refuel()
  56. print("refueling")
  57. local function attemptRefuel(slot)
  58. turtle.select(slot)
  59. if turtle.refuel(0) then
  60. local initialFuelLevel = turtle.getFuelLevel()
  61. turtle.refuel()
  62. local fuelIncrease = turtle.getFuelLevel() - initialFuelLevel
  63. return fuelIncrease
  64. end
  65. return 0
  66. end
  67.  
  68. local function burnCoalUntilFull()
  69. while turtle.getFuelLevel() < turtle.getFuelLimit() do
  70. local initialFuelLevel = turtle.getFuelLevel()
  71. if turtle.getItemCount(1) > 0 and turtle.getItemDetail(1).name == "minecraft:coal" then
  72. turtle.select(1)
  73. turtle.refuel()
  74. else
  75. break
  76. end
  77. if turtle.getFuelLevel() == initialFuelLevel then
  78. break
  79. end
  80. end
  81. end
  82.  
  83. -- Attempt to consume items in inventory for refueling
  84. for slot = 1, 16 do
  85. local fuelIncrease = attemptRefuel(slot)
  86. if fuelIncrease > 0 then
  87. if fuelIncrease < 80 then -- Arbitrary threshold, assuming coal is 80 fuel
  88. turtle.refuel(math.floor(fuelIncrease / 80)) -- Refuel with coal until it matches consumed item
  89. end
  90. return true
  91. end
  92. end
  93.  
  94. -- Burn coal until fuel is full
  95. burnCoalUntilFull()
  96.  
  97. return turtle.getFuelLevel() == turtle.getFuelLimit() -- Return whether the turtle's fuel is full
  98. end
  99.  
  100. refuel()
  101. checkJunkChest()
  102. fillInventory()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement