Allow comet tails on vanilla bodies (#1069)

Made this because I tried to add a comet tail to ember twin but it kept
saying `Comet CaveTwin_Body does not orbit anything. That makes no
sense` because Orbit.primaryBody didn't have anything.
So now it grabs the primary body from the astro object but also takes
into account Orbit.primaryBody

![image](https://github.com/user-attachments/assets/bf79b4cb-b79c-4adc-af32-c0b09bf11a72)


## Bug fixes

- Fixed a bug that didn't allow comet tails to be made on unmoved
vanilla planets/moons.
This commit is contained in:
xen-42 2025-03-15 15:09:11 -04:00 committed by GitHub
commit a4066db80b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 21 additions and 10 deletions

View File

@ -60,14 +60,22 @@ namespace NewHorizons.Builder.Body
}
}
public static void Make(GameObject planetGO, Sector sector, CometTailModule cometTailModule, PlanetConfig config)
public static void Make(GameObject planetGO, Sector sector, CometTailModule cometTailModule, PlanetConfig config, AstroObject ao)
{
if (config.Orbit.primaryBody == null)
var primaryBody = ao.GetPrimaryBody();
if (!string.IsNullOrEmpty(config.Orbit.primaryBody)) primaryBody = AstroObjectLocator.GetAstroObject(config.Orbit.primaryBody);
if (primaryBody == null)
{
NHLogger.LogError($"Comet {planetGO.name} does not orbit anything. That makes no sense");
return;
}
if (string.IsNullOrEmpty(cometTailModule.primaryBody))
cometTailModule.primaryBody = !string.IsNullOrEmpty(config.Orbit.primaryBody) ? config.Orbit.primaryBody
: primaryBody.GetKey();
var rootObj = new GameObject("CometRoot");
rootObj.SetActive(false);
rootObj.transform.parent = sector?.transform ?? planetGO.transform;
@ -79,13 +87,11 @@ namespace NewHorizons.Builder.Body
if (cometTailModule.rotationOverride != null) controller.SetRotationOverride(cometTailModule.rotationOverride);
if (string.IsNullOrEmpty(cometTailModule.primaryBody)) cometTailModule.primaryBody = config.Orbit.primaryBody;
Delay.FireOnNextUpdate(() =>
{
controller.SetPrimaryBody(
AstroObjectLocator.GetAstroObject(cometTailModule.primaryBody).transform,
AstroObjectLocator.GetAstroObject(config.Orbit.primaryBody).GetAttachedOWRigidbody()
AstroObjectLocator.GetAstroObject(cometTailModule.primaryBody).transform,
primaryBody.GetAttachedOWRigidbody()
);
});

View File

@ -203,7 +203,7 @@ namespace NewHorizons.Builder.Body
if (body.Config.CometTail != null)
{
CometTailBuilder.Make(proxy, null, body.Config.CometTail, body.Config);
CometTailBuilder.Make(proxy, null, body.Config.CometTail, body.Config, planetGO.GetComponent<AstroObject>());
}
if (body.Config.Props?.proxyDetails != null)

View File

@ -657,7 +657,7 @@ namespace NewHorizons.Handlers
if (body.Config.CometTail != null)
{
CometTailBuilder.Make(go, sector, body.Config.CometTail, body.Config);
CometTailBuilder.Make(go, sector, body.Config.CometTail, body.Config, go.GetComponent<AstroObject>());
}
if (body.Config.Lava != null)

View File

@ -445,6 +445,11 @@ namespace NewHorizons.Utility
return globalMusicController._endTimesSource.clip.length;
}
public static string GetKey(this AstroObject ao)
{
return ao._name == AstroObject.Name.CustomString ? ao.GetCustomName() : ao._name.ToString();
}
public static CodeMatcher LogInstructions(this CodeMatcher matcher, string prefix)
{
matcher.InstructionEnumeration().LogInstructions(prefix);

View File

@ -65,7 +65,7 @@ namespace NewHorizons.Utility.OuterWilds
public static void RegisterCustomAstroObject(AstroObject ao)
{
var key = ao._name == AstroObject.Name.CustomString ? ao.GetCustomName() : ao._name.ToString();
var key = ao.GetKey();
if (_customAstroObjectDictionary.ContainsKey(key))
{
@ -81,7 +81,7 @@ namespace NewHorizons.Utility.OuterWilds
public static void DeregisterCustomAstroObject(AstroObject ao)
{
var key = ao._name == AstroObject.Name.CustomString ? ao.GetCustomName() : ao._name.ToString();
var key = ao.GetKey();
_customAstroObjectDictionary.Remove(key);
}