Implemented block break XP drops

This commit is contained in:
Dylan K. Taylor
2018-04-15 19:03:18 +01:00
parent 1e2122d854
commit 532269a484
9 changed files with 84 additions and 3 deletions

View File

@ -471,6 +471,30 @@ class Block extends Position implements BlockIds, Metadatable{
];
}
/**
* Returns how much XP will be dropped by breaking this block with the given item.
*
* @param Item $item
*
* @return int
*/
public function getXpDropForTool(Item $item) : int{
if($item->hasEnchantment(Enchantment::SILK_TOUCH) or !$this->isCompatibleWithTool($item)){
return 0;
}
return $this->getXpDropAmount();
}
/**
* Returns how much XP this block will drop when broken with an appropriate tool.
*
* @return int
*/
protected function getXpDropAmount() : int{
return 0;
}
/**
* Returns whether Silk Touch enchanted tools will cause this block to drop as itself. Since most blocks drop
* themselves anyway, this is implicitly true.

View File

@ -57,4 +57,7 @@ class CoalOre extends Solid{
];
}
public function getXpDropForTool(Item $item) : int{
return mt_rand(0, 2);
}
}

View File

@ -56,4 +56,8 @@ class DiamondOre extends Solid{
ItemFactory::get(Item::DIAMOND)
];
}
protected function getXpDropAmount() : int{
return mt_rand(3, 7);
}
}

View File

@ -57,4 +57,7 @@ class LapisOre extends Solid{
];
}
protected function getXpDropAmount() : int{
return mt_rand(2, 5);
}
}

View File

@ -57,4 +57,8 @@ class MonsterSpawner extends Transparent{
public function isAffectedBySilkTouch() : bool{
return false;
}
protected function getXpDropAmount() : int{
return mt_rand(15, 43);
}
}

View File

@ -57,4 +57,7 @@ class NetherQuartzOre extends Solid{
];
}
protected function getXpDropAmount() : int{
return mt_rand(2, 5);
}
}

View File

@ -70,4 +70,8 @@ class RedstoneOre extends Solid{
ItemFactory::get(Item::REDSTONE_DUST, 0, mt_rand(4, 5))
];
}
protected function getXpDropAmount() : int{
return mt_rand(1, 5);
}
}