From 90cb018de21b327eba349a1621749e79fb04493c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 26 Sep 2017 19:39:05 +0100 Subject: [PATCH] Re-organise some Block code --- src/pocketmine/block/Block.php | 151 +++++++++++++++++---------------- 1 file changed, 77 insertions(+), 74 deletions(-) diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 7f385e3dd..00fb632af 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -144,6 +144,22 @@ class Block extends Position implements BlockIds, Metadatable{ return $this->meta & $this->getVariantBitmask(); } + + /** + * AKA: Block->isPlaceable + * @return bool + */ + public function canBePlaced() : bool{ + return true; + } + + /** + * @return bool + */ + public function canBeReplaced() : bool{ + return false; + } + /** * Places the Block, using block space and block target, and side. Returns if the block has been placed. * @@ -171,6 +187,10 @@ class Block extends Position implements BlockIds, Metadatable{ return true; } + public function canBeBrokenWith(Item $item) : bool{ + return $this->getHardness() !== -1; + } + /** * Do the actions needed so the block is broken with the Item * @@ -183,6 +203,63 @@ class Block extends Position implements BlockIds, Metadatable{ return $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true); } + + /** + * Returns the seconds that this block takes to be broken using an specific Item + * + * @param Item $item + * + * @return float + */ + public function getBreakTime(Item $item) : float{ + $base = $this->getHardness() * 1.5; + if($this->canBeBrokenWith($item)){ + if($this->getToolType() === Tool::TYPE_SHEARS and $item->isShears()){ + $base /= 15; + }elseif( + ($this->getToolType() === Tool::TYPE_PICKAXE and ($tier = $item->isPickaxe()) !== false) or + ($this->getToolType() === Tool::TYPE_AXE and ($tier = $item->isAxe()) !== false) or + ($this->getToolType() === Tool::TYPE_SHOVEL and ($tier = $item->isShovel()) !== false) + ){ + switch($tier){ + case Tool::TIER_WOODEN: + $base /= 2; + break; + case Tool::TIER_STONE: + $base /= 4; + break; + case Tool::TIER_IRON: + $base /= 6; + break; + case Tool::TIER_DIAMOND: + $base /= 8; + break; + case Tool::TIER_GOLD: + $base /= 12; + break; + } + } + }else{ + $base *= 3.33; + } + + if($item->isSword()){ + $base *= 0.5; + } + + return $base; + } + + + /** + * Returns whether random block updates will be done on this block. + * + * @return bool + */ + public function ticksRandomly() : bool{ + return false; + } + /** * Fires a block update on the Block * @@ -274,30 +351,6 @@ class Block extends Position implements BlockIds, Metadatable{ return false; } - /** - * Returns whether random block updates will be done on this block. - * - * @return bool - */ - public function ticksRandomly() : bool{ - return false; - } - - /** - * AKA: Block->isPlaceable - * @return bool - */ - public function canBePlaced() : bool{ - return true; - } - - /** - * @return bool - */ - public function canBeReplaced() : bool{ - return false; - } - /** * @return bool */ @@ -364,56 +417,6 @@ class Block extends Position implements BlockIds, Metadatable{ ]; } - /** - * Returns the seconds that this block takes to be broken using an specific Item - * - * @param Item $item - * - * @return float - */ - public function getBreakTime(Item $item) : float{ - $base = $this->getHardness() * 1.5; - if($this->canBeBrokenWith($item)){ - if($this->getToolType() === Tool::TYPE_SHEARS and $item->isShears()){ - $base /= 15; - }elseif( - ($this->getToolType() === Tool::TYPE_PICKAXE and ($tier = $item->isPickaxe()) !== false) or - ($this->getToolType() === Tool::TYPE_AXE and ($tier = $item->isAxe()) !== false) or - ($this->getToolType() === Tool::TYPE_SHOVEL and ($tier = $item->isShovel()) !== false) - ){ - switch($tier){ - case Tool::TIER_WOODEN: - $base /= 2; - break; - case Tool::TIER_STONE: - $base /= 4; - break; - case Tool::TIER_IRON: - $base /= 6; - break; - case Tool::TIER_DIAMOND: - $base /= 8; - break; - case Tool::TIER_GOLD: - $base /= 12; - break; - } - } - }else{ - $base *= 3.33; - } - - if($item->isSword()){ - $base *= 0.5; - } - - return $base; - } - - public function canBeBrokenWith(Item $item) : bool{ - return $this->getHardness() !== -1; - } - /** * Returns the time in ticks which the block will fuel a furnace for. * @return int