mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 07:54:19 +00:00
Improved entity attack push
This commit is contained in:
parent
e6c510e7fd
commit
99c5ad789b
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user