All types of coral now have fully dynamic types

This commit is contained in:
Dylan K. Taylor
2021-05-19 22:49:44 +01:00
parent 69fa8e8db7
commit af678f985d
11 changed files with 161 additions and 96 deletions

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\CoralType;
use pocketmine\block\utils\InvalidBlockStateException;
use pocketmine\data\bedrock\CoralTypeIdMap;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
@ -41,13 +41,18 @@ final class FloorCoralFan extends BaseCoral{
private int $axis = Axis::X;
public function __construct(BlockIdentifierFlattened $idInfo, string $name, BlockBreakInfo $breakInfo, CoralType $coralType){
parent::__construct($idInfo, $name, $breakInfo, $coralType);
public function __construct(BlockIdentifierFlattened $idInfo, string $name, BlockBreakInfo $breakInfo){
parent::__construct($idInfo, $name, $breakInfo);
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->dead = $id === $this->idInfo->getSecondId();
$this->axis = ($stateMeta >> 3) === BlockLegacyMetadata::CORAL_FAN_EAST_WEST ? Axis::X : Axis::Z;
$coralType = CoralTypeIdMap::getInstance()->fromId($stateMeta & BlockLegacyMetadata::CORAL_FAN_TYPE_MASK);
if($coralType === null){
throw new InvalidBlockStateException("No such coral type");
}
$this->coralType = $coralType;
}
public function getId() : int{
@ -63,10 +68,15 @@ final class FloorCoralFan extends BaseCoral{
}
protected function writeStateToMeta() : int{
return ($this->axis === Axis::X ? BlockLegacyMetadata::CORAL_FAN_EAST_WEST : BlockLegacyMetadata::CORAL_FAN_NORTH_SOUTH) << 3;
return (($this->axis === Axis::X ? BlockLegacyMetadata::CORAL_FAN_EAST_WEST : BlockLegacyMetadata::CORAL_FAN_NORTH_SOUTH) << 3) |
CoralTypeIdMap::getInstance()->toId($this->coralType);
}
public function getStateBitmask() : int{
return 0b1111;
}
public function getNonPersistentStateBitmask() : int{
return 0b1000;
}