From 90e23ed86f11283185d8cc3f89c1822e5a926159 Mon Sep 17 00:00:00 2001 From: StewStrong Date: Mon, 20 Nov 2023 23:58:21 -0700 Subject: [PATCH] Don't drag entities that are mounted to an entity --- .../client/renderer/MixinGameRenderer.java | 60 +++++++++---------- .../mod/common/util/EntityDragger.kt | 3 +- .../common/util/EntityDraggingInformation.kt | 3 +- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/common/src/main/java/org/valkyrienskies/mod/mixin/client/renderer/MixinGameRenderer.java b/common/src/main/java/org/valkyrienskies/mod/mixin/client/renderer/MixinGameRenderer.java index 46f0bbaa6..8bfef4dfd 100644 --- a/common/src/main/java/org/valkyrienskies/mod/mixin/client/renderer/MixinGameRenderer.java +++ b/common/src/main/java/org/valkyrienskies/mod/mixin/client/renderer/MixinGameRenderer.java @@ -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())); } } diff --git a/common/src/main/kotlin/org/valkyrienskies/mod/common/util/EntityDragger.kt b/common/src/main/kotlin/org/valkyrienskies/mod/common/util/EntityDragger.kt index 64472ca35..425ef4c48 100644 --- a/common/src/main/kotlin/org/valkyrienskies/mod/common/util/EntityDragger.kt +++ b/common/src/main/kotlin/org/valkyrienskies/mod/common/util/EntityDragger.kt @@ -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 @@ -114,6 +114,7 @@ object EntityDragger { } } entityDraggingInformation.ticksSinceStoodOnShip++ + entityDraggingInformation.mountedToEntity = entity.vehicle != null } } } diff --git a/common/src/main/kotlin/org/valkyrienskies/mod/common/util/EntityDraggingInformation.kt b/common/src/main/kotlin/org/valkyrienskies/mod/common/util/EntityDraggingInformation.kt index e0b140942..690263a87 100644 --- a/common/src/main/kotlin/org/valkyrienskies/mod/common/util/EntityDraggingInformation.kt +++ b/common/src/main/kotlin/org/valkyrienskies/mod/common/util/EntityDraggingInformation.kt @@ -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 } }