use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class LocalPlayer method getViewRotation.
/**
* orientation of camera if one is present else use {@link #getPosition(Vector3f)}
*
* @param dest will hold the result
* @return dest
*/
public Quaternionf getViewRotation(Quaternionf dest) {
ClientComponent clientComponent = getClientEntity().getComponent(ClientComponent.class);
LocationComponent location = clientComponent.camera.getComponent(LocationComponent.class);
return location.getWorldRotation(dest);
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class ItemPickupAuthoritySystem method onDropItemEvent.
@ReceiveEvent
public void onDropItemEvent(DropItemEvent event, EntityRef itemEntity, ItemComponent itemComponent) {
for (Component component : itemComponent.pickupPrefab.iterateComponents()) {
Component componentCopy = library.getComponentLibrary().copy(component);
if (componentCopy instanceof LocationComponent) {
((LocationComponent) componentCopy).setWorldPosition(event.getPosition());
}
itemEntity.addOrSaveComponent(componentCopy);
}
if (!itemEntity.hasComponent(LocationComponent.class)) {
itemEntity.addComponent(new LocationComponent(event.getPosition()));
}
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class PlayerSystem method onConnect.
@ReceiveEvent(components = ClientComponent.class)
public void onConnect(ConnectedEvent connected, EntityRef entity) {
LocationComponent loc = entity.getComponent(LocationComponent.class);
// for new clients, the player store will return default values
PlayerStore playerStore = connected.getPlayerStore();
Client owner = networkSystem.getOwner(entity);
Vector3ic minViewDist = ViewDistance.LEGALLY_BLIND.getChunkDistance();
if (playerStore.hasCharacter()) {
Vector3fc storedLocation = playerStore.getRelevanceLocation();
loc.setWorldPosition(storedLocation);
entity.saveComponent(loc);
if (worldProvider.isBlockRelevant(storedLocation)) {
// chunk for spawning location is ready, so spawn right now
playerStore.restoreEntities();
EntityRef character = playerStore.getCharacter();
Vector3ic viewDist = owner.getViewDistance().getChunkDistance();
addRelevanceEntity(entity, viewDist, owner);
restoreCharacter(entity, character);
} else {
// otherwise wait until chunk is ready
addRelevanceEntity(entity, minViewDist, owner);
clientsPreparingToSpawn.add(new SpawningClientInfo(entity, storedLocation, playerStore));
}
} else {
Vector3fc spawnPosition = worldGenerator.getSpawnPosition(entity);
loc.setWorldPosition(spawnPosition);
entity.saveComponent(loc);
addRelevanceEntity(entity, minViewDist, owner);
if (worldProvider.isBlockRelevant(spawnPosition)) {
spawnPlayer(entity);
} else {
clientsPreparingToSpawn.add(new SpawningClientInfo(entity, spawnPosition));
}
}
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class PojoEntityPool method create.
private EntityRef create(Prefab prefab, Vector3fc position, Quaternionfc rotation, boolean sendLifecycleEvents) {
EntityBuilder builder = newBuilder(prefab);
builder.setSendLifecycleEvents(sendLifecycleEvents);
LocationComponent loc = builder.getComponent(LocationComponent.class);
if (loc == null && (position != null || rotation != null)) {
loc = new LocationComponent();
builder.addComponent(loc);
}
if (position != null) {
loc.setWorldPosition(position);
}
if (rotation != null) {
loc.setWorldRotation(rotation);
}
return builder.build();
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class CharacterSystem method update.
@Override
public void update(float delta) {
Iterable<EntityRef> characterEntities = entityManager.getEntitiesWith(CharacterComponent.class, LocationComponent.class);
for (EntityRef characterEntity : characterEntities) {
CharacterComponent characterComponent = characterEntity.getComponent(CharacterComponent.class);
if (characterComponent == null) {
// could have changed during events below
continue;
}
LocationComponent characterLocation = characterEntity.getComponent(LocationComponent.class);
if (characterLocation == null) {
// could have changed during events below
continue;
}
EntityRef target = characterComponent.authorizedInteractionTarget;
if (target.isActive()) {
LocationComponent targetLocation = target.getComponent(LocationComponent.class);
if (targetLocation == null) {
// could have changed during events below
continue;
}
float maxInteractionRange = characterComponent.interactionRange;
if (isDistanceToLarge(characterLocation, targetLocation, maxInteractionRange)) {
InteractionUtil.cancelInteractionAsServer(characterEntity);
}
}
}
}
Aggregations