Added a trait for blocks which face opposite their placing player

This commit is contained in:
Dylan K. Taylor
2021-04-27 21:28:26 +01:00
parent 72045b3d7e
commit 8a3df1212a
8 changed files with 59 additions and 71 deletions

View File

@ -24,15 +24,16 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\tile\Chest as TileChest;
use pocketmine\block\utils\FacesOppositePlacingPlayerTrait;
use pocketmine\block\utils\NormalHorizontalFacingInMetadataTrait;
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
class Chest extends Transparent{
use FacesOppositePlacingPlayerTrait;
use NormalHorizontalFacingInMetadataTrait;
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
@ -47,14 +48,6 @@ class Chest extends Transparent{
return [AxisAlignedBB::one()->contract(0.025, 0, 0.025)->trim(Facing::UP, 0.05)];
}
public function place(BlockTransaction $tx, 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($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
public function onPostPlace() : void{
$tile = $this->pos->getWorld()->getTile($this->pos);
if($tile instanceof TileChest){