Search in sources :

Example 1 with MessagePlayOutSpawnPlayer

use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSpawnPlayer in project LanternServer by LanternPowered.

the class HumanoidEntityProtocol method spawn.

@Override
protected void spawn(EntityProtocolUpdateContext context) {
    final int entityId = getRootEntityId();
    final Vector3d rot = this.entity.getRotation();
    final Vector3d headRot = this.entity instanceof LanternLiving ? ((LanternLiving) this.entity).getHeadRotation() : null;
    final Vector3d pos = this.entity.getPosition();
    final Vector3d vel = this.entity.getVelocity();
    final double yaw = rot.getY();
    final double pitch = headRot != null ? headRot.getX() : rot.getX();
    context.sendToAllExceptSelf(() -> new MessagePlayOutSpawnPlayer(entityId, this.entity.getUniqueId(), pos, wrapAngle(yaw), wrapAngle(pitch), fillParameters(true)));
    if (headRot != null) {
        context.sendToAllExceptSelf(() -> new MessagePlayOutEntityHeadLook(entityId, wrapAngle(headRot.getY())));
    }
    if (!vel.equals(Vector3d.ZERO)) {
        context.sendToAllExceptSelf(() -> new MessagePlayOutEntityVelocity(entityId, vel.getX(), vel.getY(), vel.getZ()));
    }
    spawnWithEquipment(context);
}
Also used : MessagePlayOutSpawnPlayer(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSpawnPlayer) Vector3d(com.flowpowered.math.vector.Vector3d) MessagePlayOutEntityVelocity(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityVelocity) LanternLiving(org.lanternpowered.server.entity.LanternLiving) MessagePlayOutEntityHeadLook(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityHeadLook)

Aggregations

Vector3d (com.flowpowered.math.vector.Vector3d)1 LanternLiving (org.lanternpowered.server.entity.LanternLiving)1 MessagePlayOutEntityHeadLook (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityHeadLook)1 MessagePlayOutEntityVelocity (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityVelocity)1 MessagePlayOutSpawnPlayer (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSpawnPlayer)1