mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Use dynamic state detection to localize stateinfo stored in tiles (hack)
This commit is contained in:
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\Color;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\ItemFactory;
|
||||
use pocketmine\lang\TranslationContainer;
|
||||
@ -50,6 +51,8 @@ class Bed extends Transparent{
|
||||
protected $occupied = false;
|
||||
/** @var bool */
|
||||
protected $head = false;
|
||||
/** @var int */
|
||||
protected $color = Color::RED;
|
||||
|
||||
public function __construct(){
|
||||
|
||||
@ -71,6 +74,16 @@ class Bed extends Transparent{
|
||||
return 0b1111;
|
||||
}
|
||||
|
||||
public function updateState() : void{
|
||||
parent::updateState();
|
||||
//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 getHardness() : float{
|
||||
return 0.2;
|
||||
}
|
||||
@ -161,6 +174,7 @@ class Bed extends Transparent{
|
||||
}
|
||||
|
||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
|
||||
$this->color = $item->getDamage(); //TODO: replace this with a proper colour getter
|
||||
$down = $this->getSide(Facing::DOWN);
|
||||
if(!$down->isTransparent()){
|
||||
$this->facing = $player !== null ? Bearing::toFacing($player->getDirection()) : Facing::NORTH;
|
||||
@ -172,8 +186,15 @@ class Bed extends Transparent{
|
||||
$nextState->head = true;
|
||||
$this->getLevel()->setBlock($next, $nextState);
|
||||
|
||||
Tile::createTile(Tile::BED, $this->getLevel(), TileBed::createNBT($this, $face, $item, $player));
|
||||
Tile::createTile(Tile::BED, $this->getLevel(), TileBed::createNBT($next, $face, $item, $player));
|
||||
//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;
|
||||
}
|
||||
@ -191,12 +212,7 @@ class Bed extends Transparent{
|
||||
}
|
||||
|
||||
public function getItem() : Item{
|
||||
$tile = $this->getLevel()->getTile($this);
|
||||
if($tile instanceof TileBed){
|
||||
return ItemFactory::get($this->getItemId(), $tile->getColor());
|
||||
}
|
||||
|
||||
return ItemFactory::get($this->getItemId(), 14); //Red
|
||||
return ItemFactory::get($this->getItemId(), $this->color);
|
||||
}
|
||||
|
||||
public function isAffectedBySilkTouch() : bool{
|
||||
|
@ -93,7 +93,7 @@ class Chest extends Transparent{
|
||||
}
|
||||
|
||||
if(parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){
|
||||
$tile = Tile::createTile(Tile::CHEST, $this->getLevel(), TileChest::createNBT($this, $face, $item, $player));
|
||||
$tile = Tile::createTile(Tile::CHEST, $this->getLevel(), TileChest::createNBT($this, $item));
|
||||
|
||||
if($chest instanceof TileChest and $tile instanceof TileChest){
|
||||
$chest->pairWith($tile);
|
||||
|
@ -43,7 +43,7 @@ class EnchantingTable extends Transparent{
|
||||
|
||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
|
||||
if(parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){
|
||||
Tile::createTile(Tile::ENCHANT_TABLE, $this->getLevel(), TileEnchantTable::createNBT($this, $face, $item, $player));
|
||||
Tile::createTile(Tile::ENCHANT_TABLE, $this->getLevel(), TileEnchantTable::createNBT($this, $item));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ class EnderChest extends Chest{
|
||||
}
|
||||
|
||||
if(Block::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){
|
||||
Tile::createTile(Tile::ENDER_CHEST, $this->getLevel(), TileEnderChest::createNBT($this, $face, $item, $player));
|
||||
Tile::createTile(Tile::ENDER_CHEST, $this->getLevel(), TileEnderChest::createNBT($this, $item));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ class FlowerPot extends Flowable{
|
||||
}
|
||||
|
||||
if(parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){
|
||||
Tile::createTile(Tile::FLOWER_POT, $this->getLevel(), TileFlowerPot::createNBT($this, $face, $item, $player));
|
||||
Tile::createTile(Tile::FLOWER_POT, $this->getLevel(), TileFlowerPot::createNBT($this, $item));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ class Furnace extends Solid{
|
||||
$this->facing = Bearing::toFacing(Bearing::opposite($player->getDirection()));
|
||||
}
|
||||
if(parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){
|
||||
Tile::createTile(Tile::FURNACE, $this->getLevel(), TileFurnace::createNBT($this, $face, $item, $player));
|
||||
Tile::createTile(Tile::FURNACE, $this->getLevel(), TileFurnace::createNBT($this, $item));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ class ItemFrame extends Flowable{
|
||||
$this->facing = $face;
|
||||
|
||||
if(parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){
|
||||
Tile::createTile(Tile::ITEM_FRAME, $this->getLevel(), TileItemFrame::createNBT($this, $face, $item, $player));
|
||||
Tile::createTile(Tile::ITEM_FRAME, $this->getLevel(), TileItemFrame::createNBT($this, $item));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ class SignPost extends Transparent{
|
||||
}
|
||||
|
||||
if($ret){
|
||||
Tile::createTile(Tile::SIGN, $this->getLevel(), TileSign::createNBT($this, $face, $item, $player));
|
||||
Tile::createTile(Tile::SIGN, $this->getLevel(), TileSign::createNBT($this, $item));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,10 @@ class Skull extends Flowable{
|
||||
/** @var int */
|
||||
protected $facing = Facing::NORTH;
|
||||
|
||||
protected $type = TileSkull::TYPE_SKELETON;
|
||||
/** @var int */
|
||||
protected $rotation = 0; //TODO: split this into floor skull and wall skull handling
|
||||
|
||||
public function __construct(){
|
||||
|
||||
}
|
||||
@ -55,6 +59,15 @@ class Skull extends Flowable{
|
||||
return 0b111;
|
||||
}
|
||||
|
||||
public function updateState() : void{
|
||||
parent::updateState();
|
||||
$tile = $this->level->getTile($this);
|
||||
if($tile instanceof TileSkull){
|
||||
$this->type = $tile->getType();
|
||||
$this->rotation = $tile->getRotation();
|
||||
}
|
||||
}
|
||||
|
||||
public function getHardness() : float{
|
||||
return 1;
|
||||
}
|
||||
@ -74,8 +87,17 @@ class Skull extends Flowable{
|
||||
}
|
||||
|
||||
$this->facing = $face;
|
||||
$this->type = $item->getDamage(); //TODO: replace this with a proper variant getter
|
||||
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)){
|
||||
Tile::createTile(Tile::SKULL, $this->getLevel(), TileSkull::createNBT($this, $face, $item, $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;
|
||||
}
|
||||
|
||||
@ -83,8 +105,7 @@ class Skull extends Flowable{
|
||||
}
|
||||
|
||||
public function getItem() : Item{
|
||||
$tile = $this->level->getTile($this);
|
||||
return ItemFactory::get(Item::SKULL, $tile instanceof TileSkull ? $tile->getType() : 0);
|
||||
return ItemFactory::get(Item::SKULL, $this->type);
|
||||
}
|
||||
|
||||
public function isAffectedBySilkTouch() : bool{
|
||||
|
@ -83,7 +83,7 @@ class StandingBanner extends Transparent{
|
||||
}
|
||||
|
||||
if($ret){
|
||||
Tile::createTile(Tile::BANNER, $this->getLevel(), TileBanner::createNBT($this, $face, $item, $player));
|
||||
Tile::createTile(Tile::BANNER, $this->getLevel(), TileBanner::createNBT($this, $item));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user