mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
* 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>
37 lines
1 KiB
C#
37 lines
1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace MinecraftClient.Inventory.ItemPalettes
|
|
{
|
|
public abstract class ItemPalette
|
|
{
|
|
protected abstract Dictionary<int, ItemType> GetDict();
|
|
private readonly Dictionary<ItemType, int> DictReverse = new Dictionary<ItemType, int>();
|
|
|
|
public ItemPalette()
|
|
{
|
|
// 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)
|
|
{
|
|
return DictReverse[itemType];
|
|
}
|
|
}
|
|
}
|