From a45763328bdb6703304ac97dd5164665e5ab180e Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 28 Jul 2023 12:36:46 +0100 Subject: [PATCH] Added constants for default knockback force and vertical limit --- src/entity/Living.php | 13 ++++++++++++- src/event/entity/EntityDamageByEntityEvent.php | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/entity/Living.php b/src/entity/Living.php index d1fbf4b8e..1b5b582da 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -80,6 +80,17 @@ use const M_PI; abstract class Living extends Entity{ protected const DEFAULT_BREATH_TICKS = 300; + /** + * The default knockback multiplier when an entity is hit by another entity. + * Larger values knock the entity back with increased velocity. + */ + public const DEFAULT_KNOCKBACK_FORCE = 0.4; + /** + * Limit of an entity's vertical knockback velocity when hit by another entity. Without this limit, the entity + * may be knocked far up into the air with large knockback forces. + */ + public const DEFAULT_KNOCKBACK_VERTICAL_LIMIT = 0.4; + private const TAG_LEGACY_HEALTH = "HealF"; //TAG_Float private const TAG_HEALTH = "Health"; //TAG_Float private const TAG_BREATH_TICKS = "Air"; //TAG_Short @@ -567,7 +578,7 @@ abstract class Living extends Entity{ $this->broadcastAnimation(new HurtAnimation($this)); } - public function knockBack(float $x, float $z, float $force = 0.4, ?float $verticalLimit = 0.4) : void{ + public function knockBack(float $x, float $z, float $force = self::DEFAULT_KNOCKBACK_FORCE, ?float $verticalLimit = self::DEFAULT_KNOCKBACK_VERTICAL_LIMIT) : void{ $f = sqrt($x * $x + $z * $z); if($f <= 0){ return; diff --git a/src/event/entity/EntityDamageByEntityEvent.php b/src/event/entity/EntityDamageByEntityEvent.php index 6264375bb..11214a3e0 100644 --- a/src/event/entity/EntityDamageByEntityEvent.php +++ b/src/event/entity/EntityDamageByEntityEvent.php @@ -36,7 +36,7 @@ class EntityDamageByEntityEvent extends EntityDamageEvent{ /** * @param float[] $modifiers */ - public function __construct(Entity $damager, Entity $entity, int $cause, float $damage, array $modifiers = [], private float $knockBack = 0.4){ + public function __construct(Entity $damager, Entity $entity, int $cause, float $damage, array $modifiers = [], private float $knockBack = Living::DEFAULT_KNOCKBACK_FORCE){ $this->damagerEntityId = $damager->getId(); parent::__construct($entity, $cause, $damage, $modifiers); $this->addAttackerModifiers($damager);