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{ public function getDropsForCompatibleTool(Item $item) : array{
if($this->isHeadPart()){ if($this->isHeadPart()){
return [$this->getItem()]; return parent::getDropsForCompatibleTool($item);
} }
return []; return [];
} }
public function getPickedItem() : Item{ public function getItem() : Item{
return $this->getItem();
}
private function getItem() : Item{
$tile = $this->getLevel()->getTile($this); $tile = $this->getLevel()->getTile($this);
if($tile instanceof TileBed){ if($tile instanceof TileBed){
return ItemFactory::get($this->getItemId(), $tile->getColor()); return ItemFactory::get($this->getItemId(), $tile->getColor());

View File

@ -120,6 +120,10 @@ class Block extends Position implements BlockIds, Metadatable{
return $this->id; return $this->id;
} }
public function getItem() : Item{
return ItemFactory::get($this->getItemId(), $this->getVariant());
}
/** /**
* @internal * @internal
* @return int * @return int
@ -127,7 +131,6 @@ class Block extends Position implements BlockIds, Metadatable{
public function getRuntimeId() : int{ public function getRuntimeId() : int{
return BlockFactory::toStaticRuntimeId($this->getId(), $this->getDamage()); return BlockFactory::toStaticRuntimeId($this->getId(), $this->getDamage());
} }
/** /**
* @return int * @return int
*/ */
@ -467,9 +470,7 @@ class Block extends Position implements BlockIds, Metadatable{
* @return Item[] * @return Item[]
*/ */
public function getDropsForCompatibleTool(Item $item) : array{ public function getDropsForCompatibleTool(Item $item) : array{
return [ return [$this->getItem()];
ItemFactory::get($this->getItemId(), $this->getVariant())
];
} }
/** /**
@ -480,9 +481,7 @@ class Block extends Position implements BlockIds, Metadatable{
* @return Item[] * @return Item[]
*/ */
public function getSilkTouchDrops(Item $item) : array{ public function getSilkTouchDrops(Item $item) : array{
return [ return [$this->getItem()];
ItemFactory::get($this->getItemId(), $this->getVariant())
];
} }
/** /**
@ -524,7 +523,7 @@ class Block extends Position implements BlockIds, Metadatable{
* @return Item * @return Item
*/ */
public function getPickedItem() : 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; return false;
} }
private function getItem() : Item{ public function getItem() : Item{
$tile = $this->level->getTile($this); $tile = $this->level->getTile($this);
return ItemFactory::get(Item::SKULL, $tile instanceof TileSkull ? $tile->getType() : 0); return ItemFactory::get(Item::SKULL, $tile instanceof TileSkull ? $tile->getType() : 0);
} }
public function getDropsForCompatibleTool(Item $item) : array{
return [$this->getItem()];
}
public function isAffectedBySilkTouch() : bool{ public function isAffectedBySilkTouch() : bool{
return false; return false;
} }
public function getPickedItem() : Item{
return $this->getItem();
}
} }