From ca3c85c8d9bf430b1e4c853a1d0557376a3339e3 Mon Sep 17 00:00:00 2001 From: Tides Date: Tue, 17 Dec 2024 17:37:36 -0600 Subject: [PATCH] Fix enchantments --- Obsidian.API/Inventory/ItemMeta.cs | 4 +-- Obsidian.API/Inventory/ItemMetaBuilder.cs | 38 ++++++++++++++++------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Obsidian.API/Inventory/ItemMeta.cs b/Obsidian.API/Inventory/ItemMeta.cs index 09fb394c..f54e30eb 100644 --- a/Obsidian.API/Inventory/ItemMeta.cs +++ b/Obsidian.API/Inventory/ItemMeta.cs @@ -12,8 +12,8 @@ public struct ItemMeta : IEquatable public bool Unbreakable { get; internal set; } - public IReadOnlyDictionary Enchantments { get; internal set; } - public IReadOnlyDictionary StoredEnchantments { get; internal set; } + public IReadOnlyDictionary Enchantments { get; internal set; } + public IReadOnlyDictionary StoredEnchantments { get; internal set; } public IReadOnlyList CanDestroy { get; internal set; } diff --git a/Obsidian.API/Inventory/ItemMetaBuilder.cs b/Obsidian.API/Inventory/ItemMetaBuilder.cs index 15c692ff..2e04e437 100644 --- a/Obsidian.API/Inventory/ItemMetaBuilder.cs +++ b/Obsidian.API/Inventory/ItemMetaBuilder.cs @@ -11,15 +11,15 @@ public class ItemMetaBuilder public bool Unbreakable { get; internal set; } - public IReadOnlyDictionary Enchantments { get; } - public IReadOnlyDictionary StoredEnchantments { get; } + public IReadOnlyDictionary Enchantments { get; } + public IReadOnlyDictionary StoredEnchantments { get; } public IReadOnlyList CanDestroy { get; } public IReadOnlyList Lore { get; } - private readonly Dictionary enchantments = []; - private readonly Dictionary storedEnchantments = []; + private readonly Dictionary enchantments = []; + private readonly Dictionary storedEnchantments = []; private readonly List canDestroy = []; @@ -27,8 +27,8 @@ public class ItemMetaBuilder public ItemMetaBuilder() { - Enchantments = new ReadOnlyDictionary(enchantments); - StoredEnchantments = new ReadOnlyDictionary(storedEnchantments); + Enchantments = new ReadOnlyDictionary(enchantments); + StoredEnchantments = new ReadOnlyDictionary(storedEnchantments); CanDestroy = new ReadOnlyCollection(canDestroy); Lore = new ReadOnlyCollection(lore); } @@ -91,9 +91,10 @@ public ItemMetaBuilder IsUnbreakable(bool unbreakable) public ItemMetaBuilder AddEnchantment(EnchantmentType type, int level) { - enchantments.Add(type, new Enchantment + var enchantmentId = type.GetHashCode(); + enchantments.Add(enchantmentId, new Enchantment { - Type = type, + Id = enchantmentId, Level = level }); @@ -102,9 +103,22 @@ public ItemMetaBuilder AddEnchantment(EnchantmentType type, int level) public ItemMetaBuilder AddStoredEnchantment(EnchantmentType type, int level) { - storedEnchantments.Add(type, new Enchantment + var enchantmentId = type.GetHashCode(); + + storedEnchantments.Add(enchantmentId, new Enchantment + { + Id = enchantmentId, + Level = level + }); + + return this; + } + + public ItemMetaBuilder AddStoredEnchantment(int id, int level) + { + storedEnchantments.Add(id, new Enchantment { - Type = type, + Id = id, Level = level }); @@ -121,8 +135,8 @@ public ItemMeta Build() Durability = Durability, Unbreakable = Unbreakable, - Enchantments = new ReadOnlyDictionary(new Dictionary(enchantments)), - StoredEnchantments = new ReadOnlyDictionary(new Dictionary(storedEnchantments)), + Enchantments = new ReadOnlyDictionary(new Dictionary(enchantments)), + StoredEnchantments = new ReadOnlyDictionary(new Dictionary(storedEnchantments)), CanDestroy = new ReadOnlyCollection(new List(canDestroy)) };