Block: Migrated all trivial drops code to getDropsForCompatibleTool()

getDrops() should now be overridden only for special cases. There are some non-trivial overrides left that are going to need some extra work to clean up.
This commit is contained in:
Dylan K. Taylor 2017-12-13 12:49:58 +00:00
parent 8c47a338df
commit 56f1a6ba37
34 changed files with 38 additions and 36 deletions

View File

@ -199,7 +199,7 @@ class Bed extends Transparent{
return true;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
if($this->isHeadPart()){
$tile = $this->getLevel()->getTile($this);
if($tile instanceof TileBed){

View File

@ -38,7 +38,7 @@ class Beetroot extends Crops{
return "Beetroot Block";
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
if($this->meta >= 0x07){
return [
ItemFactory::get(Item::BEETROOT, 0, 1),

View File

@ -46,7 +46,7 @@ class Bookshelf extends Solid{
return BlockToolType::TYPE_AXE;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::BOOK, 0, 3)
];

View File

@ -33,7 +33,7 @@ class BrownMushroomBlock extends RedMushroomBlock{
return "Brown Mushroom Block";
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
Item::get(Item::BROWN_MUSHROOM, 0, mt_rand(0, 2))
];

View File

@ -85,7 +85,7 @@ class Cake extends Transparent implements FoodSource{
return false;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [];
}

View File

@ -38,7 +38,7 @@ class Carrot extends Crops{
return "Carrot Block";
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::CARROT, 0, $this->meta >= 0x07 ? mt_rand(1, 4) : 1)
];

View File

@ -46,7 +46,7 @@ class Clay extends Solid{
return "Clay Block";
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::CLAY_BALL, 0, 4)
];

View File

@ -58,7 +58,7 @@ class Cobweb extends Flowable{
$entity->resetFallDistance();
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
//TODO: correct drops
return [];
}

View File

@ -107,7 +107,7 @@ class Farmland extends Transparent{
return false;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::DIRT, 0, 1)
];

View File

@ -79,7 +79,7 @@ class Fire extends Flowable{
}
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [];
}

View File

@ -96,8 +96,8 @@ class FlowerPot extends Flowable{
return true;
}
public function getDrops(Item $item) : array{
$items = parent::getDrops($item);
public function getDropsForCompatibleTool(Item $item) : array{
$items = parent::getDropsForCompatibleTool($item);
$tile = $this->getLevel()->getTile($this);
if($tile instanceof TileFlowerPot){

View File

@ -41,7 +41,7 @@ class Glass extends Transparent{
return 0.3;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [];
}
}

View File

@ -41,7 +41,7 @@ class GlassPane extends Thin{
return 0.3;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [];
}
}

View File

@ -50,7 +50,7 @@ class Glowstone extends Transparent{
return 15;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::GLOWSTONE_DUST, 0, mt_rand(2, 4))
];

View File

@ -52,7 +52,7 @@ class Grass extends Solid{
return BlockToolType::TYPE_SHOVEL;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::DIRT, 0, 1)
];

View File

@ -69,7 +69,7 @@ class GrassPath extends Transparent{
return false;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::DIRT, 0, 1)
];

View File

@ -46,14 +46,14 @@ class Gravel extends Fallable{
return BlockToolType::TYPE_SHOVEL;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
if(mt_rand(1, 10) === 1){
return [
ItemFactory::get(Item::FLINT, 0, 1)
];
}
return parent::getDrops($item);
return parent::getDropsForCompatibleTool($item);
}
}

View File

@ -74,7 +74,7 @@ class Ice extends Transparent{
return false;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [];
}
}

View File

@ -99,8 +99,8 @@ class ItemFrame extends Flowable{
return 0;
}
public function getDrops(Item $item) : array{
$drops = parent::getDrops($item);
public function getDropsForCompatibleTool(Item $item) : array{
$drops = parent::getDropsForCompatibleTool($item);
$tile = $this->level->getTile($this);
if($tile instanceof TileItemFrame){

View File

@ -72,7 +72,7 @@ abstract class Liquid extends Transparent{
return null;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [];
}

View File

@ -46,7 +46,7 @@ class Melon extends Transparent{
return BlockToolType::TYPE_AXE;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::MELON_SLICE, 0, mt_rand(3, 7))
];

View File

@ -83,7 +83,7 @@ class MelonStem extends Crops{
return false;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::MELON_SEEDS, 0, mt_rand(0, 2))
];

View File

@ -45,7 +45,7 @@ class MonsterSpawner extends Transparent{
return "Monster Spawner";
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [];
}
}

View File

@ -50,7 +50,7 @@ class Mycelium extends Solid{
return 0.6;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::DIRT, 0, 1)
];

View File

@ -85,7 +85,7 @@ class NetherWartPlant extends Flowable{
return false;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get($this->getItemId(), 0, ($this->getDamage() === 3 ? mt_rand(2, 4) : 1))
];

View File

@ -38,7 +38,7 @@ class Potato extends Crops{
return "Potato Block";
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::POTATO, 0, $this->getDamage() >= 0x07 ? mt_rand(1, 4) : 1)
];

View File

@ -83,7 +83,7 @@ class PumpkinStem extends Crops{
return false;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::PUMPKIN_SEEDS, 0, mt_rand(0, 2))
];

View File

@ -45,7 +45,7 @@ class RedMushroomBlock extends Solid{
return BlockToolType::TYPE_AXE;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
Item::get(Item::RED_MUSHROOM, 0, mt_rand(0, 2))
];

View File

@ -46,7 +46,7 @@ class SeaLantern extends Transparent{
return 15;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
return [
ItemFactory::get(Item::PRISMARINE_CRYSTALS, 0, 3)
];

View File

@ -71,7 +71,7 @@ class Skull extends Flowable{
return true;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
$tile = $this->level->getTile($this);
if($tile instanceof TileSkull){
return [

View File

@ -95,7 +95,7 @@ class StandingBanner extends Transparent{
return 0;
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
$tile = $this->level->getTile($this);
$drop = ItemFactory::get(Item::BANNER, ($tile instanceof TileBanner ? $tile->getBaseColor() : 0));

View File

@ -81,6 +81,8 @@ class TallGrass extends Flowable{
];
}
//TODO: check shears
return [];
}

View File

@ -201,7 +201,7 @@ class Vine extends Flowable{
public function getDrops(Item $item) : array{
if($item->isShears()){
return parent::getDrops($item);
return $this->getDropsForCompatibleTool($item);
}
return [];

View File

@ -38,7 +38,7 @@ class Wheat extends Crops{
return "Wheat Block";
}
public function getDrops(Item $item) : array{
public function getDropsForCompatibleTool(Item $item) : array{
if($this->meta >= 0x07){
return [
ItemFactory::get(Item::WHEAT, 0, 1),