Automate creation of tiles when they are used to store block properties

This commit is contained in:
Dylan K. Taylor
2018-10-29 18:20:05 +00:00
parent 3f3bdaeba5
commit 1170b66fd5
8 changed files with 76 additions and 80 deletions

View File

@ -59,8 +59,8 @@ class Skull extends Flowable{
return 0b111;
}
public function updateState() : void{
parent::updateState();
public function readStateFromWorld() : void{
parent::readStateFromWorld();
$tile = $this->level->getTile($this);
if($tile instanceof TileSkull){
$this->type = $tile->getType();
@ -68,6 +68,15 @@ class Skull extends Flowable{
}
}
public function writeStateToWorld() : void{
parent::writeStateToWorld();
$tile = Tile::createTile(Tile::SKULL, $this->getLevel(), TileSkull::createNBT($this));
if($tile instanceof TileSkull){
$tile->setRotation($this->rotation);
$tile->setType($this->type);
}
}
public function getHardness() : float{
return 1;
}
@ -91,17 +100,7 @@ class Skull extends Flowable{
if($player !== null and $face === Facing::UP){
$this->rotation = ((int) floor(($player->yaw * 16 / 360) + 0.5)) & 0xf;
}
if(parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){
//TODO: make this automatic on block set
$tile = Tile::createTile(Tile::SKULL, $this->getLevel(), TileSkull::createNBT($this));
if($tile instanceof TileSkull){
$tile->setRotation($this->rotation);
$tile->setType($this->type);
}
return true;
}
return false;
return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
public function getItem() : Item{