Dimencia

Untitled

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