mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Entity: do not assume that save IDs are always strings
this is only the first of many changes needed to make entity savedata fully format-agnostic, but it's a start.
This commit is contained in:
parent
4b46549cd1
commit
e6348bbd34
@ -473,7 +473,7 @@ abstract class Entity{
|
||||
$nbt = EntityDataHelper::createBaseNBT($this->location, $this->motion, $this->location->yaw, $this->location->pitch);
|
||||
|
||||
if(!($this instanceof Player)){
|
||||
$nbt->setString("id", EntityFactory::getInstance()->getSaveId(get_class($this)));
|
||||
EntityFactory::getInstance()->injectSaveId(get_class($this), $nbt);
|
||||
|
||||
if($this->getNameTag() !== ""){
|
||||
$nbt->setString("CustomName", $this->getNameTag());
|
||||
|
@ -227,6 +227,14 @@ final class EntityFactory{
|
||||
return $entity;
|
||||
}
|
||||
|
||||
public function injectSaveId(string $class, CompoundTag $saveData) : void{
|
||||
if(isset($this->saveNames[$class])){
|
||||
$saveData->setTag("id", new StringTag(reset($this->saveNames[$class])));
|
||||
}else{
|
||||
throw new \InvalidArgumentException("Entity $class is not registered");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-param class-string<Entity> $class
|
||||
*/
|
||||
|
@ -530,6 +530,11 @@ parameters:
|
||||
count: 1
|
||||
path: ../../../src/data/bedrock/LegacyToStringBidirectionalIdMap.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$value of class pocketmine\\\\nbt\\\\tag\\\\StringTag constructor expects string, string\\|false given\\.$#"
|
||||
count: 1
|
||||
path: ../../../src/entity/EntityFactory.php
|
||||
|
||||
-
|
||||
message: "#^Method pocketmine\\\\entity\\\\EntityFactory\\:\\:getSaveId\\(\\) should return string but returns string\\|false\\.$#"
|
||||
count: 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user