mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-12 14:35:35 +00:00
Block: get rid of getNonPersistentStateBitmask(), add writeStateToItemMeta()
this is more flexible and less confusing.
This commit is contained in:
parent
01b48a21d9
commit
bdac98beaf
@ -54,8 +54,8 @@ class Anvil extends Transparent implements Fallable{
|
|||||||
return 0b1111;
|
return 0b1111;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNonPersistentStateBitmask() : int{
|
protected function writeStateToItemMeta() : int{
|
||||||
return 0b11;
|
return $this->damage << 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDamage() : int{ return $this->damage; }
|
public function getDamage() : int{ return $this->damage; }
|
||||||
|
@ -30,8 +30,6 @@ use pocketmine\block\utils\DyeColor;
|
|||||||
use pocketmine\data\bedrock\DyeColorIdMap;
|
use pocketmine\data\bedrock\DyeColorIdMap;
|
||||||
use pocketmine\item\Banner as ItemBanner;
|
use pocketmine\item\Banner as ItemBanner;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ItemFactory;
|
|
||||||
use pocketmine\item\ItemIds;
|
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
@ -126,8 +124,8 @@ abstract class BaseBanner extends Transparent{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function asItem() : Item{
|
protected function writeStateToItemMeta() : int{
|
||||||
return ItemFactory::getInstance()->get(ItemIds::BANNER, DyeColorIdMap::getInstance()->toInvertedId($this->color));
|
return DyeColorIdMap::getInstance()->toInvertedId($this->color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDropsForCompatibleTool(Item $item) : array{
|
public function getDropsForCompatibleTool(Item $item) : array{
|
||||||
|
@ -30,7 +30,6 @@ use pocketmine\block\utils\DyeColor;
|
|||||||
use pocketmine\block\utils\HorizontalFacingTrait;
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
use pocketmine\data\bedrock\DyeColorIdMap;
|
use pocketmine\data\bedrock\DyeColorIdMap;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ItemFactory;
|
|
||||||
use pocketmine\lang\KnownTranslationKeys;
|
use pocketmine\lang\KnownTranslationKeys;
|
||||||
use pocketmine\lang\TranslationContainer;
|
use pocketmine\lang\TranslationContainer;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
@ -197,8 +196,8 @@ class Bed extends Transparent{
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function asItem() : Item{
|
protected function writeStateToItemMeta() : int{
|
||||||
return ItemFactory::getInstance()->get($this->idInfo->getItemId(), DyeColorIdMap::getInstance()->toId($this->color));
|
return DyeColorIdMap::getInstance()->toId($this->color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAffectedBlocks() : array{
|
public function getAffectedBlocks() : array{
|
||||||
|
@ -98,7 +98,7 @@ class Block{
|
|||||||
public function asItem() : Item{
|
public function asItem() : Item{
|
||||||
return ItemFactory::getInstance()->get(
|
return ItemFactory::getInstance()->get(
|
||||||
$this->idInfo->getItemId(),
|
$this->idInfo->getItemId(),
|
||||||
$this->idInfo->getVariant() | ($this->writeStateToMeta() & ~$this->getNonPersistentStateBitmask())
|
$this->idInfo->getVariant() | $this->writeStateToItemMeta()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,6 +108,10 @@ class Block{
|
|||||||
return $this->idInfo->getVariant() | $stateMeta;
|
return $this->idInfo->getVariant() | $stateMeta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function writeStateToItemMeta() : int{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a bitmask used to extract state bits from block metadata.
|
* Returns a bitmask used to extract state bits from block metadata.
|
||||||
*/
|
*/
|
||||||
@ -115,10 +119,6 @@ class Block{
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNonPersistentStateBitmask() : int{
|
|
||||||
return $this->getStateBitmask();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function writeStateToMeta() : int{
|
protected function writeStateToMeta() : int{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -44,12 +44,12 @@ final class Coral extends BaseCoral{
|
|||||||
return CoralTypeIdMap::getInstance()->toId($this->coralType);
|
return CoralTypeIdMap::getInstance()->toId($this->coralType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getStateBitmask() : int{
|
protected function writeStateToItemMeta() : int{
|
||||||
return 0b0111;
|
return $this->writeStateToMeta();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNonPersistentStateBitmask() : int{
|
public function getStateBitmask() : int{
|
||||||
return 0b0000;
|
return 0b0111;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function readStateFromWorld() : void{
|
public function readStateFromWorld() : void{
|
||||||
|
@ -52,12 +52,12 @@ final class CoralBlock extends Opaque{
|
|||||||
return ($this->dead ? BlockLegacyMetadata::CORAL_BLOCK_FLAG_DEAD : 0) | CoralTypeIdMap::getInstance()->toId($this->coralType);
|
return ($this->dead ? BlockLegacyMetadata::CORAL_BLOCK_FLAG_DEAD : 0) | CoralTypeIdMap::getInstance()->toId($this->coralType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getStateBitmask() : int{
|
protected function writeStateToItemMeta() : int{
|
||||||
return 0b1111;
|
return $this->writeStateToMeta();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNonPersistentStateBitmask() : int{
|
public function getStateBitmask() : int{
|
||||||
return 0;
|
return 0b1111;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCoralType() : CoralType{ return $this->coralType; }
|
public function getCoralType() : CoralType{ return $this->coralType; }
|
||||||
|
@ -41,12 +41,12 @@ class Dirt extends Opaque{
|
|||||||
return $this->coarse ? BlockLegacyMetadata::DIRT_FLAG_COARSE : 0;
|
return $this->coarse ? BlockLegacyMetadata::DIRT_FLAG_COARSE : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getStateBitmask() : int{
|
protected function writeStateToItemMeta() : int{
|
||||||
return 0b1;
|
return $this->writeStateToMeta();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNonPersistentStateBitmask() : int{
|
public function getStateBitmask() : int{
|
||||||
return 0;
|
return 0b1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isCoarse() : bool{ return $this->coarse; }
|
public function isCoarse() : bool{ return $this->coarse; }
|
||||||
|
@ -64,7 +64,7 @@ final class FloorCoralFan extends BaseCoral{
|
|||||||
//TODO: HACK! workaround dead flag being lost when broken / blockpicked (original impl only uses first ID)
|
//TODO: HACK! workaround dead flag being lost when broken / blockpicked (original impl only uses first ID)
|
||||||
return ItemFactory::getInstance()->get(
|
return ItemFactory::getInstance()->get(
|
||||||
$this->dead ? ItemIds::CORAL_FAN_DEAD : ItemIds::CORAL_FAN,
|
$this->dead ? ItemIds::CORAL_FAN_DEAD : ItemIds::CORAL_FAN,
|
||||||
CoralTypeIdMap::getInstance()->toId($this->coralType)
|
$this->writeStateToItemMeta()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,12 +73,12 @@ final class FloorCoralFan extends BaseCoral{
|
|||||||
CoralTypeIdMap::getInstance()->toId($this->coralType);
|
CoralTypeIdMap::getInstance()->toId($this->coralType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getStateBitmask() : int{
|
protected function writeStateToItemMeta() : int{
|
||||||
return 0b1111;
|
return CoralTypeIdMap::getInstance()->toId($this->coralType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNonPersistentStateBitmask() : int{
|
public function getStateBitmask() : int{
|
||||||
return 0b1000;
|
return 0b1111;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAxis() : int{ return $this->axis; }
|
public function getAxis() : int{ return $this->axis; }
|
||||||
|
@ -27,8 +27,6 @@ use pocketmine\block\tile\Skull as TileSkull;
|
|||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
use pocketmine\block\utils\SkullType;
|
use pocketmine\block\utils\SkullType;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ItemFactory;
|
|
||||||
use pocketmine\item\ItemIds;
|
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
@ -142,7 +140,7 @@ class Skull extends Flowable{
|
|||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function asItem() : Item{
|
protected function writeStateToItemMeta() : int{
|
||||||
return ItemFactory::getInstance()->get(ItemIds::SKULL, $this->skullType->getMagicNumber());
|
return $this->skullType->getMagicNumber();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,12 +35,12 @@ class Sponge extends Opaque{
|
|||||||
$this->wet = ($stateMeta & BlockLegacyMetadata::SPONGE_FLAG_WET) !== 0;
|
$this->wet = ($stateMeta & BlockLegacyMetadata::SPONGE_FLAG_WET) !== 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getStateBitmask() : int{
|
protected function writeStateToItemMeta() : int{
|
||||||
return 0b1;
|
return $this->writeStateToMeta();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNonPersistentStateBitmask() : int{
|
public function getStateBitmask() : int{
|
||||||
return 0;
|
return 0b1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isWet() : bool{ return $this->wet; }
|
public function isWet() : bool{ return $this->wet; }
|
||||||
|
@ -53,12 +53,14 @@ class TNT extends Opaque{
|
|||||||
return ($this->unstable ? BlockLegacyMetadata::TNT_FLAG_UNSTABLE : 0) | ($this->worksUnderwater ? BlockLegacyMetadata::TNT_FLAG_UNDERWATER : 0);
|
return ($this->unstable ? BlockLegacyMetadata::TNT_FLAG_UNSTABLE : 0) | ($this->worksUnderwater ? BlockLegacyMetadata::TNT_FLAG_UNDERWATER : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function writeStateToItemMeta() : int{
|
||||||
|
return $this->worksUnderwater ? BlockLegacyMetadata::TNT_FLAG_UNDERWATER : 0;
|
||||||
|
}
|
||||||
|
|
||||||
public function getStateBitmask() : int{
|
public function getStateBitmask() : int{
|
||||||
return 0b11;
|
return 0b11;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNonPersistentStateBitmask() : int{ return 0b1; }
|
|
||||||
|
|
||||||
public function isUnstable() : bool{ return $this->unstable; }
|
public function isUnstable() : bool{ return $this->unstable; }
|
||||||
|
|
||||||
/** @return $this */
|
/** @return $this */
|
||||||
|
@ -96,18 +96,18 @@ final class WallCoralFan extends BaseCoral{
|
|||||||
return (BlockDataSerializer::writeCoralFacing($this->facing) << 2) | ($this->dead ? BlockLegacyMetadata::CORAL_FAN_HANG_FLAG_DEAD : 0) | $coralTypeFlag;
|
return (BlockDataSerializer::writeCoralFacing($this->facing) << 2) | ($this->dead ? BlockLegacyMetadata::CORAL_FAN_HANG_FLAG_DEAD : 0) | $coralTypeFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getStateBitmask() : int{
|
protected function writeStateToItemMeta() : int{
|
||||||
return 0b1111;
|
return CoralTypeIdMap::getInstance()->toId($this->coralType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNonPersistentStateBitmask() : int{
|
public function getStateBitmask() : int{
|
||||||
return 0b1110;
|
return 0b1111;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function asItem() : Item{
|
public function asItem() : Item{
|
||||||
return ItemFactory::getInstance()->get(
|
return ItemFactory::getInstance()->get(
|
||||||
$this->dead ? ItemIds::CORAL_FAN_DEAD : ItemIds::CORAL_FAN,
|
$this->dead ? ItemIds::CORAL_FAN_DEAD : ItemIds::CORAL_FAN,
|
||||||
CoralTypeIdMap::getInstance()->toId($this->coralType)
|
$this->writeStateToItemMeta()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,17 +47,17 @@ trait ColorInMetadataTrait{
|
|||||||
return DyeColorIdMap::getInstance()->toId($this->color);
|
return DyeColorIdMap::getInstance()->toId($this->color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Block::writeStateToItemMeta()
|
||||||
|
*/
|
||||||
|
protected function writeStateToItemMeta() : int{
|
||||||
|
return DyeColorIdMap::getInstance()->toId($this->color);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see Block::getStateBitmask()
|
* @see Block::getStateBitmask()
|
||||||
*/
|
*/
|
||||||
public function getStateBitmask() : int{
|
public function getStateBitmask() : int{
|
||||||
return 0b1111;
|
return 0b1111;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see Block::getNonPersistentStateBitmask()
|
|
||||||
*/
|
|
||||||
public function getNonPersistentStateBitmask() : int{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user