Skip to content

Commit

Permalink
better item detection of nothing/air
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyGalbreath committed Oct 28, 2023
1 parent c44c37f commit 18422c1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/ChatLinkItemMod.cs
@@ -1,6 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.RegularExpressions;
using Vintagestory.API.Common;
using Vintagestory.API.Config;
using Vintagestory.API.Datastructures;
using Vintagestory.API.Server;
using Vintagestory.GameContent;
Expand Down Expand Up @@ -36,14 +37,14 @@ public class ChatLinkItemMod : ModSystem {

int slotNum = sender.InventoryManager.ActiveHotbarSlotNumber;
ItemStack itemStack = sender.InventoryManager.GetHotbarItemstack(slotNum);
string pageCode = GuiHandbookItemStackPage.PageCodeForStack(itemStack);
string pageCode = itemStack == null ? "" : GuiHandbookItemStackPage.PageCodeForStack(itemStack);

if (pageCode is not { Length: > 0 }) {
return;
}
string replacement = $"[{(pageCode is { Length: > 0 } ?
$"<a href=\"handbook://{pageCode}\">{itemStack!.GetName()}</a>" :
itemStack?.GetName() ?? Lang.Get("game:nothing"))}]";

foreach (Match match in matches) {
message = message.Replace(match.Value, $"<a href=\"handbook://{pageCode}\">{itemStack.GetName()}</a>");
message = message.Replace(match.Value, replacement);
}
}
}

0 comments on commit 18422c1

Please sign in to comment.