Skip to content

Commit

Permalink
Mace Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
KnosTx committed Sep 9, 2024
1 parent f2543bd commit d6f6a62
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/item/Mace.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,26 @@ public function onDestroyBlock(Block $block, array &$returnedItems) : bool{
}

public function onAttackEntity(Entity $victim, array &$returnedItems) : bool{
if($victim->getLastDamageCause()->getCause() == EntityDamageEvent::CAUSE_ENTITY_ATTACK){
$damageEvent = $victim->getLastDamageCause();

/** @var Entity $user */
$user = $victim->getLastDamageCause()->getDamager();
$height = $user->getFallDistance();
if($damageEvent instanceof EntityDamageEvent && $damageEvent->getCause() == EntityDamageEvent::CAUSE_ENTITY_ATTACK){

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);
/** @var Entity|null $user */
$user = $damageEvent->getDamager();

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

View workflow job for this annotation

GitHub Actions / PHP 8.1 / PHPStan analysis

Call to an undefined method pocketmine\event\entity\EntityDamageEvent::getDamager().

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

View workflow job for this annotation

GitHub Actions / PHP 8.2 / PHPStan analysis

Call to an undefined method pocketmine\event\entity\EntityDamageEvent::getDamager().

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

View workflow job for this annotation

GitHub Actions / PHP 8.3 / PHPStan analysis

Call to an undefined method pocketmine\event\entity\EntityDamageEvent::getDamager().

$motion = $user->getMotion();
$user->setMotion(new Vector3($motion->x, 0, $motion->z));
if($user !== null){
$height = $user->getFallDistance();

$user->fallDistance = 0;
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);

$motion = $user->getMotion();
$user->setMotion(new Vector3($motion->x, 0, $motion->z));

$user->fallDistance = 0;
}
}
}

Expand Down

0 comments on commit d6f6a62

Please sign in to comment.