Skip to content

Commit

Permalink
Don't drag entities that are mounted to an entity
Browse files Browse the repository at this point in the history
  • Loading branch information
StewStrong committed Nov 21, 2023
1 parent 183167f commit 90e23ed
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,41 +144,39 @@ private void preRender(final float tickDelta, final long startTime, final boolea
continue;
}

if (entityShouldBeHere == null) {
final EntityDraggingInformation entityDraggingInformation =
((IEntityDraggingInformationProvider) entity).getDraggingInformation();
final Long lastShipStoodOn = entityDraggingInformation.getLastShipStoodOn();
// Then try getting [entityShouldBeHere] from [entityDraggingInformation]
if (lastShipStoodOn != null && entityDraggingInformation.isEntityBeingDraggedByAShip()) {
final ClientShip shipObject =
VSGameUtilsKt.getShipObjectWorld(clientWorld).getLoadedShips().getById(lastShipStoodOn);
if (shipObject != null) {
entityDraggingInformation.setCachedLastPosition(
new Vector3d(entity.xo, entity.yo, entity.zo));
entityDraggingInformation.setRestoreCachedLastPosition(true);
final EntityDraggingInformation entityDraggingInformation =
((IEntityDraggingInformationProvider) entity).getDraggingInformation();
final Long lastShipStoodOn = entityDraggingInformation.getLastShipStoodOn();
// Then try getting [entityShouldBeHere] from [entityDraggingInformation]
if (lastShipStoodOn != null && entityDraggingInformation.isEntityBeingDraggedByAShip()) {
final ClientShip shipObject =
VSGameUtilsKt.getShipObjectWorld(clientWorld).getLoadedShips().getById(lastShipStoodOn);
if (shipObject != null) {
entityDraggingInformation.setCachedLastPosition(
new Vector3d(entity.xo, entity.yo, entity.zo));
entityDraggingInformation.setRestoreCachedLastPosition(true);

// The velocity added to the entity by ship dragging
final Vector3dc entityAddedVelocity = entityDraggingInformation.getAddedMovementLastTick();
// The velocity added to the entity by ship dragging
final Vector3dc entityAddedVelocity = entityDraggingInformation.getAddedMovementLastTick();

// The velocity of the entity before we added ship dragging
final double entityMovementX = entity.getX() - entityAddedVelocity.x() - entity.xo;
final double entityMovementY = entity.getY() - entityAddedVelocity.y() - entity.yo;
final double entityMovementZ = entity.getZ() - entityAddedVelocity.z() - entity.zo;
// The velocity of the entity before we added ship dragging
final double entityMovementX = entity.getX() - entityAddedVelocity.x() - entity.xo;
final double entityMovementY = entity.getY() - entityAddedVelocity.y() - entity.yo;
final double entityMovementZ = entity.getZ() - entityAddedVelocity.z() - entity.zo;

// Without ship dragging, the entity would've been here
final Vector3dc entityShouldBeHerePreTransform = new Vector3d(
entity.xo + entityMovementX * tickDelta,
entity.yo + entityMovementY * tickDelta,
entity.zo + entityMovementZ * tickDelta
);
// Without ship dragging, the entity would've been here
final Vector3dc entityShouldBeHerePreTransform = new Vector3d(
entity.xo + entityMovementX * tickDelta,
entity.yo + entityMovementY * tickDelta,
entity.zo + entityMovementZ * tickDelta
);

// Move [entityShouldBeHerePreTransform] with the ship, using the prev transform and the
// current render transform
entityShouldBeHere = shipObject.getRenderTransform().getShipToWorldMatrix()
.transformPosition(
shipObject.getPrevTickShipTransform().getWorldToShipMatrix()
.transformPosition(entityShouldBeHerePreTransform, new Vector3d()));
}
// Move [entityShouldBeHerePreTransform] with the ship, using the prev transform and the
// current render transform
entityShouldBeHere = shipObject.getRenderTransform().getShipToWorldMatrix()
.transformPosition(
shipObject.getPrevTickShipTransform().getWorldToShipMatrix()
.transformPosition(entityShouldBeHerePreTransform, new Vector3d()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object EntityDragger {
if (shipDraggingEntity != null) {
if (entityDraggingInformation.isEntityBeingDraggedByAShip()) {
// Compute how much we should drag the entity
val shipData = entity.level.shipObjectWorld.queryableShipData.getById(shipDraggingEntity)
val shipData = entity.level.shipObjectWorld.allShips.getById(shipDraggingEntity)
if (shipData != null) {
dragTheEntity = true

Expand Down Expand Up @@ -114,6 +114,7 @@ object EntityDragger {
}
}
entityDraggingInformation.ticksSinceStoodOnShip++
entityDraggingInformation.mountedToEntity = entity.vehicle != null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ class EntityDraggingInformation {
field = value
}
var ticksSinceStoodOnShip: Int = 0
var mountedToEntity: Boolean = false

// Used by the client rendering code only
var cachedLastPosition: Vector3dc? = null
var restoreCachedLastPosition = false

fun isEntityBeingDraggedByAShip(): Boolean {
return (lastShipStoodOn != null) && (ticksSinceStoodOnShip < 10)
return (lastShipStoodOn != null) && (ticksSinceStoodOnShip < 10) && !mountedToEntity
}
}

Expand Down

0 comments on commit 90e23ed

Please sign in to comment.