Cleaned up non-trivial getDrops() stuff

This commit is contained in:
Dylan K. Taylor 2017-12-13 14:47:50 +00:00
parent 90eed14cd6
commit 717b36a983
5 changed files with 48 additions and 28 deletions

View File

@ -56,13 +56,17 @@ class DeadBush extends Flowable{
return BlockToolType::TYPE_SHEARS; return BlockToolType::TYPE_SHEARS;
} }
public function getDrops(Item $item) : array{ public function getToolHarvestLevel() : int{
if($item->isShears()){ return 1;
return parent::getDrops($item);
} }
public function getDrops(Item $item) : array{
if(!$this->isCompatibleWithTool($item)){
return [ return [
ItemFactory::get(Item::STICK, 0, mt_rand(0, 2)) ItemFactory::get(Item::STICK, 0, mt_rand(0, 2))
]; ];
} }
return parent::getDrops($item);
}
} }

View File

@ -109,19 +109,25 @@ class DoublePlant extends Flowable{
return 0x07; return 0x07;
} }
public function getToolType() : int{
return ($this->meta === 2 or $this->meta === 3) ? BlockToolType::TYPE_SHEARS : BlockToolType::TYPE_NONE;
}
public function getToolHarvestLevel() : int{
return ($this->meta === 2 or $this->meta === 3) ? 1 : 0; //only grass or fern require shears
}
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($this->meta & self::BITFLAG_TOP){ if($this->meta & self::BITFLAG_TOP){
if(!$item->isShears() and ($this->meta === 2 or $this->meta === 3)){ //grass or fern if($this->isCompatibleWithTool($item)){
return parent::getDrops($item);
}
if(mt_rand(0, 24) === 0){ if(mt_rand(0, 24) === 0){
return [ return [
ItemFactory::get(Item::SEEDS, 0, 1) ItemFactory::get(Item::SEEDS, 0, 1)
]; ];
} }
return [];
}
return parent::getDrops($item);
} }
return []; return [];

View File

@ -173,10 +173,7 @@ class Leaves extends Transparent{
} }
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isShears()){ if(!$this->isCompatibleWithTool($item)){
return parent::getDrops($item);
}
$drops = []; $drops = [];
if(mt_rand(1, 20) === 1){ //Saplings if(mt_rand(1, 20) === 1){ //Saplings
$drops[] = $this->getSaplingItem(); $drops[] = $this->getSaplingItem();
@ -188,6 +185,9 @@ class Leaves extends Transparent{
return $drops; return $drops;
} }
return parent::getDrops($item);
}
public function getSaplingItem() : Item{ public function getSaplingItem() : Item{
return ItemFactory::get(Item::SAPLING, $this->getVariant()); return ItemFactory::get(Item::SAPLING, $this->getVariant());
} }

View File

@ -74,15 +74,25 @@ class TallGrass extends Flowable{
return false; return false;
} }
public function getToolType() : int{
return BlockToolType::TYPE_SHEARS;
}
public function getToolHarvestLevel() : int{
return 1;
}
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($this->isCompatibleWithTool($item)){
return parent::getDrops($item);
}
if(mt_rand(0, 15) === 0){ if(mt_rand(0, 15) === 0){
return [ return [
ItemFactory::get(Item::WHEAT_SEEDS, 0, 1) ItemFactory::get(Item::WHEAT_SEEDS, 0, 1)
]; ];
} }
//TODO: check shears
return []; return [];
} }

View File

@ -200,7 +200,7 @@ class Vine extends Flowable{
} }
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isShears()){ if($item->getBlockToolType() & BlockToolType::TYPE_SHEARS){
return $this->getDropsForCompatibleTool($item); return $this->getDropsForCompatibleTool($item);
} }