Skip to content

Commit

Permalink
Mace Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
KnosTx committed Sep 10, 2024
1 parent 5756e80 commit ea922db
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/item/Mace.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getBlockToolHarvestLevel() : int{
}

public function getMiningEfficiency(bool $isCorrectTool) : float{
return parent::getMiningEfficiency($isCorrectTool) * 1.5; //swords break any block 1.5x faster than hand
return parent::getMiningEfficiency($isCorrectTool) * 1.5;
}

public function getBaseMiningEfficiency() : float{
Expand All @@ -63,23 +63,17 @@ public function onDestroyBlock(Block $block, array &$returnedItems) : bool{
return false;
}

private function getDamager() : ?EntityDamageByEntityEvent{
return $this->damager ?? null;
}

public function onAttackEntity(EntityDamageByEntityEvent $damager, Entity $victim, array &$returnedItems) : bool{

Check failure on line 66 in src/item/Mace.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 / PHPStan analysis

Method pocketmine\item\Mace::onAttackEntity() has parameter $returnedItems with no value type specified in iterable type array.

Check failure on line 66 in src/item/Mace.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 / PHPStan analysis

Parameter #1 $damager (pocketmine\event\entity\EntityDamageByEntityEvent) of method pocketmine\item\Mace::onAttackEntity() is not contravariant with parameter #1 $victim (pocketmine\entity\Entity) of method pocketmine\item\Item::onAttackEntity().

Check failure on line 66 in src/item/Mace.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 / PHPStan analysis

Parameter #2 $victim (pocketmine\entity\Entity) of method pocketmine\item\Mace::onAttackEntity() is not contravariant with parameter #2 $returnedItems (array) of method pocketmine\item\Item::onAttackEntity().

Check failure on line 66 in src/item/Mace.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 / PHPStan analysis

Parameter #2 $victim of method pocketmine\item\Mace::onAttackEntity() is not passed by reference but parameter #2 $returnedItems of method pocketmine\item\Item::onAttackEntity() is passed by reference.

Check failure on line 66 in src/item/Mace.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 / PHPStan analysis

Parameter #3 $returnedItems of method pocketmine\item\Mace::onAttackEntity() is not optional.

Check failure on line 66 in src/item/Mace.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 / PHPStan analysis

Method pocketmine\item\Mace::onAttackEntity() has parameter $returnedItems with no value type specified in iterable type array.

Check failure on line 66 in src/item/Mace.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 / PHPStan analysis

Parameter #1 $damager (pocketmine\event\entity\EntityDamageByEntityEvent) of method pocketmine\item\Mace::onAttackEntity() is not contravariant with parameter #1 $victim (pocketmine\entity\Entity) of method pocketmine\item\Item::onAttackEntity().

Check failure on line 66 in src/item/Mace.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 / PHPStan analysis

Parameter #2 $victim (pocketmine\entity\Entity) of method pocketmine\item\Mace::onAttackEntity() is not contravariant with parameter #2 $returnedItems (array) of method pocketmine\item\Item::onAttackEntity().

Check failure on line 66 in src/item/Mace.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 / PHPStan analysis

Parameter #2 $victim of method pocketmine\item\Mace::onAttackEntity() is not passed by reference but parameter #2 $returnedItems of method pocketmine\item\Item::onAttackEntity() is passed by reference.

Check failure on line 66 in src/item/Mace.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 / PHPStan analysis

Parameter #3 $returnedItems of method pocketmine\item\Mace::onAttackEntity() is not optional.

Check failure on line 66 in src/item/Mace.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 / PHPStan analysis

Method pocketmine\item\Mace::onAttackEntity() has parameter $returnedItems with no value type specified in iterable type array.

Check failure on line 66 in src/item/Mace.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 / PHPStan analysis

Parameter #1 $damager (pocketmine\event\entity\EntityDamageByEntityEvent) of method pocketmine\item\Mace::onAttackEntity() is not contravariant with parameter #1 $victim (pocketmine\entity\Entity) of method pocketmine\item\Item::onAttackEntity().

Check failure on line 66 in src/item/Mace.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 / PHPStan analysis

Parameter #2 $victim (pocketmine\entity\Entity) of method pocketmine\item\Mace::onAttackEntity() is not contravariant with parameter #2 $returnedItems (array) of method pocketmine\item\Item::onAttackEntity().

Check failure on line 66 in src/item/Mace.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 / PHPStan analysis

Parameter #2 $victim of method pocketmine\item\Mace::onAttackEntity() is not passed by reference but parameter #2 $returnedItems of method pocketmine\item\Item::onAttackEntity() is passed by reference.

Check failure on line 66 in src/item/Mace.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 / PHPStan analysis

Parameter #3 $returnedItems of method pocketmine\item\Mace::onAttackEntity() is not optional.
$damageEvent = $victim->getLastDamageCause();

if($damageEvent instanceof EntityDamageEvent && $damageEvent->getCause() == EntityDamageEvent::CAUSE_ENTITY_ATTACK){
if($damageEvent instanceof EntityDamageByEntityEvent){

/** @var Entity|null $user */
$user = $damageEvent->getDamager();

if($user !== null){
$height = $user->getFallDistance();

if($height >= 2) {
// The damage dealt with the mace is boosted 5+ damage for every block fallen after the first.
$damage = ($height - 1) * 5;
$victim->setHealth($victim->getHealth() - $damage);

Expand Down

0 comments on commit ea922db

Please sign in to comment.