2020-08-17 23:08:50 +08:00
|
|
|
|
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);
|
2020-08-25 04:38:08 +08:00
|
|
|
|
|
2020-09-13 16:33:25 +02:00
|
|
|
|
// Hardcoded placeholder types for internal and network use
|
|
|
|
|
|
DictReverse[ItemType.Unknown] = (int)ItemType.Unknown;
|
|
|
|
|
|
DictReverse[ItemType.Null] = (int)ItemType.Null;
|
2020-08-17 23:08:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ItemType FromId(int id)
|
|
|
|
|
|
{
|
2020-09-13 16:33:25 +02:00
|
|
|
|
// Unknown item types may appear on Forge servers for custom items
|
2020-08-25 04:38:08 +08:00
|
|
|
|
if (!GetDict().ContainsKey(id))
|
|
|
|
|
|
return ItemType.Unknown;
|
|
|
|
|
|
|
2020-08-17 23:08:50 +08:00
|
|
|
|
return GetDict()[id];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int ToId(ItemType itemType)
|
|
|
|
|
|
{
|
|
|
|
|
|
return DictReverse[itemType];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|