From 7af7783cc8ef288e776756a283aaa1a9c8cca5c6 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 12 Oct 2018 20:05:44 +0100 Subject: [PATCH] BlockFactory: Register block to id|variant without setting state to allow non-zero default states This will be needed to deal with things like chest/furnace which don't use 0 as a valid state (these both use facing horizontal for rotation, and vertical is invalid, so 0 would mean downwards facing which is invalid. --- src/pocketmine/block/BlockFactory.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/pocketmine/block/BlockFactory.php b/src/pocketmine/block/BlockFactory.php index b14259a82..539f4de08 100644 --- a/src/pocketmine/block/BlockFactory.php +++ b/src/pocketmine/block/BlockFactory.php @@ -464,7 +464,9 @@ class BlockFactory{ throw new \InvalidArgumentException("Block variant collides with state bitmask"); } - for($m = $variant; $m <= ($variant | $stateMask); ++$m){ + self::fillStaticArrays(($id << 4) | $variant, $block); //register default state mapped to variant, for blocks which don't use 0 as valid state + + for($m = $variant + 1; $m <= ($variant | $stateMask); ++$m){ if(($m & ~$stateMask) !== $variant){ continue; } @@ -478,15 +480,19 @@ class BlockFactory{ $v = clone $block; $v->readStateFromMeta($m & $stateMask); if($v->getDamage() === $m){ //don't register anything that isn't the same when we read it back again - self::$fullList[$index] = $v; - self::$stateMasks[$index] = $stateMask; - self::$lightFilter[$index] = min(15, $v->getLightFilter() + 1); //opacity plus 1 standard light filter - self::$diffusesSkyLight[$index] = $v->diffusesSkyLight(); - self::$blastResistance[$index] = $v->getBlastResistance(); + self::fillStaticArrays($index, $v); } } } + private static function fillStaticArrays(int $index, Block $block) : void{ + self::$fullList[$index] = $block; + self::$stateMasks[$index] = $block->getStateBitmask(); + self::$lightFilter[$index] = min(15, $block->getLightFilter() + 1); //opacity plus 1 standard light filter + self::$diffusesSkyLight[$index] = $block->diffusesSkyLight(); + self::$blastResistance[$index] = $block->getBlastResistance(); + } + /** * Returns a new Block instance with the specified ID, meta and position. *