Search in sources :

Example 6 with EntityMetadataMessage

use of net.glowstone.net.message.play.entity.EntityMetadataMessage in project Glowstone by GlowstoneMC.

the class GlowEntity method createUpdateMessage.

/**
 * Creates a {@link Message} which can be sent to a client to update this entity.
 *
 * @param session Session to update this entity for
 * @return A message which can update this entity.
 */
public List<Message> createUpdateMessage(GlowSession session) {
    double x = location.getX();
    double y = location.getY();
    double z = location.getZ();
    double dx = x * 32 - previousLocation.getX() * 32;
    double dy = y * 32 - previousLocation.getY() * 32;
    double dz = z * 32 - previousLocation.getZ() * 32;
    dx *= 128;
    dy *= 128;
    dz *= 128;
    boolean teleport = dx > Short.MAX_VALUE || dy > Short.MAX_VALUE || dz > Short.MAX_VALUE || dx < Short.MIN_VALUE || dy < Short.MIN_VALUE || dz < Short.MIN_VALUE;
    List<Message> result = new LinkedList<>();
    boolean moved = hasMoved();
    boolean rotated = hasRotated();
    if (teleported || moved && teleport) {
        result.add(new EntityTeleportMessage(entityId, location));
    } else if (rotated) {
        int yaw = Position.getIntYaw(location);
        int pitch = Position.getIntPitch(location);
        if (moved) {
            result.add(new RelativeEntityPositionRotationMessage(entityId, (short) dx, (short) dy, (short) dz, yaw, pitch));
        } else {
            result.add(new EntityRotationMessage(entityId, yaw, pitch));
        }
    } else if (moved) {
        result.add(new RelativeEntityPositionMessage(entityId, (short) dx, (short) dy, (short) dz));
    }
    // send changed metadata
    List<Entry> changes = metadata.getChanges();
    if (!changes.isEmpty()) {
        result.add(new EntityMetadataMessage(entityId, changes));
    }
    // send velocity if needed
    if (velocityChanged) {
        result.add(new EntityVelocityMessage(entityId, velocity));
    }
    if (passengerChanged) {
        // A player can be a passenger of any arbitrary entity, e.g. a boat
        // In case the current session belongs to this player passenger
        // We need to send the self_id
        List<Integer> passengerIds = new ArrayList<>();
        getPassengers().forEach(e -> passengerIds.add(e.getEntityId()));
        result.add(new SetPassengerMessage(getEntityId(), passengerIds.stream().mapToInt(Integer::intValue).toArray()));
        passengerChanged = false;
    }
    if (leashHolderChanged) {
        int attached = isLeashed() && session.getPlayer().getEntityId() == leashHolder.getEntityId() ? 0 : this.getEntityId();
        int holder = !isLeashed() ? -1 : leashHolder.getEntityId();
        // createAfterSpawnMessage()
        if (!isLeashed() || session.getPlayer().canSeeEntity(leashHolder)) {
            result.add(new AttachEntityMessage(attached, holder));
        }
    }
    return result;
}
Also used : EntityRotationMessage(net.glowstone.net.message.play.entity.EntityRotationMessage) EntityStatusMessage(net.glowstone.net.message.play.entity.EntityStatusMessage) InteractEntityMessage(net.glowstone.net.message.play.player.InteractEntityMessage) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage) EntityTeleportMessage(net.glowstone.net.message.play.entity.EntityTeleportMessage) SetPassengerMessage(net.glowstone.net.message.play.entity.SetPassengerMessage) Message(com.flowpowered.network.Message) TextMessage(net.glowstone.util.TextMessage) RelativeEntityPositionMessage(net.glowstone.net.message.play.entity.RelativeEntityPositionMessage) EntityVelocityMessage(net.glowstone.net.message.play.entity.EntityVelocityMessage) AttachEntityMessage(net.glowstone.net.message.play.entity.AttachEntityMessage) RelativeEntityPositionRotationMessage(net.glowstone.net.message.play.entity.RelativeEntityPositionRotationMessage) SetPassengerMessage(net.glowstone.net.message.play.entity.SetPassengerMessage) EntityVelocityMessage(net.glowstone.net.message.play.entity.EntityVelocityMessage) ArrayList(java.util.ArrayList) EntityRotationMessage(net.glowstone.net.message.play.entity.EntityRotationMessage) LinkedList(java.util.LinkedList) RelativeEntityPositionRotationMessage(net.glowstone.net.message.play.entity.RelativeEntityPositionRotationMessage) RelativeEntityPositionMessage(net.glowstone.net.message.play.entity.RelativeEntityPositionMessage) Entry(net.glowstone.entity.meta.MetadataMap.Entry) AttachEntityMessage(net.glowstone.net.message.play.entity.AttachEntityMessage) EntityTeleportMessage(net.glowstone.net.message.play.entity.EntityTeleportMessage) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage)

Example 7 with EntityMetadataMessage

use of net.glowstone.net.message.play.entity.EntityMetadataMessage in project Glowstone by GlowstoneMC.

the class GlowArmorStand method createSpawnMessage.

