fix(LocalPlayer): do not crash when the camera is not on
Restores the alternate behavior described in the docstring,
correcting a regression introduced in
This "LocalPlayer without camera" situation has come up in headless MTE tests.
-// Copyright 2021 The Terasology Foundation
+// Copyright 2022 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.engine.logic.players;
@@ -115,27 +115,35 @@ public Quaternionf getRotation(Quaternionf dest) {
}
/**
- * position of camera if one is present else use {@link #getPosition(Vector3f)}
+ * position of camera if one is present else use {@link #getPosition}
*
* @param dest will hold the result
* @return dest
*/
public Vector3f getViewPosition(Vector3f dest) {
ClientComponent clientComponent = getClientEntity().getComponent(ClientComponent.class);
+ if (clientComponent.camera.exists()) {
LocationComponent location = clientComponent.camera.getComponent(LocationComponent.class);
return location.getWorldPosition(dest);
+ } else {
+ return getPosition(dest);
+ }
}
/**
- * orientation of camera if one is present else use {@link #getPosition(Vector3f)}
+ * orientation of camera if one is present else use {@link #getRotation}
*
* @param dest will hold the result
* @return dest
*/
public Quaternionf getViewRotation(Quaternionf dest) {
ClientComponent clientComponent = getClientEntity().getComponent(ClientComponent.class);
+ if (clientComponent.camera.exists()) {
LocationComponent location = clientComponent.camera.getComponent(LocationComponent.class);
return location.getWorldRotation(dest);
+ } else {
+ return getRotation(dest);
+ }
}
/**
