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:
@ -34,8 +34,23 @@ class Ladder extends Transparent{
|
||||
|
||||
protected $id = self::LADDER;
|
||||
|
||||
public function __construct(int $meta = 0){
|
||||
$this->setDamage($meta);
|
||||
/** @var int */
|
||||
protected $facing = Facing::NORTH;
|
||||
|
||||
public function __construct(){
|
||||
|
||||
}
|
||||
|
||||
protected function writeStateToMeta() : int{
|
||||
return $this->facing;
|
||||
}
|
||||
|
||||
public function readStateFromMeta(int $meta) : void{
|
||||
$this->facing = $meta;
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
return 0b111;
|
||||
}
|
||||
|
||||
public function getName() : string{
|
||||
@ -69,13 +84,13 @@ class Ladder extends Transparent{
|
||||
$minX = $minZ = 0;
|
||||
$maxX = $maxZ = 1;
|
||||
|
||||
if($this->meta === 2){
|
||||
if($this->facing === Facing::NORTH){
|
||||
$minZ = 1 - $f;
|
||||
}elseif($this->meta === 3){
|
||||
}elseif($this->facing === Facing::SOUTH){
|
||||
$maxZ = $f;
|
||||
}elseif($this->meta === 4){
|
||||
}elseif($this->facing === Facing::WEST){
|
||||
$minX = 1 - $f;
|
||||
}elseif($this->meta === 5){
|
||||
}elseif($this->facing === Facing::EAST){
|
||||
$maxX = $f;
|
||||
}
|
||||
|
||||
@ -92,7 +107,7 @@ class Ladder extends Transparent{
|
||||
|
||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
|
||||
if(!$blockClicked->isTransparent() and Facing::axis($face) !== Facing::AXIS_Y){
|
||||
$this->meta = $face;
|
||||
$this->facing = $face;
|
||||
return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||
}
|
||||
|
||||
@ -100,7 +115,7 @@ class Ladder extends Transparent{
|
||||
}
|
||||
|
||||
public function onNearbyBlockChange() : void{
|
||||
if(!$this->getSide($this->meta ^ 0x01)->isSolid()){ //Replace with common break method
|
||||
if(!$this->getSide(Facing::opposite($this->facing))->isSolid()){ //Replace with common break method
|
||||
$this->level->useBreakOn($this);
|
||||
}
|
||||
}
|
||||
@ -108,8 +123,4 @@ class Ladder extends Transparent{
|
||||
public function getToolType() : int{
|
||||
return BlockToolType::TYPE_AXE;
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user