This repository has been archived by the owner on May 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(spawning): Rework spawn system to iterate many chunks per tick, only checking one block instead of slice to be more similar to vanilla rollback(spawning): Remove checks for bounding box space until performance issues resolved
- Loading branch information
Showing
21 changed files
with
377 additions
and
492 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/GlobalSpawnInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
package com.mineinabyss.mobzy.spawning | ||
|
||
object GlobalSpawnInfo { | ||
var iterationNumber: Int = 0 | ||
var iterationNumber: Long = 0 | ||
internal set | ||
|
||
var playerGroupCount = 0 | ||
internal set | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/PlayerSpawnInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.mineinabyss.mobzy.spawning | ||
|
||
import com.mineinabyss.geary.datatypes.GearyEntity | ||
import com.mineinabyss.geary.helpers.fastForEach | ||
import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull | ||
import com.mineinabyss.mobzy.spawning.conditions.collectPrefabs | ||
import org.bukkit.Chunk | ||
|
||
class PlayerSpawnInfo { | ||
companion object { | ||
fun countIn(chunks: List<Chunk>): MutableMap<GearyEntity, Int> { | ||
val count = mutableMapOf<GearyEntity, Int>() | ||
chunks.forEach { chunk -> | ||
chunk.entities.fastForEach { bukkitEntity -> | ||
val entity = bukkitEntity.toGearyOrNull() ?: return@fastForEach | ||
entity.collectPrefabs().forEach { prefab -> | ||
count[prefab] = count.getOrDefault(prefab, 0) + 1 | ||
} | ||
} | ||
} | ||
return count | ||
} | ||
} | ||
} |
34 changes: 14 additions & 20 deletions
34
mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/SpawnConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,36 @@ | ||
package com.mineinabyss.mobzy.spawning | ||
|
||
import com.mineinabyss.geary.datatypes.GearyEntity | ||
import com.mineinabyss.geary.prefabs.PrefabKey | ||
import com.mineinabyss.idofront.serialization.DurationSerializer | ||
import com.mineinabyss.idofront.serialization.IntRangeSerializer | ||
import com.mineinabyss.idofront.time.ticks | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.Transient | ||
import kotlin.time.Duration | ||
|
||
/** | ||
* @property chunkSpawnRad the minimum number of chunks away from the player in which a mob can spawn | ||
* @property maxCommandSpawns the maximum number of mobs to spawn with /mobzy spawn | ||
* @property spawnChunksAroundPlayer the minimum number of chunks away from the player in which a mob can spawn | ||
* @property playerGroupRadius the radius around which players will count mobs towards the local mob cap | ||
* @property spawnTaskDelay the delay in ticks between each attempted mob spawn | ||
* @property creatureTypeCaps Per-player mob caps for spawning of [NMSCreatureType]s on the server. | ||
* @property spawnHeightRange The maximum amount above or below players that mobs can spawn. | ||
*/ | ||
@Serializable | ||
class SpawnConfig( | ||
@Serializable(with = IntRangeSerializer::class) | ||
val chunkSpawnRad: IntRange = 2..4, | ||
val maxCommandSpawns: Int = 20, | ||
val playerGroupRadius: Double = 96.0, | ||
@Serializable(with = DurationSerializer::class) | ||
val spawnTaskDelay: Duration = 40.ticks, | ||
val globalMobCap: Map<PrefabKey, Int> = mapOf(), | ||
val localMobCap: Map<PrefabKey, Int> = mapOf(), | ||
val localMobCapRadius: Double = 256.0, | ||
val spawnHeightRange: Int = 40, | ||
val preventSpawningInsideBlock: Boolean = true, | ||
val retriesUpWhenInsideBlock: Int = 3 | ||
val spawnHeightRange: Int = 48, | ||
val spawnChunksAroundPlayer: Int = 4, | ||
val spawnCategories: Map<PrefabKey, SpawnCategory> = mapOf(), | ||
val retriesUpWhenInsideBlock: Int = 3, | ||
val maxSpawnAttemptsPerCategoryPerTick: Int = 64, | ||
) { | ||
@Serializable | ||
data class SpawnCategory( | ||
val localMax: Int, | ||
val every: @Serializable(with = DurationSerializer::class) Duration = 1.ticks, | ||
val position: SpawnPosition = SpawnPosition.GROUND, | ||
val minDistanceFromPlayer: Int = 24, | ||
) | ||
@Transient | ||
val localMobCapEntities = localMobCap.mapKeys { it.key.toEntity() } | ||
|
||
fun capsToCheckFor(types: Set<GearyEntity>): Map<GearyEntity, Int> = types | ||
.intersect(localMobCapEntities.keys) | ||
.associateWith { localMobCapEntities[it]!! } | ||
val spawnCategoryEntities = spawnCategories.mapKeys { it.key.toEntity() } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.