Don't auto-create tiles on activate

this complicates the code unnecessarily and doesn't produce the desired effect in most cases anyway.
This commit is contained in:
Dylan K. Taylor 2018-09-28 20:12:41 +01:00
parent 594a2041b6
commit 8e6a5813ea
4 changed files with 22 additions and 45 deletions

View File

@ -109,23 +109,18 @@ class Chest extends Transparent{
public function onActivate(Item $item, Player $player = null) : bool{ public function onActivate(Item $item, Player $player = null) : bool{
if($player instanceof Player){ if($player instanceof Player){
$t = $this->getLevel()->getTile($this); $chest = $this->getLevel()->getTile($this);
$chest = null; if($chest instanceof TileChest){
if($t instanceof TileChest){ if(
$chest = $t; !$this->getSide(Facing::UP)->isTransparent() or
}else{ ($chest->isPaired() and !$chest->getPair()->getBlock()->getSide(Facing::UP)->isTransparent()) or
$chest = Tile::createTile(Tile::CHEST, $this->getLevel(), TileChest::createNBT($this)); !$chest->canOpenWith($item->getCustomName())
} ){
return true;
}
if( $player->addWindow($chest->getInventory());
!$this->getSide(Facing::UP)->isTransparent() or
($chest->isPaired() and !$chest->getPair()->getBlock()->getSide(Facing::UP)->isTransparent()) or
!$chest->canOpenWith($item->getCustomName())
){
return true;
} }
$player->addWindow($chest->getInventory());
} }
return true; return true;

View File

@ -76,21 +76,11 @@ class EnderChest extends Chest{
public function onActivate(Item $item, Player $player = null) : bool{ public function onActivate(Item $item, Player $player = null) : bool{
if($player instanceof Player){ if($player instanceof Player){
$enderChest = $this->getLevel()->getTile($this);
$t = $this->getLevel()->getTile($this); if($enderChest instanceof TileEnderChest and $this->getSide(Facing::UP)->isTransparent()){
$enderChest = null; $player->getEnderChestInventory()->setHolderPosition($enderChest);
if($t instanceof TileEnderChest){ $player->addWindow($player->getEnderChestInventory());
$enderChest = $t;
}else{
$enderChest = Tile::createTile(Tile::ENDER_CHEST, $this->getLevel(), TileEnderChest::createNBT($this));
} }
if(!$this->getSide(Facing::UP)->isTransparent()){
return true;
}
$player->getEnderChestInventory()->setHolderPosition($enderChest);
$player->addWindow($player->getEnderChestInventory());
} }
return true; return true;

View File

@ -104,15 +104,9 @@ class Furnace extends Solid{
public function onActivate(Item $item, Player $player = null) : bool{ public function onActivate(Item $item, Player $player = null) : bool{
if($player instanceof Player){ if($player instanceof Player){
$furnace = $this->getLevel()->getTile($this); $furnace = $this->getLevel()->getTile($this);
if(!($furnace instanceof TileFurnace)){ if($furnace instanceof TileFurnace and $furnace->canOpenWith($item->getCustomName())){
$furnace = Tile::createTile(Tile::FURNACE, $this->getLevel(), TileFurnace::createNBT($this)); $player->addWindow($furnace->getInventory());
} }
if(!$furnace->canOpenWith($item->getCustomName())){
return true;
}
$player->addWindow($furnace->getInventory());
} }
return true; return true;

View File

@ -60,14 +60,12 @@ class ItemFrame extends Flowable{
public function onActivate(Item $item, Player $player = null) : bool{ public function onActivate(Item $item, Player $player = null) : bool{
$tile = $this->level->getTile($this); $tile = $this->level->getTile($this);
if(!($tile instanceof TileItemFrame)){ if($tile instanceof TileItemFrame){
$tile = Tile::createTile(Tile::ITEM_FRAME, $this->getLevel(), TileItemFrame::createNBT($this)); if($tile->hasItem()){
} $tile->setItemRotation(($tile->getItemRotation() + 1) % 8);
}elseif(!$item->isNull()){
if($tile->hasItem()){ $tile->setItem($item->pop());
$tile->setItemRotation(($tile->getItemRotation() + 1) % 8); }
}elseif(!$item->isNull()){
$tile->setItem($item->pop());
} }
return true; return true;