use of org.terasology.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();
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.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.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 Quat4f(1, 0, 0, 0));
}
}
use of org.terasology.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 Quat4f(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.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class LocalPlayer method getViewRotation.
public Quat4f getViewRotation() {
ClientComponent clientComponent = getClientEntity().getComponent(ClientComponent.class);
if (clientComponent == null) {
return new Quat4f(Quat4f.IDENTITY);
}
LocationComponent location = clientComponent.camera.getComponent(LocationComponent.class);
if (location == null) {
return getRotation();
}
return location.getWorldRotation();
}
Aggregations