mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-14 17:59:41 +00:00
Clean up some AnimatePacket boilerplate code
This commit is contained in:
parent
d81388f62c
commit
5df56a1bac
@ -1190,10 +1190,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
|
|
||||||
$this->level->setSleepTicks(0);
|
$this->level->setSleepTicks(0);
|
||||||
|
|
||||||
$pk = new AnimatePacket();
|
$this->broadcastAnimation([$this], AnimatePacket::ACTION_STOP_SLEEP);
|
||||||
$pk->entityRuntimeId = $this->id;
|
|
||||||
$pk->action = AnimatePacket::ACTION_STOP_SLEEP;
|
|
||||||
$this->sendDataPacket($pk);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2349,13 +2346,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($ev->getModifier(EntityDamageEvent::MODIFIER_CRITICAL) > 0){
|
if($ev->getModifier(EntityDamageEvent::MODIFIER_CRITICAL) > 0){
|
||||||
$pk = new AnimatePacket();
|
$entity->broadcastAnimation(null, AnimatePacket::ACTION_CRITICAL_HIT);
|
||||||
$pk->action = AnimatePacket::ACTION_CRITICAL_HIT;
|
|
||||||
$pk->entityRuntimeId = $entity->getId();
|
|
||||||
$this->server->broadcastPacket($entity->getViewers(), $pk);
|
|
||||||
if($entity instanceof Player){
|
|
||||||
$entity->sendDataPacket($pk);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($meleeEnchantments as $enchantment){
|
foreach($meleeEnchantments as $enchantment){
|
||||||
@ -2416,11 +2407,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$pk = new AnimatePacket();
|
$this->broadcastAnimation($this->getViewers(), $ev->getAnimationType());
|
||||||
$pk->entityRuntimeId = $this->getId();
|
|
||||||
$pk->action = $ev->getAnimationType();
|
|
||||||
$this->server->broadcastPacket($this->getViewers(), $pk);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3088,6 +3075,14 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
parent::broadcastEntityEvent($eventId, $eventData, $players);
|
parent::broadcastEntityEvent($eventId, $eventData, $players);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function broadcastAnimation(?array $players, int $animationId) : void{
|
||||||
|
if($this->spawned and $players === null){
|
||||||
|
$players = $this->getViewers();
|
||||||
|
$players[] = $this;
|
||||||
|
}
|
||||||
|
parent::broadcastAnimation($players, $animationId);
|
||||||
|
}
|
||||||
|
|
||||||
public function getOffsetPosition(Vector3 $vector3) : Vector3{
|
public function getOffsetPosition(Vector3 $vector3) : Vector3{
|
||||||
$result = parent::getOffsetPosition($vector3);
|
$result = parent::getOffsetPosition($vector3);
|
||||||
$result->y += 0.001; //Hack for MCPE falling underground for no good reason (TODO: find out why it's doing this)
|
$result->y += 0.001; //Hack for MCPE falling underground for no good reason (TODO: find out why it's doing this)
|
||||||
|
@ -63,6 +63,7 @@ use pocketmine\nbt\tag\FloatTag;
|
|||||||
use pocketmine\nbt\tag\ListTag;
|
use pocketmine\nbt\tag\ListTag;
|
||||||
use pocketmine\nbt\tag\StringTag;
|
use pocketmine\nbt\tag\StringTag;
|
||||||
use pocketmine\network\mcpe\protocol\AddEntityPacket;
|
use pocketmine\network\mcpe\protocol\AddEntityPacket;
|
||||||
|
use pocketmine\network\mcpe\protocol\AnimatePacket;
|
||||||
use pocketmine\network\mcpe\protocol\EntityEventPacket;
|
use pocketmine\network\mcpe\protocol\EntityEventPacket;
|
||||||
use pocketmine\network\mcpe\protocol\MoveEntityAbsolutePacket;
|
use pocketmine\network\mcpe\protocol\MoveEntityAbsolutePacket;
|
||||||
use pocketmine\network\mcpe\protocol\RemoveEntityPacket;
|
use pocketmine\network\mcpe\protocol\RemoveEntityPacket;
|
||||||
@ -2118,6 +2119,13 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
$this->server->broadcastPacket($players ?? $this->getViewers(), $pk);
|
$this->server->broadcastPacket($players ?? $this->getViewers(), $pk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function broadcastAnimation(?array $players, int $animationId) : void{
|
||||||
|
$pk = new AnimatePacket();
|
||||||
|
$pk->entityRuntimeId = $this->id;
|
||||||
|
$pk->action = $animationId;
|
||||||
|
$this->server->broadcastPacket($players ?? $this->getViewers(), $pk);
|
||||||
|
}
|
||||||
|
|
||||||
public function __destruct(){
|
public function __destruct(){
|
||||||
$this->close();
|
$this->close();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user