Dimencia

Untitled

Mar 22nd, 2021
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.03 KB | None | 0 0
  1. -- BaseBuilding Turtle
  2.  
  3. -- Digs out rooms 16x16x4, with a staircase spiraling along the edges
  4. -- Should always be started at the top-left corner of the area to dig...
  5.  
  6. -- No idea how I'm gonna get the stars to work, but the main part should be really easy
  7.  
  8. local startZ = 2
  9. local startX = 9
  10. local startY = 10
  11.  
  12. local cobbleSlot = 1
  13. local firstFuelSlot = 12
  14. local numFuelSlots = 4
  15.  
  16.  
  17. function refuel()
  18. -- Fix the inventory. Let's reserve the last 4 slots all for coal
  19. -- So first, check those 4 slots and if they have noncoal in them, drop them
  20. -- Then check all other slots, and if they have coal, try to put them in those 4 slots
  21. -- Also, discard all cobblestone except slot 1, stack it there
  22.  
  23. -- There are 16 slots, we want 12-16
  24. for i=firstFuelSlot,firstFuelSlot+numFuelSlots do
  25. local data = turtle.getItemDetail(i)
  26. if data ~= nil then
  27. print("Found in slot " .. i .. ": ", data.name)
  28. if data.name ~= "minecraft:coal" then
  29. turtle.select(i)
  30. turtle.drop()
  31. print("Dropping slot " .. i .. " because it's in the coal slot")
  32. end
  33. end
  34. end
  35. -- Now the rest
  36. for i=1,firstFuelSlot-1 do
  37. local data = turtle.getItemDetail(i)
  38. if data ~= nil then
  39. print("Found in slot " .. i .. ": ", data.name)
  40. if data.name == "minecraft:coal" then
  41. -- Just try them all
  42. turtle.select(i)
  43. print("Transferring coal to all fuel slots")
  44. for j=firstFuelSlot,firstFuelSlot+numFuelSlots do
  45. turtle.transferTo(j)
  46. end
  47. elseif data.name == "minecraft:cobblestone" then
  48. -- Try to transfer it to cobbleSlot
  49. turtle.select(i)
  50. turtle.transferTo(cobbleSlot)
  51. -- Drop any remainders
  52. turtle.drop()
  53. end
  54. end
  55. end
  56. -- And lastly, iterate the fuel slots and refuel
  57. for i=firstFuelSlot,firstFuelSlot+numFuelSlots do
  58. turtle.select(i)
  59. turtle.refuel()
  60. end
  61. end
  62.  
  63.  
  64. turtle.select(firstFuelSlot)
  65. turtle.refuel()
  66. turtle.select(cobbleSlot)
  67.  
  68. local sz=1
  69. local sx=1
  70. local sy=1
  71. if startZ then sz = startZ startZ = nil end
  72. if startX then sx = startX startX = nil end
  73. if startY then sy = startY startY = nil end
  74.  
  75. while(true) do
  76. for z=sz,4 do
  77.  
  78. for x=sx,16 do -- Same, always already in the first one
  79.  
  80. for y=sy,16 do -- We're always inside the first one
  81.  
  82. turtle.dig()
  83. turtle.suck()
  84. turtle.forward()
  85. if not turtle.detectDown() and z == 4 then turtle.placeDown() end -- Make sure the floors are filled in
  86. if not turtle.detectUp() and z == 1 then turtle.placeUp() end -- And the ceilings, which are 1 below the floors
  87. end
  88. sy = 1
  89. -- Reached the end on this side, turn (right/left)...
  90. if x < 16 then
  91. if x%2 == 1 then turtle.turnRight() else turtle.turnLeft() end
  92. turtle.dig()
  93. turtle.forward()
  94. if x%2 == 1 then turtle.turnRight() else turtle.turnLeft() end
  95. if not turtle.detectDown() and z == 4 then turtle.placeDown() end -- Make sure the floors are filled in
  96. if not turtle.detectUp() and z == 1 then turtle.placeUp() end -- And the ceilings, which are 1 below the floors
  97. end
  98. -- Ready to iterate again
  99. end
  100. sx = 1
  101. -- We've cleared out a 16x16 area on this level.
  102. -- And we are currently in the last block we broke...
  103. -- So the staircase is to our left. But, for everything except z==1
  104. -- We need to do a 180 and go to the opening
  105. if z > 1 then
  106. turtle.turnLeft()
  107. turtle.turnLeft()
  108. for i=2,z do
  109. turtle.forward()
  110. end
  111. turtle.turnRight()
  112. turtle.forward() -- There should already be nothing there
  113. turtle.turnLeft()
  114. else
  115. turtle.turnLeft()
  116. turtle.dig()
  117. turtle.forward()
  118. turtle.turnLeft()
  119. end
  120. -- Both situations leave us facing to where we need to dig and go down
  121. -- Also good to drop items/refuel
  122. refuel()
  123. turtle.dig()
  124. turtle.forward()
  125. turtle.digUp()
  126. turtle.digDown()
  127. turtle.down()
  128. if z < 4 then
  129. -- Figure out how to get back to our starting point.
  130. turtle.turnLeft()
  131. turtle.dig()
  132. turtle.forward()
  133. turtle.turnLeft()
  134. for temp=1,z do -- We will be [z] blocks from the edge on this side
  135. turtle.dig()
  136. turtle.forward()
  137. end
  138. turtle.turnRight()
  139. -- And a full 16 blocks from the next edge inclusive, but, we're inclusive on two points
  140. -- So up to 15
  141. for temp=1,15 do
  142. turtle.dig()
  143. turtle.forward()
  144. end
  145. turtle.turnRight() -- And it's ready to iterate again
  146. end
  147. end
  148. sz = 1
  149. -- We have successfully dug 16x16x4
  150. -- And are on our stairwell area, on the 5th block into the stairwell
  151.  
  152. -- This is a good time to ditch items, since we don't pick things up on the stairwell and they won't fall
  153.  
  154. refuel()
  155.  
  156.  
  157. -- Continue the stairwell down to 8
  158. for temp=5,8 do -- This works for both halves
  159. turtle.dig()
  160. turtle.forward()
  161. turtle.digUp()
  162. turtle.digDown()
  163. turtle.down()
  164. end
  165. -- Get back to the starting position
  166. turtle.turnLeft()
  167. turtle.dig()
  168. turtle.forward()
  169. turtle.turnLeft()
  170. -- We are on block 8 and want to be on block 1
  171. for temp=8,1,-1 do
  172. turtle.dig()
  173. turtle.forward()
  174. end
  175. turtle.turnRight()
  176. -- And we're ready to iterate again
  177. end
Add Comment
Please, Sign In to add comment