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;
}
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()));
}
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;
}
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()));
}
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()));
}
Aggregations