mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-10 20:08:01 +00:00
Check consistency of block remaps
This commit is contained in:
parent
85ee628a74
commit
2a6009f8bf
@ -56,6 +56,7 @@ use function array_fill;
|
|||||||
use function array_filter;
|
use function array_filter;
|
||||||
use function get_class;
|
use function get_class;
|
||||||
use function min;
|
use function min;
|
||||||
|
use function var_dump;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages deserializing block types from their legacy blockIDs and metadata.
|
* Manages deserializing block types from their legacy blockIDs and metadata.
|
||||||
|
@ -145,14 +145,26 @@ class BlockTest extends TestCase{
|
|||||||
|
|
||||||
public function testConsistency() : void{
|
public function testConsistency() : void{
|
||||||
$list = json_decode(file_get_contents(__DIR__ . '/block_factory_consistency_check.json'), true);
|
$list = json_decode(file_get_contents(__DIR__ . '/block_factory_consistency_check.json'), true);
|
||||||
|
$knownStates = $list["knownStates"];
|
||||||
|
$remaps = $list["remaps"];
|
||||||
|
|
||||||
$states = $this->blockFactory->getAllKnownStates();
|
$states = $this->blockFactory->getAllKnownStates();
|
||||||
foreach($states as $k => $state){
|
foreach($states as $k => $state){
|
||||||
self::assertArrayHasKey($k, $list, "New block state $k (" . $state->getName() . ") - consistency check may need regenerating");
|
if($state->getFullId() !== $k){
|
||||||
self::assertSame($list[$k], $state->getName());
|
self::assertArrayHasKey($k, $remaps, "New remap of state $k (" . $state->getName() . ") - consistency check may need regenerating");
|
||||||
|
self::assertSame($state->getFullId(), $remaps[$k], "Mismatched full IDs of remapped state $k");
|
||||||
|
}else{
|
||||||
|
self::assertArrayHasKey($k, $knownStates, "New block state $k (" . $state->getName() . ") - consistency check may need regenerating");
|
||||||
|
self::assertSame($knownStates[$k], $state->getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
foreach($list as $k => $name){
|
foreach($knownStates as $k => $name){
|
||||||
self::assertArrayHasKey($k, $states, "Missing previously-known block state $k ($name)");
|
self::assertArrayHasKey($k, $states, "Missing previously-known block state $k ($name)");
|
||||||
self::assertSame($name, $states[$k]->getName());
|
self::assertSame($name, $states[$k]->getName());
|
||||||
}
|
}
|
||||||
|
foreach($remaps as $origin => $destination){
|
||||||
|
self::assertArrayHasKey($origin, $states, "Missing previously-remapped state $origin");
|
||||||
|
self::assertSame($destination, $states[$origin]->getFullId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
@ -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). */
|
/* This script needs to be re-run after any intentional blockfactory change (adding or removing a block state). */
|
||||||
|
|
||||||
$factory = new \pocketmine\block\BlockFactory();
|
$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){
|
foreach($old as $k => $name){
|
||||||
if(!isset($new[$k])){
|
if(!isset($new[$k])){
|
||||||
echo "Removed state for $name (" . ($k >> \pocketmine\block\Block::INTERNAL_METADATA_BITS) . ":" . ($k & \pocketmine\block\Block::INTERNAL_METADATA_MASK) . ")\n";
|
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";
|
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(
|
file_put_contents(__DIR__ . '/block_factory_consistency_check.json', json_encode(
|
||||||
$new
|
[
|
||||||
|
"knownStates" => $new,
|
||||||
|
"remaps" => $remaps
|
||||||
|
],
|
||||||
));
|
));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user