mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-16 03:51:37 +00:00
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.
This commit is contained in:
@@ -492,7 +492,7 @@ abstract class Entity{
|
|||||||
new FloatTag($this->location->pitch)
|
new FloatTag($this->location->pitch)
|
||||||
]));
|
]));
|
||||||
|
|
||||||
if(!($this instanceof Player)){
|
if(!($this instanceof NeverSavedWithChunkEntity)){
|
||||||
EntityFactory::getInstance()->injectSaveId(get_class($this), $nbt);
|
EntityFactory::getInstance()->injectSaveId(get_class($this), $nbt);
|
||||||
|
|
||||||
if($this->getNameTag() !== ""){
|
if($this->getNameTag() !== ""){
|
||||||
|
36
src/entity/NeverSavedWithChunkEntity.php
Normal file
36
src/entity/NeverSavedWithChunkEntity.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace pocketmine\entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decorator for entities that will never be saved with a chunk.
|
||||||
|
* Entities implementing this interface are not required to register a save ID.
|
||||||
|
*
|
||||||
|
* This differs from {@link Entity::canSaveWithChunk()} because it can't be changed after the entity is created.
|
||||||
|
* We can't use canSaveWithChunk() to decide whether an entity needs a save ID, but we can use an interface like this.
|
||||||
|
* An attribute would also work, but `instanceof NonSaveable` is easier.
|
||||||
|
*/
|
||||||
|
interface NeverSavedWithChunkEntity{
|
||||||
|
|
||||||
|
}
|
@@ -41,6 +41,7 @@ use pocketmine\entity\Entity;
|
|||||||
use pocketmine\entity\Human;
|
use pocketmine\entity\Human;
|
||||||
use pocketmine\entity\Living;
|
use pocketmine\entity\Living;
|
||||||
use pocketmine\entity\Location;
|
use pocketmine\entity\Location;
|
||||||
|
use pocketmine\entity\NeverSavedWithChunkEntity;
|
||||||
use pocketmine\entity\object\ItemEntity;
|
use pocketmine\entity\object\ItemEntity;
|
||||||
use pocketmine\entity\projectile\Arrow;
|
use pocketmine\entity\projectile\Arrow;
|
||||||
use pocketmine\entity\Skin;
|
use pocketmine\entity\Skin;
|
||||||
@@ -169,7 +170,7 @@ use const PHP_INT_MAX;
|
|||||||
/**
|
/**
|
||||||
* Main class that handles networking, recovery, and packet sending to the server part
|
* Main class that handles networking, recovery, and packet sending to the server part
|
||||||
*/
|
*/
|
||||||
class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
class Player extends Human implements CommandSender, ChunkListener, IPlayer, NeverSavedWithChunkEntity{
|
||||||
use PermissibleDelegateTrait;
|
use PermissibleDelegateTrait;
|
||||||
|
|
||||||
private const MOVES_PER_TICK = 2;
|
private const MOVES_PER_TICK = 2;
|
||||||
|
@@ -42,6 +42,7 @@ use pocketmine\data\SavedDataLoadingException;
|
|||||||
use pocketmine\entity\Entity;
|
use pocketmine\entity\Entity;
|
||||||
use pocketmine\entity\EntityFactory;
|
use pocketmine\entity\EntityFactory;
|
||||||
use pocketmine\entity\Location;
|
use pocketmine\entity\Location;
|
||||||
|
use pocketmine\entity\NeverSavedWithChunkEntity;
|
||||||
use pocketmine\entity\object\ExperienceOrb;
|
use pocketmine\entity\object\ExperienceOrb;
|
||||||
use pocketmine\entity\object\ItemEntity;
|
use pocketmine\entity\object\ItemEntity;
|
||||||
use pocketmine\event\block\BlockBreakEvent;
|
use pocketmine\event\block\BlockBreakEvent;
|
||||||
@@ -2776,7 +2777,7 @@ class World implements ChunkManager{
|
|||||||
throw new AssumptionFailedError("Found two different entities sharing entity ID " . $entity->getId());
|
throw new AssumptionFailedError("Found two different entities sharing entity ID " . $entity->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
|
//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.
|
//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");
|
throw new \LogicException("Entity " . $entity::class . " is not registered for a save ID in EntityFactory");
|
||||||
|
Reference in New Issue
Block a user