From 4ac7dde0a4853f0d5a8fbe8d4b2b157212d00835 Mon Sep 17 00:00:00 2001 From: MrPurple6411 Date: Sun, 10 Dec 2023 01:43:41 -0700 Subject: [PATCH 1/2] Fix CC3 1.0.0.2 bug. Fix: Correct Invalid Cast exception when trying to remove a node from a custom fabricator. --- Nautilus/Crafting/ModCraftTreeLinkingNode.cs | 13 ++++++------- Nautilus/Handlers/CraftTreeHandler.cs | 8 +------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/Nautilus/Crafting/ModCraftTreeLinkingNode.cs b/Nautilus/Crafting/ModCraftTreeLinkingNode.cs index d1c84bb2..32e9700a 100644 --- a/Nautilus/Crafting/ModCraftTreeLinkingNode.cs +++ b/Nautilus/Crafting/ModCraftTreeLinkingNode.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Nautilus.Handlers; +using Nautilus.Utility; using UnityEngine; using UnityEngine.Assertions; @@ -83,16 +84,15 @@ public ModCraftTreeTab AddTabNode(string nameID) /// public ModCraftTreeTab GetTabNode(string nameID) { - foreach (ModCraftTreeTab node in ChildNodes) + foreach (var node in ChildNodes) { if (node == null) { continue; } - if (node.Name == nameID && node.Action == TreeAction.Expand) + if (node.Name == nameID && node.Action == TreeAction.Expand && node is ModCraftTreeTab tab) { - ModCraftTreeTab tab = node; return tab; } } @@ -107,16 +107,15 @@ public ModCraftTreeTab GetTabNode(string nameID) /// public ModCraftTreeCraft GetCraftingNode(TechType techType) { - foreach (ModCraftTreeNode node in ChildNodes) + foreach (var node in ChildNodes) { if (node == null) { continue; } - if (node.TechType == techType && node.Action == TreeAction.Craft) + if (node.TechType == techType && node.Action == TreeAction.Craft && node is ModCraftTreeCraft craftNode) { - ModCraftTreeCraft craftNode = (ModCraftTreeCraft)node; return craftNode; } } @@ -131,7 +130,7 @@ public ModCraftTreeCraft GetCraftingNode(TechType techType) /// public ModCraftTreeNode GetNode(string nameID) { - foreach (ModCraftTreeNode node in ChildNodes) + foreach (var node in ChildNodes) { if (node == null) { diff --git a/Nautilus/Handlers/CraftTreeHandler.cs b/Nautilus/Handlers/CraftTreeHandler.cs index c16a6ca4..8ffa5076 100644 --- a/Nautilus/Handlers/CraftTreeHandler.cs +++ b/Nautilus/Handlers/CraftTreeHandler.cs @@ -190,13 +190,7 @@ public static void RemoveNode(CraftTree.Type craftTree, params string[] stepsToN { if(CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root)) { - var tab = root.GetTabNode(stepsToNode); - if(tab == null) - { - root.GetNode(stepsToNode)?.RemoveNode(); - return; - } - tab.RemoveNode(); + root.GetNode(stepsToNode)?.RemoveNode(); return; } CraftTreePatcher.NodesToRemove.Add(new Node(stepsToNode, craftTree)); From 7b96ee96eabc052a600800c3f898f884e77a90c0 Mon Sep 17 00:00:00 2001 From: MrPurple6411 Date: Sun, 10 Dec 2023 01:47:11 -0700 Subject: [PATCH 2/2] Fix formatting and misplaced usings --- Nautilus/Handlers/CraftTreeHandler.cs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Nautilus/Handlers/CraftTreeHandler.cs b/Nautilus/Handlers/CraftTreeHandler.cs index 8ffa5076..e086faf7 100644 --- a/Nautilus/Handlers/CraftTreeHandler.cs +++ b/Nautilus/Handlers/CraftTreeHandler.cs @@ -1,14 +1,13 @@ +namespace Nautilus.Handlers; + using System.Linq; using Nautilus.Crafting; using Nautilus.Patchers; -using Nautilus.Utility; - -namespace Nautilus.Handlers; /// /// A handler class for creating and modifying crafting trees. /// -public static class CraftTreeHandler +public static class CraftTreeHandler { /// /// Adds a new crafting node to the root of the specified crafting tree, at the provided tab location. @@ -23,7 +22,7 @@ public static class CraftTreeHandler /// public static void AddCraftingNode(CraftTree.Type craftTree, TechType craftingItem, params string[] stepsToTab) { - if(CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root)) + if (CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root)) { root.AddCraftNode(craftingItem, stepsToTab.LastOrDefault()); return; @@ -40,7 +39,7 @@ public static void AddCraftingNode(CraftTree.Type craftTree, TechType craftingIt public static void AddCraftingNode(CraftTree.Type craftTree, TechType craftingItem) { - if(CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root)) + if (CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root)) { root.AddCraftNode(craftingItem); return; @@ -58,7 +57,7 @@ public static void AddCraftingNode(CraftTree.Type craftTree, TechType craftingIt /// The sprite of the tab. public static void AddTabNode(CraftTree.Type craftTree, string name, string displayName, Atlas.Sprite sprite) { - if(CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root)) + if (CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root)) { root.AddTabNode(name, displayName, sprite); return; @@ -76,7 +75,7 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp public static void AddTabNode(CraftTree.Type craftTree, string name, string displayName, UnityEngine.Sprite sprite) { - if(CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root)) + if (CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root)) { root.AddTabNode(name, displayName, sprite); return; @@ -99,7 +98,7 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp /// public static void AddTabNode(CraftTree.Type craftTree, string name, string displayName, Atlas.Sprite sprite, params string[] stepsToTab) { - if(CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root)) + if (CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root)) { root.AddTabNode(name, displayName, sprite, "English", stepsToTab.LastOrDefault()); return; @@ -122,7 +121,7 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp /// public static void AddTabNode(CraftTree.Type craftTree, string name, string displayName, UnityEngine.Sprite sprite, params string[] stepsToTab) { - if(CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root)) + if (CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root)) { root.AddTabNode(name, displayName, sprite, "English", stepsToTab.LastOrDefault()); return; @@ -188,7 +187,7 @@ public static void AddTabNode(CraftTree.Type craftTree, string name, string disp public static void RemoveNode(CraftTree.Type craftTree, params string[] stepsToNode) { - if(CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root)) + if (CraftTreePatcher.CustomTrees.TryGetValue(craftTree, out var root)) { root.GetNode(stepsToNode)?.RemoveNode(); return;