Skip to content

[XItemStack] - Add functionality to edit ItemStack / ItemMeta #337

@bestlinuxgamers

Description

@bestlinuxgamers

Description

To modify ItemStacks independently of the Minecraft version, it is necessary to reimplement the deserialization functionality of the XItemStack class. This often results in "ItemBuilder"s that either fail to support all features or do not work across most versions. However, the required code already kinda exists - it just cannot be directly used for this purpose.

I think diversifying the (de)serialization logic of XItemStack would be a great idea. Instead of storing an ItemStack directly in a YAML-config, it should be stored within a Java object, which can then be serialized into and deserialized from YAML. But can also be created from a Bukkit-ItemStack and create a Bukkit-ItemStack (with its properties). This approach would also provide greater flexibility for potential new serialization formats such as Gson/JSON. If we would add functionality for modifying the attributes of this intermediary object, we would essentially get the perfect ItemBuilder.

Of course I know that this would be a significant change, requiring a complete restructuring of the XItemStack code. However, I believe this functionality would be universally useful for almost every Minecraft developer.

I would be willing to implement these changes myself, but I first wanted to check for interest and see if such a modification would even be accepted.

If so, I would like to discuss the concrete implementation of this. I have thought of two possible implementation approaches:

  1. The attributes of an ItemStack are stored as plain global variables. Maybe wrapped with Optional<> to identify if an attribute is set or uninitialized. While values for specific child classes of ItemMeta would have their own XItemMeta class to store, load, apply all relevant data (or ItemMeta-specific attributes are just being saved to the global variables of XItemStack too).
    (pros: Simple to implement, minimal overhead)
    (cons: Might become difficult to manage, potential clutter)

  2. Each attribute receives its own class, providing two functions: void from(ItemStack item) and void to(ItemStack item). The XItemStack would then consist of a list of these objects, each responsible for storing the necessary values for a specific attribute.
    (pros: Easier to extend/edit with new Mc behaviour, clean separation of concerns)
    (cons: Potential performance overhead, more complex)

Would love to hear your thoughts on this!

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions