Skip to content

Commit 279dcda

Browse files
committed
chore: make spawn-delay configurable & other misc
1 parent f2ec727 commit 279dcda

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

geary-papermc-spawning/src/main/kotlin/com/mineinabyss/geary/papermc/spawning/SpawningFeature.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class SpawningFeature(context: FeatureContext) : Feature(context) {
9494
val spawnChooser = SpawnChooser(wg, caps)
9595
val mobSpawner = MobSpawner(spawnChooser, LocationSpread(triesForNearbyLoc = 10))
9696
val task = SpawnTask(
97+
spawnDelay = config.spawnDelay,
9798
runTimes = config.runTimes,
9899
locationChooser = SpawnLocationChooser(config.range),
99100
spawnAttempts = config.maxSpawnAttemptsPerPlayer,

geary-papermc-spawning/src/main/kotlin/com/mineinabyss/geary/papermc/spawning/choosing/SpawnLocationChooser.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ class SpawnLocationChooser(
3838
val highestY = newLoc.world.getHighestBlockAt(newLoc).y.toDouble() + 1
3939
if (abs(highestY - newLoc.y) <= range) return newLoc.apply { y = highestY }
4040
if (!newLoc.block.isPassable) return newLoc
41-
(newLoc.y.toInt() downTo newLoc.y.toInt() - range)
42-
.forEach {
43-
newLoc.y = it.toDouble()
44-
if (!newLoc.block.isPassable) return newLoc.up(1)
45-
}
41+
42+
(newLoc.y.toInt() downTo newLoc.y.toInt() - range).forEach {
43+
newLoc.y = it.toDouble()
44+
if (!newLoc.block.isPassable) return newLoc.up(1)
45+
}
4646
return location
4747
}
4848

geary-papermc-spawning/src/main/kotlin/com/mineinabyss/geary/papermc/spawning/config/SpawnConfig.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.mineinabyss.geary.papermc.spawning.config
33
import com.charleskorn.kaml.YamlComment
44
import com.mineinabyss.geary.papermc.spawning.components.SpawnCategory
55
import com.mineinabyss.idofront.serialization.DurationSerializer
6+
import com.mineinabyss.idofront.time.ticks
67
import kotlinx.serialization.Serializable
78
import kotlin.time.Duration
89

@@ -22,6 +23,8 @@ data class SpawnConfig(
2223
),
2324
@YamlComment("Options about the spawn range of mobs around each player")
2425
val range: Range = Range(),
26+
@YamlComment("The delay between each spawning-task run")
27+
val spawnDelay: @Serializable(DurationSerializer::class) Duration = 1.ticks,
2528
@YamlComment("How often should each spawn category, attempt spawns. The higher a value, the more time between spawn attempts.")
2629
val runTimes: Map<SpawnPosition, @Serializable(with = DurationSerializer::class) Duration> = mapOf(),
2730
@YamlComment("How many times to try and find a valid spawn position around a player before giving up.")

geary-papermc-spawning/src/main/kotlin/com/mineinabyss/geary/papermc/spawning/tasks/SpawnTask.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import org.bukkit.GameMode.SPECTATOR
1414
import kotlin.time.Duration
1515

1616
class SpawnTask(
17+
val spawnDelay: Duration,
1718
val runTimes: Map<SpawnPosition, Duration>,
1819
val locationChooser: SpawnLocationChooser,
1920
val spawnAttempts: Int,
@@ -26,15 +27,15 @@ class SpawnTask(
2627
}.onFailure {
2728
gearyPaper.logger.d { it.stackTraceToString() }
2829
}
29-
delay(1.ticks)
30+
delay(spawnDelay)
3031
}
3132
}
3233

3334
fun run() {
3435
val currTick = Bukkit.getCurrentTick()
35-
val allowedSpawnPositions: List<SpawnPosition> = SpawnPosition.entries
36+
val allowedSpawnPositions = SpawnPosition.entries
3637
.filter { currTick % runTimes.getOrDefault(it, 1.ticks).inWholeTicks == 0L }
37-
.takeUnless { it.isEmpty() } ?: return
38+
.ifEmpty { return }
3839
val onlinePlayers = Bukkit.getOnlinePlayers().filter { !it.isDead && it.gameMode != SPECTATOR }
3940

4041
onlinePlayers.forEach { player ->
@@ -43,8 +44,8 @@ class SpawnTask(
4344
if (attemptedPositions.isEmpty()) return@forEach
4445
val spawnLoc = locationChooser.chooseSpawnLocationNear(onlinePlayers, player.location) ?: return@repeat
4546
val type = SpawnPositionReader.spawnPositionFor(spawnLoc)
46-
if (type in allowedSpawnPositions) {
47-
attemptedPositions.remove(type)
47+
48+
if (attemptedPositions.remove(type)) {
4849
mobSpawner.attemptSpawnAt(spawnLoc, type)
4950
}
5051
}

0 commit comments

Comments
 (0)