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;
}
public function getToolHarvestLevel() : int{
return 1;
}
public function getDrops(Item $item) : array{
if($item->isShears()){
return parent::getDrops($item);
if(!$this->isCompatibleWithTool($item)){
return [
ItemFactory::get(Item::STICK, 0, mt_rand(0, 2))
];
}
return [
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;
}
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{
if($this->meta & self::BITFLAG_TOP){
if(!$item->isShears() and ($this->meta === 2 or $this->meta === 3)){ //grass or fern
if(mt_rand(0, 24) === 0){
return [
ItemFactory::get(Item::SEEDS, 0, 1)
];
}
return [];
if($this->isCompatibleWithTool($item)){
return parent::getDrops($item);
}
return parent::getDrops($item);
if(mt_rand(0, 24) === 0){
return [
ItemFactory::get(Item::SEEDS, 0, 1)
];
}
}
return [];

View File

@ -173,19 +173,19 @@ class Leaves extends Transparent{
}
public function getDrops(Item $item) : array{
if($item->isShears()){
return parent::getDrops($item);
if(!$this->isCompatibleWithTool($item)){
$drops = [];
if(mt_rand(1, 20) === 1){ //Saplings
$drops[] = $this->getSaplingItem();
}
if($this->canDropApples() and mt_rand(1, 200) === 1){ //Apples
$drops[] = ItemFactory::get(Item::APPLE, 0, 1);
}
return $drops;
}
$drops = [];
if(mt_rand(1, 20) === 1){ //Saplings
$drops[] = $this->getSaplingItem();
}
if($this->canDropApples() and mt_rand(1, 200) === 1){ //Apples
$drops[] = ItemFactory::get(Item::APPLE, 0, 1);
}
return $drops;
return parent::getDrops($item);
}
public function getSaplingItem() : Item{

View File

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

View File

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