mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-19 23:44:17 +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:
parent
c972e65741
commit
5ec3f4655f
@ -557,14 +557,14 @@ abstract class Living extends Entity{
|
||||
$e = $source->getChild();
|
||||
if($e !== null){
|
||||
$motion = $e->getMotion();
|
||||
$this->knockBack($motion->x, $motion->z, $source->getKnockBack());
|
||||
$this->knockBack($motion->x, $motion->z, $source->getKnockBack(), $source->getVerticalKnockBackLimit());
|
||||
}
|
||||
}elseif($source instanceof EntityDamageByEntityEvent){
|
||||
$e = $source->getDamager();
|
||||
if($e !== null){
|
||||
$deltaX = $this->location->x - $e->location->x;
|
||||
$deltaZ = $this->location->z - $e->location->z;
|
||||
$this->knockBack($deltaX, $deltaZ, $source->getKnockBack());
|
||||
$this->knockBack($deltaX, $deltaZ, $source->getKnockBack(), $source->getVerticalKnockBackLimit());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user