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; + } + } + } +}