Added Block->getVariantBitmask(0 to cut down on getDrops() boilerplate, fixed several blocks incorrectly retaining meta when broken

This commit is contained in:
Dylan K. Taylor
2017-08-18 19:49:28 +01:00
parent 384a4b3a09
commit 41c6cb6f97
41 changed files with 145 additions and 96 deletions

View File

@ -398,8 +398,9 @@ class Block extends Position implements BlockIds, Metadatable{
return $block;
}
/** @var int */
protected $id;
/** @var int */
protected $meta = 0;
/** @var string */
protected $fallbackName;
@ -460,6 +461,19 @@ class Block extends Position implements BlockIds, Metadatable{
$this->meta = $meta & 0x0f;
}
/**
* Bitmask to use to remove superfluous information from block meta when getting its item form or name.
* This defaults to -1 (don't remove any data). Used to remove rotation data and bitflags from block drops.
*
* If your block should not have any meta value when it's dropped as an item, override this to return 0 in
* descendent classes.
*
* @return int
*/
public function getVariantBitmask() : int{
return -1;
}
/**
* Places the Block, using block space and block target, and side. Returns if the block has been placed.
*
@ -658,7 +672,7 @@ class Block extends Position implements BlockIds, Metadatable{
*/
public function getDrops(Item $item) : array{
return [
Item::get($this->getItemId(), $this->getDamage(), 1),
Item::get($this->getItemId(), $this->getDamage() & $this->getVariantBitmask(), 1),
];
}