Skip to content

Commit

Permalink
Fix items can't be picked up #4
Browse files Browse the repository at this point in the history
  • Loading branch information
t0stiman committed Mar 13, 2024
1 parent 637680f commit 65400fc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions src/Patches/ItemBase_Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Linq;
using DV.CabControls;
using DV.CabControls.Spec;
using HarmonyLib;
using UnityEngine;

namespace custom_item_mod.Patches;

[HarmonyPatch(typeof(ItemBase))]
[HarmonyPatch(nameof(ItemBase.Awake))]
public class ItemBase_Patch
{
private static void Prefix(ref ItemBase __instance)
{
var inventoryItemSpec = __instance.GetComponent<InventoryItemSpec>();
if (inventoryItemSpec is null)
{
Main.Error($"{nameof(ItemBase_Patch)}: inventoryItemSpec is null");
return;
}

//custom items only
if (!inventoryItemSpec.localizationKeyName.StartsWith(Main.MyModEntry.Info.Id))
{
return;
}

var itemComponent = __instance.GetComponent<Item>();
if (itemComponent.colliderGameObjects.Length == 0)
{
itemComponent.colliderGameObjects = __instance.gameObject.GetComponentsInChildren<Collider>()
.Select(collider => collider.gameObject).ToArray();
}
}
}
2 changes: 1 addition & 1 deletion src/Patches/LocalizationManager_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class LocalizationManager_GetTranslation_Patch
private static bool Prefix(ref string __result, string Term)
{
if (!Term.StartsWith(Main.MyModEntry.Info.Id)) {
return true;
return true; // execute original function
}

foreach (var item in ItemModsFinder.CustomItems)
Expand Down

0 comments on commit 65400fc

Please sign in to comment.