From 76e213ae7328d7f1d8d16fd2b07f0facd7328916 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 25 Aug 2017 13:06:16 +0100 Subject: [PATCH] Cleaned up shared rotation code, fixed quartz pillar rotation, added bone blocks --- src/pocketmine/block/BlockFactory.php | 2 +- src/pocketmine/block/BoneBlock.php | 69 +++++++++++++++++++ src/pocketmine/block/Quartz.php | 16 +++-- src/pocketmine/block/Wood.php | 16 +---- .../block/utils/PillarRotationHelper.php | 39 +++++++++++ 5 files changed, 124 insertions(+), 18 deletions(-) create mode 100644 src/pocketmine/block/BoneBlock.php create mode 100644 src/pocketmine/block/utils/PillarRotationHelper.php diff --git a/src/pocketmine/block/BlockFactory.php b/src/pocketmine/block/BlockFactory.php index a6bf9472ce..1d727faf92 100644 --- a/src/pocketmine/block/BlockFactory.php +++ b/src/pocketmine/block/BlockFactory.php @@ -277,7 +277,7 @@ class BlockFactory{ self::registerBlock(new Magma()); self::registerBlock(new NetherWartBlock()); self::registerBlock(new NetherBrick(Block::RED_NETHER_BRICK, 0, "Red Nether Bricks")); - //TODO: BONE_BLOCK + self::registerBlock(new BoneBlock()); //TODO: SHULKER_BOX self::registerBlock(new GlazedTerracotta(Block::PURPLE_GLAZED_TERRACOTTA, 0, "Purple Glazed Terracotta")); diff --git a/src/pocketmine/block/BoneBlock.php b/src/pocketmine/block/BoneBlock.php new file mode 100644 index 0000000000..eef5c517f7 --- /dev/null +++ b/src/pocketmine/block/BoneBlock.php @@ -0,0 +1,69 @@ +meta = $meta; + } + + public function getName() : string{ + return "Bone Block"; + } + + public function getHardness() : float{ + return 2; + } + + public function getToolType() : int{ + return Tool::TYPE_PICKAXE; + } + + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + $this->meta = PillarRotationHelper::getMetaFromFace($this->meta, $face); + return $this->getLevel()->setBlock($block, $this, true, true); + } + + public function getVariantBitmask() : int{ + return 0x03; + } + + public function getDrops(Item $item) : array{ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ + return parent::getDrops($item); // TODO: Change the autogenerated stub + } + + return []; + } + +} \ No newline at end of file diff --git a/src/pocketmine/block/Quartz.php b/src/pocketmine/block/Quartz.php index bf2340cd7b..dbf249fd07 100644 --- a/src/pocketmine/block/Quartz.php +++ b/src/pocketmine/block/Quartz.php @@ -23,15 +23,17 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\PillarRotationHelper; use pocketmine\item\Item; use pocketmine\item\Tool; +use pocketmine\math\Vector3; +use pocketmine\Player; class Quartz extends Solid{ const QUARTZ_NORMAL = 0; const QUARTZ_CHISELED = 1; const QUARTZ_PILLAR = 2; - const QUARTZ_PILLAR2 = 3; protected $id = self::QUARTZ_BLOCK; @@ -47,10 +49,16 @@ class Quartz extends Solid{ static $names = [ self::QUARTZ_NORMAL => "Quartz Block", self::QUARTZ_CHISELED => "Chiseled Quartz Block", - self::QUARTZ_PILLAR => "Quartz Pillar", - self::QUARTZ_PILLAR2 => "Quartz Pillar" + self::QUARTZ_PILLAR => "Quartz Pillar" ]; - return $names[$this->meta & 0x03]; + return $names[$this->meta & 0x03] ?? "Unknown"; + } + + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + if($this->meta !== self::QUARTZ_NORMAL){ + $this->meta = PillarRotationHelper::getMetaFromFace($this->meta, $face); + } + return $this->getLevel()->setBlock($block, $this, true, true); } public function getToolType() : int{ diff --git a/src/pocketmine/block/Wood.php b/src/pocketmine/block/Wood.php index 6bdb45dee9..f285ae4c9d 100644 --- a/src/pocketmine/block/Wood.php +++ b/src/pocketmine/block/Wood.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\PillarRotationHelper; use pocketmine\item\Item; use pocketmine\item\Tool; use pocketmine\math\Vector3; @@ -55,19 +56,8 @@ class Wood extends Solid{ } public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ - $faces = [ - Vector3::SIDE_DOWN => 0, - Vector3::SIDE_UP => 0, - Vector3::SIDE_NORTH => 0b1000, - Vector3::SIDE_SOUTH => 0b1000, - Vector3::SIDE_WEST => 0b0100, - Vector3::SIDE_EAST => 0b0100 - ]; - - $this->meta = ($this->meta & 0x03) | $faces[$face]; - $this->getLevel()->setBlock($block, $this, true, true); - - return true; + $this->meta = PillarRotationHelper::getMetaFromFace($this->meta, $face); + return $this->getLevel()->setBlock($block, $this, true, true); } public function getVariantBitmask() : int{ diff --git a/src/pocketmine/block/utils/PillarRotationHelper.php b/src/pocketmine/block/utils/PillarRotationHelper.php new file mode 100644 index 0000000000..3cb3a928ae --- /dev/null +++ b/src/pocketmine/block/utils/PillarRotationHelper.php @@ -0,0 +1,39 @@ + 0, + Vector3::SIDE_NORTH => 0x08, + Vector3::SIDE_WEST => 0x04, + ]; + + return ($meta & 0x03) | $faces[$face & ~0x01]; + } +} \ No newline at end of file