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

Commit

Permalink
Don't attack entities that are closed. (Hacky solution Fixes #379 Fixes
Browse files Browse the repository at this point in the history
#376 Fixes #368 Fixes #321)
  • Loading branch information
95CivicSi committed May 3, 2020
1 parent 94debce commit 0b14a9e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function onUpdate(int $currentTick) : bool{
$this->entityBaseTick($tickDiff);

$target = $this->updateMove($tickDiff);
if($target instanceof Player){
if($target instanceof Player && !$target->isClosed()){
$this->attackEntity($target);
}elseif(
$target instanceof Vector3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ public function onUpdate(int $currentTick) : bool{
if($this->isFriendly()){
if(!($target instanceof Player)){
if($target instanceof Entity){
$this->attackEntity($target);
if(!$target->isClosed()){
$this->attackEntity($target);
}
}elseif(
$target instanceof Vector3
&& (($this->x - $target->x) ** 2 + ($this->z - $target->z) ** 2) <= 1
Expand All @@ -140,7 +142,9 @@ public function onUpdate(int $currentTick) : bool{
}
}else{
if($target instanceof Entity){
$this->attackEntity($target);
if(!$target->isClosed()){
$this->attackEntity($target);
}
}elseif(
$target instanceof Vector3
&& (($this->x - $target->x) ** 2 + ($this->z - $target->z) ** 2) <= 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ public function onUpdate(int $currentTick) : bool{
if($this->isFriendly()){
if(!($target instanceof Player)){
if($target instanceof Entity){
$this->attackEntity($target);
if(!$target->isClosed()){
$this->attackEntity($target);
}
}elseif(
$target instanceof Vector3
&& (($this->x - $target->x) ** 2 + ($this->z - $target->z) ** 2) <= 1
Expand All @@ -140,7 +142,9 @@ public function onUpdate(int $currentTick) : bool{
}
}else{
if($target instanceof Entity){
$this->attackEntity($target);
if(!$target->isClosed()){
$this->attackEntity($target);
}
}elseif(
$target instanceof Vector3
&& (($this->x - $target->x) ** 2 + ($this->z - $target->z) ** 2) <= 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public abstract function attackEntity(Entity $player);
* @param Entity $player
*/
public function checkAndAttackEntity(Entity $player){
if($player->isClosed()){
return;
}
if($this instanceof IntfTameable and $this->isTamed()){
if($player instanceof Player and strcasecmp($player->getName(), $this->getOwner()->getName()) === 0){
// a tamed entity doesn't attack it's owner!
Expand Down
2 changes: 1 addition & 1 deletion src/revivalpmmp/pureentities/utils/MobDamageCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class MobDamageCalculator{
* @return float the final damage calculated with respect to armor etc. pp worn by player
*/
public static function calculateFinalDamage(Entity $player, float $damageFromEntity) : float{
if($player instanceof Player and $player->getArmorInventory() !== null){
if($player instanceof Player and !$player->isClosed()){
$playerArmor = $player->getArmorInventory();
$armorItems = [$playerArmor->getHelmet(), $playerArmor->getChestplate(), $playerArmor->getLeggings(), $playerArmor->getBoots()];

Expand Down

0 comments on commit 0b14a9e

Please sign in to comment.