mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-23 03:16:35 +00:00
Mojang cannot be relied on ...
This commit is contained in:
parent
643556a366
commit
a75bc5d537
@ -38,9 +38,9 @@ final class BlockStateData{
|
|||||||
*/
|
*/
|
||||||
public const CURRENT_VERSION =
|
public const CURRENT_VERSION =
|
||||||
(1 << 24) | //major
|
(1 << 24) | //major
|
||||||
(16 << 16) | //minor
|
(18 << 16) | //minor
|
||||||
(210 << 8) | //patch
|
(10 << 8) | //patch
|
||||||
(3); //revision
|
(1); //revision
|
||||||
|
|
||||||
public const TAG_NAME = "name";
|
public const TAG_NAME = "name";
|
||||||
public const TAG_STATES = "states";
|
public const TAG_STATES = "states";
|
||||||
|
@ -70,13 +70,16 @@ final class BlockStateUpgradeSchema{
|
|||||||
public int $maxVersionMajor,
|
public int $maxVersionMajor,
|
||||||
public int $maxVersionMinor,
|
public int $maxVersionMinor,
|
||||||
public int $maxVersionPatch,
|
public int $maxVersionPatch,
|
||||||
public int $maxVersionRevision
|
public int $maxVersionRevision,
|
||||||
|
private int $priority
|
||||||
){}
|
){}
|
||||||
|
|
||||||
public function getVersionId() : int{
|
public function getVersionId() : int{
|
||||||
return ($this->maxVersionMajor << 24) | ($this->maxVersionMinor << 16) | ($this->maxVersionPatch << 8) | $this->maxVersionRevision;
|
return ($this->maxVersionMajor << 24) | ($this->maxVersionMinor << 16) | ($this->maxVersionPatch << 8) | $this->maxVersionRevision;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPriority() : int{ return $this->priority; }
|
||||||
|
|
||||||
public function isEmpty() : bool{
|
public function isEmpty() : bool{
|
||||||
foreach([
|
foreach([
|
||||||
$this->renamedIds,
|
$this->renamedIds,
|
||||||
@ -93,22 +96,4 @@ final class BlockStateUpgradeSchema{
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isBackwardsCompatible() : bool{
|
|
||||||
if($this->backwardsCompatible === null){
|
|
||||||
$this->backwardsCompatible = true;
|
|
||||||
foreach([
|
|
||||||
$this->renamedIds,
|
|
||||||
$this->removedProperties,
|
|
||||||
$this->remappedPropertyValues,
|
|
||||||
$this->remappedStates
|
|
||||||
] as $bcBreakingRules){
|
|
||||||
if(count($bcBreakingRules) !== 0){
|
|
||||||
$this->backwardsCompatible = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//schemas which only add properties are backwards compatible
|
|
||||||
return $this->backwardsCompatible;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -111,12 +111,13 @@ final class BlockStateUpgradeSchemaUtils{
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function fromJsonModel(BlockStateUpgradeSchemaModel $model) : BlockStateUpgradeSchema{
|
public static function fromJsonModel(BlockStateUpgradeSchemaModel $model, int $priority) : BlockStateUpgradeSchema{
|
||||||
$result = new BlockStateUpgradeSchema(
|
$result = new BlockStateUpgradeSchema(
|
||||||
$model->maxVersionMajor,
|
$model->maxVersionMajor,
|
||||||
$model->maxVersionMinor,
|
$model->maxVersionMinor,
|
||||||
$model->maxVersionPatch,
|
$model->maxVersionPatch,
|
||||||
$model->maxVersionRevision
|
$model->maxVersionRevision,
|
||||||
|
$priority
|
||||||
);
|
);
|
||||||
$result->renamedIds = $model->renamedIds ?? [];
|
$result->renamedIds = $model->renamedIds ?? [];
|
||||||
$result->renamedProperties = $model->renamedProperties ?? [];
|
$result->renamedProperties = $model->renamedProperties ?? [];
|
||||||
@ -280,7 +281,7 @@ final class BlockStateUpgradeSchemaUtils{
|
|||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$schema = self::loadSchemaFromString($raw);
|
$schema = self::loadSchemaFromString($raw, $priority);
|
||||||
}catch(\RuntimeException $e){
|
}catch(\RuntimeException $e){
|
||||||
throw new \RuntimeException("Loading schema file $fullPath: " . $e->getMessage(), 0, $e);
|
throw new \RuntimeException("Loading schema file $fullPath: " . $e->getMessage(), 0, $e);
|
||||||
}
|
}
|
||||||
@ -298,7 +299,7 @@ final class BlockStateUpgradeSchemaUtils{
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function loadSchemaFromString(string $raw) : BlockStateUpgradeSchema{
|
public static function loadSchemaFromString(string $raw, int $priority) : BlockStateUpgradeSchema{
|
||||||
try{
|
try{
|
||||||
$json = json_decode($raw, false, flags: JSON_THROW_ON_ERROR);
|
$json = json_decode($raw, false, flags: JSON_THROW_ON_ERROR);
|
||||||
}catch(\JsonException $e){
|
}catch(\JsonException $e){
|
||||||
@ -315,6 +316,6 @@ final class BlockStateUpgradeSchemaUtils{
|
|||||||
throw new \RuntimeException($e->getMessage(), 0, $e);
|
throw new \RuntimeException($e->getMessage(), 0, $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::fromJsonModel($model);
|
return self::fromJsonModel($model, $priority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@ use pocketmine\data\bedrock\blockstate\BlockStateData;
|
|||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\nbt\tag\Tag;
|
use pocketmine\nbt\tag\Tag;
|
||||||
use pocketmine\utils\Utils;
|
use pocketmine\utils\Utils;
|
||||||
use function array_unshift;
|
|
||||||
use function ksort;
|
use function ksort;
|
||||||
use const SORT_NUMERIC;
|
use const SORT_NUMERIC;
|
||||||
|
|
||||||
@ -46,19 +45,16 @@ final class BlockStateUpgrader{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function addSchema(BlockStateUpgradeSchema $schema) : void{
|
public function addSchema(BlockStateUpgradeSchema $schema) : void{
|
||||||
if(!$schema->isBackwardsCompatible()){
|
$schemaList = $this->upgradeSchemas[$schema->getVersionId()] ?? [];
|
||||||
$schemaList = $this->upgradeSchemas[$schema->getVersionId()] ?? [];
|
|
||||||
foreach($schemaList as $otherSchema){
|
$priority = $schema->getPriority();
|
||||||
if(!$otherSchema->isBackwardsCompatible()){
|
if(isset($schemaList[$priority])){
|
||||||
throw new \InvalidArgumentException("Cannot add two backwards-incompatible schemas with the same version");
|
throw new \InvalidArgumentException("Cannot add two schemas to the same version with the same priority");
|
||||||
}
|
|
||||||
}
|
|
||||||
array_unshift($schemaList, $schema);
|
|
||||||
$this->upgradeSchemas[$schema->getVersionId()] = $schemaList;
|
|
||||||
}else{
|
|
||||||
//Backwards-compatible schemas can be added in any order
|
|
||||||
$this->upgradeSchemas[$schema->getVersionId()][] = $schema;
|
|
||||||
}
|
}
|
||||||
|
$schemaList[$priority] = $schema;
|
||||||
|
ksort($schemaList, SORT_NUMERIC);
|
||||||
|
$this->upgradeSchemas[$schema->getVersionId()] = $schemaList;
|
||||||
|
|
||||||
ksort($this->upgradeSchemas, SORT_NUMERIC);
|
ksort($this->upgradeSchemas, SORT_NUMERIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,11 +67,6 @@ final class BlockStateUpgrader{
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
foreach($schemas as $schema){
|
foreach($schemas as $schema){
|
||||||
if(!$schema->isBackwardsCompatible() && $resultVersion === $version){
|
|
||||||
//backwards-compatible updates typically don't bump version and must always be applied because we
|
|
||||||
//can't tell any different, but backwards-incompatible ones SHOULD always get their own version bump
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$oldName = $blockStateData->getName();
|
$oldName = $blockStateData->getName();
|
||||||
if(isset($schema->remappedStates[$oldName])){
|
if(isset($schema->remappedStates[$oldName])){
|
||||||
foreach($schema->remappedStates[$oldName] as $remap){
|
foreach($schema->remappedStates[$oldName] as $remap){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user