From dd9cbb74f0bfeac9203e11f681db535cee55a0ef Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 20 Sep 2025 00:01:16 +0100 Subject: [PATCH] Added NeverSavedWithChunkEntity interface closes #6809 turns out we can actually use this for players too. we need this also for fireworks and probably lightning in the future. --- src/entity/Entity.php | 2 +- src/entity/NeverSavedWithChunkEntity.php | 36 ++++++++++++++++++++++++ src/player/Player.php | 3 +- src/world/World.php | 3 +- 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 src/entity/NeverSavedWithChunkEntity.php diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 73a0b3a9c..89f66d6b1 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -492,7 +492,7 @@ abstract class Entity{ new FloatTag($this->location->pitch) ])); - if(!($this instanceof Player)){ + if(!($this instanceof NeverSavedWithChunkEntity)){ EntityFactory::getInstance()->injectSaveId(get_class($this), $nbt); if($this->getNameTag() !== ""){ diff --git a/src/entity/NeverSavedWithChunkEntity.php b/src/entity/NeverSavedWithChunkEntity.php new file mode 100644 index 000000000..2245abdd9 --- /dev/null +++ b/src/entity/NeverSavedWithChunkEntity.php @@ -0,0 +1,36 @@ +getId()); } } - if(!EntityFactory::getInstance()->isRegistered($entity::class) && !$entity instanceof Player){ + if(!EntityFactory::getInstance()->isRegistered($entity::class) && !$entity instanceof NeverSavedWithChunkEntity){ //canSaveWithChunk is mutable, so that means it could be toggled after adding the entity and cause a crash //later on. Better we just force all entities to have a save ID, even if it might not be needed. throw new \LogicException("Entity " . $entity::class . " is not registered for a save ID in EntityFactory");