mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-09 03:06:55 +00:00
Nuke Block->meta, split into variant and state properties, lots of cleanup
This is a major change to the way block metadata is handled within the PM core. This separates variant metadata (which really ought to be part of the ID) from state metadata, and in a couple of cases flattens separate states of blocks together. The result of this is that invalid variants can be much more easily detected, and additionally state handling is much cleaner since meta is only needed at the serialize layer instead of throughout the code.
This commit is contained in:
@ -42,8 +42,31 @@ class Trapdoor extends Transparent{
|
||||
|
||||
protected $id = self::TRAPDOOR;
|
||||
|
||||
public function __construct(int $meta = 0){
|
||||
$this->setDamage($meta);
|
||||
/** @var int */
|
||||
protected $facing = Facing::NORTH;
|
||||
/** @var bool */
|
||||
protected $open = false;
|
||||
/** @var bool */
|
||||
protected $top = false;
|
||||
|
||||
public function __construct(){
|
||||
|
||||
}
|
||||
|
||||
protected function writeStateToMeta() : int{
|
||||
return (5 - $this->facing) | ($this->top ? self::MASK_UPPER : 0) | ($this->open ? self::MASK_OPENED : 0);
|
||||
}
|
||||
|
||||
public function readStateFromMeta(int $meta) : void{
|
||||
//TODO: in PC the values are reversed (3 - (5 - facing))
|
||||
|
||||
$this->facing = 5 - ($meta & 0x03);
|
||||
$this->top = ($meta & self::MASK_UPPER) !== 0;
|
||||
$this->open = ($meta & self::MASK_OPENED) !== 0;
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
return 0b1111;
|
||||
}
|
||||
|
||||
public function getName() : string{
|
||||
@ -55,26 +78,22 @@ class Trapdoor extends Transparent{
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
|
||||
$damage = $this->getDamage();
|
||||
|
||||
$f = 0.1875;
|
||||
|
||||
if(($damage & self::MASK_UPPER) > 0){
|
||||
if($this->top){
|
||||
$bb = new AxisAlignedBB(0, 1 - $f, 0, 1, 1, 1);
|
||||
}else{
|
||||
$bb = new AxisAlignedBB(0, 0, 0, 1, $f, 1);
|
||||
}
|
||||
|
||||
if(($damage & self::MASK_OPENED) > 0){
|
||||
$side = $damage & 0x03;
|
||||
if($side === self::MASK_SIDE_NORTH){
|
||||
if($this->open){
|
||||
if($this->facing === Facing::NORTH){
|
||||
$bb->setBounds(0, 0, 1 - $f, 1, 1, 1);
|
||||
}elseif($side === self::MASK_SIDE_SOUTH){
|
||||
}elseif($this->facing === Facing::SOUTH){
|
||||
$bb->setBounds(0, 0, 0, 1, 1, $f);
|
||||
}elseif($side === self::MASK_SIDE_WEST){
|
||||
}elseif($this->facing === Facing::WEST){
|
||||
$bb->setBounds(1 - $f, 0, 0, 1, 1, 1);
|
||||
}elseif($side === self::MASK_SIDE_EAST){
|
||||
}elseif($this->facing === Facing::EAST){
|
||||
$bb->setBounds(0, 0, 0, $f, 1, 1);
|
||||
}
|
||||
}
|
||||
@ -84,23 +103,18 @@ class Trapdoor extends Transparent{
|
||||
|
||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
|
||||
if($player !== null){
|
||||
//TODO: in PC the values are reversed (3 - (5 - facing))
|
||||
$this->meta = 5 - Bearing::toFacing(Bearing::opposite($player->getDirection()));
|
||||
$this->facing = Bearing::toFacing(Bearing::opposite($player->getDirection()));
|
||||
}
|
||||
if(($clickVector->y > 0.5 and $face !== Facing::UP) or $face === Facing::DOWN){
|
||||
$this->meta |= self::MASK_UPPER; //top half of block
|
||||
$this->top = true;
|
||||
}
|
||||
|
||||
return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function onActivate(Item $item, Player $player = null) : bool{
|
||||
$this->meta ^= self::MASK_OPENED;
|
||||
$this->getLevel()->setBlock($this, $this, true);
|
||||
$this->open = !$this->open;
|
||||
$this->level->setBlock($this, $this, true);
|
||||
$this->level->addSound(new DoorSound($this));
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user