@Override
public List<Message> createSpawnMessage() {
    double x = location.getX();
    double y = location.getY();
    double z = location.getZ();
    int yaw = Position.getIntYaw(location);
    int pitch = Position.getIntPitch(location);
    return Arrays.asList(// TODO: once UUID is documented, actually use the appropriate ID here
    new SpawnObjectMessage(id, UUID.randomUUID(), 78, x, y, z, pitch, yaw), new EntityMetadataMessage(id, metadata.getEntryList()), new EntityEquipmentMessage(id, EntityEquipmentMessage.HELD_ITEM, getItemInHand()), new EntityEquipmentMessage(id, EntityEquipmentMessage.BOOTS_SLOT, getBoots()), new EntityEquipmentMessage(id, EntityEquipmentMessage.LEGGINGS_SLOT, getLeggings()), new EntityEquipmentMessage(id, EntityEquipmentMessage.CHESTPLATE_SLOT, getChestplate()), new EntityEquipmentMessage(id, EntityEquipmentMessage.HELMET_SLOT, getHelmet()));
}
Also used : SpawnObjectMessage(net.glowstone.net.message.play.entity.SpawnObjectMessage) EntityEquipmentMessage(net.glowstone.net.message.play.entity.EntityEquipmentMessage) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage)

Example 8 with EntityMetadataMessage

use of net.glowstone.net.message.play.entity.EntityMetadataMessage in project Glowstone by GlowstoneMC.

the class GlowAgeable method createSpawnMessage.

@Override
public List<Message> createSpawnMessage() {
    List<Message> messages = super.createSpawnMessage();
    MetadataMap map = new MetadataMap(GlowAgeable.class);
    map.set(MetadataIndex.AGE_ISBABY, !isAdult());
    messages.add(new EntityMetadataMessage(entityId, map.getEntryList()));
    return messages;
}
Also used : MetadataMap(net.glowstone.entity.meta.MetadataMap) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage) Message(com.flowpowered.network.Message) InteractEntityMessage(net.glowstone.net.message.play.player.InteractEntityMessage) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage)

Example 9 with EntityMetadataMessage

use of net.glowstone.net.message.play.entity.EntityMetadataMessage in project Glowstone by GlowstoneMC.

the class GlowLeashHitch method createSpawnMessage.

@Override
public List<Message> createSpawnMessage() {
    int x = location.getBlockX();
    int y = location.getBlockY();
    int z = location.getBlockZ();
    return Lists.newArrayList(new SpawnObjectMessage(entityId, getUniqueId(), EntityNetworkUtil.getObjectId(EntityType.LEASH_HITCH), x, y, z, 0, 0), new EntityMetadataMessage(entityId, metadata.getEntryList()));
}
Also used : SpawnObjectMessage(net.glowstone.net.message.play.entity.SpawnObjectMessage) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage)

Example 10 with EntityMetadataMessage

use of net.glowstone.net.message.play.entity.EntityMetadataMessage in project Glowstone by GlowstoneMC.

the class GlowAreaEffectCloud method createSpawnMessage.

@Override
public List<Message> createSpawnMessage() {
    MetadataMap metadataMap = new MetadataMap(GlowAreaEffectCloud.class);
    metadataMap.set(MetadataIndex.AREAEFFECTCLOUD_COLOR, color);
    metadataMap.set(MetadataIndex.AREAEFFECTCLOUD_RADIUS, radius);
    if (particle != null) {
        metadataMap.set(MetadataIndex.AREAEFFECTCLOUD_PARTICLE, new ParticleBuilder(particle));
    }
    return Arrays.asList(new SpawnObjectMessage(entityId, getUniqueId(), NETWORK_TYPE_ID, location), new EntityMetadataMessage(entityId, metadataMap.getEntryList()));
}
Also used : MetadataMap(net.glowstone.entity.meta.MetadataMap) SpawnObjectMessage(net.glowstone.net.message.play.entity.SpawnObjectMessage) ParticleBuilder(com.destroystokyo.paper.ParticleBuilder) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage)

Aggregations

EntityMetadataMessage (net.glowstone.net.message.play.entity.EntityMetadataMessage)10 Message (com.flowpowered.network.Message)5 MetadataMap (net.glowstone.entity.meta.MetadataMap)5 SpawnObjectMessage (net.glowstone.net.message.play.entity.SpawnObjectMessage)5 EntityVelocityMessage (net.glowstone.net.message.play.entity.EntityVelocityMessage)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 SetPassengerMessage (net.glowstone.net.message.play.entity.SetPassengerMessage)2 TextMessage (net.glowstone.util.TextMessage)2 ClientOption (com.destroystokyo.paper.ClientOption)1 MaterialTags (com.destroystokyo.paper.MaterialTags)1 ParticleBuilder (com.destroystokyo.paper.ParticleBuilder)1 Title (com.destroystokyo.paper.Title)1 PlayerProfile (com.destroystokyo.paper.profile.PlayerProfile)1 Preconditions (com.google.common.base.Preconditions)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableList (com.google.common.collect.ImmutableList)1 ByteBuf (io.netty.buffer.ByteBuf)1 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1