API Request - Fluent builders for meta data

It might be a nicer, and more developer friendly to make fluent builders to allow us to append extra data & properties to items or blocks (which presumably can be inherited from attribute interfaces somehow or another). If you don’t know what I mean by fluent builders, here’s a link I came across when looking at the Fanciful chat formatting library. As you can probably tell from the linked library, it uses fluent builders to compile effects for chat formatting. Similarly, I personally think it’d be nice if we could add enchantments to items, effects to fireworks, potentially even raw NBT data via fluent builders. I’m not the most experience java developer by far, so I’m not sure if this is a wise decision or even remotely plausible, but from what I’ve seem from Fanciful, it can be a more pleasant way to work. I’m not aware of any practices that say it’s a bad thing at least. This is probably going to end terribly, but I’ll try to add a small code excerpt as to what that may look like

// Sorry for the Bukkit-like code, but it should hopefully get my point across
ItemStack is = new ItemStack(Material.DIAMOND_SWORD, 1);
is.addEnchant(Enchantment.DAMAGE_ALL, 1, true).addEnchant(Enchantment.KNOCKBACK, 2, true);

Although I understand the result of the returns of the addEnchant() in Bukkit is boolean to determine whether the enchant is applied, so I guess there may be more important uses for returns. Just thinking fluent building may be something to consider for the sake of convenience, or at least in events that another return type isn’t necessary.

Thoughts on this? Or perchance where fluent builders can be used otherwise if at all? (I’m just a fan of fluent builders, if you can’t tell)

Sponge needs to handle meta-data altogether better than bukkit. I never liked how meta-data worked for items, blocks and mobs in bukkit. Also, it needs to persist, that would be very useful.

Wouldn’t this imply ItemStack being immutable? ItemStack#addEnchant seems to be returning an ItemStack by the way you are using it. In my opinion, mutable ItemStacks would be better, but I could be wrong.

Haha, I’m wrong again. Fluent methods aren’t always immutable. I guess I was only thinking of String and like BigInteger.

I’m not wise to the differences of immutable and mutable, but immutable seems to imply that it’s state can’t change, and I’m not sure how a fluent builder would implicate that, honestly. (Just took a look at this nifty little page, so I could just be confused as to the meanings of those terms)

  • Material has become this: game.getGameRegistery().getItem(“diamond_sword”)
  • Their isn’t anything for Enchantments yet but i don’t think it will be an enum (to prevent incompatibility with mods)

And it looks like a good idea. As long methods don’t get confusing.

1 Like