use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class PlayerStoreBuilder method build.
public EntityData.PlayerStore build(EngineEntityManager entityManager) {
EntityData.PlayerStore.Builder playerEntityStore = EntityData.PlayerStore.newBuilder();
playerEntityStore.setCharacterPosX(relevanceLocation.x());
playerEntityStore.setCharacterPosY(relevanceLocation.y());
playerEntityStore.setCharacterPosZ(relevanceLocation.z());
playerEntityStore.setHasCharacter(characterEntityId != null);
if (characterEntityId != null) {
EntityRef character = entityManager.getEntity(characterEntityId);
EntityStorer store = new EntityStorer(entityManager);
store.store(character, PlayerStoreInternal.CHARACTER);
storedEntities = store.getStoredEntities();
playerEntityStore.setStore(store.finaliseStore());
} else {
storedEntities = Sets.newHashSet();
}
return playerEntityStore.build();
}
use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class BlockPlacedMetric method createTelemetryFieldToValue.
@Override
public Map<String, ?> createTelemetryFieldToValue() {
localPlayer = CoreRegistry.get(LocalPlayer.class);
EntityRef playerEntity = localPlayer.getCharacterEntity();
if (playerEntity.hasComponent(GamePlayStatsComponent.class)) {
GamePlayStatsComponent gamePlayStatsComponent = playerEntity.getComponent(GamePlayStatsComponent.class);
telemetryFieldToValue.clear();
telemetryFieldToValue.putAll(gamePlayStatsComponent.blockPlacedMap);
return telemetryFieldToValue;
} else {
return telemetryFieldToValue;
}
}
use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class LoadEntities method step.
@Override
public boolean step() {
EntityManager em = context.get(EntityManager.class);
boolean entityCreated = false;
for (EntityRef entity : em.getAllEntities()) {
entityCreated = true;
logger.error("Entity created before load: {}", entity.toFullDescription());
}
if (entityCreated) {
throw new IllegalStateException("Entity creation detected during component system initialisation, game load aborting");
}
StorageManager storageManager = context.get(StorageManager.class);
try {
storageManager.loadGlobalStore();
} catch (IOException e) {
logger.error("Failed to load global data.", e);
}
return true;
}
use of org.terasology.engine.entitySystem.entity.EntityRef 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.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class CreateWorldEntity method step.
@Override
public boolean step() {
this.entityManager = context.get(EntityManager.class);
this.worldGenerator = context.get(WorldGenerator.class);
this.config = context.get(Config.class);
this.chunkProvider = context.get(ChunkProvider.class);
this.worldConfigurator = worldGenerator.getConfigurator();
Iterator<EntityRef> worldEntityIterator = entityManager.getEntitiesWith(WorldComponent.class).iterator();
if (worldEntityIterator.hasNext()) {
EntityRef worldEntity = worldEntityIterator.next();
worldEntityIterator.forEachRemaining(w -> logger.warn("Ignored extra world {}", w));
chunkProvider.setWorldEntity(worldEntity);
// replace the world generator values from the components in the world entity
worldConfigurator.getProperties().forEach((key, currentComponent) -> {
Component component = worldEntity.getComponent(currentComponent.getClass());
if (component != null) {
worldConfigurator.setProperty(key, component);
}
});
} else {
// create world entity if one does not exist.
EntityRef worldEntity = createWorldPoolsAndEntity();
chunkProvider.setWorldEntity(worldEntity);
// transfer all world generation parameters from Config to WorldEntity
SimpleUri generatorUri = worldGenerator.getUri();
worldConfigurator.getProperties().forEach((key, currentComponent) -> {
Class<? extends Component> clazz = currentComponent.getClass();
Component moduleComponent = gameManifest.getModuleConfig(generatorUri, key, clazz);
if (moduleComponent != null) {
// configure entity from component
worldEntity.addComponent(moduleComponent);
worldConfigurator.setProperty(key, moduleComponent);
} else {
worldEntity.addComponent(currentComponent);
}
});
}
return true;
}
Aggregations