From fd2f839d902316b741a4b56ebcdf47c173e237d9 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sat, 8 Oct 2022 17:47:31 -0400 Subject: [PATCH 01/10] Allow rafts to be added to Giant's Deep --- NewHorizons/Builder/Props/RaftBuilder.cs | 3 ++- NewHorizons/Patches/RaftPatches.cs | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Builder/Props/RaftBuilder.cs b/NewHorizons/Builder/Props/RaftBuilder.cs index 2e8c6a15..aaddb41a 100644 --- a/NewHorizons/Builder/Props/RaftBuilder.cs +++ b/NewHorizons/Builder/Props/RaftBuilder.cs @@ -43,8 +43,9 @@ namespace NewHorizons.Builder.Props // Detectors var fluidDetector = raftObject.transform.Find("Detector_Raft").GetComponent(); - var waterVolume = planetGO.GetComponentInChildren(); + var waterVolume = (FluidVolume)planetGO.GetComponentInChildren() ?? planetGO.GetComponentInChildren(); fluidDetector._alignmentFluid = waterVolume; + fluidDetector._buoyancy.checkAgainstWaves = true; // Light sensors foreach (var lightSensor in raftObject.GetComponentsInChildren()) diff --git a/NewHorizons/Patches/RaftPatches.cs b/NewHorizons/Patches/RaftPatches.cs index fea55497..dc0814d8 100644 --- a/NewHorizons/Patches/RaftPatches.cs +++ b/NewHorizons/Patches/RaftPatches.cs @@ -84,7 +84,7 @@ namespace NewHorizons.Patches [HarmonyPatch(typeof(AlignToSurfaceFluidDetector), "ManagedFixedUpdate")] public static bool AlignToSurfaceFluidDetector_ManagedFixedUpdate(AlignToSurfaceFluidDetector __instance) { - if (!(__instance._alignmentFluid is NHFluidVolume)) return true; + if (!(__instance._alignmentFluid is NHFluidVolume || __instance._alignmentFluid is SphereOceanFluidVolume)) return true; // Mostly copy pasting from the AlignWithDirection class AsymmetricFluidDetector_ManagedFixedUpdate(__instance); @@ -104,5 +104,14 @@ namespace NewHorizons.Patches return false; } + + [HarmonyPrefix] + [HarmonyPatch(typeof(FluidVolume), "GetDepthAtPosition")] + public static bool SphereOceanFluidVolume_GetDepthAtPosition(SphereOceanFluidVolume __instance, ref float __result, Vector3 worldPosition) + { + Vector3 vector = __instance.transform.InverseTransformPoint(worldPosition); + __result = Mathf.Sqrt(vector.x * vector.x + vector.z * vector.z + vector.y * vector.y) - __instance._radius; + return false; + } } } From 25a56c65fc8ae4c6dbb448acaf3cf64587ec0f38 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sat, 8 Oct 2022 17:52:10 -0400 Subject: [PATCH 02/10] Add acceleration to rafts --- NewHorizons/Builder/Props/RaftBuilder.cs | 1 + NewHorizons/External/Modules/PropModule.cs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/NewHorizons/Builder/Props/RaftBuilder.cs b/NewHorizons/Builder/Props/RaftBuilder.cs index aaddb41a..a85c5923 100644 --- a/NewHorizons/Builder/Props/RaftBuilder.cs +++ b/NewHorizons/Builder/Props/RaftBuilder.cs @@ -38,6 +38,7 @@ namespace NewHorizons.Builder.Props raftController._riverFluid = null; raftController._sector = sector; + raftController._acceleration = info?.acceleration ?? 5f; sector.OnOccupantEnterSector += raftController.OnOccupantEnterSector; sector.OnOccupantExitSector += raftController.OnOccupantExitSector; diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index 807aa9d6..4910b958 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -233,6 +233,11 @@ namespace NewHorizons.External.Modules /// Position of the raft /// public MVector3 position; + + /// + /// Acceleration of the raft + /// + [DefaultValue(5f)] public float acceleration = 5f; } [JsonObject] From 58639d41c7c911eaf7ae8130747f7b53a1c279a3 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 8 Oct 2022 21:57:38 +0000 Subject: [PATCH 03/10] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index ddfb16c5..48119472 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -1339,6 +1339,12 @@ "position": { "description": "Position of the raft", "$ref": "#/definitions/MVector3" + }, + "acceleration": { + "type": "number", + "description": "Acceleration of the raft", + "format": "float", + "default": 5.0 } } }, From 99308b2e6a2d919c9e88e82159758ae50fea5a89 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 9 Oct 2022 17:52:20 -0400 Subject: [PATCH 04/10] Add default to summary --- NewHorizons/External/Modules/PropModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index 4910b958..fa81ebf0 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -235,7 +235,7 @@ namespace NewHorizons.External.Modules public MVector3 position; /// - /// Acceleration of the raft + /// Acceleration of the raft. Default acceleration is 5. /// [DefaultValue(5f)] public float acceleration = 5f; } From 5d2dcc8bb55d44fe2decb85c78269f353f214949 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 9 Oct 2022 17:57:57 -0400 Subject: [PATCH 05/10] Change this patch --- NewHorizons/Patches/RaftPatches.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Patches/RaftPatches.cs b/NewHorizons/Patches/RaftPatches.cs index dc0814d8..45786278 100644 --- a/NewHorizons/Patches/RaftPatches.cs +++ b/NewHorizons/Patches/RaftPatches.cs @@ -107,11 +107,16 @@ namespace NewHorizons.Patches [HarmonyPrefix] [HarmonyPatch(typeof(FluidVolume), "GetDepthAtPosition")] - public static bool SphereOceanFluidVolume_GetDepthAtPosition(SphereOceanFluidVolume __instance, ref float __result, Vector3 worldPosition) + public static bool FluidVolume_GetDepthAtPosition(FluidVolume __instance, ref float __result, Vector3 worldPosition) { - Vector3 vector = __instance.transform.InverseTransformPoint(worldPosition); - __result = Mathf.Sqrt(vector.x * vector.x + vector.z * vector.z + vector.y * vector.y) - __instance._radius; - return false; + if (__instance is RadialFluidVolume radialFluidVolume) + { + Vector3 vector = radialFluidVolume.transform.InverseTransformPoint(worldPosition); + __result = Mathf.Sqrt(vector.x * vector.x + vector.z * vector.z + vector.y * vector.y) - radialFluidVolume._radius; + return false; + } + else + return true; } } } From 27c9c4182f9c6ebeac1c540b1550d5a6e68e5ae9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 9 Oct 2022 21:59:50 +0000 Subject: [PATCH 06/10] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 48119472..cbd0b20d 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -1342,7 +1342,7 @@ }, "acceleration": { "type": "number", - "description": "Acceleration of the raft", + "description": "Acceleration of the raft. Default acceleration is 5.", "format": "float", "default": 5.0 } From 84203dd5dfe33d170baece2ec49baccc5c63b3b1 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 9 Oct 2022 18:01:18 -0400 Subject: [PATCH 07/10] Keep it as SphereOceanFluidVolume --- NewHorizons/Patches/RaftPatches.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Patches/RaftPatches.cs b/NewHorizons/Patches/RaftPatches.cs index 45786278..0f180f22 100644 --- a/NewHorizons/Patches/RaftPatches.cs +++ b/NewHorizons/Patches/RaftPatches.cs @@ -109,10 +109,10 @@ namespace NewHorizons.Patches [HarmonyPatch(typeof(FluidVolume), "GetDepthAtPosition")] public static bool FluidVolume_GetDepthAtPosition(FluidVolume __instance, ref float __result, Vector3 worldPosition) { - if (__instance is RadialFluidVolume radialFluidVolume) + if (__instance is SphereOceanFluidVolume sphereOceanFluidVolume) { - Vector3 vector = radialFluidVolume.transform.InverseTransformPoint(worldPosition); - __result = Mathf.Sqrt(vector.x * vector.x + vector.z * vector.z + vector.y * vector.y) - radialFluidVolume._radius; + Vector3 vector = sphereOceanFluidVolume.transform.InverseTransformPoint(worldPosition); + __result = Mathf.Sqrt(vector.x * vector.x + vector.z * vector.z + vector.y * vector.y) - sphereOceanFluidVolume._radius; return false; } else From 723b550b70787ffa0f524c4d323b983a94a45250 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sun, 9 Oct 2022 15:05:20 -0700 Subject: [PATCH 08/10] clean this up slightly --- NewHorizons/Patches/RaftPatches.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Patches/RaftPatches.cs b/NewHorizons/Patches/RaftPatches.cs index 0f180f22..de8dd91d 100644 --- a/NewHorizons/Patches/RaftPatches.cs +++ b/NewHorizons/Patches/RaftPatches.cs @@ -74,17 +74,17 @@ namespace NewHorizons.Patches } [HarmonyReversePatch] - [HarmonyPatch(typeof(AsymmetricFluidDetector), "ManagedFixedUpdate")] + [HarmonyPatch(typeof(AsymmetricFluidDetector), nameof(AsymmetricFluidDetector.ManagedFixedUpdate))] public static void AsymmetricFluidDetector_ManagedFixedUpdate(AsymmetricFluidDetector __instance) { // This is like doing base.FixedUpdate } [HarmonyPrefix] - [HarmonyPatch(typeof(AlignToSurfaceFluidDetector), "ManagedFixedUpdate")] + [HarmonyPatch(typeof(AlignToSurfaceFluidDetector), nameof(AlignToSurfaceFluidDetector.ManagedFixedUpdate))] public static bool AlignToSurfaceFluidDetector_ManagedFixedUpdate(AlignToSurfaceFluidDetector __instance) { - if (!(__instance._alignmentFluid is NHFluidVolume || __instance._alignmentFluid is SphereOceanFluidVolume)) return true; + if (__instance._alignmentFluid is not (NHFluidVolume or SphereOceanFluidVolume)) return true; // Mostly copy pasting from the AlignWithDirection class AsymmetricFluidDetector_ManagedFixedUpdate(__instance); @@ -106,7 +106,7 @@ namespace NewHorizons.Patches } [HarmonyPrefix] - [HarmonyPatch(typeof(FluidVolume), "GetDepthAtPosition")] + [HarmonyPatch(typeof(FluidVolume), nameof(FluidVolume.GetDepthAtPosition))] public static bool FluidVolume_GetDepthAtPosition(FluidVolume __instance, ref float __result, Vector3 worldPosition) { if (__instance is SphereOceanFluidVolume sphereOceanFluidVolume) From fb8b09fb3eaa153caf68d9d5a0bf4e3e0658daf9 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sun, 9 Oct 2022 15:06:49 -0700 Subject: [PATCH 09/10] remove the ? since its just a float --- NewHorizons/Builder/Props/RaftBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Props/RaftBuilder.cs b/NewHorizons/Builder/Props/RaftBuilder.cs index a85c5923..05fe3d2b 100644 --- a/NewHorizons/Builder/Props/RaftBuilder.cs +++ b/NewHorizons/Builder/Props/RaftBuilder.cs @@ -38,7 +38,7 @@ namespace NewHorizons.Builder.Props raftController._riverFluid = null; raftController._sector = sector; - raftController._acceleration = info?.acceleration ?? 5f; + raftController._acceleration = info.acceleration; sector.OnOccupantEnterSector += raftController.OnOccupantEnterSector; sector.OnOccupantExitSector += raftController.OnOccupantExitSector; From e748c49a3f2b6babd0ba4511e6f441f2ebd0cb7b Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sun, 9 Oct 2022 15:14:13 -0700 Subject: [PATCH 10/10] remove NHFluidVolume since we now patch a proper depth function into RadialFluidVolume --- NewHorizons/Builder/Body/WaterBuilder.cs | 3 +-- NewHorizons/Builder/Props/RaftBuilder.cs | 5 ++--- NewHorizons/Components/Volumes/NHFluidVolume.cs | 13 ------------- NewHorizons/Patches/RaftPatches.cs | 16 ++++++---------- 4 files changed, 9 insertions(+), 28 deletions(-) delete mode 100644 NewHorizons/Components/Volumes/NHFluidVolume.cs diff --git a/NewHorizons/Builder/Body/WaterBuilder.cs b/NewHorizons/Builder/Body/WaterBuilder.cs index a05dd63e..6b75af04 100644 --- a/NewHorizons/Builder/Body/WaterBuilder.cs +++ b/NewHorizons/Builder/Body/WaterBuilder.cs @@ -3,7 +3,6 @@ using NewHorizons.Utility; using UnityEngine; using NewHorizons.External.Modules.VariableSize; using Tessellation; -using NewHorizons.Components.Volumes; namespace NewHorizons.Builder.Body { @@ -80,7 +79,7 @@ namespace NewHorizons.Builder.Body var buoyancyTriggerVolume = buoyancyObject.AddComponent(); buoyancyTriggerVolume._owCollider = owCollider; - var fluidVolume = buoyancyObject.AddComponent(); + var fluidVolume = buoyancyObject.AddComponent(); fluidVolume._fluidType = FluidVolume.Type.WATER; fluidVolume._attachedBody = rb; fluidVolume._triggerVolume = buoyancyTriggerVolume; diff --git a/NewHorizons/Builder/Props/RaftBuilder.cs b/NewHorizons/Builder/Props/RaftBuilder.cs index 05fe3d2b..65e54f46 100644 --- a/NewHorizons/Builder/Props/RaftBuilder.cs +++ b/NewHorizons/Builder/Props/RaftBuilder.cs @@ -1,5 +1,4 @@ -using NewHorizons.Components.Volumes; -using NewHorizons.External.Modules; +using NewHorizons.External.Modules; using NewHorizons.Handlers; using NewHorizons.Utility; using UnityEngine; @@ -44,7 +43,7 @@ namespace NewHorizons.Builder.Props // Detectors var fluidDetector = raftObject.transform.Find("Detector_Raft").GetComponent(); - var waterVolume = (FluidVolume)planetGO.GetComponentInChildren() ?? planetGO.GetComponentInChildren(); + var waterVolume = planetGO.GetComponentInChildren(); fluidDetector._alignmentFluid = waterVolume; fluidDetector._buoyancy.checkAgainstWaves = true; diff --git a/NewHorizons/Components/Volumes/NHFluidVolume.cs b/NewHorizons/Components/Volumes/NHFluidVolume.cs deleted file mode 100644 index 3b5a4a00..00000000 --- a/NewHorizons/Components/Volumes/NHFluidVolume.cs +++ /dev/null @@ -1,13 +0,0 @@ -using UnityEngine; -namespace NewHorizons.Components.Volumes -{ - public class NHFluidVolume : RadialFluidVolume - { - public override float GetDepthAtPosition(Vector3 worldPosition) - { - Vector3 vector = transform.InverseTransformPoint(worldPosition); - float dist = Mathf.Sqrt(vector.x * vector.x + vector.z * vector.z + vector.y * vector.y); - return dist - _radius; - } - } -} diff --git a/NewHorizons/Patches/RaftPatches.cs b/NewHorizons/Patches/RaftPatches.cs index de8dd91d..196885c0 100644 --- a/NewHorizons/Patches/RaftPatches.cs +++ b/NewHorizons/Patches/RaftPatches.cs @@ -1,5 +1,4 @@ using HarmonyLib; -using NewHorizons.Components.Volumes; using UnityEngine; namespace NewHorizons.Patches { @@ -84,7 +83,7 @@ namespace NewHorizons.Patches [HarmonyPatch(typeof(AlignToSurfaceFluidDetector), nameof(AlignToSurfaceFluidDetector.ManagedFixedUpdate))] public static bool AlignToSurfaceFluidDetector_ManagedFixedUpdate(AlignToSurfaceFluidDetector __instance) { - if (__instance._alignmentFluid is not (NHFluidVolume or SphereOceanFluidVolume)) return true; + if (__instance._alignmentFluid is not RadialFluidVolume) return true; // Mostly copy pasting from the AlignWithDirection class AsymmetricFluidDetector_ManagedFixedUpdate(__instance); @@ -109,14 +108,11 @@ namespace NewHorizons.Patches [HarmonyPatch(typeof(FluidVolume), nameof(FluidVolume.GetDepthAtPosition))] public static bool FluidVolume_GetDepthAtPosition(FluidVolume __instance, ref float __result, Vector3 worldPosition) { - if (__instance is SphereOceanFluidVolume sphereOceanFluidVolume) - { - Vector3 vector = sphereOceanFluidVolume.transform.InverseTransformPoint(worldPosition); - __result = Mathf.Sqrt(vector.x * vector.x + vector.z * vector.z + vector.y * vector.y) - sphereOceanFluidVolume._radius; - return false; - } - else - return true; + if (__instance is not RadialFluidVolume radialFluidVolume) return true; + + Vector3 vector = radialFluidVolume.transform.InverseTransformPoint(worldPosition); + __result = Mathf.Sqrt(vector.x * vector.x + vector.z * vector.z + vector.y * vector.y) - radialFluidVolume._radius; + return false; } } }