Dimencia

Untitled

Mar 22nd, 2021
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.40 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 = nil
  9. local startX = nil
  10. local startY = nil
  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. -- Then reselect slot 1
  62. select(cobbleSlot)
  63. end
  64.  
  65.  
  66. turtle.select(firstFuelSlot)
  67. turtle.refuel()
  68. turtle.select(cobbleSlot)
  69.  
  70. local sz=1
  71. local sx=1
  72. local sy=1
  73. if startZ then sz = startZ startZ = nil end
  74. if startX then sx = startX startX = nil end
  75. if startY then sy = startY startY = nil end
  76.  
  77. while(true) do
  78. for z=sz,4 do
  79.  
  80. for x=sx,16 do -- Same, always already in the first one
  81.  
  82. for y=sy,16 do -- We're always inside the first one
  83.  
  84. turtle.dig()
  85. --turtle.suck() -- Dig already does this, nice
  86. turtle.forward()
  87. if not turtle.detectDown() and z == 4 then turtle.placeDown() end -- Make sure the floors are filled in
  88. if not turtle.detectUp() and z == 1 then turtle.placeUp() end -- And the ceilings, which are 1 below the floors
  89. end
  90. sy = 1
  91. -- Reached the end on this side, turn (right/left)...
  92. if x < 16 then
  93. if x%2 == 1 then turtle.turnRight() else turtle.turnLeft() end
  94. turtle.dig()
  95. turtle.forward()
  96. if x%2 == 1 then turtle.turnRight() else turtle.turnLeft() end
  97. if not turtle.detectDown() and z == 4 then turtle.placeDown() end -- Make sure the floors are filled in
  98. if not turtle.detectUp() and z == 1 then turtle.placeUp() end -- And the ceilings, which are 1 below the floors
  99. end
  100. -- And, since we don't suck anymore, we can refuel at any point
  101. refuel()
  102. -- Ready to iterate again
  103. end
  104. sx = 1
  105. -- We've cleared out a 16x16 area on this level.
  106. -- And we are currently in the last block we broke...
  107. -- So the staircase is to our left. But, for everything except z==1
  108. -- We need to do a 180 and go to the opening
  109. if z > 1 then
  110. turtle.turnLeft()
  111. turtle.turnLeft()
  112. for i=2,z do
  113. turtle.forward()
  114. end
  115. turtle.turnRight()
  116. turtle.forward() -- There should already be nothing there
  117. turtle.turnLeft()
  118. else
  119. turtle.turnLeft()
  120. turtle.dig()
  121. turtle.forward()
  122. turtle.turnLeft()
  123. end
  124. -- Both situations leave us facing to where we need to dig and go down
  125. -- Also good to drop items/refuel
  126. refuel()
  127. if not turtle.detectDown() and z == 4 then turtle.placeDown() end -- Make sure the floors are filled in
  128. turtle.dig()
  129. turtle.forward()
  130. turtle.digUp()
  131. turtle.digDown()
  132. turtle.down()
  133. if not turtle.detectDown() and z == 4 then turtle.placeDown() end -- Make sure the floors are filled in
  134. if z < 4 then
  135. -- Figure out how to get back to our starting point.
  136. turtle.turnLeft()
  137. turtle.dig()
  138. turtle.forward()
  139. turtle.turnLeft()
  140. for temp=1,z do -- We will be [z] blocks from the edge on this side
  141. turtle.dig()
  142. turtle.forward()
  143. end
  144. turtle.turnRight()
  145. -- And a full 16 blocks from the next edge inclusive, but, we're inclusive on two points
  146. -- So up to 15
  147. for temp=1,15 do
  148. turtle.dig()
  149. turtle.forward()
  150. end
  151. turtle.turnRight() -- And it's ready to iterate again
  152. end
  153. end
  154. sz = 1
  155. -- We have successfully dug 16x16x4
  156. -- And are on our stairwell area, on the 5th block into the stairwell
  157.  
  158. -- This is a good time to ditch items, since we don't pick things up on the stairwell and they won't fall
  159.  
  160. refuel()
  161.  
  162.  
  163. -- Continue the stairwell down to 8
  164. for temp=5,8 do -- This works for both halves
  165. turtle.dig()
  166. turtle.forward()
  167. turtle.digUp()
  168. turtle.digDown()
  169. turtle.down()
  170. end
  171. -- Get back to the starting position
  172. turtle.turnLeft()
  173. turtle.dig()
  174. turtle.forward()
  175. turtle.turnLeft()
  176. -- We are on block 8 and want to be on block 1
  177. for temp=8,1,-1 do
  178. turtle.dig()
  179. turtle.forward()
  180. end
  181. turtle.turnRight()
  182. -- And we're ready to iterate again
  183. end
Add Comment
Please, Sign In to add comment