Cleanup NetworkUtil
This commit is contained in:
parent
0eabbf9ec1
commit
6fae09d410
|
@ -14,25 +14,30 @@ import java.util.*
|
|||
object NetworkUtil {
|
||||
|
||||
fun findDestinations(world: World, startPos: BlockPos): List<PacketSink> {
|
||||
val results = mutableListOf<PacketSink>()
|
||||
val results = LinkedList<PacketSink>()
|
||||
val visited = hashSetOf(startPos)
|
||||
val queue = LinkedList<BlockPos>()
|
||||
addAdjacent(queue, visited, startPos)
|
||||
|
||||
while (queue.isNotEmpty()) {
|
||||
val pos = queue.pop()
|
||||
|
||||
val sink = PhyAttributes.PACKET_SINK.getFirstOrNull(world, pos)
|
||||
if (sink != null) {
|
||||
results.add(sink)
|
||||
}
|
||||
if (pos === startPos || world.getBlockState(pos).block is NetworkCable) {
|
||||
|
||||
if (world.getBlockState(pos).block is NetworkCable) {
|
||||
addAdjacent(queue, visited, pos)
|
||||
}
|
||||
|
||||
visited.add(pos)
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
fun addAdjacent(queue: MutableList<BlockPos>, visited: Set<BlockPos>, pos: BlockPos) {
|
||||
private fun addAdjacent(queue: MutableList<BlockPos>, visited: Set<BlockPos>, pos: BlockPos) {
|
||||
for (dir in Direction.values()) {
|
||||
val newPos = pos.offset(dir)
|
||||
if (newPos !in visited) {
|
||||
|
|
Loading…
Reference in New Issue