Added constants for default knockback force and vertical limit

This commit is contained in:
Dylan K. Taylor
2023-07-28 12:36:46 +01:00
parent 82a5ea9ed3
commit a45763328b
2 changed files with 13 additions and 2 deletions

View File

@ -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;