diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/Entity.kt b/src/main/java/de/bixilon/minosoft/data/entities/entities/Entity.kt index ca8fe643e..54cc1ceca 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/Entity.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/Entity.kt @@ -55,10 +55,20 @@ abstract class Entity( ) : Initializable, EntityAttachable { private var flags: Int by data(FLAGS_DATA, 0x00) { it.toInt() } protected val random = Random() + var _id: Int? = null + var _uuid: UUID? = null val id: Int? - get() = session.world.entities.getId(this) + get() { + if (_id != null) return _id + _id = session.world.entities.getId(this) + return _id + } open val uuid: UUID? - get() = session.world.entities.getUUID(this) + get() { + if (_uuid != null) return _uuid + _uuid = session.world.entities.getUUID(this) + return _uuid + } @Deprecated(message = "Use session.version", replaceWith = ReplaceWith("session.version.versionId")) protected val versionId: Int get() = session.version.versionId @@ -95,6 +105,7 @@ abstract class Entity( open val canRaycast: Boolean get() = true + var age = 0 private set diff --git a/src/main/java/de/bixilon/minosoft/data/world/entities/WorldEntities.kt b/src/main/java/de/bixilon/minosoft/data/world/entities/WorldEntities.kt index 697c56b95..299ebab91 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/entities/WorldEntities.kt +++ b/src/main/java/de/bixilon/minosoft/data/world/entities/WorldEntities.kt @@ -96,6 +96,8 @@ class WorldEntities : Iterable { fun remove(entity: Entity) { lock.lock() + entity._id = null + entity._uuid = null if (entity !is LocalPlayerEntity && !entities.remove(entity)) { lock.unlock() return @@ -112,6 +114,8 @@ class WorldEntities : Iterable { lock.unlock() return } + entity._id = null + entity._uuid = null if (entity is LocalPlayerEntity) { idEntityMap.put(entityId, entity) lock.unlock() @@ -192,6 +196,8 @@ class WorldEntities : Iterable { fun clear(session: PlaySession, local: Boolean = false) { this.lock.lock() for (entity in this.entities) { + entity._id = null + entity._uuid = null if (!local && entity is LocalPlayerEntity) continue entityIdMap.remove(entity)?.let { idEntityMap.remove(it) } entityUUIDMap.remove(entity)?.let { uuidEntityMap.remove(it) } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/entity/spawn/EntityObjectSpawnS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/entity/spawn/EntityObjectSpawnS2CP.kt index 782c8cbfa..021f47349 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/entity/spawn/EntityObjectSpawnS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/entity/spawn/EntityObjectSpawnS2CP.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -62,11 +62,11 @@ class EntityObjectSpawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket { } entity.startInit() entity.setObjectData(data) + velocity?.let { entity.physics.velocity = it } } override fun handle(session: PlaySession) { session.world.entities.add(entityId, entityUUID, entity) - velocity?.let { entity.physics.velocity = it } } override fun log(reducedLog: Boolean) {