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);
}
public function onPostPlace() : void{
}
/**
* 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());
}
if(parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){
$tile = $this->world->getTile($this);
if($tile instanceof TileChest){
foreach([
Facing::rotateY($this->facing, true),
Facing::rotateY($this->facing, false)
] as $side){
$c = $this->getSide($side);
if($c instanceof Chest and $c->isSameType($this) and $c->facing === $this->facing){
$pair = $this->world->getTile($c);
if($pair instanceof TileChest and !$pair->isPaired()){
$pair->pairWith($tile);
$tile->pairWith($pair);
break;
}
return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
public function onPostPlace() : void{
$tile = $this->world->getTile($this);
if($tile instanceof TileChest){
foreach([
Facing::rotateY($this->facing, true),
Facing::rotateY($this->facing, false)
] as $side){
$c = $this->getSide($side);
if($c instanceof Chest and $c->isSameType($this) and $c->facing === $this->facing){
$pair = $this->world->getTile($c);
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{

View File

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