Advertisement
hornedcommando

Turtle Butler

Apr 16th, 2024 (edited)
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | Gaming | 0 0
  1. --Import Relative Location Libraries
  2. local tTurtle = require("TrackingTurtle")
  3.  
  4. local myTurtle = tTurtle.create()
  5.  
  6. local function checkJunkChest()
  7. myTurtle.turnLeft()
  8. for _ = 1, 3 do
  9. myTurtle.up()
  10. end
  11. for _ = 1, 6 do
  12. myTurtle.forward()
  13. end
  14. myTurtle.turnRight()
  15. for _ = 1, 2 do
  16. myTurtle.forward()
  17. end
  18. myTurtle.turnLeft()
  19. myTurtle.down()
  20. for _ = 1, 2 do
  21. myTurtle.forward()
  22. end
  23. myTurtle.turnLeft()
  24. myTurtle.down()
  25. end
  26.  
  27. local function fillInventory()
  28. -- Pull items from the chest until the inventory is full
  29. for slot = 1, 16 do
  30. if turtle.getItemCount(slot) == 0 then
  31. -- Select the current slot to store items from the chest
  32. turtle.select(slot)
  33. -- Attempt to pull items from the chest
  34. if turtle.suckDown() then
  35. print("Pulled items from the chest.")
  36. else
  37. -- If no items are left in the chest, stop pulling
  38. print("No more items in the chest.")
  39. break
  40. end
  41. end
  42. end
  43. end
  44.  
  45. local function refuel()
  46. print("refueling")
  47. local function attemptRefuel(slot)
  48. turtle.select(slot)
  49. if turtle.refuel(0) then
  50. local initialFuelLevel = turtle.getFuelLevel()
  51. turtle.refuel()
  52. local fuelIncrease = turtle.getFuelLevel() - initialFuelLevel
  53. return fuelIncrease
  54. end
  55. return 0
  56. end
  57.  
  58. local function burnCoalUntilFull()
  59. while turtle.getFuelLevel() < turtle.getFuelLimit() do
  60. local initialFuelLevel = turtle.getFuelLevel()
  61. if turtle.getItemCount(1) > 0 and turtle.getItemDetail(1).name == "minecraft:coal" then
  62. turtle.select(1)
  63. turtle.refuel()
  64. else
  65. break
  66. end
  67. if turtle.getFuelLevel() == initialFuelLevel then
  68. break
  69. end
  70. end
  71. end
  72.  
  73. -- Attempt to consume items in inventory for refueling
  74. for slot = 1, 16 do
  75. local fuelIncrease = attemptRefuel(slot)
  76. if fuelIncrease > 0 then
  77. if fuelIncrease < 80 then -- Arbitrary threshold, assuming coal is 80 fuel
  78. turtle.refuel(math.floor(fuelIncrease / 80)) -- Refuel with coal until it matches consumed item
  79. end
  80. return true
  81. end
  82. end
  83.  
  84. -- Burn coal until fuel is full
  85. burnCoalUntilFull()
  86.  
  87. return turtle.getFuelLevel() == turtle.getFuelLimit() -- Return whether the turtle's fuel is full
  88. end
  89.  
  90. local function sort()
  91. for i = 1, 16 do
  92. turtle.select(i)
  93. local item = turtle.getItemDetail()
  94.  
  95. end
  96.  
  97. end
  98.  
  99. local function stack(itemName)
  100. print("Checking inventory")
  101. for slot = 1, 16 do
  102. if turtle.getItemDetail(slot) then
  103. local item = turtle.getItemDetail(slot)
  104. print("Slot: " .. slot .. " Item: " .. item.name)
  105. if item.name ~= itemName then
  106. print("this is not" .. itemName)
  107. turtle.select(slot)
  108. turtle.drop()
  109. else
  110. print(itemName .. " found in slot " .. slot)
  111. end
  112. else
  113. print("Slot: " .. slot .. " is empty")
  114. end
  115. end
  116. end
  117.  
  118. local function searchInventory(name)
  119. for slot = 1, 16 do
  120. turtle.select(slot)
  121. local slotDetail = turtle.getItemDetail()
  122. if slotDetail and slotDetail.name:find(name) then
  123. return true, slot
  124. -- Return the slot number if item found
  125. end
  126. end
  127. return false -- Return false if item not found
  128. end
  129.  
  130. local function makeInvar()
  131. searchInventory("kubejs:nickel_compound")
  132. turtle.drop()
  133. sleep(6)
  134. turtle.suck()
  135. myTurtle.turnLeft()
  136. myTurtle.turnLeft()
  137. searchInventory("kubejs:invar_compound")
  138. turtle.drop()
  139. myTurtle.turnRight()
  140. myTurtle.turnRight()
  141. sleep(4)
  142. end
  143.  
  144. while true do
  145. makeInvar()
  146. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement