Check consistency of block remaps

This commit is contained in:
Dylan K. Taylor
2021-06-21 20:30:27 +01:00
parent 85ee628a74
commit 2a6009f8bf
4 changed files with 46 additions and 12 deletions

View File

@ -26,14 +26,19 @@ require dirname(__DIR__, 3) . '/vendor/autoload.php';
/* This script needs to be re-run after any intentional blockfactory change (adding or removing a block state). */
$factory = new \pocketmine\block\BlockFactory();
$remaps = [];
$new = [];
foreach($factory->getAllKnownStates() as $index => $block){
if($block->getFullId() !== $index){
$remaps[$index] = $block->getFullId();
}else{
$new[$index] = $block->getName();
}
}
$oldTable = json_decode(file_get_contents(__DIR__ . '/block_factory_consistency_check.json'), true);
$old = $oldTable["knownStates"];
$oldRemaps = $oldTable["remaps"];
$old = json_decode(file_get_contents(__DIR__ . '/block_factory_consistency_check.json'), true);
$new = array_map(
function(\pocketmine\block\Block $block) : string{
return $block->getName();
},
$factory->getAllKnownStates()
);
foreach($old as $k => $name){
if(!isset($new[$k])){
echo "Removed state for $name (" . ($k >> \pocketmine\block\Block::INTERNAL_METADATA_BITS) . ":" . ($k & \pocketmine\block\Block::INTERNAL_METADATA_MASK) . ")\n";
@ -46,6 +51,22 @@ foreach($new as $k => $name){
echo "Name changed (" . ($k >> \pocketmine\block\Block::INTERNAL_METADATA_BITS) . ":" . ($k & \pocketmine\block\Block::INTERNAL_METADATA_MASK) . "): " . $old[$k] . " -> " . $name . "\n";
}
}
foreach($oldRemaps as $index => $mapped){
if(!isset($remaps[$index])){
echo "Removed remap of " . ($index >> 4) . ":" . ($index & 0xf) . "\n";
}
}
foreach($remaps as $index => $mapped){
if(!isset($oldRemaps[$index])){
echo "New remap of " . ($index >> 4) . ":" . ($index & 0xf) . " (" . ($mapped >> 4) . ":" . ($mapped & 0xf) . ") (" . $new[$mapped] . ")\n";
}elseif($oldRemaps[$index] !== $mapped){
echo "Remap changed for " . ($index >> 4) . ":" . ($index & 0xf) . " (" . ($oldRemaps[$index] >> 4) . ":" . ($oldRemaps[$index] & 0xf) . " (" . $old[$oldRemaps[$index]] . ") -> " . ($mapped >> 4) . ":" . ($mapped & 0xf) . " (" . $new[$mapped] . "))\n";
}
}
file_put_contents(__DIR__ . '/block_factory_consistency_check.json', json_encode(
$new
[
"knownStates" => $new,
"remaps" => $remaps
],
));