Пример #1
0
 private void updateEntity(NetData.UpdateEntityMessage updateEntity) {
   EntityRef currentEntity = networkSystem.getEntity(updateEntity.getNetId());
   if (currentEntity.exists()) {
     NetworkComponent netComp = currentEntity.getComponent(NetworkComponent.class);
     if (netComp == null) {
       logger.error(
           "Updating entity with no network component: {}, expected netId {}",
           currentEntity,
           updateEntity.getNetId());
       return;
     }
     if (netComp.getNetworkId() != updateEntity.getNetId()) {
       logger.error("Network ID wrong before update");
     }
     boolean blockEntityBefore = currentEntity.hasComponent(BlockComponent.class);
     entitySerializer.deserializeOnto(currentEntity, updateEntity.getEntity());
     BlockComponent blockComponent = currentEntity.getComponent(BlockComponent.class);
     if (blockComponent != null && !blockEntityBefore) {
       if (!blockEntityRegistry
           .getExistingBlockEntityAt(blockComponent.getPosition())
           .equals(currentEntity)) {
         logger.error("Failed to associated new block entity");
       }
     }
     if (netComp.getNetworkId() != updateEntity.getNetId()) {
       logger.error(
           "Network ID lost in update: {}, {} -> {}",
           currentEntity,
           updateEntity.getNetId(),
           netComp.getNetworkId());
     }
   } else {
     logger.warn("Received update for non-existent entity {}", updateEntity.getNetId());
   }
 }
Пример #2
0
 private void sendEntities(NetData.NetMessage.Builder message) {
   TIntIterator dirtyIterator = netDirty.iterator();
   while (dirtyIterator.hasNext()) {
     int netId = dirtyIterator.next();
     EntityRef entity = networkSystem.getEntity(netId);
     if (isOwned(entity)) {
       Set<Class<? extends Component>> emptyComponentClassSet = Collections.emptySet();
       EntityData.PackedEntity entityData =
           entitySerializer.serialize(
               entity,
               emptyComponentClassSet,
               changedComponents.get(netId),
               emptyComponentClassSet,
               new ClientComponentFieldCheck());
       if (entityData != null) {
         message.addUpdateEntity(
             NetData.UpdateEntityMessage.newBuilder().setEntity(entityData).setNetId(netId));
       }
     }
   }
   netDirty.clear();
 }
Пример #3
0
 private void createEntityMessage(NetData.CreateEntityMessage message) {
   entitySerializer.deserialize(message.getEntity());
 }