mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +00:00
fix a bunch of bugs
This commit is contained in:
@ -60,4 +60,6 @@ final class BlockDataUpgrader{
|
||||
|
||||
return $this->blockStateUpgrader->upgrade($blockStateData);
|
||||
}
|
||||
|
||||
public function getBlockStateUpgrader() : BlockStateUpgrader{ return $this->blockStateUpgrader; }
|
||||
}
|
||||
|
@ -70,6 +70,9 @@ final class ItemDataUpgrader{
|
||||
ksort($this->idMetaUpgradeSchemas, SORT_NUMERIC);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SavedDataLoadingException
|
||||
*/
|
||||
private function upgradeItemTypeNbt(CompoundTag $tag) : SavedItemData{
|
||||
if(($nameIdTag = $tag->getTag(SavedItemData::TAG_NAME)) instanceof StringTag){
|
||||
//Bedrock 1.6+
|
||||
@ -98,6 +101,11 @@ final class ItemDataUpgrader{
|
||||
}elseif(($r12BlockId = $this->r12ItemIdToBlockIdMap->itemIdToBlockId($rawNameId)) !== null){
|
||||
//this is a legacy blockitem represented by ID + meta
|
||||
$blockStateData = $this->blockDataUpgrader->upgradeStringIdMeta($r12BlockId, $meta);
|
||||
if($blockStateData === null){
|
||||
throw new SavedDataLoadingException("Expected a blockstate to be associated with this block");
|
||||
}
|
||||
//the block data upgrader returns states from 1.18.10, which need to be updated to the current version the usual way
|
||||
$blockStateData = $this->blockDataUpgrader->getBlockStateUpgrader()->upgrade($blockStateData);
|
||||
}else{
|
||||
//probably a standard item
|
||||
$blockStateData = null;
|
||||
@ -112,6 +120,7 @@ final class ItemDataUpgrader{
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
* @throws SavedDataLoadingException
|
||||
*/
|
||||
private static function deserializeListOfStrings(?ListTag $list, string $tagName) : array{
|
||||
if($list === null){
|
||||
@ -129,6 +138,9 @@ final class ItemDataUpgrader{
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SavedDataLoadingException
|
||||
*/
|
||||
public function upgradeItemStackNbt(CompoundTag $tag) : SavedItemStackData{
|
||||
$savedItemData = $this->upgradeItemTypeNbt($tag);
|
||||
try{
|
||||
@ -169,6 +181,6 @@ final class ItemDataUpgrader{
|
||||
}
|
||||
}
|
||||
|
||||
return [$id, $meta];
|
||||
return [$newId, $newMeta];
|
||||
}
|
||||
}
|
||||
|
@ -40,10 +40,10 @@ final class ItemIdMetaUpgradeSchema{
|
||||
public function getPriority() : int{ return $this->priority; }
|
||||
|
||||
public function renameId(string $id) : ?string{
|
||||
return $this->renamedIds[$id] ?? null;
|
||||
return $this->renamedIds[mb_strtolower($id, 'US-ASCII')] ?? null;
|
||||
}
|
||||
|
||||
public function remapMeta(string $id, int $meta) : ?string{
|
||||
return $this->remappedMetas[$id][$meta] ?? null;
|
||||
return $this->remappedMetas[mb_strtolower($id, 'US-ASCII')][$meta] ?? null;
|
||||
}
|
||||
}
|
||||
|
@ -68,20 +68,34 @@ final class R12ItemIdToBlockIdMap{
|
||||
return new self($builtMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
* @phpstan-var array<string, string>
|
||||
*/
|
||||
private array $itemToBlock = [];
|
||||
/**
|
||||
* @var string[]
|
||||
* @phpstan-var array<string, string>
|
||||
*/
|
||||
private array $blockToItem = [];
|
||||
|
||||
/**
|
||||
* @param string[] $itemToBlock
|
||||
* @phpstan-param array<string, string> $itemToBlock
|
||||
*/
|
||||
public function __construct(private array $itemToBlock){}
|
||||
public function __construct(array $itemToBlock){
|
||||
foreach($itemToBlock as $itemId => $blockId){
|
||||
$this->itemToBlock[mb_strtolower($itemId, 'US-ASCII')] = $blockId;
|
||||
$this->blockToItem[mb_strtolower($blockId, 'US-ASCII')] = $itemId;
|
||||
}
|
||||
}
|
||||
|
||||
public function itemIdToBlockId(string $itemId) : ?string{
|
||||
return $this->itemToBlock[$itemId] ?? null;
|
||||
return $this->itemToBlock[mb_strtolower($itemId, 'US-ASCII')] ?? null;
|
||||
}
|
||||
|
||||
public function blockIdToItemId(string $blockId) : ?string{
|
||||
//we don't need this for any functionality, so we're not concerned about performance here
|
||||
//however, it might be nice to have for debugging
|
||||
$itemId = array_search($blockId, $this->itemToBlock, true);
|
||||
return $itemId !== false ? $itemId : null;
|
||||
//we don't need this for any functionality, but it might be nice to have for debugging
|
||||
return $this->blockToItem[mb_strtolower($blockId, 'US-ASCII')] ?? null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user