fix(build): the mod's stations appear under Crafting in Valheim 1.0's build menu
Valheim 1.0 lists pieces by Piece.m_usage tags. Jotunn sets only the old category, so a cloned piece kept its source's tags: the Crystal Golem and the Bound Sentry, cloned from guard_stone, landed under Decorations. A postfix on PieceManager.AddPiece now sets the tag from the category for every Hammer piece of this mod. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
83bade65cb
commit
2c5079bf8c
1 changed files with 42 additions and 0 deletions
42
JotunnModStub/PieceUsageTags.cs
Normal file
42
JotunnModStub/PieceUsageTags.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
using HarmonyLib;
|
||||
using Jotunn.Configs;
|
||||
using Jotunn.Entities;
|
||||
using Jotunn.Managers;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// Puts every Hammer piece of this mod under the right entry of Valheim 1.0's build menu.
|
||||
///
|
||||
/// The 1.0 menu lists pieces by Piece.m_usage, a set of tags (Crafting, Decor, Defense...), and
|
||||
/// no longer by the old m_category alone. Jotunn's PieceConfig.Category still sets m_category and
|
||||
/// leaves m_usage untouched, so a cloned piece keeps the tags of whatever it was cloned from. The
|
||||
/// Crystal Golem and the Bound Sentry are cloned from guard_stone, a decoration, and turned up
|
||||
/// under Decorations while every other race station sat under Crafting only because their own
|
||||
/// source pieces happened to be crafting ones.
|
||||
///
|
||||
/// One patch rather than a line at each of the eighteen registrations: every piece goes through
|
||||
/// PieceManager.AddPiece, and Jotunn has already applied the config's category by then, so the
|
||||
/// tag is read off that. Other mods' pieces and the cultivator's are left alone.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(PieceManager), nameof(PieceManager.AddPiece))]
|
||||
public static class PieceUsageTags
|
||||
{
|
||||
public static void Postfix(CustomPiece customPiece)
|
||||
{
|
||||
if (customPiece?.Piece == null || customPiece.SourceMod == null) return;
|
||||
if (customPiece.SourceMod.GUID != RacesOfValheim.PluginGUID) return;
|
||||
if (customPiece.PieceTable != PieceTables.Hammer) return;
|
||||
|
||||
switch (customPiece.Piece.m_category)
|
||||
{
|
||||
case Piece.PieceCategory.Crafting:
|
||||
customPiece.Piece.m_usage = Piece.UsageTagFlags.Crafting;
|
||||
break;
|
||||
case Piece.PieceCategory.Misc:
|
||||
customPiece.Piece.m_usage = Piece.UsageTagFlags.Misc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue