Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2395 from PEMapModder/patch-6
Browse files Browse the repository at this point in the history
Allow $base in knockback() to be dynamic and getters/setters in EntityDa...
  • Loading branch information
msjyoo committed Dec 18, 2014
2 parents db2dfc4 + 96122d3 commit 9fc2509
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/pocketmine/entity/Living.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){
$deltaX = $this->x - $e->x;
$deltaZ = $this->z - $e->z;
$yaw = atan2($deltaX, $deltaZ);
$this->knockBack($e, $damage, sin($yaw), cos($yaw));
$this->knockBack($e, $damage, sin($yaw), cos($yaw), $source->getKnockBack());
}

$this->setHealth($this->getHealth() - $damage);
Expand All @@ -114,9 +114,8 @@ public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){
$this->attackTime = 10; //0.5 seconds cooldown
}

public function knockBack(Entity $attacker, $damage, $x, $z){
public function knockBack(Entity $attacker, $damage, $x, $z, $base = 0.4){
$f = sqrt($x ** 2 + $z ** 2);
$base = 0.4;

$motion = new Vector3($this->motionX, $this->motionY, $this->motionZ);

Expand Down
23 changes: 18 additions & 5 deletions src/pocketmine/event/entity/EntityDamageByEntityEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ class EntityDamageByEntityEvent extends EntityDamageEvent{

/** @var Entity */
private $damager;

/** @var float */
private $knockBack;

/**
* @param Entity $damager
* @param Entity $entity
* @param int $cause
* @param int|int[] $damage
* @param float $knockBack
*/
public function __construct(Entity $damager, Entity $entity, $cause, $damage){
public function __construct(Entity $damager, Entity $entity, $cause, $damage, $knockBack = 0.4){
$this->damager = $damager;
$this->knockBack = $knockBack;
parent::__construct($entity, $cause, $damage);
}

Expand All @@ -48,6 +51,16 @@ public function __construct(Entity $damager, Entity $entity, $cause, $damage){
public function getDamager(){
return $this->damager;
}


}
/**
* @return float
*/
public function getKnockBack(){
return $this->knockBack;
}
/**
* @param float $knockBack
*/
public function setKnockBack($knockBack){
$this->knockBack = $knockBack;
}
}

0 comments on commit 9fc2509

Please sign in to comment.