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: Forced despawn when far away component
chore(spawning): Don't spawn in unloaded chunks
- Loading branch information
Showing
7 changed files
with
58 additions
and
29 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/despawning/DespawnSystems.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,33 @@ | ||
package com.mineinabyss.mobzy.features.despawning | ||
|
||
import com.mineinabyss.geary.modules.GearyModule | ||
import com.mineinabyss.geary.papermc.tracking.entities.toGeary | ||
import com.mineinabyss.geary.systems.builders.system | ||
import com.mineinabyss.geary.systems.query.Query | ||
import com.mineinabyss.idofront.typealiases.BukkitEntity | ||
import org.bukkit.event.EventHandler | ||
import org.bukkit.event.Listener | ||
import org.bukkit.event.world.EntitiesUnloadEvent | ||
import kotlin.time.Duration.Companion.seconds | ||
|
||
class DespawnSystems : Listener { | ||
//TODO this event fires when chunk unloaded but at ChunkUnloadEvent there are no entities in the chunk??? | ||
@EventHandler | ||
fun EntitiesUnloadEvent.removeCustomOnChunkUnload() { | ||
if (!chunk.isLoaded) return | ||
|
||
for (entity in chunk.entities) { | ||
val removeOnUnload = entity.toGeary().get<RemoveOnChunkUnload>() ?: continue | ||
if (!(removeOnUnload.keepIfRenamed && entity.customName() != null)) | ||
entity.remove() | ||
} | ||
} | ||
} | ||
|
||
fun GearyModule.removeWhenFarAway() = system(object : Query() { | ||
val bukkit by get<BukkitEntity>() | ||
val remove by get<RemoveWhenFarAway>() | ||
}).every(3.seconds).exec { | ||
if (bukkit.customName == null && bukkit.world.getNearbyPlayers(bukkit.location, remove.distance).isEmpty()) | ||
bukkit.remove() | ||
} |
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
17 changes: 0 additions & 17 deletions
17
...es/src/main/kotlin/com/mineinabyss/mobzy/features/despawning/RemoveOnChunkUnloadSystem.kt
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
...y-features/src/main/kotlin/com/mineinabyss/mobzy/features/despawning/RemoveWhenFarAway.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,14 @@ | ||
package com.mineinabyss.mobzy.features.despawning | ||
|
||
import kotlinx.serialization.EncodeDefault | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
@SerialName("mobzy:despawn.when_far_away") | ||
data class RemoveWhenFarAway( | ||
@EncodeDefault(EncodeDefault.Mode.NEVER) | ||
val keepIfRenamed: Boolean = true, | ||
@EncodeDefault(EncodeDefault.Mode.NEVER) | ||
val distance: Double = 128.0, | ||
) |
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
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