mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-03 08:35:20 +00:00
Use reflection to locate BlockTypeIds and ItemTypeIds for VanillaBlocks/VanillaItems (#6498)
Use reflection to locate BlockTypeIds and ItemTypeIds for VanillaBlocks/VanillaItems Since BlockTypeIds and ItemTypeIds are derived from VanillaBlocks and VanillaItems respectively anyway (they only exist to allow identifying blocks/items without having to create instances of them), this hack is probably OK, and reduces the chances of mistakes. Previously it was explored to have these IDs generated by auto-incrementing in VanillaBlocks/Items and have the constants generated that way, but this proved to be too problematic because of unstable diffs no matter how we chose to sort the elements. See #6313 for previous research on the subject. This is obviously not a desirable hack to keep long-term. In the future it will probably make sense to redesign VanillaBlocks like so: enum VanillaBlocks { ... } VanillaBlocks::STONE (the type ID) VanillaBlocks::STONE->new() (to create a block) However, more research is needed on this, as I'd prefer not to make block creation any more verbose.
This commit is contained in:
@ -51,6 +51,7 @@ class BlockTypeIdsTest extends TestCase{
|
||||
foreach(Utils::stringifyKeys(VanillaBlocks::getAll()) as $name => $block){
|
||||
$expected = $block->getTypeId();
|
||||
$actual = $reflect->getConstant($name);
|
||||
self::assertNotFalse($actual, "VanillaBlocks::$name() does not have a BlockTypeIds constant");
|
||||
self::assertSame($expected, $actual, "VanillaBlocks::$name() does not match BlockTypeIds::$name");
|
||||
}
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ class ItemTypeIdsTest extends TestCase{
|
||||
}
|
||||
$expected = $item->getTypeId();
|
||||
$actual = $reflect->getConstant($name);
|
||||
self::assertNotFalse($actual, "VanillaItems::$name() does not have an ItemTypeIds constant");
|
||||
self::assertSame($expected, $actual, "VanillaItems::$name() type ID does not match ItemTypeIds::$name");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user