I’ve already working on using Zay-ES for client/server.
Here how it’s done.
On client side :
[java]public class RemoteEntity
{
private EntityId id;
private List<EntityComponent> components;
public RemoteEntity()
{
}
public EntityId getId()
{
return id;
}
public List<EntityComponent> getComponents()
{
return components;
}
}[/java]
[java]public class RemoteEntityData extends DefaultEntityData
{
private static RemoteEntityData instance;
public RemoteEntityData()
{
super();
}
public static RemoteEntityData getInstance()
{
if(instance == null)
instance = new RemoteEntityData();
return instance;
}
public void loadRemoteEntity(RemoteEntity entity)
{
for(EntityComponent _c : entity.getComponents())
setComponent(entity.getId(), _c);
}
}
[/java]
And on server side :
[java]public class RemoteEntity
{
private EntityId id;
private List<EntityComponent> components = new ArrayList<EntityComponent>();
public RemoteEntity()
{
}
public RemoteEntity(EntityId id, EntityComponent... components)
{
this.id = id;
for(EntityComponent _c : components)
this.components.add(_c);
}
public RemoteEntity(EntityId id, Class... types)
{
this.id = id;
for(Class _class : types)
{
EntityComponent _c = MasterEntityData.getInstance().getComponent(id, _class);
if(_c == null)
{
LogHandler.getInstance().warning("Cannot get component type " + _class.getSimpleName());
continue;
}
components.add(_c);
}
}
public RemoteEntity(EntityId id, EntityComponent[] components, EntityComponent... toAdd)
{
this.id = id;
for(EntityComponent _c : components)
this.components.add(_c);
for(EntityComponent _cAdd : toAdd)
this.components.add(_cAdd);
}
public void setComponents(EntityComponent ... components)
{
for(EntityComponent _c : components)
this.components.add(_c);
}
public List<EntityComponent> getComponents()
{
return components;
}
}[/java]
[java]public class MasterEntityData extends DefaultEntityData
{
private static MasterEntityData instance;
public MasterEntityData()
{
this.setIdGenerator(DefaultIdGenerator.getInstance());
}
public static MasterEntityData getInstance()
{
if(instance == null)
instance = new MasterEntityData();
return instance;
}
public RemoteEntity getRemoteEntity(EntityId entityId, Class<? extends EntityComponent>... types)
{
EntityComponent[] values = new EntityComponent[types.length];
for( int i = 0; i < values.length; i++ )
values[i] = getComponent( entityId, types[i] );
return new RemoteEntity(entityId, values);
}
}[/java]
[java]public class DefaultIdGenerator implements EntityIdGenerator
{
private long nextId;
private static DefaultIdGenerator instance;
public DefaultIdGenerator()
{
}
public static DefaultIdGenerator getInstance()
{
if(instance == null)
instance = new DefaultIdGenerator();
return instance;
}
@Override
public long nextEntityId()
{
return nextId++;
}
}[/java]
How it’s working
 
To get entities from server to client, you need to create a new RemoteEntity object with for parameters, the EntityId of the entity you want to send and its components you want to send.
Example :
[java]RemoteEntity _entity = new RemoteEntity(_entitty.getId(), NameComponent.class, PositionComponent.class);[/java]
You send this object over the network to the client and handle it like that :
[java]RemoteEntityData.getInstance().loadRemoteEntity(_entity);[/java]
I don’t know if it’s clear but if you have some questions, ask me.
And I can’t tell if it’s the best way to do this.