use of org.terasology.network.serialization.ServerComponentFieldCheck in project Terasology by MovingBlocks.
the class NetClient method sendDirtyEntities.
private void sendDirtyEntities(NetData.NetMessage.Builder message) {
TIntIterator dirtyIterator = netDirty.iterator();
while (dirtyIterator.hasNext()) {
int netId = dirtyIterator.next();
EntityRef entity = networkSystem.getEntity(netId);
if (!entity.exists()) {
logger.error("Sending non-existent entity update for netId {}", netId);
}
boolean isOwner = networkSystem.getOwner(entity) == this;
EntityData.PackedEntity entityData = entitySerializer.serialize(entity, addedComponents.get(netId), dirtyComponents.get(netId), removedComponents.get(netId), new ServerComponentFieldCheck(isOwner, false));
if (entityData != null) {
message.addUpdateEntity(NetData.UpdateEntityMessage.newBuilder().setEntity(entityData).setNetId(netId));
}
}
netDirty.clear();
addedComponents.clear();
removedComponents.clear();
dirtyComponents.clear();
}
use of org.terasology.network.serialization.ServerComponentFieldCheck in project Terasology by MovingBlocks.
the class NetClient method sendInitialEntities.
private void sendInitialEntities(NetData.NetMessage.Builder message) {
int[] initial = netInitial.toArray();
netInitial.clear();
Arrays.sort(initial);
for (int netId : initial) {
netRelevant.add(netId);
EntityRef entity = networkSystem.getEntity(netId);
if (!entity.hasComponent(NetworkComponent.class)) {
logger.error("Sending net entity with no network component: {} - {}", netId, entity);
continue;
}
// Note: Send owner->server fields on initial create
Client owner = networkSystem.getOwner(entity);
EntityData.PackedEntity entityData = entitySerializer.serialize(entity, true, new ServerComponentFieldCheck(owner == this, true)).build();
NetData.CreateEntityMessage.Builder createMessage = NetData.CreateEntityMessage.newBuilder().setEntity(entityData);
BlockComponent blockComponent = entity.getComponent(BlockComponent.class);
if (blockComponent != null) {
createMessage.setBlockPos(NetMessageUtil.convert(blockComponent.getPosition()));
}
message.addCreateEntity(createMessage);
}
}
Aggregations