Skip to content

feat: Alternative to ItemStack for displaying menu items in an immutable way #19

@0ffz

Description

@0ffz

Compose benefits greatly from immutable structures (skipping recomposition), but Bukkit's ItemStack type that is used to display items in inventories is fundamentally mutable. There are a few potential alternatives to this I can think of, try to decide on the best and implement it:

Immutable itemstack class

  • We can reuse SerializableItemStack in Idofront, perhaps with a typealias, and mark it with a compose immutable annotation
  • Most of the work is done for us, we just convert to a normal ItemStack in the Item composable before rendering.
  • Downsides are the same as any other data class, copy chains when trying to edit small parts of the itemstack. We can theoretically build helpers for this into Idofront but don't currently have many use-cases like this

Modifiers

  • Create modifiers for different data components an item might have, ex. Modifier.itemName("something").lore("a", "b", "c").unbreakable()...
  • This is likely the more native compose way of doing things, modifiers can be combined and cached within compose's existing systems
  • Theoretically more efficient once we switch to android's newer style Modifier classes, since we can modify an underlying ItemStack on recomposition without needing to create an entirely new class each time
  • Downsides are much manual work to implement each modifier, more work to update

Extra parameters on the Item composable

  • Simlar to compose's parameters on Text for styling
  • Can be used in conjunction with Modifiers, i.e. the parameters just apply modifiers under the hood for usability, or separately until we work out this system
  • Like Modifiers, requires us to manually support all attributes we want to modify

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Default

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions