mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 10:53:05 +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:
@ -33,8 +33,30 @@ class EndRod extends Flowable{
|
||||
|
||||
protected $id = Block::END_ROD;
|
||||
|
||||
public function __construct(int $meta = 0){
|
||||
$this->setDamage($meta);
|
||||
/** @var int */
|
||||
protected $facing = Facing::DOWN;
|
||||
|
||||
public function __construct(){
|
||||
|
||||
}
|
||||
|
||||
protected function writeStateToMeta() : int{
|
||||
if(Facing::axis($this->facing) === Facing::AXIS_Y){
|
||||
return $this->facing;
|
||||
}
|
||||
return $this->facing ^ 1; //TODO: in PC this is always the same as facing, just PE is stupid
|
||||
}
|
||||
|
||||
public function readStateFromMeta(int $meta) : void{
|
||||
if($meta === 0 or $meta === 1){
|
||||
$this->facing = $meta;
|
||||
}else{
|
||||
$this->facing = $meta ^ 1; //TODO: see above
|
||||
}
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
return 0b111;
|
||||
}
|
||||
|
||||
public function getName() : string{
|
||||
@ -42,13 +64,9 @@ class EndRod extends Flowable{
|
||||
}
|
||||
|
||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
|
||||
if(Facing::axis($face) === Facing::AXIS_Y){
|
||||
$this->meta = $face;
|
||||
}else{
|
||||
$this->meta = $face ^ 0x01;
|
||||
}
|
||||
if($blockClicked instanceof EndRod and $blockClicked->getDamage() === $this->meta){
|
||||
$this->meta ^= 0x01;
|
||||
$this->facing = $face;
|
||||
if($blockClicked instanceof EndRod and $blockClicked->facing === $this->facing){
|
||||
$this->facing = Facing::opposite($face);
|
||||
}
|
||||
|
||||
return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||
@ -63,7 +81,7 @@ class EndRod extends Flowable{
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
$m = $this->meta >> 1; //everything except up/down are inverted, but we can still use this for axis
|
||||
$m = Facing::axis($this->facing);
|
||||
$width = 0.375;
|
||||
|
||||
switch($m){
|
||||
@ -98,8 +116,4 @@ class EndRod extends Flowable{
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user