diff --git a/common/src/main/java/org/valkyrienskies/mod/mixin/feature/teleport_reconnected_player_to_ship/MixinServerPlayer.java b/common/src/main/java/org/valkyrienskies/mod/mixin/feature/teleport_reconnected_player_to_ship/MixinServerPlayer.java index a5d9bc662..7f6d7136b 100644 --- a/common/src/main/java/org/valkyrienskies/mod/mixin/feature/teleport_reconnected_player_to_ship/MixinServerPlayer.java +++ b/common/src/main/java/org/valkyrienskies/mod/mixin/feature/teleport_reconnected_player_to_ship/MixinServerPlayer.java @@ -11,6 +11,7 @@ import org.joml.Vector3d; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -25,6 +26,11 @@ public abstract class MixinServerPlayer extends Player { @Shadow public abstract ServerLevel serverLevel(); + // The maximum number of ticks before the player is no longer considered aboard a ship + // if they are no longer directly touching it + @Unique + private static final int MAX_ONBOARD_TICKS = 4; + public MixinServerPlayer(final Level level, final BlockPos blockPos, final float f, final GameProfile gameProfile) { super(level, blockPos, f, gameProfile); @@ -39,7 +45,7 @@ void teleportToShip(final CompoundTag compoundTag, final CallbackInfo ci) { final long lastShipId = compoundTag.getLong("LastShipId"); final Ship ship = VSGameUtilsKt.getShipObjectWorld(serverLevel()).getAllShips().getById(lastShipId); - // If ship doesn't exist, don't bother + // Don't teleport if the ship doesn't exist anymore if (ship == null) return; @@ -58,19 +64,19 @@ void teleportToShip(final CompoundTag compoundTag, final CallbackInfo ci) { void rememberLastShip(final CompoundTag compoundTag, final CallbackInfo ci) { final EntityDraggingInformation draggingInformation = ((IEntityDraggingInformationProvider) this).getDraggingInformation(); - if (draggingInformation.getTicksSinceStoodOnShip() > 4) + if (draggingInformation.getTicksSinceStoodOnShip() > MAX_ONBOARD_TICKS) return; @Nullable final Long lastShipId = draggingInformation.getLastShipStoodOn(); if (lastShipId == null) return; - compoundTag.putLong("LastShipId", lastShipId); - final Ship ship = VSGameUtilsKt.getShipObjectWorld(serverLevel()).getAllShips().getById(lastShipId); if (ship == null) return; + compoundTag.putLong("LastShipId", lastShipId); + // Get position relative to ship // (Technically, this grabs the position in the shipyard, but it works well enough...) final Vector3d playerWorldPosition = new Vector3d(getX(), getY(), getZ());