RacesOfValheim/JotunnModStub/Trenta/TrentaVisuals.cs
Ferdinando d0ed92c553 feat(trenta): add the Trenta race
A vegan, tree-born race unlocking new perks per boss defeated: skin/hair
tint, blocked non-vegan food, awakened seed foods after Eikthyr, a mob
hostility list, Photosynthesis, elemental resistances, Purple Rain after
the Elder, swim/poison/wet immunity after Bonemass, Last Stand and Thorns
after Moder, a Homecoming Portal after Yagluth, Hornet's Nest after the
Queen, and Muspell (a half-size Elder transformation with Stomp/Spike
attacks) after Fader.

Also fixes RaceScale never listing Trenta as self-sizing, which let a
shared Player.Update postfix fight Muspell's own scale changes every
frame.
2026-08-04 20:58:01 +02:00

53 lines
2.1 KiB
C#

using UnityEngine;
namespace RacesOfValheim
{
/// <summary>
/// The Trenta's looks: body scale, skin tint, and whatever cosmetic parts the race wears.
///
/// Everything here runs for local and remote players alike, which is why it takes a Player
/// rather than reading Player.m_localPlayer.
/// </summary>
public static class TrentaVisuals
{
/// <summary>
/// Reads the race off the ZDO so remote players render correctly, falling back to
/// m_customData for the main-menu preview which has no ZNetView.
/// </summary>
public static string GetPlayerRace(Player player)
{
if (player == null) return "Human";
ZNetView nview = player.GetComponent<ZNetView>();
if (nview != null && nview.IsValid())
{
string race = nview.GetZDO().GetString("RacesOfValheim_Race", "");
if (!string.IsNullOrEmpty(race)) return race;
}
if (player.m_customData != null && player.m_customData.TryGetValue("Race", out string custom))
{
return custom;
}
return "Human";
}
public static bool IsTrentaPlayer(Player player)
{
return GetPlayerRace(player) == TrentaConfig.RaceId;
}
// TODO: the rest of the cosmetic work. Skin and hair/beard tint are already handled by
// Trenta_VisEquipment_UpdateColors_Patch in TrentaPatches.cs.
//
// Body scale goes on the player's "Visual" child, not the root transform - scaling the
// root drags the collider and the camera pivot with it. RaceScale owns the list of races
// that resize, so the Trenta has to be added there rather than fighting it per-frame.
//
// Extra meshes (bark, foliage) are hung off a bone of the player's rig and hidden by
// collapsing every unwanted bone to zero scale - a creature prefab's mesh usually ships
// with Read/Write disabled and cannot be carved at runtime. DvergarVisuals.ApplyHood is
// the worked example.
}
}