From 0414f8354115c351f614ac8a13ba0da8b78cd162 Mon Sep 17 00:00:00 2001 From: Moritz Ruth Date: Mon, 14 Jun 2021 15:24:59 +0200 Subject: [PATCH] Entity changes --- .../src/main/kotlin/space/uranos/entity/Entity.kt | 13 ++++++++++--- .../main/kotlin/space/uranos/entity/UranosEntity.kt | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/uranos-api/src/main/kotlin/space/uranos/entity/Entity.kt b/uranos-api/src/main/kotlin/space/uranos/entity/Entity.kt index 3b16203..63f8e7f 100644 --- a/uranos-api/src/main/kotlin/space/uranos/entity/Entity.kt +++ b/uranos-api/src/main/kotlin/space/uranos/entity/Entity.kt @@ -23,10 +23,17 @@ interface Entity { */ val numericID: Int + /** + * If players should be added to [visibleTo] when they join. + * + * Defaults to true. + */ + var visibleToNewPlayers: Boolean + /** * Players that can see this entity if it is in their view distance. */ - val viewers: MutableSet + val visibleTo: MutableSet fun belongsToChunk(key: Chunk.Key): Boolean @@ -34,9 +41,9 @@ interface Entity { suspend fun setWorld(world: World?) /** - * If players should be added to [viewers] when they enter [world]. + * Players who currently have this entity loaded (= it is in their viewing distance). */ - var visibleToNewPlayers: Boolean + val viewers: Set var glowing: Boolean // It seems like every entity can glow diff --git a/uranos-server/src/main/kotlin/space/uranos/entity/UranosEntity.kt b/uranos-server/src/main/kotlin/space/uranos/entity/UranosEntity.kt index 3576bd8..8d345f6 100644 --- a/uranos-server/src/main/kotlin/space/uranos/entity/UranosEntity.kt +++ b/uranos-server/src/main/kotlin/space/uranos/entity/UranosEntity.kt @@ -31,6 +31,8 @@ sealed class UranosEntity(server: UranosServer) : Entity { override var visibleToNewPlayers: Boolean = true + override val visibleTo = mutableSetOf() + private val worldMutex = Mutex() final override var world: World? = null; private set