API reference Obsidian.API.Data
ItemAttachments class
Items kept in an attachment, like a player's extra slots for accessories: register an attachment with ItemAttachments.Codec (and ItemAttachments.NetworkCodec to sync it), then reach its slots with ItemAttachments.GetItemAccess, from a menu's MenuSlots or the plugin's own code.
public static class ItemAttachments
In Obsidian.API.
Remarks
The engine knows these attachments hold items. With vanilla's keep_inventory rule off, a player's death drops them where they died, like vanilla drops the inventory, unless the type was registered with copyOnDeath; with the rule on they're kept. Items with the curse of vanishing are destroyed instead of dropped, like vanilla's.
The value is the slots' stacks, empty slots null, as long as the highest slot holding something. A get decodes a detached copy, like any attachment's.
Properties
Codec
public static ComponentCodec<ItemStack[]> Codec { get; }Saves the slots like vanilla's minecraft:container component: a list of the slots holding something, each { slot, item }. Registering an attachment with it makes it an item attachment.
NetworkCodec
public static ComponentNetworkCodec<ItemStack[]> NetworkCodec { get; }Sends the slots to Obsidian clients as a list of optional stacks, like vanilla's container contents. A client mod registers the same type with ItemAttachments.Codec and this to read them.
Methods
GetItemAccess(IAttachmentHolder, AttachmentType<ItemStack[]>, int)
public static IItemAccess GetItemAccess(this IAttachmentHolder holder, AttachmentType<ItemStack[]> type, int slotCount);Access to the first slotCount slots of holder's item attachment, which a menu shows with new MenuSlot(access, index). Each call reads or changes the saved value in one step, so the attachment stays the only copy of the items: it's saved, synced and kept or dropped at a death as it is. A change raises AttachmentType.Changed.
Remarks
Slots take any item, a stack up to its own size; give a menu slot its rules (MenuSlot.MayPlace, MenuSlot.MaxStackSize). Once the plugin unloads, or the holder is retired (a player who left), the access takes and gives nothing. It never waits, so a menu may call it holding its locks.
Fields
MaxSlots
public const int MaxSlots = 256;The most slots an item attachment holds, like vanilla's minecraft:container component.