mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Fix crash on custom item IDs from Forge servers (#1233)
* Fix unknown item id cause crashes for handling non-vanilla item (i.e. forge item) * Add Unknown item type and use ItemType.Unknown for unknown items Co-authored-by: ORelio <ORelio@users.noreply.github.com>
This commit is contained in:
parent
70c991cd30
commit
b648e4f86d
2 changed files with 9 additions and 3 deletions
|
|
@ -15,17 +15,22 @@ namespace MinecraftClient.Inventory.ItemPalettes
|
|||
// Index reverse mappings for use in ToId()
|
||||
foreach (KeyValuePair<int, ItemType> entry in GetDict())
|
||||
DictReverse.Add(entry.Value, entry.Key);
|
||||
|
||||
DictReverse[ItemType.Unknown] = -2;
|
||||
DictReverse[ItemType.Null] = -1;
|
||||
}
|
||||
|
||||
public ItemType FromId(int id)
|
||||
{
|
||||
// Unknown item types may appear of Forge servers for custom items
|
||||
if (!GetDict().ContainsKey(id))
|
||||
return ItemType.Unknown;
|
||||
|
||||
return GetDict()[id];
|
||||
}
|
||||
|
||||
public int ToId(ItemType itemType)
|
||||
{
|
||||
if (itemType == ItemType.Null)
|
||||
return -1;
|
||||
return DictReverse[itemType];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ namespace MinecraftClient.Inventory
|
|||
/// </summary>
|
||||
public enum ItemType
|
||||
{
|
||||
Null = -1, // Unspecified item type
|
||||
Unknown = -2, // Unsupported item type (Forge mod custom item...)
|
||||
Null = -1, // Unspecified item type (Used in the network protocol)
|
||||
|
||||
AcaciaBoat,
|
||||
AcaciaButton,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue