mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Rename Block->canBeBrokenWith() to isCompatibleWithTool() and add documentation
This name better describes it. "can be broken with" implies that items which this returns false for cannot destroy the block at all, which is incorrect. What this actually returns is whether the item is the best tool to use to break the block.
This commit is contained in:
parent
0004e7429f
commit
da3640357c
@ -111,7 +111,7 @@ class Anvil extends Fallable{
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
if($this->canBeBrokenWith($item)){
|
||||
if($this->isCompatibleWithTool($item)){
|
||||
return [
|
||||
ItemFactory::get($this->getItemId(), $this->getDamage() & 0x0c, 1)
|
||||
];
|
||||
|
@ -218,7 +218,18 @@ class Block extends Position implements BlockIds, Metadatable{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function canBeBrokenWith(Item $item) : bool{
|
||||
/**
|
||||
* Returns whether the specified item is the proper tool to use for breaking this block. This checks tool type and
|
||||
* harvest level requirement.
|
||||
*
|
||||
* In most cases this is also used to determine whether block drops should be created or not, except in some
|
||||
* special cases such as vines.
|
||||
*
|
||||
* @param Item $tool
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isCompatibleWithTool(Item $tool) : bool{
|
||||
if($this->getHardness() < 0){
|
||||
return false;
|
||||
}
|
||||
@ -226,7 +237,7 @@ class Block extends Position implements BlockIds, Metadatable{
|
||||
$toolType = $this->getToolType();
|
||||
$harvestLevel = $this->getToolHarvestLevel();
|
||||
return $toolType === BlockToolType::TYPE_NONE or $harvestLevel === 0 or (
|
||||
($toolType & $item->getBlockToolType()) !== 0 and $item->getBlockToolHarvestLevel() >= $harvestLevel);
|
||||
($toolType & $tool->getBlockToolType()) !== 0 and $tool->getBlockToolHarvestLevel() >= $harvestLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -251,7 +262,7 @@ class Block extends Position implements BlockIds, Metadatable{
|
||||
*/
|
||||
public function getBreakTime(Item $item) : float{
|
||||
$base = $this->getHardness();
|
||||
if($this->canBeBrokenWith($item)){
|
||||
if($this->isCompatibleWithTool($item)){
|
||||
$base *= 1.5;
|
||||
}else{
|
||||
$base *= 5;
|
||||
@ -422,7 +433,7 @@ class Block extends Position implements BlockIds, Metadatable{
|
||||
* @return Item[]
|
||||
*/
|
||||
public function getDrops(Item $item) : array{
|
||||
if($this->canBeBrokenWith($item)){
|
||||
if($this->isCompatibleWithTool($item)){
|
||||
return [
|
||||
ItemFactory::get($this->getItemId(), $this->getVariant(), 1)
|
||||
];
|
||||
|
@ -52,7 +52,7 @@ class CoalOre extends Solid{
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
if($this->canBeBrokenWith($item)){
|
||||
if($this->isCompatibleWithTool($item)){
|
||||
return [
|
||||
ItemFactory::get(Item::COAL, 0, 1)
|
||||
];
|
||||
|
@ -52,7 +52,7 @@ class DiamondOre extends Solid{
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
if($this->canBeBrokenWith($item)){
|
||||
if($this->isCompatibleWithTool($item)){
|
||||
return [
|
||||
ItemFactory::get(Item::DIAMOND, 0, 1)
|
||||
];
|
||||
|
@ -52,7 +52,7 @@ class EmeraldOre extends Solid{
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
if($this->canBeBrokenWith($item)){
|
||||
if($this->isCompatibleWithTool($item)){
|
||||
return [
|
||||
ItemFactory::get(Item::EMERALD, 0, 1)
|
||||
];
|
||||
|
@ -102,7 +102,7 @@ class EnderChest extends Chest{
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
if($this->canBeBrokenWith($item)){
|
||||
if($this->isCompatibleWithTool($item)){
|
||||
return [
|
||||
ItemFactory::get(Item::OBSIDIAN, 0, 8)
|
||||
];
|
||||
|
@ -52,7 +52,7 @@ class LapisOre extends Solid{
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
if($this->canBeBrokenWith($item)){
|
||||
if($this->isCompatibleWithTool($item)){
|
||||
return [
|
||||
ItemFactory::get(Item::DYE, 4, mt_rand(4, 8))
|
||||
];
|
||||
|
@ -52,7 +52,7 @@ class NetherQuartzOre extends Solid{
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
if($this->canBeBrokenWith($item)){
|
||||
if($this->isCompatibleWithTool($item)){
|
||||
return [
|
||||
ItemFactory::get(Item::QUARTZ, 0, 1)
|
||||
];
|
||||
|
@ -56,7 +56,7 @@ class NetherReactor extends Solid{
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
if($this->canBeBrokenWith($item)){
|
||||
if($this->isCompatibleWithTool($item)){
|
||||
return [
|
||||
ItemFactory::get(Item::IRON_INGOT, 0, 6),
|
||||
ItemFactory::get(Item::DIAMOND, 0, 3)
|
||||
|
@ -69,7 +69,7 @@ class RedstoneOre extends Solid{
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
if($this->canBeBrokenWith($item)){
|
||||
if($this->isCompatibleWithTool($item)){
|
||||
return [
|
||||
ItemFactory::get(Item::REDSTONE_DUST, 0, mt_rand(4, 5))
|
||||
];
|
||||
|
@ -68,7 +68,7 @@ class Stone extends Solid{
|
||||
}
|
||||
|
||||
public function getDrops(Item $item) : array{
|
||||
if($this->canBeBrokenWith($item)){
|
||||
if($this->isCompatibleWithTool($item)){
|
||||
if($this->getDamage() === self::NORMAL){
|
||||
return [
|
||||
ItemFactory::get(Item::COBBLESTONE, $this->getDamage(), 1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user