mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
EntityDamageByEntityEvent: added APIs to get and set vertical knockback limits
this was requested and PR'd as far back as 2020 (see #3782). Since no issue was filed about this, it became forgotten until #5946. However, #5946 overcomplicates the solution to the problem, and breaks BC without an obvious reason.
This commit is contained in:
@ -36,7 +36,15 @@ class EntityDamageByEntityEvent extends EntityDamageEvent{
|
||||
/**
|
||||
* @param float[] $modifiers
|
||||
*/
|
||||
public function __construct(Entity $damager, Entity $entity, int $cause, float $damage, array $modifiers = [], private float $knockBack = Living::DEFAULT_KNOCKBACK_FORCE){
|
||||
public function __construct(
|
||||
Entity $damager,
|
||||
Entity $entity,
|
||||
int $cause,
|
||||
float $damage,
|
||||
array $modifiers = [],
|
||||
private float $knockBack = Living::DEFAULT_KNOCKBACK_FORCE,
|
||||
private float $verticalKnockBackLimit = Living::DEFAULT_KNOCKBACK_VERTICAL_LIMIT
|
||||
){
|
||||
$this->damagerEntityId = $damager->getId();
|
||||
parent::__construct($entity, $cause, $damage, $modifiers);
|
||||
$this->addAttackerModifiers($damager);
|
||||
@ -79,4 +87,22 @@ class EntityDamageByEntityEvent extends EntityDamageEvent{
|
||||
public function setKnockBack(float $knockBack) : void{
|
||||
$this->knockBack = $knockBack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum upwards velocity the victim may have after being knocked back.
|
||||
* This ensures that the victim doesn't fly up into the sky when high levels of knockback are applied.
|
||||
*
|
||||
* @see Living::DEFAULT_KNOCKBACK_VERTICAL_LIMIT
|
||||
*/
|
||||
public function getVerticalKnockBackLimit() : float{
|
||||
return $this->verticalKnockBackLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum upwards velocity the victim may have after being knocked back.
|
||||
* Larger values will allow the victim to fly higher if the knockback force is also large.
|
||||
*/
|
||||
public function setVerticalKnockBackLimit(float $verticalKnockBackLimit) : void{
|
||||
$this->verticalKnockBackLimit = $verticalKnockBackLimit;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user