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

Commit

Permalink
Fix search radius not being used for cap checks
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed Dec 5, 2023
1 parent c3b007c commit 32d798f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ class CapFull : CheckingListener() {
val Pointers.spawnInfo by get<SpawnInfo>().on(event)

override fun Pointers.check(): Boolean =
(spawnInfo.localTypes[spawnType.prefab] ?: 0) < conf.max
spawnInfo.nearbyEntities(spawnType.prefab, conf.radius) < conf.max
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package com.mineinabyss.mobzy.spawning.vertical

import com.mineinabyss.geary.papermc.tracking.entities.toGeary
import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull
import com.mineinabyss.geary.prefabs.PrefabKey
import com.mineinabyss.geary.prefabs.helpers.prefabs
import com.mineinabyss.idofront.location.down
import com.mineinabyss.idofront.location.up
import com.mineinabyss.idofront.typealiases.BukkitEntity
import com.mineinabyss.mobzy.spawning.SpawnPosition
import com.mineinabyss.mobzy.spawning.components.SubChunkBlockComposition
import org.bukkit.ChunkSnapshot
import org.bukkit.Location
import org.bukkit.entity.Entity
import org.bukkit.entity.SpawnCategory
import kotlin.random.Random

//TODO name could be confused with SpawnRegion
Expand All @@ -26,21 +23,16 @@ import kotlin.random.Random
class SpawnInfo(
val bottom: Location,
val top: Location,
searchRadius: Double = 400.0,
chunkSnapshot: ChunkSnapshot? = null,
) {
val chunkSnapshot: ChunkSnapshot by lazy { chunkSnapshot ?: bottom.chunk.chunkSnapshot }

val blockComposition by lazy { SubChunkBlockComposition(this.chunkSnapshot, bottom.blockY) }

private val searchRadiusSquared = searchRadius * searchRadius

val localMobs: Collection<BukkitEntity> by lazy {
bottom.getNearbyEntities(searchRadiusSquared, searchRadiusSquared, searchRadiusSquared)
}
val localTypes: Map<PrefabKey?, Int> by lazy { categorizeByType(localMobs) }
val localCategories: Map<SpawnCategory, Int> by lazy {
localMobs.groupingBy { it.spawnCategory }.eachCount()
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()
}

//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 32d798f

Please sign in to comment.