use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class MovementDebugCommands method teleportMeToPlayer.
@Command(shortDescription = "Teleport to player", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String teleportMeToPlayer(@Sender EntityRef sender, @CommandParam("username") String username) {
for (EntityRef clientEntity : entityManager.getEntitiesWith(ClientComponent.class)) {
EntityRef clientInfo = clientEntity.getComponent(ClientComponent.class).clientInfo;
DisplayNameComponent name = clientInfo.getComponent(DisplayNameComponent.class);
if (username.equalsIgnoreCase(name.name)) {
LocationComponent locationComponent = clientEntity.getComponent(LocationComponent.class);
if (locationComponent != null) {
Vector3f vLocation = locationComponent.getWorldPosition(new Vector3f());
ClientComponent clientComp = sender.getComponent(ClientComponent.class);
if (clientComp != null) {
clientComp.character.send(new CharacterTeleportEvent(vLocation));
return "Teleporting you to " + username + " at " + vLocation.x + " " + vLocation.y + " " + vLocation.z;
}
}
}
}
throw new IllegalArgumentException("No such user '" + username + "'");
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class FirstPersonClientSystem method update.
/**
* modifies the held item mount point to move the held item in first person view
*/
@Override
public void update(float delta) {
// ensure empty hand is shown if no item is hold at the moment
if (!currentHeldItem.exists() && currentHeldItem != getHandEntity()) {
linkHeldItemLocationForLocalPlayer(getHandEntity());
}
// ensure that there are no lingering items that are marked as still held. This situation happens with client side predicted items
for (EntityRef entityRef : entityManager.getEntitiesWith(ItemIsHeldComponent.class)) {
if (!entityRef.equals(currentHeldItem) && !entityRef.equals(handEntity)) {
entityRef.destroy();
}
}
// get the first person mount point and rotate it away from the camera
CharacterHeldItemComponent characterHeldItemComponent = localPlayer.getCharacterEntity().getComponent(CharacterHeldItemComponent.class);
FirstPersonHeldItemMountPointComponent mountPointComponent = localPlayer.getCameraEntity().getComponent(FirstPersonHeldItemMountPointComponent.class);
if (characterHeldItemComponent == null || mountPointComponent == null) {
return;
}
LocationComponent locationComponent = mountPointComponent.mountPointEntity.getComponent(LocationComponent.class);
if (locationComponent == null) {
return;
}
long timeElapsedSinceLastUsed = time.getGameTimeInMs() - characterHeldItemComponent.lastItemUsedTime;
float animateAmount = 0f;
if (timeElapsedSinceLastUsed < USEANIMATIONLENGTH) {
// half way through the animation will be the maximum extent of rotation and translation
animateAmount = 1f - Math.abs(((float) timeElapsedSinceLastUsed / (float) USEANIMATIONLENGTH) - 0.5f);
}
float addPitch = 15f * animateAmount;
float addYaw = 10f * animateAmount;
locationComponent.setLocalRotation(new Quaternionf().rotationYXZ(TeraMath.DEG_TO_RAD * (mountPointComponent.rotateDegrees.y + addYaw), TeraMath.DEG_TO_RAD * (mountPointComponent.rotateDegrees.x + addPitch), TeraMath.DEG_TO_RAD * mountPointComponent.rotateDegrees.z));
Vector3f offset = new Vector3f(0.25f * animateAmount, -0.12f * animateAmount, 0f);
offset.add(mountPointComponent.translate);
locationComponent.setLocalPosition(offset);
mountPointComponent.mountPointEntity.saveComponent(locationComponent);
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class NameTagClientSystem method createOrUpdateNameTagFor.
private void createOrUpdateNameTagFor(EntityRef entity, NameTagComponent nameTagComponent) {
EntityRef nameTag = nameTagEntityToFloatingTextMap.get(entity);
Vector3f offset = new Vector3f(0, nameTagComponent.yOffset, 0);
if (nameTag != null) {
FloatingTextComponent floatingText = nameTag.getComponent(FloatingTextComponent.class);
floatingText.text = nameTagComponent.text;
floatingText.textColor = nameTagComponent.textColor;
floatingText.scale = nameTagComponent.scale;
nameTag.saveComponent(floatingText);
LocationComponent nameTagLoc = nameTag.getComponent(LocationComponent.class);
nameTagLoc.setLocalPosition(offset);
nameTag.saveComponent(nameTagLoc);
} else {
EntityBuilder nameTagBuilder = entityManager.newBuilder();
FloatingTextComponent floatingTextComponent = new FloatingTextComponent();
nameTagBuilder.addComponent(floatingTextComponent);
LocationComponent locationComponent = new LocationComponent();
nameTagBuilder.addComponent(locationComponent);
floatingTextComponent.text = nameTagComponent.text;
floatingTextComponent.textColor = nameTagComponent.textColor;
floatingTextComponent.scale = nameTagComponent.scale;
nameTagBuilder.setOwner(entity);
nameTagBuilder.setPersistent(false);
nameTag = nameTagBuilder.build();
nameTagEntityToFloatingTextMap.put(entity, nameTag);
Location.attachChild(entity, nameTag, offset, new Quaternionf());
}
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class CameraClientSystem method mountCamera.
private void mountCamera() {
ClientComponent clientComponent = localPlayer.getClientEntity().getComponent(ClientComponent.class);
EntityRef targetEntityForCamera = GazeAuthoritySystem.getGazeEntityForCharacter(clientComponent.character);
// TODO: why is the camera setup differently
LocationComponent cameraLocation = clientComponent.camera.getComponent(LocationComponent.class);
// if the camera already has a location, use that as the relative position of the camera
if (cameraLocation != null) {
Location.attachChild(targetEntityForCamera, clientComponent.camera, cameraLocation.getLocalPosition(), new Quaternionf());
} else {
Location.attachChild(targetEntityForCamera, clientComponent.camera, new Vector3f(0, 0, 0), new Quaternionf());
}
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class LocalPlayer method getViewPosition.
/**
* position of camera if one is present else use {@link #getPosition(Vector3f)}
*
* @param dest will hold the result
* @return dest
*/
public Vector3f getViewPosition(Vector3f dest) {
ClientComponent clientComponent = getClientEntity().getComponent(ClientComponent.class);
LocationComponent location = clientComponent.camera.getComponent(LocationComponent.class);
return location.getWorldPosition(dest);
}
Aggregations