Block: add onPostPlace() hook

This commit is contained in:
Dylan K. Taylor 2019-05-27 17:30:57 +01:00
parent 11d21448fc
commit 28f3322337
3 changed files with 22 additions and 19 deletions

View File

@ -253,6 +253,10 @@ class Block extends Position implements BlockLegacyIds, Metadatable{
return $this->getWorld()->setBlock($blockReplace, $this); return $this->getWorld()->setBlock($blockReplace, $this);
} }
public function onPostPlace() : void{
}
/** /**
* Returns an object containing information about the destruction requirements of this block. * Returns an object containing information about the destruction requirements of this block.
* *

View File

@ -62,29 +62,27 @@ class Chest extends Transparent{
$this->facing = Facing::opposite($player->getHorizontalFacing()); $this->facing = Facing::opposite($player->getHorizontalFacing());
} }
if(parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){ return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
$tile = $this->world->getTile($this); }
if($tile instanceof TileChest){
foreach([ public function onPostPlace() : void{
Facing::rotateY($this->facing, true), $tile = $this->world->getTile($this);
Facing::rotateY($this->facing, false) if($tile instanceof TileChest){
] as $side){ foreach([
$c = $this->getSide($side); Facing::rotateY($this->facing, true),
if($c instanceof Chest and $c->isSameType($this) and $c->facing === $this->facing){ Facing::rotateY($this->facing, false)
$pair = $this->world->getTile($c); ] as $side){
if($pair instanceof TileChest and !$pair->isPaired()){ $c = $this->getSide($side);
$pair->pairWith($tile); if($c instanceof Chest and $c->isSameType($this) and $c->facing === $this->facing){
$tile->pairWith($pair); $pair = $this->world->getTile($c);
break; if($pair instanceof TileChest and !$pair->isPaired()){
} $pair->pairWith($tile);
$tile->pairWith($pair);
break;
} }
} }
} }
return true;
} }
return false;
} }
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{

View File

@ -1863,6 +1863,7 @@ class World implements ChunkManager, Metadatable{
//TODO: seal this up inside block placement //TODO: seal this up inside block placement
$tile->copyDataFromItem($item); $tile->copyDataFromItem($item);
} }
$hand->onPostPlace();
if($playSound){ if($playSound){
$this->addSound($hand, new BlockPlaceSound($hand)); $this->addSound($hand, new BlockPlaceSound($hand));