diff --git a/NewHorizons/Components/Fixers/PlayerShipAtmosphereDetectorFix.cs b/NewHorizons/Components/Fixers/PlayerShipAtmosphereDetectorFix.cs new file mode 100644 index 00000000..25d135c1 --- /dev/null +++ b/NewHorizons/Components/Fixers/PlayerShipAtmosphereDetectorFix.cs @@ -0,0 +1,33 @@ +using NewHorizons.Utility.OWML; +using UnityEngine; + +namespace NewHorizons.Components.Fixers; + +/// +/// Fixes a bug where spawning into the ship would not trigger the hatch entryway, so the player could drown if the ship flew into water +/// +internal class PlayerShipAtmosphereDetectorFix : MonoBehaviour +{ + private PlayerCameraFluidDetector _fluidDetector; + private SimpleFluidVolume _shipAtmosphereVolume; + + public void Start() + { + _fluidDetector = Locator.GetPlayerCameraDetector().GetComponent(); + _shipAtmosphereVolume = Locator.GetShipBody().transform.Find("Volumes/ShipAtmosphereVolume").GetComponent(); + } + + public void Update() + { + if (PlayerState.IsInsideShip()) + { + if (!_fluidDetector._activeVolumes.Contains(_shipAtmosphereVolume)) + { + NHLogger.LogVerbose($"{nameof(PlayerShipAtmosphereDetectorFix)} had to add the ship atmosphere volume [{_shipAtmosphereVolume}] to the fluid detector"); + _fluidDetector.AddVolume(_shipAtmosphereVolume); + } + NHLogger.LogVerbose($"{nameof(PlayerShipAtmosphereDetectorFix)} applied its fix"); + Component.Destroy(this); + } + } +} diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 0314cf61..da1d2795 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -601,6 +601,7 @@ namespace NewHorizons Locator.GetPlayerBody().gameObject.AddComponent(); Locator.GetPlayerBody().gameObject.AddComponent(); Locator.GetPlayerBody().gameObject.AddComponent(); + Locator.GetPlayerBody().gameObject.AddComponent(); PlayerSpawnHandler.OnSystemReady(shouldWarpInFromShip, shouldWarpInFromVessel);