Ubidibity

chunkgrok.lua

Jun 24th, 2025
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | Gaming | 0 0
  1. width = 16 -- Grid width (can be smaller for testing)
  2. local fuelThreshold = 500 -- Refuel when below this level
  3.  
  4. -- Helper function to refuel using coal or charcoal in inventory
  5. local function refuelFromInventory()
  6. if turtle.getFuelLevel() >= fuelThreshold then
  7. return false -- No need to refuel
  8. end
  9. for i = 1, 14 do -- Skip slot 15 (patching blocks) and 16 (ender chest)
  10. turtle.select(i)
  11. local item = turtle.getItemDetail()
  12. if item and (item.name == "minecraft:coal" or item.name == "minecraft:charcoal") then
  13. turtle.refuel()
  14. if turtle.getFuelLevel() >= fuelThreshold then
  15. return true -- Refueled enough
  16. end
  17. end
  18. end
  19. return false -- Couldn't refuel enough
  20. end
  21.  
  22. -- Function to dump inventory into ender chest
  23. local function dumpToEnderChest()
  24. -- Verify slot 16 has ender chest
  25. turtle.select(16)
  26. local item = turtle.getItemDetail()
  27. if not item or item.name ~= "enderstorage:ender_chest" then
  28. print("Error: No ender chest in slot 16!")
  29. error("Missing enderstorage:ender_chest")
  30. end
  31. -- Place ender chest below
  32. while not turtle.placeDown() do
  33. turtle.digDown() -- Clear any block preventing placement
  34. end
  35. -- Dump items from slots 1-14 (slot 15 is for patching blocks)
  36. for i = 1, 14 do
  37. turtle.select(i)
  38. if turtle.getItemCount(i) > 0 then
  39. if not turtle.dropDown() then
  40. print("Warning: Ender chest full!")
  41. turtle.digDown() -- Retrieve ender chest
  42. error("Ender chest full")
  43. end
  44. end
  45. end
  46. -- Pick up ender chest
  47. turtle.select(16)
  48. turtle.digDown() -- Retrieve ender chest
  49. end
  50.  
  51. -- Modified digger function with fluid patching
  52. local function digger()
  53. -- Attempt to move forward, handle fluids
  54. local moved = false
  55. while not moved do
  56. if turtle.forward() then
  57. moved = true
  58. else
  59. turtle.dig() -- Try digging (e.g., gravel, sand)
  60. if not turtle.forward() then
  61. -- Assume fluid (e.g., water); patch with block from slot 15
  62. turtle.select(15)
  63. local item = turtle.getItemDetail()
  64. if item and (item.name == "minecraft:dirt" or item.name == "minecraft:cobblestone") then
  65. turtle.place() -- Place block to patch fluid
  66. if turtle.forward() then
  67. moved = true
  68. end
  69. else
  70. print("Warning: No patching blocks in slot 15!")
  71. -- Try to continue without patching
  72. if turtle.forward() then
  73. moved = true
  74. else
  75. error("Cannot move forward; check for obstacles or fluids")
  76. end
  77. end
  78. else
  79. moved = true
  80. end
  81. end
  82. end
  83. turtle.digUp()
  84. turtle.digDown()
  85. -- Refuel if needed
  86. refuelFromInventory()
  87. -- Check if slots 1-14 are full (use slot 14 as indicator)
  88. if turtle.getItemCount(14) > 0 then
  89. dumpToEnderChest()
  90. end
  91. end
  92.  
  93. -- Flip function for serpentine pattern
  94. local function flip(flipper)
  95. if flipper == 0 then
  96. turtle.turnRight()
  97. digger()
  98. turtle.turnRight()
  99. else
  100. turtle.turnLeft()
  101. digger()
  102. turtle.turnLeft()
  103. end
  104. end
  105.  
  106. -- Main loop
  107. while turtle.digDown() do
  108. while not turtle.down() do
  109. turtle.digDown()
  110. end
  111. while not turtle.down() do
  112. turtle.digDown()
  113. end
  114. while not turtle.down() do
  115. turtle.digDown()
  116. end
  117. while not turtle.down() do
  118. turtle.digDown()
  119. end
  120.  
  121. local flop = 0
  122. for y = 1, width do
  123. for x = 1, width - 1 do
  124. digger()
  125. end
  126. print(y)
  127. if y ~= width then
  128. flip(flop)
  129. flop = 1 - flop
  130. end
  131. end
  132. turtle.digDown()
  133. if flop == 1 then
  134. turtle.turnRight()
  135. else
  136. turtle.turnLeft()
  137. end
  138. end
Add Comment
Please, Sign In to add comment