[Solved] Using modded items metadata

Hello there, me again :slight_smile:

I have a mod (that I did) which comes with several new items, and some of them are composed of numerous metadata versions. For example, I have a new Ore item that can be Iron, Gold or Lazuli according to its metadata:
mcfr_b_i:ore 0 → iron
mcfr_b_i:ore 1 → gold
mcfr_b_i:ore 2 → lazuli

How can I possibly manage to create an ItemStack in my Sponge plugin that specify these kind of datas, as there is no Key to use for it.

(I already know how to use modded items, with the game registry, but I’m asking for metadata)

Thanks a lot !

Are you talking about item damage (like planks:3) or like an NBT tag?

Oh, do you mean that actually, different plank types are defined by the item damage ?

If that’s the case, which Key must be used ?

You wouldn’t use a key, you’d do something like this.

1 Like

Or, you could create a Sponge bridge for your mod which declares Keys and DataManipulators. Just because they don’t exist yet doesn’t mean you can’t make them.

But that could cause incompatibilities with SpongeVanilla and is it really worth it when you could just use the damage?

Damage values were removed from the Sponge API because they’re horrible practices, and probably going to be even phased out in vanilla in favor of BlockState templates. Meanwhile, a plugin specifically interacting with a Forge mod breaks on SpongeVanilla anyway, because the mod isn’t installed, and even if it was supposed to be conditional, it’s trivial to conditionalize those parts of it which depend on the mod. At least this way NMS doesn’t come into the picture at all on the plugin’s side.

Still, removal of damage just causes frustration on trying to access variants of certain blocks with unknown types, where damage is a better quicker way to do it in some cases. It should be deprecated if anything.

I tried to apply what codeHusky said, but it seems pie_flavor was right about the unsafeDamages being removed…

How can I manage to process items of different types and get their variants ? The fact is that I don’t know in advance which kind of items I will have to deal with, it can be litteraly anything, and I must access the variants…

And whatever, how can I create Sponge <-> Forge bridge to get my own Keys ?

Thanks a lot for your answers !

You make an API using Sponge types, that accesses the different parts of the mod. Specifically, you would implement the Data API with the backing being Minecraft NBT.

Well, it does work. I’m currently doing that on my development server with HuskyCrates with code that looks like this.

return ItemStack.builder()

I don’t agree that this is “poor practice”. Once damage is removed (if it is) it’ll be useless, but at least it’s something you can do.
You’re going to do something similar if you want to interact with NBT anyway.

Plus, making an API just to set a damage value seems like a bunch of work just for a small thing that could be fixed with a few slightly sloppy lines.

Yes, it does work, indeed. I was trying to do it with the item.setRawData(dataView) which doesn’t work, but with the ItemStack.Builder, it works fine.

Thanks a lot for your answers :slight_smile:

1 Like