use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class MovementDebugCommands method teleportPlayerToPlayer.
@Command(shortDescription = "Teleport User1 to User2", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String teleportPlayerToPlayer(@CommandParam("usernameFrom") String usernameFrom, @CommandParam("usernameTo") String usernameTo) {
if (usernameFrom.equalsIgnoreCase(usernameTo)) {
throw new IllegalArgumentException("Why teleport to yourself...");
}
EntityRef entityFrom = null;
EntityRef entityTo = null;
boolean foundEntityFrom = false;
boolean foundEntityTo = false;
for (EntityRef clientEntity : entityManager.getEntitiesWith(ClientComponent.class)) {
EntityRef clientInfo = clientEntity.getComponent(ClientComponent.class).clientInfo;
DisplayNameComponent name = clientInfo.getComponent(DisplayNameComponent.class);
if (!foundEntityFrom && usernameFrom.equalsIgnoreCase(name.name)) {
entityFrom = clientEntity;
foundEntityFrom = true;
} else if (!foundEntityTo && usernameTo.equalsIgnoreCase(name.name)) {
entityTo = clientEntity;
foundEntityTo = true;
}
if (foundEntityFrom && foundEntityTo) {
break;
}
}
if (!foundEntityFrom) {
throw new IllegalArgumentException("No such user '" + usernameFrom + "'");
}
if (!foundEntityTo) {
throw new IllegalArgumentException("No such user '" + usernameTo + "'");
}
LocationComponent locationComponent = entityTo.getComponent(LocationComponent.class);
if (locationComponent != null) {
Vector3f vLocation = locationComponent.getWorldPosition(new Vector3f());
ClientComponent clientComp = entityFrom.getComponent(ClientComponent.class);
if (clientComp != null) {
clientComp.character.send(new CharacterTeleportEvent(vLocation));
return "Teleporting " + usernameFrom + " to " + usernameTo + " at " + vLocation.x + " " + vLocation.y + " " + vLocation.z;
}
}
throw new IllegalArgumentException("User " + usernameTo + " has an invalid location.");
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class SaveTransaction method createChunkPosToUnsavedOwnerLessEntitiesMap.
private Map<Vector3i, Collection<EntityRef>> createChunkPosToUnsavedOwnerLessEntitiesMap() {
Map<Vector3i, Collection<EntityRef>> chunkPosToEntitiesMap = Maps.newHashMap();
for (EntityRef entity : privateEntityManager.getEntitiesWith(LocationComponent.class)) {
/*
* Note: Entities with owners get saved with the owner. Entities that are always relevant don't get stored
* in chunk as the chunk is not always loaded
*/
if (entity.isPersistent() && !entity.getOwner().exists() && !entity.hasComponent(ClientComponent.class) && !entity.isAlwaysRelevant()) {
LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
if (locationComponent != null) {
Vector3f loc = locationComponent.getWorldPosition(new Vector3f());
Vector3i chunkPos = Chunks.toChunkPos((int) loc.x, (int) loc.y, (int) loc.z, new Vector3i());
Collection<EntityRef> collection = chunkPosToEntitiesMap.get(chunkPos);
if (collection == null) {
collection = Lists.newArrayList();
chunkPosToEntitiesMap.put(chunkPos, collection);
}
collection.add(entity);
}
}
}
return chunkPosToEntitiesMap;
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class PlayerStoreInternal method setCharacter.
@Override
public void setCharacter(EntityRef character) {
this.character = character;
hasCharacter = character.exists();
LocationComponent location = character.getComponent(LocationComponent.class);
if (location == null) {
return;
}
Vector3f position = location.getWorldPosition(new Vector3f());
if (position.isFinite()) {
setRelevanceLocation(position);
}
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class ReadWriteStorageManager method createPlayerStore.
private PlayerStoreBuilder createPlayerStore(Client client, EntityRef character) {
LocationComponent location = character.getComponent(LocationComponent.class);
Vector3f relevanceLocation;
if (location != null) {
relevanceLocation = location.getWorldPosition(new Vector3f());
} else {
relevanceLocation = new Vector3f();
}
Long characterId;
if (character.exists()) {
characterId = character.getId();
} else {
characterId = null;
}
return new PlayerStoreBuilder(characterId, relevanceLocation);
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class BulletPhysics method updateTrigger.
@Override
public // TODO: update if detectGroups changed
boolean updateTrigger(EntityRef entity) {
LocationComponent location = entity.getComponent(LocationComponent.class);
if (location == null) {
logger.warn("Trying to update or create trigger of entity that has no LocationComponent?! Entity: {}", entity);
return false;
}
btPairCachingGhostObject triggerObj = entityTriggers.get(entity);
if (triggerObj != null) {
float scale = location.getWorldScale();
if (Math.abs(triggerObj.getCollisionShape().getLocalScaling().x - scale) > SIMD_EPSILON) {
discreteDynamicsWorld.removeCollisionObject(triggerObj);
newTrigger(entity);
} else {
Quaternionf worldRotation = location.getWorldRotation(new Quaternionf());
Vector3f position = location.getWorldPosition(new Vector3f());
if (!position.isFinite() || !worldRotation.isFinite()) {
logger.warn("Can't update Trigger entity with a non-finite position/rotation?! Entity: {}", entity);
return false;
}
triggerObj.setWorldTransform(new Matrix4f().translationRotateScale(position, worldRotation, 1.0f));
}
return true;
} else {
newTrigger(entity);
return false;
}
}
Aggregations