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; return true;
} }
public function getDrops(Item $item) : array{ public function getDropsForCompatibleTool(Item $item) : array{
if($this->isHeadPart()){ if($this->isHeadPart()){
$tile = $this->getLevel()->getTile($this); $tile = $this->getLevel()->getTile($this);
if($tile instanceof TileBed){ if($tile instanceof TileBed){

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -85,7 +85,7 @@ class NetherWartPlant extends Flowable{
return false; return false;
} }
public function getDrops(Item $item) : array{ public function getDropsForCompatibleTool(Item $item) : array{
return [ return [
ItemFactory::get($this->getItemId(), 0, ($this->getDamage() === 3 ? mt_rand(2, 4) : 1)) 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"; return "Potato Block";
} }
public function getDrops(Item $item) : array{ public function getDropsForCompatibleTool(Item $item) : array{
return [ return [
ItemFactory::get(Item::POTATO, 0, $this->getDamage() >= 0x07 ? mt_rand(1, 4) : 1) 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; return false;
} }
public function getDrops(Item $item) : array{ public function getDropsForCompatibleTool(Item $item) : array{
return [ return [
ItemFactory::get(Item::PUMPKIN_SEEDS, 0, mt_rand(0, 2)) ItemFactory::get(Item::PUMPKIN_SEEDS, 0, mt_rand(0, 2))
]; ];

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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