本文整理汇总了PHP中pocketmine\entity\Entity::getHardness方法的典型用法代码示例。如果您正苦于以下问题:PHP Entity::getHardness方法的具体用法?PHP Entity::getHardness怎么用?PHP Entity::getHardness使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\entity\Entity
的用法示例。
在下文中一共展示了Entity::getHardness方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: useOn
/**
* TODO: Move this to each item
*
* @param Entity|Block $object
* @param 1 for break|2 for Touch $type
*
* @return bool
*/
public function useOn($object, $type = 1)
{
if ($this->isUnbreakable()) {
return true;
}
$unbreakingl = $this->getEnchantmentLevel(Enchantment::TYPE_MINING_DURABILITY);
$unbreakingl = $unbreakingl > 3 ? 3 : $unbreakingl;
if (mt_rand(1, $unbreakingl + 1) !== 1) {
return true;
}
if ($type === 1) {
if ($object instanceof Entity) {
if ($this->isHoe() !== false or $this->isSword() !== false) {
//Hoe and Sword
$this->meta++;
return true;
} elseif ($this->isPickaxe() !== false or $this->isAxe() !== false or $this->isShovel() !== false) {
//Pickaxe Axe and Shovel
$this->meta += 2;
return true;
}
return true;
//Other tool do not lost durability white hitting
} elseif ($object instanceof Block) {
if ($this->isShears() !== false) {
if ($object->getToolType() === Tool::TYPE_SHEARS) {
//This should be checked in each block
$this->meta++;
}
return true;
} elseif ($object->getHardness() > 0) {
//Sword Pickaxe Axe and Shovel
if ($this->isSword() !== false) {
$this->meta += 2;
return true;
} elseif ($this->isPickaxe() !== false or $this->isAxe() !== false or $this->isShovel() !== false) {
$this->meta += 1;
return true;
}
}
}
} elseif ($type === 2) {
//For Touch. only trigger when OnActivate return true
if ($this->isHoe() !== false or $this->id === self::FLINT_STEEL or $this->isShovel() !== false) {
$this->meta++;
return true;
}
}
return true;
}