Need help: custom enchantments?

Hello everyone,

I just started learning Sponge, and I wondered how I could make my own, custom, enchantments (as an excercise).
With a custom enchantment I mean something not in Minecraft Vanilla (like vampire or something).

I have searched for a while, without result.

Is it possible? And if so, how hard is it to make? Is there any example code I can see?

So a custom enchantment wouldn’t be able to be a literal custom enchantment. It would be a protocol hack to show the enchantment glow, with an edited lore. It’s totally possible, and you can see a plugin for an older version of Sponge here.

1 Like

No protocol hack really needed… Just have empty enchantment data attached


I only need to add lore? That seems easy.

I tried that today.
However, while trying to do that, I have come to a problem:

	public void onInteraction(InteractItemEvent event) {
		logger.warn("-- item --");
		ItemStack stack = event.getItemStack().createStack();"Stack: " + stack.toString());
		boolean supported = stack.supports(Keys.ITEM_DURABILITY);"durability support: " + supported);
		MutableBoundedValue<Integer> dur = stack.getValue(Keys.ITEM_DURABILITY).get();"durability: " + dur.get());

This code keeps throwing java.util.NoSuchElementExceptions at the one to last line. I can’t seem to find out why. Does anyone know what I’m doing wrong?

Ah, I found a solution.

Apparently, the only thing obstructing me was my own infamiliarity with the API. I added some .isPresent() and it solved 80% of the issue.

1 Like

I’d recommend a hefty read of the docs.