From ceaf969203b57d7ace05af9946b1182020b607f4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 26 Feb 2019 19:41:56 +0000 Subject: [PATCH] EnderChest: fix hierarchy --- src/pocketmine/block/Chest.php | 1 - src/pocketmine/block/EnderChest.php | 35 ++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index 757e67c3d..be2f38ea1 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -67,7 +67,6 @@ class Chest extends Transparent{ } if(parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){ - //TODO: this is fragile and might have unintended side effects on ender chests if modified carelessly $tile = $this->level->getTile($this); if($tile instanceof TileChest){ foreach([ diff --git a/src/pocketmine/block/EnderChest.php b/src/pocketmine/block/EnderChest.php index 59c3429c3..6630ffcb0 100644 --- a/src/pocketmine/block/EnderChest.php +++ b/src/pocketmine/block/EnderChest.php @@ -23,15 +23,32 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\BlockDataValidator; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\item\TieredTool; +use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\tile\EnderChest as TileEnderChest; -class EnderChest extends Chest{ +class EnderChest extends Transparent{ + + /** @var int */ + protected $facing = Facing::NORTH; + + protected function writeStateToMeta() : int{ + return $this->facing; + } + + public function readStateFromData(int $id, int $stateMeta) : void{ + $this->facing = BlockDataValidator::readHorizontalFacing($stateMeta); + } + + public function getStateBitmask() : int{ + return 0b111; + } public function getHardness() : float{ return 22.5; @@ -53,6 +70,18 @@ class EnderChest extends Chest{ return TieredTool::TIER_WOODEN; } + protected function recalculateBoundingBox() : ?AxisAlignedBB{ + //these are slightly bigger than in PC + return AxisAlignedBB::one()->contract(0.025, 0, 0.025)->trim(Facing::UP, 0.05); + } + + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + if($player !== null){ + $this->facing = Facing::opposite($player->getHorizontalFacing()); + } + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); + } + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player instanceof Player){ $enderChest = $this->getLevel()->getTile($this); @@ -70,8 +99,4 @@ class EnderChest extends Chest{ ItemFactory::get(Item::OBSIDIAN, 0, 8) ]; } - - public function getFuelTime() : int{ - return 0; - } }