mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
Automate creation and deletion of Tiles for appropriate blocks
closes #880
This commit is contained in:
@ -41,6 +41,7 @@ use pocketmine\metadata\Metadatable;
|
||||
use pocketmine\metadata\MetadataValue;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\plugin\Plugin;
|
||||
use pocketmine\tile\TileFactory;
|
||||
use function array_merge;
|
||||
use function assert;
|
||||
use function dechex;
|
||||
@ -172,8 +173,26 @@ class Block extends Position implements BlockIds, Metadatable{
|
||||
$this->collisionBoxes = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class of Tile associated with this block.
|
||||
*
|
||||
* @return string|null class extending Tile, or null
|
||||
*/
|
||||
protected function getTileClass() : ?string{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function writeStateToWorld() : void{
|
||||
$this->level->getChunkAtPosition($this)->setBlock($this->x & 0xf, $this->y, $this->z & 0xf, $this->getId(), $this->getDamage());
|
||||
|
||||
$tileType = $this->getTileClass();
|
||||
$oldTile = $this->level->getTile($this);
|
||||
if($oldTile !== null and ($tileType === null or !($oldTile instanceof $tileType))){
|
||||
$oldTile->close();
|
||||
}
|
||||
if($tileType !== null){
|
||||
$this->level->addTile(TileFactory::create($tileType, $this->level, $this->asVector3()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -315,6 +334,9 @@ class Block extends Position implements BlockIds, Metadatable{
|
||||
* @return bool
|
||||
*/
|
||||
public function onBreak(Item $item, Player $player = null) : bool{
|
||||
if(($t = $this->level->getTile($this)) !== null){
|
||||
$t->onBlockDestroyed();
|
||||
}
|
||||
return $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user