use of org.terasology.engine.network.NetworkComponent in project Terasology by MovingBlocks.
the class NetworkSystemImpl method onEntityComponentRemoved.
@Override
public void onEntityComponentRemoved(EntityRef entity, Class<? extends Component> component) {
ComponentMetadata<? extends Component> metadata = componentLibrary.getMetadata(component);
NetworkComponent netComp = entity.getComponent(NetworkComponent.class);
if (netComp != null && netComp.getNetworkId() != NULL_NET_ID) {
if (mode.isServer()) {
if (metadata.isReplicated()) {
for (NetClient client : netClientList) {
logger.debug("Component {} removed from {}", component, entity);
client.setComponentRemoved(netComp.getNetworkId(), component);
}
}
}
}
if (mode.isAuthority() && metadata.isReferenceOwner()) {
ownershipHelper.listOwnedEntities(entity.getComponent(component)).forEach(EntityRef::destroy);
}
}
use of org.terasology.engine.network.NetworkComponent in project Terasology by MovingBlocks.
the class CreateWorldEntity method createWorldPoolsAndEntity.
private EntityRef createWorldPoolsAndEntity() {
entityManager.createWorldPools(gameManifest);
EntityRef worldEntity = entityManager.create();
worldEntity.addComponent(new WorldComponent());
NetworkComponent networkComponent = new NetworkComponent();
networkComponent.replicateMode = NetworkComponent.ReplicateMode.ALWAYS;
worldEntity.addComponent(networkComponent);
return worldEntity;
}
use of org.terasology.engine.network.NetworkComponent 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.network.NetworkComponent in project Terasology by MovingBlocks.
the class BlockTypeEntityGenerator method generateBlockTypeEntity.
private void generateBlockTypeEntity(Block block) {
EntityBuilder builder = entityManager.newBuilder(blockTypePrefab);
builder.getComponent(BlockTypeComponent.class).block = block;
// TODO: Copy across settings as necessary
Optional<Prefab> prefab = block.getPrefab();
if (prefab.isPresent()) {
for (Component comp : prefab.get().iterateComponents()) {
if (!(comp instanceof NetworkComponent)) {
builder.addComponent(entityManager.getComponentLibrary().copy(comp));
}
}
}
block.setEntity(builder.build());
}
use of org.terasology.engine.network.NetworkComponent in project Terasology by MovingBlocks.
the class EventSystemReplayImpl method broadcastEvent.
private void broadcastEvent(EntityRef entity, Event event, EventMetadata metadata) {
if (networkSystem.getMode().isServer()) {
NetworkComponent netComp = entity.getComponent(NetworkComponent.class);
BlockComponent blockComp = entity.getComponent(BlockComponent.class);
if (netComp != null || blockComp != null) {
Client instigatorClient = null;
if (metadata.isSkipInstigator() && event instanceof NetworkEvent) {
instigatorClient = networkSystem.getOwner(((NetworkEvent) event).getInstigator());
}
for (Client client : networkSystem.getPlayers()) {
if (!client.equals(instigatorClient)) {
client.send(event, entity);
}
}
}
}
}
Aggregations