Clean up item handling of blocks

This commit is contained in:
Dylan K. Taylor 2018-09-23 14:21:37 +01:00
parent ed1c511c3c
commit 1427da0aeb
3 changed files with 10 additions and 23 deletions

View File

@ -184,17 +184,13 @@ class Bed extends Transparent{
public function getDropsForCompatibleTool(Item $item) : array{
if($this->isHeadPart()){
return [$this->getItem()];
return parent::getDropsForCompatibleTool($item);
}
return [];
}
public function getPickedItem() : Item{
return $this->getItem();
}
private function getItem() : Item{
public function getItem() : Item{
$tile = $this->getLevel()->getTile($this);
if($tile instanceof TileBed){
return ItemFactory::get($this->getItemId(), $tile->getColor());

View File

@ -120,6 +120,10 @@ class Block extends Position implements BlockIds, Metadatable{
return $this->id;
}
public function getItem() : Item{
return ItemFactory::get($this->getItemId(), $this->getVariant());
}
/**
* @internal
* @return int
@ -127,7 +131,6 @@ class Block extends Position implements BlockIds, Metadatable{
public function getRuntimeId() : int{
return BlockFactory::toStaticRuntimeId($this->getId(), $this->getDamage());
}
/**
* @return int
*/
@ -467,9 +470,7 @@ class Block extends Position implements BlockIds, Metadatable{
* @return Item[]
*/
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get($this->getItemId(), $this->getVariant())
];
return [$this->getItem()];
}
/**
@ -480,9 +481,7 @@ class Block extends Position implements BlockIds, Metadatable{
* @return Item[]
*/
public function getSilkTouchDrops(Item $item) : array{
return [
ItemFactory::get($this->getItemId(), $this->getVariant())
];
return [$this->getItem()];
}
/**
@ -524,7 +523,7 @@ class Block extends Position implements BlockIds, Metadatable{
* @return Item
*/
public function getPickedItem() : Item{
return ItemFactory::get($this->getItemId(), $this->getVariant());
return $this->getItem();
}
/**

View File

@ -83,20 +83,12 @@ class Skull extends Flowable{
return false;
}
private function getItem() : Item{
public function getItem() : Item{
$tile = $this->level->getTile($this);
return ItemFactory::get(Item::SKULL, $tile instanceof TileSkull ? $tile->getType() : 0);
}
public function getDropsForCompatibleTool(Item $item) : array{
return [$this->getItem()];
}
public function isAffectedBySilkTouch() : bool{
return false;
}
public function getPickedItem() : Item{
return $this->getItem();
}
}