Skip to content

Commit

Permalink
Revert "chore: remove finite check from LocalPlayer (#4662)"
Browse files Browse the repository at this point in the history
This reverts commit ac62052.
  • Loading branch information
jdrueckert authored Jun 24, 2021
1 parent deeb213 commit 74254a2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import org.terasology.engine.logic.characters.CharacterComponent;
import org.terasology.engine.logic.characters.CharacterMovementComponent;
import org.terasology.engine.logic.characters.CharacterSystem;
import org.terasology.engine.logic.characters.events.ActivationPredicted;
import org.terasology.engine.logic.characters.events.ActivationRequest;
import org.terasology.engine.logic.common.ActivateEvent;
import org.terasology.engine.logic.location.LocationComponent;
import org.terasology.engine.logic.characters.events.ActivationPredicted;
import org.terasology.engine.logic.characters.events.ActivationRequest;
import org.terasology.engine.math.Direction;
import org.terasology.engine.network.ClientComponent;
import org.terasology.engine.physics.HitResult;
Expand Down Expand Up @@ -99,7 +99,13 @@ public boolean isValid() {
*/
public Vector3f getPosition(Vector3f dest) {
LocationComponent location = getCharacterEntity().getComponent(LocationComponent.class);
return location.getWorldPosition(dest);
if (location != null) {
Vector3f result = location.getWorldPosition(new Vector3f());
if (result.isFinite()) { //TODO: MP finite check seems to hide a larger underlying problem
dest.set(result);
}
}
return dest;
}

/**
Expand All @@ -110,7 +116,13 @@ public Vector3f getPosition(Vector3f dest) {
*/
public Quaternionf getRotation(Quaternionf dest) {
LocationComponent location = getCharacterEntity().getComponent(LocationComponent.class);
return location.getWorldRotation(dest);
if (location != null) {
Quaternionf result = location.getWorldRotation(new Quaternionf());
if (result.isFinite()) { //TODO: MP finite check seems to hide a larger underlying problem
dest.set(result);
}
}
return dest;
}

/**
Expand All @@ -121,8 +133,18 @@ public Quaternionf getRotation(Quaternionf dest) {
*/
public Vector3f getViewPosition(Vector3f dest) {
ClientComponent clientComponent = getClientEntity().getComponent(ClientComponent.class);
if (clientComponent == null) {
return dest;
}
LocationComponent location = clientComponent.camera.getComponent(LocationComponent.class);
return location.getWorldPosition(dest);
if (location != null) {
Vector3f result = location.getWorldPosition(new Vector3f());
if (result.isFinite()) { //TODO: MP finite check seems to hide a larger underlying problem
dest.set(result);
return dest;
}
}
return getPosition(dest);
}

/**
Expand All @@ -133,8 +155,18 @@ public Vector3f getViewPosition(Vector3f dest) {
*/
public Quaternionf getViewRotation(Quaternionf dest) {
ClientComponent clientComponent = getClientEntity().getComponent(ClientComponent.class);
if (clientComponent == null) {
return new Quaternionf();
}
LocationComponent location = clientComponent.camera.getComponent(LocationComponent.class);
return location.getWorldRotation(dest);
if (location != null) {
Quaternionf result = location.getWorldRotation(new Quaternionf());
if (result.isFinite()) { //TODO: MP finite check seems to hide a larger underlying problem
dest.set(result);
return dest;
}
}
return getRotation(dest);
}

/**
Expand All @@ -150,7 +182,10 @@ public Vector3f getViewDirection(Vector3f dest) {

public Vector3f getVelocity(Vector3f dest) {
CharacterMovementComponent movement = getCharacterEntity().getComponent(CharacterMovementComponent.class);
return dest.set(movement.getVelocity());
if (movement != null) {
return dest.set(movement.getVelocity());
}
return dest;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ public String get() {
debugLine3.bindText(new ReadOnlyBinding<String>() {
@Override
public String get() {
if (!localPlayer.isValid()) {
return "";
}
Vector3f pos = localPlayer.getPosition(new Vector3f());
Vector3i chunkPos = Chunks.toChunkPos(pos, new Vector3i());
Vector3f rotation = localPlayer.getViewDirection(new Vector3f());
Expand Down

0 comments on commit 74254a2

Please sign in to comment.