Search in sources :

Example 1 with LanternLiving

use of org.lanternpowered.server.entity.LanternLiving in project LanternServer by LanternPowered.

the class CreatureEntityProtocol method spawn.

@Override
protected void spawn(EntityProtocolUpdateContext context) {
    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();
    final double headYaw = headRot != null ? headRot.getY() : 0;
    context.sendToAllExceptSelf(() -> new MessagePlayOutSpawnMob(getRootEntityId(), this.entity.getUniqueId(), getMobType(), pos, wrapAngle(yaw), wrapAngle(pitch), wrapAngle(headYaw), vel, fillParameters(true)));
    spawnWithEquipment(context);
}
Also used : Vector3d(com.flowpowered.math.vector.Vector3d) MessagePlayOutSpawnMob(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSpawnMob) LanternLiving(org.lanternpowered.server.entity.LanternLiving)

Example 2 with LanternLiving

use of org.lanternpowered.server.entity.LanternLiving 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)

Example 3 with LanternLiving

use of org.lanternpowered.server.entity.LanternLiving in project LanternServer by LanternPowered.

the class EntityProtocol method handleEvent.

@Override
protected void handleEvent(EntityProtocolUpdateContext context, EntityEvent event) {
    if (event instanceof CollectEntityEvent) {
        final LanternLiving collector = (LanternLiving) ((CollectEntityEvent) event).getCollector();
        context.getId(collector).ifPresent(id -> {
            final int count = ((CollectEntityEvent) event).getCollectedItemsCount();
            context.sendToAll(() -> new MessagePlayOutEntityCollectItem(id, getRootEntityId(), count));
        });
    } else {
        super.handleEvent(context, event);
    }
}
Also used : CollectEntityEvent(org.lanternpowered.server.entity.event.CollectEntityEvent) LanternLiving(org.lanternpowered.server.entity.LanternLiving) MessagePlayOutEntityCollectItem(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityCollectItem)

Aggregations

LanternLiving (org.lanternpowered.server.entity.LanternLiving)3 Vector3d (com.flowpowered.math.vector.Vector3d)2 CollectEntityEvent (org.lanternpowered.server.entity.event.CollectEntityEvent)1 MessagePlayOutEntityCollectItem (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityCollectItem)1 MessagePlayOutEntityHeadLook (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityHeadLook)1 MessagePlayOutEntityVelocity (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityVelocity)1 MessagePlayOutSpawnMob (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSpawnMob)1 MessagePlayOutSpawnPlayer (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSpawnPlayer)1