Skip to content

API reference Obsidian.API.Utilities

Extensions class

public static class Extensions

In Obsidian.API.

Methods

public static string Capitalize(this string value);public static bool EqualsIgnoreCase(this string a, string b);public static ChatMessage FromNbt(this ChatMessage chatMessage, NbtCompound root);

GetDescription(Enum)

public static string GetDescription(this Enum value);

Remarks

This method is not and shouldn't be used in performance-critical sections. Source: https://stackoverflow.com/a/1415187

public static int GetIndexFromArray(this string[] array, string value);public static int GetIndexFromJaggedArray(this int[][] array, int[] value);public static List<string> GetStateValues(this int[] indexes, Dictionary<string, string[]> valueStores);public static bool IsNullOrAir(this ItemStack item);public static bool IsNullOrEmpty(this string value);public static bool IsNullOrWhitespace(this string value);

ItemFromNbt(NbtCompound)

public static ItemStack ItemFromNbt(this NbtCompound item);

Reads a stack saved like vanilla's ItemStack.CODEC, or null when the compound is missing or its item is unknown. Components Obsidian doesn't model are kept in ItemStack.UnmodeledComponents.

Remarks

Stacks Obsidian saved before it used vanilla's codec, with a byte Count and a tag holding Damage and Unbreakable, are read too.

public static ClickComponent ToClickComponent(this NbtCompound compound);public static EnchantmentType ToEnchantType(this string source);public static HoverComponent ToHoverComponent(this NbtCompound compound);public static IList<int> ToList(this Vector value);public static NbtCompound ToNbt(this ChatMessage chatMessage, string name = "");public static NbtCompound ToNbt(this ClickComponent clickComponent);public static NbtCompound ToNbt(this HoverComponent hoverComponent);

ToNbt(ItemStack, string)

public static NbtCompound ToNbt(this ItemStack item, string name = "");

Saves a stack like vanilla's ItemStack.CODEC: its id, count and the components set on it (its patch).

Remarks

Modeled persistent components and plugins' components are saved in vanilla's patch format. Loaded NBT beyond the models is retained. Components vanilla doesn't persist are skipped, as vanilla's codec skips them, and so is a component received only from the network that has no saved codec yet: losing that one component is better than failing the whole chunk or player save it's part of (see docs/known-gaps/item-components-without-a-saved-codec.md).

public static string ToPascalCase(this string snakeCase);public static string ToSnakeCase(this string str);public static Vector ToVector(this IList<int> value);

TrimResourceTag(string, bool)

public static string TrimResourceTag(this string value, bool keepUnderscores = false);

Trims resource tag from the start and removes '_' characters.

public static void WriteChatMessage(this INbtWriter writer, ChatMessage chatMessage);public static void WriteNbtCompound(this INetStreamWriter writer, NbtCompound compound);

On this page