mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Added Block->getVariantBitmask(0 to cut down on getDrops() boilerplate, fixed several blocks incorrectly retaining meta when broken
This commit is contained in:
parent
384a4b3a09
commit
41c6cb6f97
@ -30,4 +30,6 @@ class ActivatorRail extends Rail{
|
||||
public function getName() : string{
|
||||
return "Activator Rail";
|
||||
}
|
||||
|
||||
//TODO
|
||||
}
|
||||
|
@ -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),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -44,4 +44,10 @@ class BrewingStand extends Transparent{
|
||||
public function getToolType() : int{
|
||||
return Tool::TYPE_PICKAXE;
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//TODO
|
||||
}
|
@ -118,11 +118,13 @@ class BurningFurnace extends Solid{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
if($item->isPickaxe() >= Tool::TIER_WOODEN){
|
||||
return [
|
||||
Item::get($this->getItemId(), 0, 1)
|
||||
];
|
||||
return parent::getDrops($item);
|
||||
}
|
||||
|
||||
return [];
|
||||
|
@ -125,9 +125,7 @@ class Cactus extends Transparent{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
return [
|
||||
Item::get($this->getItemId(), 0, 1)
|
||||
];
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -169,10 +169,8 @@ class Chest extends Transparent{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
return [
|
||||
Item::get($this->getItemId(), 0, 1)
|
||||
];
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getFuelTime() : int{
|
||||
|
@ -34,4 +34,6 @@ class CocoaBlock extends Solid{
|
||||
public function getName() : string{
|
||||
return "Cocoa Block";
|
||||
}
|
||||
|
||||
//TODO
|
||||
}
|
||||
|
@ -42,4 +42,6 @@ class DaylightSensor extends Transparent{
|
||||
public function getFuelTime() : int{
|
||||
return 300;
|
||||
}
|
||||
|
||||
//TODO
|
||||
}
|
||||
|
@ -30,4 +30,6 @@ class DetectorRail extends Rail{
|
||||
public function getName() : string{
|
||||
return "Detector Rail";
|
||||
}
|
||||
|
||||
//TODO
|
||||
}
|
||||
|
@ -282,4 +282,8 @@ abstract class Door extends Transparent{
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -104,6 +104,10 @@ class DoublePlant extends Flowable{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0x07;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
if(!$item->isShears() and ($this->meta === 2 or $this->meta === 3)){ //grass or fern
|
||||
if(mt_rand(0, 24) === 0){
|
||||
@ -115,8 +119,6 @@ class DoublePlant extends Flowable{
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
Item::get($this->getItemId(), $this->getDamage() & 0x07, 1)
|
||||
];
|
||||
return parent::getDrops($item);
|
||||
}
|
||||
}
|
@ -92,9 +92,7 @@ class EnchantingTable extends Transparent{
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
if($item->isPickaxe() >= Tool::TIER_WOODEN){
|
||||
return [
|
||||
Item::get($this->getItemId(), 0, 1)
|
||||
];
|
||||
return parent::getDrops($item);
|
||||
}
|
||||
|
||||
return [];
|
||||
|
@ -97,10 +97,7 @@ class EndRod extends Flowable{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
return [
|
||||
Item::get($this->getId(), 0, 1)
|
||||
];
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
@ -75,10 +75,8 @@ class FenceGate extends Transparent{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
return [
|
||||
Item::get($this->getItemId(), 0, 1)
|
||||
];
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function onActivate(Item $item, Player $player = null) : bool{
|
||||
|
@ -52,11 +52,13 @@ class GlazedTerracotta extends Solid{
|
||||
return $this->getLevel()->setBlock($block, $this, true, true);
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
if($item->isPickaxe() >= Tool::TIER_WOODEN){
|
||||
return [
|
||||
Item::get($this->getItemId(), 0, 1)
|
||||
];
|
||||
return parent::getDrops($item);
|
||||
}
|
||||
|
||||
return [];
|
||||
|
@ -53,9 +53,7 @@ class Gravel extends Fallable{
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
Item::get(Item::GRAVEL, 0, 1)
|
||||
];
|
||||
return parent::getDrops($item);
|
||||
}
|
||||
|
||||
}
|
@ -58,10 +58,7 @@ class HayBale extends Solid{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
return [
|
||||
Item::get($this->getItemId(), 0, 1)
|
||||
];
|
||||
public function getVariantBitmask() : int{
|
||||
return 0x03;
|
||||
}
|
||||
|
||||
}
|
@ -46,11 +46,13 @@ class IronBars extends Thin{
|
||||
return Tool::TYPE_PICKAXE;
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
if($item->isPickaxe() >= Tool::TIER_WOODEN){
|
||||
return [
|
||||
Item::get($this->getItemId(), 0, 1)
|
||||
];
|
||||
return parent::getDrops($item);
|
||||
}
|
||||
|
||||
return [];
|
||||
|
@ -139,10 +139,7 @@ class ItemFrame extends Flowable{
|
||||
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
return [
|
||||
Item::get($this->getItemId(), 0, 1)
|
||||
];
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
@ -149,9 +149,7 @@ class Ladder extends Transparent{
|
||||
return Tool::TYPE_AXE;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
return [
|
||||
Item::get($this->getItemId(), 0, 1)
|
||||
];
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -55,11 +55,13 @@ class Prismarine extends Solid{
|
||||
return Tool::TYPE_PICKAXE;
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0x03;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
if($item->isPickaxe() >= Tool::TIER_WOODEN){
|
||||
return [
|
||||
Item::get($this->getItemId(), $this->getDamage() & 0x03, 1)
|
||||
];
|
||||
return parent::getDrops($item);
|
||||
}
|
||||
|
||||
return [];
|
||||
|
@ -56,4 +56,7 @@ class Pumpkin extends Solid{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -57,11 +57,13 @@ class Quartz extends Solid{
|
||||
return Tool::TYPE_PICKAXE;
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0x03;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
if($item->isPickaxe() >= Tool::TIER_WOODEN){
|
||||
return [
|
||||
Item::get($this->getItemId(), $this->getDamage() & 0x03, 1)
|
||||
];
|
||||
return parent::getDrops($item);
|
||||
}
|
||||
|
||||
return [];
|
||||
|
@ -75,4 +75,8 @@ class Rail extends Flowable{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -55,11 +55,13 @@ class Sandstone extends Solid{
|
||||
return Tool::TYPE_PICKAXE;
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0x03;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
if($item->isPickaxe() >= Tool::TIER_WOODEN){
|
||||
return [
|
||||
Item::get($this->getItemId(), $this->getDamage() & 0x03, 1)
|
||||
];
|
||||
return parent::getDrops($item);
|
||||
}
|
||||
|
||||
return [];
|
||||
|
@ -114,4 +114,8 @@ class SignPost extends Transparent{
|
||||
public function getToolType() : int{
|
||||
return Tool::TYPE_AXE;
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -145,11 +145,13 @@ abstract class Stair extends Transparent{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
if($item->isPickaxe() >= Tool::TIER_WOODEN){
|
||||
return [
|
||||
Item::get($this->getItemId(), 0, 1)
|
||||
];
|
||||
return parent::getDrops($item);
|
||||
}
|
||||
|
||||
return [];
|
||||
|
@ -58,9 +58,7 @@ class StoneBricks extends Solid{
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
if($item->isPickaxe() >= Tool::TIER_WOODEN){
|
||||
return [
|
||||
Item::get($this->getItemId(), $this->getDamage() & 0x03, 1)
|
||||
];
|
||||
return parent::getDrops($item);
|
||||
}
|
||||
|
||||
return [];
|
||||
|
@ -38,4 +38,8 @@ class StoneButton extends Flowable{
|
||||
public function getHardness() : float{
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -42,4 +42,8 @@ class StonePressurePlate extends Transparent{
|
||||
public function getHardness() : float{
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -122,4 +122,8 @@ class Sugarcane extends Flowable{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -93,9 +93,7 @@ class Torch extends Flowable{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
return [
|
||||
Item::get($this->getItemId(), 0, 1)
|
||||
];
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -140,10 +140,8 @@ class Trapdoor extends Transparent{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
return [
|
||||
Item::get($this->getItemId(), 0, 1)
|
||||
];
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function onActivate(Item $item, Player $player = null) : bool{
|
||||
|
@ -34,4 +34,10 @@ class TripwireHook extends Flowable{
|
||||
public function getName() : string{
|
||||
return "Tripwire Hook";
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//TODO
|
||||
}
|
||||
|
@ -174,11 +174,13 @@ class Vine extends Transparent{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
if($item->isShears()){
|
||||
return [
|
||||
Item::get($this->getItemId(), 0, 1)
|
||||
];
|
||||
return parent::getDrops($item);
|
||||
}
|
||||
|
||||
return [];
|
||||
|
@ -80,9 +80,7 @@ class WaterLily extends Flowable{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
return [
|
||||
Item::get($this->getItemId(), 0, 1)
|
||||
];
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -42,4 +42,8 @@ class WeightedPressurePlateLight extends Transparent{
|
||||
public function getHardness() : float{
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -69,10 +69,8 @@ class Wood extends Solid{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
return [
|
||||
Item::get($this->getItemId(), $this->getDamage() & 0x03, 1)
|
||||
];
|
||||
public function getVariantBitmask() : int{
|
||||
return 0x03;
|
||||
}
|
||||
|
||||
public function getToolType() : int{
|
||||
|
@ -35,10 +35,4 @@ class WoodenDoor extends Door{
|
||||
public function getToolType() : int{
|
||||
return Tool::TYPE_AXE;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
return [
|
||||
Item::get($this->getItemId(), 0, 1)
|
||||
];
|
||||
}
|
||||
}
|
@ -129,10 +129,8 @@ class WoodenSlab extends Transparent{
|
||||
return Tool::TYPE_AXE;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
return [
|
||||
Item::get($this->getItemId(), $this->getDamage() & 0x07, 1)
|
||||
];
|
||||
public function getVariantBitmask() : int{
|
||||
return 0x07;
|
||||
}
|
||||
|
||||
public function getFuelTime() : int{
|
||||
|
@ -40,9 +40,14 @@ class WoodenStairs extends Stair{
|
||||
return Tool::TYPE_AXE;
|
||||
}
|
||||
|
||||
public function getVariantBitmask() : int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
//TODO: Hierarchy problem (base class is for stone stairs)
|
||||
return [
|
||||
Item::get($this->getItemId(), 0, 1)
|
||||
Item::get($this->getItemId(), $this->getDamage() & $this->getVariantBitmask(), 1)
|
||||
];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user