From 99c5ad789ba485e87f8849209bf0ef1d46b832f2 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 10 Jul 2014 13:29:29 +0200 Subject: [PATCH] Improved entity attack push --- src/pocketmine/Player.php | 23 +++++++++++++++++++++++ src/pocketmine/entity/Entity.php | 24 +++--------------------- src/pocketmine/entity/Living.php | 7 +++++-- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 5aeca85e2..58d73217e 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2182,6 +2182,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){ + if($this->dead === true){ + return; + } $pk = new EntityEventPacket(); $pk->eid = 0; $pk->event = 2; @@ -2189,6 +2192,26 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ parent::attack($damage, $source); } + public function teleport(Vector3 $pos, $yaw = null, $pitch = null){ + if(parent::teleport($pos, $yaw, $pitch)){ + $this->airTicks = 300; + $this->fallDistance = 0; + $this->orderChunks(); + $this->chunkLoadTask->setNextRun(0); + $this->forceMovement = $pos; + + $pk = new MovePlayerPacket; + $pk->eid = 0; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->bodyYaw = $this->yaw; + $pk->pitch = $this->pitch; + $pk->yaw = $this->yaw; + $this->dataPacket($pk); + } + } + /** * @param Inventory $inventory diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 5fdb4e729..1da4d5e62 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -424,7 +424,7 @@ abstract class Entity extends Position implements Metadatable{ $this->inWater = false; } - if($this->y < -64){ + if($this->y < 0 and $this->dead !== true){ $this->server->getPluginManager()->callEvent($ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_VOID, 10)); if(!$ev->isCancelled()){ $this->attack($ev->getFinalDamage(), $ev); @@ -968,7 +968,7 @@ abstract class Entity extends Position implements Metadatable{ $this->scheduleUpdate(); } - public function teleport(Vector3 $pos, $yaw = false, $pitch = false){ + public function teleport(Vector3 $pos, $yaw = null, $pitch = null){ $from = Position::fromObject($this, $this->getLevel()); $to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->getLevel()); $this->server->getPluginManager()->callEvent($ev = new EntityTeleportEvent($this, $from, $to)); @@ -978,25 +978,7 @@ abstract class Entity extends Position implements Metadatable{ $pos = $ev->getTo(); $this->setMotion(new Vector3(0, 0, 0)); - if($this->setPositionAndRotation($pos, $yaw === false ? $this->yaw : $yaw, $pitch === false ? $this->pitch : $pitch, true) !== false){ - if($this instanceof Player){ - $this->airTicks = 300; - $this->fallDistance = 0; - $this->orderChunks(); - $this->chunkLoadTask->setNextRun(0); - $this->forceMovement = $pos; - - $pk = new MovePlayerPacket; - $pk->eid = 0; - $pk->x = $this->x; - $pk->y = $this->y; - $pk->z = $this->z; - $pk->bodyYaw = $this->yaw; - $pk->pitch = $this->pitch; - $pk->yaw = $this->yaw; - $this->dataPacket($pk); - } - + if($this->setPositionAndRotation($pos, $yaw === null ? $this->yaw : $yaw, $pitch === null ? $this->pitch : $pitch, true) !== false){ return true; } diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index 8d3e25ec8..d62504ef1 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -67,8 +67,11 @@ abstract class Living extends Entity implements Damageable{ $motion = new Vector3(0, 0.25, 0); if($source instanceof EntityDamageByEntityEvent){ $e = $source->getDamager(); - $motion->x = -cos(deg2rad($e->pitch)) * sin(deg2rad($e->yaw)) * 0.5; - $motion->z = cos(deg2rad($e->pitch)) * sin(deg2rad($e->yaw)) * 0.5; + $deltaX = $this->x - $e->x; + $deltaZ = $this->z - $e->z; + $yaw = atan2($deltaX, $deltaZ); + $motion->x = sin($yaw) * 0.5; + $motion->z = cos($yaw) * 0.5; } $this->setMotion($motion); $this->setHealth($this->getHealth() - $damage);