using System;
using System.Collections.Generic;
namespace MinecraftClient.Mapping.BlockPalettes
{
public abstract class BlockPalette
{
///
/// Get mapping dictionary. Must be overriden with proper implementation.
///
/// Palette dictionary
protected abstract Dictionary GetDict();
///
/// Get material from block ID or block state ID
///
/// Block ID (up to MC 1.12) or block state (MC 1.13+)
/// Material corresponding to the specified ID
public Material FromId(int id)
{
Dictionary materials = GetDict();
if (materials.ContainsKey(id))
return materials[id];
return Material.Air;
}
///
/// Get block-state properties for a modern block state ID.
///
/// Raw block state ID.
/// Block-state property names and values, or an empty map when unavailable.
public IReadOnlyDictionary GetStateProperties(int stateId)
{
BlockStateDefinition[] definitions = GetStateDefinitions();
int low = 0;
int high = definitions.Length - 1;
while (low <= high)
{
int middle = low + ((high - low) / 2);
BlockStateDefinition definition = definitions[middle];
if (stateId < definition.FirstStateId)
{
high = middle - 1;
}
else if (stateId > definition.LastStateId)
{
low = middle + 1;
}
else
{
return definition.GetProperties(stateId);
}
}
return BlockStateDefinition.EmptyProperties;
}
///
/// Get compact block-state definitions sorted by their first state ID.
///
protected virtual BlockStateDefinition[] GetStateDefinitions()
{
return Array.Empty();
}
///
/// Returns TRUE if block ID uses old metadata encoding with ID and Meta inside one ushort
/// Only Palette112 should override this.
///
public virtual bool IdHasMetadata
{
get
{
return false;
}
}
}
}