use of org.terasology.engine.entitySystem.entity.EntityRef 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.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class ServerImpl method updateEntity.
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());
}
}
use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class AbstractClient method findNamesOfOtherPlayers.
/**
* Creates a {@code HashSet<String>} of all connected player names.
* @param entityManager
* @param player Client name to make sure it doesn't put its own name in the list.
* @return Returns all connected player names.
*/
private Set<String> findNamesOfOtherPlayers(EntityManager entityManager, EntityRef player) {
Set<String> otherNames = new HashSet<>();
for (EntityRef clientInfo : entityManager.getEntitiesWith(ClientInfoComponent.class)) {
if (!clientInfo.equals(player)) {
DisplayNameComponent displayInfo = clientInfo.getComponent(DisplayNameComponent.class);
String usedName = displayInfo.name;
otherNames.add(usedName);
}
}
return otherNames;
}
use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class LocalPlayerBlockSelectionByItemSystem method onPlaced.
@ReceiveEvent(components = OnItemActivateSelectionComponent.class)
public void onPlaced(ActivateEvent event, EntityRef itemEntity) {
if (event.getTargetLocation() == null) {
return;
}
EntityRef targetLocationEntity = event.getTarget();
this.blockSelectionComponentEntity = itemEntity;
BlockSelectionComponent blockSelectionComponent = itemEntity.getComponent(BlockSelectionComponent.class);
if (null == blockSelectionComponent.startPosition) {
// on the first item click, we start selecting blocks
targetLocationEntity.send(new SetBlockSelectionStartingPointEvent(itemEntity));
blockSelectionComponent.shouldRender = true;
} else {
// on the second item click, we will set the ending selection point and send an ApplyBlockSelectionEvent
targetLocationEntity.send(new SetBlockSelectionEndingPointEvent(itemEntity));
localPlayer.getCharacterEntity().send(new ApplyBlockSelectionEvent(itemEntity, blockSelectionComponent.currentSelection));
blockSelectionComponent.shouldRender = false;
blockSelectionComponent.currentSelection = null;
blockSelectionComponent.startPosition = null;
}
}
use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class CreateRemoteWorldEntity method step.
@Override
public boolean step() {
EntityRef worldEntity = entityManager.create();
worldEntity.addComponent(new WorldComponent());
chunkProvider.setWorldEntity(worldEntity);
return true;
}
Aggregations