mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +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;
|
||||
}
|
||||
|
||||
public function getNonPersistentStateBitmask() : int{
|
||||
return 0b11;
|
||||
protected function writeStateToItemMeta() : int{
|
||||
return $this->damage << 2;
|
||||
}
|
||||
|
||||
public function getDamage() : int{ return $this->damage; }
|
||||
|
@ -30,8 +30,6 @@ use pocketmine\block\utils\DyeColor;
|
||||
use pocketmine\data\bedrock\DyeColorIdMap;
|
||||
use pocketmine\item\Banner as ItemBanner;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\ItemFactory;
|
||||
use pocketmine\item\ItemIds;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\player\Player;
|
||||
@ -126,8 +124,8 @@ abstract class BaseBanner extends Transparent{
|
||||
}
|
||||
}
|
||||
|
||||
public function asItem() : Item{
|
||||
return ItemFactory::getInstance()->get(ItemIds::BANNER, DyeColorIdMap::getInstance()->toInvertedId($this->color));
|
||||
protected function writeStateToItemMeta() : int{
|
||||
return DyeColorIdMap::getInstance()->toInvertedId($this->color);
|
||||
}
|
||||
|
||||
public function getDropsForCompatibleTool(Item $item) : array{
|
||||
|
@ -30,7 +30,6 @@ use pocketmine\block\utils\DyeColor;
|
||||
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||
use pocketmine\data\bedrock\DyeColorIdMap;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\ItemFactory;
|
||||
use pocketmine\lang\KnownTranslationKeys;
|
||||
use pocketmine\lang\TranslationContainer;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
@ -197,8 +196,8 @@ class Bed extends Transparent{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function asItem() : Item{
|
||||
return ItemFactory::getInstance()->get($this->idInfo->getItemId(), DyeColorIdMap::getInstance()->toId($this->color));
|
||||
protected function writeStateToItemMeta() : int{
|
||||
return DyeColorIdMap::getInstance()->toId($this->color);
|
||||
}
|
||||
|
||||
public function getAffectedBlocks() : array{
|
||||
|
@ -98,7 +98,7 @@ class Block{
|
||||
public function asItem() : Item{
|
||||
return ItemFactory::getInstance()->get(
|
||||
$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;
|
||||
}
|
||||
|
||||
protected function writeStateToItemMeta() : int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a bitmask used to extract state bits from block metadata.
|
||||
*/
|
||||
@ -115,10 +119,6 @@ class Block{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getNonPersistentStateBitmask() : int{
|
||||
return $this->getStateBitmask();
|
||||
}
|
||||
|
||||
protected function writeStateToMeta() : int{
|
||||
return 0;
|
||||
}
|
||||
|
@ -44,12 +44,12 @@ final class Coral extends BaseCoral{
|
||||
return CoralTypeIdMap::getInstance()->toId($this->coralType);
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
return 0b0111;
|
||||
protected function writeStateToItemMeta() : int{
|
||||
return $this->writeStateToMeta();
|
||||
}
|
||||
|
||||
public function getNonPersistentStateBitmask() : int{
|
||||
return 0b0000;
|
||||
public function getStateBitmask() : int{
|
||||
return 0b0111;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
return 0b1111;
|
||||
protected function writeStateToItemMeta() : int{
|
||||
return $this->writeStateToMeta();
|
||||
}
|
||||
|
||||
public function getNonPersistentStateBitmask() : int{
|
||||
return 0;
|
||||
public function getStateBitmask() : int{
|
||||
return 0b1111;
|
||||
}
|
||||
|
||||
public function getCoralType() : CoralType{ return $this->coralType; }
|
||||
|
@ -41,12 +41,12 @@ class Dirt extends Opaque{
|
||||
return $this->coarse ? BlockLegacyMetadata::DIRT_FLAG_COARSE : 0;
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
return 0b1;
|
||||
protected function writeStateToItemMeta() : int{
|
||||
return $this->writeStateToMeta();
|
||||
}
|
||||
|
||||
public function getNonPersistentStateBitmask() : int{
|
||||
return 0;
|
||||
public function getStateBitmask() : int{
|
||||
return 0b1;
|
||||
}
|
||||
|
||||
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)
|
||||
return ItemFactory::getInstance()->get(
|
||||
$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);
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
return 0b1111;
|
||||
protected function writeStateToItemMeta() : int{
|
||||
return CoralTypeIdMap::getInstance()->toId($this->coralType);
|
||||
}
|
||||
|
||||
public function getNonPersistentStateBitmask() : int{
|
||||
return 0b1000;
|
||||
public function getStateBitmask() : int{
|
||||
return 0b1111;
|
||||
}
|
||||
|
||||
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\SkullType;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\ItemFactory;
|
||||
use pocketmine\item\ItemIds;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\math\Vector3;
|
||||
@ -142,7 +140,7 @@ class Skull extends Flowable{
|
||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||
}
|
||||
|
||||
public function asItem() : Item{
|
||||
return ItemFactory::getInstance()->get(ItemIds::SKULL, $this->skullType->getMagicNumber());
|
||||
protected function writeStateToItemMeta() : int{
|
||||
return $this->skullType->getMagicNumber();
|
||||
}
|
||||
}
|
||||
|
@ -35,12 +35,12 @@ class Sponge extends Opaque{
|
||||
$this->wet = ($stateMeta & BlockLegacyMetadata::SPONGE_FLAG_WET) !== 0;
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
return 0b1;
|
||||
protected function writeStateToItemMeta() : int{
|
||||
return $this->writeStateToMeta();
|
||||
}
|
||||
|
||||
public function getNonPersistentStateBitmask() : int{
|
||||
return 0;
|
||||
public function getStateBitmask() : int{
|
||||
return 0b1;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
protected function writeStateToItemMeta() : int{
|
||||
return $this->worksUnderwater ? BlockLegacyMetadata::TNT_FLAG_UNDERWATER : 0;
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
return 0b11;
|
||||
}
|
||||
|
||||
public function getNonPersistentStateBitmask() : int{ return 0b1; }
|
||||
|
||||
public function isUnstable() : bool{ return $this->unstable; }
|
||||
|
||||
/** @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;
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
return 0b1111;
|
||||
protected function writeStateToItemMeta() : int{
|
||||
return CoralTypeIdMap::getInstance()->toId($this->coralType);
|
||||
}
|
||||
|
||||
public function getNonPersistentStateBitmask() : int{
|
||||
return 0b1110;
|
||||
public function getStateBitmask() : int{
|
||||
return 0b1111;
|
||||
}
|
||||
|
||||
public function asItem() : Item{
|
||||
return ItemFactory::getInstance()->get(
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Block::writeStateToItemMeta()
|
||||
*/
|
||||
protected function writeStateToItemMeta() : int{
|
||||
return DyeColorIdMap::getInstance()->toId($this->color);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Block::getStateBitmask()
|
||||
*/
|
||||
public function getStateBitmask() : int{
|
||||
return 0b1111;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Block::getNonPersistentStateBitmask()
|
||||
*/
|
||||
public function getNonPersistentStateBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user