From 2c5079bf8ce7b24690013d2e3d3110648d070c61 Mon Sep 17 00:00:00 2001 From: kanym Date: Mon, 28 Sep 2026 15:06:22 +0200 Subject: [PATCH] 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 --- JotunnModStub/PieceUsageTags.cs | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 JotunnModStub/PieceUsageTags.cs diff --git a/JotunnModStub/PieceUsageTags.cs b/JotunnModStub/PieceUsageTags.cs new file mode 100644 index 0000000..d72d926 --- /dev/null +++ b/JotunnModStub/PieceUsageTags.cs @@ -0,0 +1,42 @@ +using HarmonyLib; +using Jotunn.Configs; +using Jotunn.Entities; +using Jotunn.Managers; + +namespace RacesOfValheim +{ + /// + /// 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. + /// + [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; + } + } + } +}