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

@ -74,16 +74,24 @@ class Bed extends Transparent{
return 0b1111;
}
public function updateState() : void{
parent::updateState();
public function readStateFromWorld() : void{
parent::readStateFromWorld();
//read extra state information from the tile - this is an ugly hack
//TODO: extend this hack to setting block as well so we don't have to deal with tile hacks in the main code
$tile = $this->level->getTile($this);
if($tile instanceof TileBed){
$this->color = $tile->getColor();
}
}
public function writeStateToWorld() : void{
parent::writeStateToWorld();
//extra block properties storage hack
$tile = Tile::createTile(Tile::BED, $this->getLevel(), TileBed::createNBT($this));
if($tile instanceof TileBed){
$tile->setColor($this->color);
}
}
public function getHardness() : float{
return 0.2;
}
@ -186,16 +194,6 @@ class Bed extends Transparent{
$nextState->head = true;
$this->getLevel()->setBlock($next, $nextState);
//TODO: make this happen automatically on block set
$tile1 = Tile::createTile(Tile::BED, $this->getLevel(), TileBed::createNBT($this));
if($tile1 instanceof TileBed){
$tile1->setColor($this->color);
}
$tile2 = Tile::createTile(Tile::BED, $this->getLevel(), TileBed::createNBT($next));
if($tile2 instanceof TileBed){
$tile2->setColor($this->color);
}
return true;
}
}