From 06870db051b4bc6f1c355d74af1f8e5d1e6c4c9e Mon Sep 17 00:00:00 2001 From: xen-42 Date: Tue, 28 Jan 2025 23:02:44 -0500 Subject: [PATCH] Fix raft docks not working on NH rafts --- NewHorizons/Builder/Props/DetailBuilder.cs | 9 +++++++ NewHorizons/Builder/Props/RaftBuilder.cs | 3 +++ .../RaftControllerPatches.cs | 27 +++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 2b7dbfde..ffdefcb5 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -459,6 +459,15 @@ namespace NewHorizons.Builder.Props { component.gameObject.AddComponent(); } + else if (component is RaftDock dock) + { + // These flood toggles are to disable flooded docks on the Stranger + // Presumably the user isn't making one of those + foreach (var toggle in dock.GetComponents()) + { + Component.DestroyImmediate(toggle); + } + } } /// diff --git a/NewHorizons/Builder/Props/RaftBuilder.cs b/NewHorizons/Builder/Props/RaftBuilder.cs index 98196885..59f734bf 100644 --- a/NewHorizons/Builder/Props/RaftBuilder.cs +++ b/NewHorizons/Builder/Props/RaftBuilder.cs @@ -66,6 +66,9 @@ namespace NewHorizons.Builder.Props var waterVolume = planetGO.GetComponentInChildren(); fluidDetector._alignmentFluid = waterVolume; fluidDetector._buoyancy.checkAgainstWaves = true; + // Rafts were unable to trigger docks because these were disabled for some reason + fluidDetector.GetComponent().enabled = true; + fluidDetector.GetComponent().enabled = true; // Light sensors foreach (var lightSensor in raftObject.GetComponentsInChildren()) diff --git a/NewHorizons/Patches/EchoesOfTheEyePatches/RaftControllerPatches.cs b/NewHorizons/Patches/EchoesOfTheEyePatches/RaftControllerPatches.cs index e615c201..48a08f08 100644 --- a/NewHorizons/Patches/EchoesOfTheEyePatches/RaftControllerPatches.cs +++ b/NewHorizons/Patches/EchoesOfTheEyePatches/RaftControllerPatches.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NewHorizons.Components.Props; using UnityEngine; namespace NewHorizons.Patches.EchoesOfTheEyePatches @@ -73,5 +74,31 @@ namespace NewHorizons.Patches.EchoesOfTheEyePatches return false; } + + [HarmonyPostfix] + [HarmonyPatch(nameof(RaftController.UpdateMoveToTarget))] + public static void UpdateMoveToTarget(RaftController __instance) + { + // If it has a riverFluid volume then its a regular stranger one + if (__instance._movingToTarget && __instance._riverFluid == null) + { + OWRigidbody raftBody = __instance._raftBody; + OWRigidbody origParentBody = __instance._raftBody.GetOrigParentBody(); + Transform transform = origParentBody.transform; + Vector3 vector = transform.TransformPoint(__instance._targetLocalPosition); + + // Base game threshold has this at 1f (after doing smoothstep on it) + // For whatever reason it never hits that for NH planets (probably since they're moving so much compared to the steady velocity of the Stranger) + // Might break for somebody with a wacky spinning planet in which case we can adjust this or add some kind of fallback (i.e., wait x seconds and then just say its there) + // Fixes #1005 + if (__instance.currentDistanceLerp > 0.999f) + { + raftBody.SetPosition(vector); + raftBody.SetRotation(transform.rotation * __instance._targetLocalRotation); + __instance.StopMovingToTarget(); + __instance.OnArriveAtTarget.Invoke(); + } + } + } } }