From a10ad42a13991d49bc276bc033ee99a95a34a4cb Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 13 Oct 2014 18:12:34 +0200 Subject: [PATCH] Removed Generic block class --- src/pocketmine/block/Block.php | 120 +++++++++++++++------------ src/pocketmine/block/Generic.php | 48 ----------- src/pocketmine/block/Solid.php | 2 +- src/pocketmine/block/Transparent.php | 2 +- 4 files changed, 67 insertions(+), 105 deletions(-) delete mode 100644 src/pocketmine/block/Generic.php diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 85b97fab1..d53602eb0 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -39,7 +39,7 @@ use pocketmine\Player; use pocketmine\plugin\Plugin; -abstract class Block extends Position implements Metadatable{ +class Block extends Position implements Metadatable{ const AIR = 0; const STONE = 1; const GRASS = 2; @@ -684,7 +684,7 @@ abstract class Block extends Position implements Metadatable{ $block = self::$list[$id]; $block = new $block($meta); }else{ - $block = new Generic($id, $meta); + $block = new Block($id, $meta); } if($pos instanceof Position){ @@ -708,6 +708,69 @@ abstract class Block extends Position implements Metadatable{ $this->name = $name; } + /** + * Places the Block, using block space and block target, and side. Returns if the block has been placed. + * + * @param Item $item + * @param Block $block + * @param Block $target + * @param int $face + * @param float $fx + * @param float $fy + * @param float $fz + * @param Player $player = null + * + * @return bool + */ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + return $this->getLevel()->setBlock($this, $this, true, true); + } + + /** + * Returns if the item can be broken with an specific Item + * + * @param Item $item + * + * @return bool + */ + public function isBreakable(Item $item){ + return $this->breakable; + } + + /** + * Do the actions needed so the block is broken with the Item + * + * @param Item $item + * + * @return mixed + */ + public function onBreak(Item $item){ + return $this->getLevel()->setBlock($this, new Air(), true, true); + } + + /** + * Fires a block update on the Block + * + * @param int $type + * + * @return void + */ + public function onUpdate($type){ + + } + + /** + * Do actions when activated by Item. Returns if it has done anything + * + * @param Item $item + * @param Player $player + * + * @return bool + */ + public function onActivate(Item $item, Player $player = null){ + return $this->isActivable; + } + /** * @return int */ @@ -811,24 +874,6 @@ abstract class Block extends Position implements Metadatable{ return "Block " . $this->name . " (" . $this->id . ":" . $this->meta . ")"; } - /** - * Returns if the item can be broken with an specific Item - * - * @param Item $item - * - * @return bool - */ - abstract function isBreakable(Item $item); - - /** - * Do the actions needed so the block is broken with the Item - * - * @param Item $item - * - * @return mixed - */ - abstract function onBreak(Item $item); - /** * Checks for collision against an AxisAlignedBB * @@ -945,41 +990,6 @@ abstract class Block extends Position implements Metadatable{ return MovingObjectPosition::fromBlock($this->x, $this->y, $this->z, $f, $vector->add($this->x, $this->y, $this->z)); } - /** - * Places the Block, using block space and block target, and side. Returns if the block has been placed. - * - * @param Item $item - * @param Block $block - * @param Block $target - * @param int $face - * @param float $fx - * @param float $fy - * @param float $fz - * @param Player $player = null - * - * @return bool - */ - abstract function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null); - - /** - * Do actions when activated by Item. Returns if it has done anything - * - * @param Item $item - * @param Player $player - * - * @return bool - */ - abstract function onActivate(Item $item, Player $player = null); - - /** - * Fires a block update on the Block - * - * @param int $type - * - * @return void - */ - abstract function onUpdate($type); - public function setMetadata($metadataKey, MetadataValue $metadataValue){ if($this->getLevel() instanceof Level){ $this->getLevel()->getBlockMetadata()->setMetadata($this, $metadataKey, $metadataValue); diff --git a/src/pocketmine/block/Generic.php b/src/pocketmine/block/Generic.php deleted file mode 100644 index a93d30303..000000000 --- a/src/pocketmine/block/Generic.php +++ /dev/null @@ -1,48 +0,0 @@ -getLevel()->setBlock($this, $this, true, true); - } - - public function isBreakable(Item $item){ - return $this->breakable; - } - - public function onBreak(Item $item){ - return $this->getLevel()->setBlock($this, new Air(), true, true); - } - - public function onUpdate($type){ - return false; - } - - public function onActivate(Item $item, Player $player = null){ - return $this->isActivable; - } -} \ No newline at end of file diff --git a/src/pocketmine/block/Solid.php b/src/pocketmine/block/Solid.php index abf6642ca..10ee27a9f 100644 --- a/src/pocketmine/block/Solid.php +++ b/src/pocketmine/block/Solid.php @@ -22,7 +22,7 @@ namespace pocketmine\block; -abstract class Solid extends Generic{ +abstract class Solid extends Block{ public function __construct($id, $meta = 0, $name = "Unknown"){ parent::__construct($id, $meta, $name); diff --git a/src/pocketmine/block/Transparent.php b/src/pocketmine/block/Transparent.php index d41b9cb54..65feab367 100644 --- a/src/pocketmine/block/Transparent.php +++ b/src/pocketmine/block/Transparent.php @@ -23,7 +23,7 @@ namespace pocketmine\block; -abstract class Transparent extends Generic{ +abstract class Transparent extends Block{ public $isActivable = false; public $breakable = true; public $isFlowable = false;