Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
perf: Optimize nearby entities prefab counting
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed Mar 26, 2024
1 parent 6101d60 commit 15f5966
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.mineinabyss.mobzy.spawning.vertical

import com.mineinabyss.geary.components.relations.InstanceOf
import com.mineinabyss.geary.helpers.componentId
import com.mineinabyss.geary.helpers.getArchetype
import com.mineinabyss.geary.helpers.toGeary
import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull
import com.mineinabyss.geary.prefabs.PrefabKey
import com.mineinabyss.geary.prefabs.configuration.components.Prefab
import com.mineinabyss.idofront.location.down
import com.mineinabyss.idofront.location.up
import com.mineinabyss.mobzy.spawning.SpawnPosition
Expand Down Expand Up @@ -29,9 +34,9 @@ class SpawnInfo(
val blockComposition by lazy { SubChunkBlockComposition(this.chunkSnapshot, bottom.blockY) }

fun nearbyEntities(key: PrefabKey, radius: Double): Int {
return bottom.world.getNearbyEntities(bottom, radius * 2, radius * 2, radius * 2) {
it.toGearyOrNull()?.prefabs?.firstOrNull()?.get<PrefabKey>() == key
}.count()
val prefabEntity = key.toEntity()
return bottom.world.getNearbyEntities(bottom, radius * 2, radius * 2, radius * 2)
.count { it.toGearyOrNull()?.instanceOf(prefabEntity) == true }
}

//adding one since if the blocks are on the same block, they still have a gap of 1 from top to bottom
Expand Down

0 comments on commit 15f5966

Please sign in to comment.