Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Uses a command computer to scan all attached blocks (within a certain range) and save the data
- of the blocks. Then check the destination to see if there is space open for the attached blocks to move to.
- If there is space, then move the ship to that spot.
- Also allows the ship to turn in place.
- Moving the ship requires fuel and engines to complete
- --]]
- local xPos,yPos,zPos = commands.getBlockPosition()
- local destination = {xPos+100,yPos,zPos}
- local difference = {destination[1]-xPos,destination[2]-yPos,destination[3]-zPos}
- local shipMap = {} --Will be a 3d map of booleans
- local count = 0
- function recursiveScan(scanPos)
- --If the scannedBlock is air or null then return false
- local scannedBlock = commands.getBlockInfo(scanPos[1],scanPos[2],scanPos[3])
- if scannedBlock == nil then
- if shipMap[scanPos[1]] == nil then
- shipMap[scanPos[1]] = {}
- end
- if shipMap[scanPos[1]][scanPos[2]] == nil then
- shipMap[scanPos[1]][scanPos[2]] = {}
- end
- shipMap[scanPos[1]][scanPos[2]][scanPos[3]] = scanPos
- return false
- elseif scannedBlock.name == "minecraft:air" then
- if shipMap[scanPos[1]] == nil then
- shipMap[scanPos[1]] = {}
- end
- if shipMap[scanPos[1]][scanPos[2]] == nil then
- shipMap[scanPos[1]][scanPos[2]] = {}
- end
- shipMap[scanPos[1]][scanPos[2]][scanPos[3]] = scanPos
- return false
- end
- --Check if position in shipMap is open
- if shipMap[scanPos[1]] == nil then
- shipMap[scanPos[1]] = {}
- end
- if shipMap[scanPos[1]][scanPos[2]] == nil then
- shipMap[scanPos[1]][scanPos[2]] = {}
- end
- shipMap[scanPos[1]][scanPos[2]][scanPos[3]] = scanPos
- count = count + 1
- --Check the surrounding blocks
- for xIndex = -1, 1, 1 do
- if shipMap[scanPos[1]+xIndex] == nil then
- shipMap[scanPos[1]+xIndex] = {}
- end
- for yIndex = -1, 1, 1 do
- if shipMap[scanPos[1]+xIndex][scanPos[2]+yIndex] == nil then
- shipMap[scanPos[1]+xIndex][scanPos[2]+yIndex] = {}
- end
- for zIndex = -1, 1, 1 do
- if shipMap[scanPos[1]+xIndex][scanPos[2]+yIndex][scanPos[3]+zIndex] == nil then
- recursiveScan({scanPos[1]+xIndex,scanPos[2]+yIndex,scanPos[3]+zIndex})
- end
- end
- end
- end
- return true
- end
- print("Starting scan")
- recursiveScan({xPos,yPos,zPos})
- print("Completed scan. "..count.." blocks found")
- print("Jumping to target")
- for xKey,xElement in pairs(shipMap) do
- for yKey,yElement in pairs(xElement) do
- for zKey,zElement in pairs(yElement) do
- if zElement then
- print("Weh")
- commands.clone(
- zElement[1]+difference[1],zElement[2]+difference[2],zElement[3]+difference[3],
- zElement[1]+difference[1],zElement[2]+difference[2],zElement[3]+difference[3],
- zElement[1]+difference[1],zElement[2]+difference[2],zElement[3]+difference[3]
- )
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement