Advertisement
ladyDia

FTL Drive Thing

Jan 29th, 2025 (edited)
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.14 KB | None | 0 0
  1. --[[
  2.     Uses a command computer to scan all attached blocks (within a certain range) and save the data
  3.     of the blocks. Then check the destination to see if there is space open for the attached blocks to move to.
  4.    
  5.     If there is space, then move the ship to that spot.
  6.  
  7.     Also allows the ship to turn in place.
  8.  
  9.     Moving the ship requires fuel and engines to complete
  10. --]]
  11.  
  12. local xPos,yPos,zPos = commands.getBlockPosition()
  13. local destination = {xPos+100,yPos,zPos}
  14. local difference = {destination[1]-xPos,destination[2]-yPos,destination[3]-zPos}
  15. local shipMap = {} --Will be a 3d map of booleans
  16. local count = 0
  17.  
  18. function recursiveScan(scanPos)
  19.     --If the scannedBlock is air or null then return false
  20.     local scannedBlock = commands.getBlockInfo(scanPos[1],scanPos[2],scanPos[3])
  21.     if scannedBlock == nil then
  22.         if shipMap[scanPos[1]] == nil then
  23.            shipMap[scanPos[1]] = {}
  24.         end
  25.         if shipMap[scanPos[1]][scanPos[2]] == nil then
  26.            shipMap[scanPos[1]][scanPos[2]] = {}
  27.         end
  28.         shipMap[scanPos[1]][scanPos[2]][scanPos[3]] = scanPos
  29.         return false
  30.     elseif scannedBlock.name == "minecraft:air" then
  31.         if shipMap[scanPos[1]] == nil then
  32.            shipMap[scanPos[1]] = {}
  33.         end
  34.         if shipMap[scanPos[1]][scanPos[2]] == nil then
  35.            shipMap[scanPos[1]][scanPos[2]] = {}
  36.         end
  37.         shipMap[scanPos[1]][scanPos[2]][scanPos[3]] = scanPos
  38.         return false
  39.     end
  40.     --Check if position in shipMap is open
  41.     if shipMap[scanPos[1]] == nil then
  42.        shipMap[scanPos[1]] = {}
  43.     end
  44.     if shipMap[scanPos[1]][scanPos[2]] == nil then
  45.        shipMap[scanPos[1]][scanPos[2]] = {}
  46.     end
  47.     shipMap[scanPos[1]][scanPos[2]][scanPos[3]] = scanPos
  48.     count = count + 1
  49.     --Check the surrounding blocks
  50.     for xIndex = -1, 1, 1 do
  51.         if shipMap[scanPos[1]+xIndex] == nil then
  52.            shipMap[scanPos[1]+xIndex] = {}
  53.         end
  54.         for yIndex = -1, 1, 1 do
  55.             if shipMap[scanPos[1]+xIndex][scanPos[2]+yIndex] == nil then
  56.                shipMap[scanPos[1]+xIndex][scanPos[2]+yIndex] = {}
  57.             end
  58.             for zIndex = -1, 1, 1 do
  59.                 if shipMap[scanPos[1]+xIndex][scanPos[2]+yIndex][scanPos[3]+zIndex] == nil then
  60.                    recursiveScan({scanPos[1]+xIndex,scanPos[2]+yIndex,scanPos[3]+zIndex})
  61.                 end
  62.             end
  63.         end
  64.     end
  65.     return true    
  66. end
  67.  
  68.  
  69. print("Starting scan")
  70. recursiveScan({xPos,yPos,zPos})
  71. print("Completed scan. "..count.." blocks found")
  72.  
  73. print("Jumping to target")
  74.  
  75. for xKey,xElement in pairs(shipMap) do
  76.     for yKey,yElement in pairs(xElement) do
  77.         for zKey,zElement in pairs(yElement) do
  78.             if zElement then
  79.                 print("Weh")
  80.                 commands.clone(
  81.                     zElement[1]+difference[1],zElement[2]+difference[2],zElement[3]+difference[3],
  82.                     zElement[1]+difference[1],zElement[2]+difference[2],zElement[3]+difference[3],
  83.                     zElement[1]+difference[1],zElement[2]+difference[2],zElement[3]+difference[3]
  84.                 )
  85.             end
  86.         end
  87.     end
  88. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement