How is mod item metadata accessed by plugins?

This is on Minecraft 12.2
Twitch modpack, All The Mods 3 Remix

I am trying to use CatClearLag-0.9.0 which deletes objects on the ground every couple minutes, excluding items in a whitelist.

Applied Energistics 2 rv6-stable-7 uses a single item “appliedenergistics2:material” and a metadata value for all the various crystals, dusts, orbs, etc.


There does not seem to be a way to specify metadata for whitelisted items in CatClearLag…

This plugin has a way to add items to its config file by holding an item and using a command, but it only ever adds the base “appliedenergistics2:material” without a metadata value, and regardless of the material added.


The metadata value does work via the built-in Minecraft /give command at the console…

/give plawerth appliedenergistics2:material 1 5
[minecraft/DedicatedServer]: Given [Silicon] * 1 to Plawerth

/give plawerth appliedenergistics2:material 1 7
[minecraft/DedicatedServer]: Given [Fluix Crystal] * 1 to Plawerth

Is there a way to make this work with a Sponge plugin?

Sadly its a little more complex then you may think.

Due to the magic number id system (both item id and sub id) being deprecated since before 1.8, this was to essentially let mod developers know that they shouldnt be using the magic ids (that being said, minecraft didnt say what to use instead and all tutorials showed how to use the magic ids … So they stuck). So sponge doesnt allow access via its API to the magic values, plugins can use NMS to gain access to the ids, however that breaks support for none NMS servers from using that plugin, aka LanternPowered will not be able to use those plugins. Not to mention the support of NMS code, something difficult to maintain due to the naming being changed, mojang server hotfixes that dont get told to the public that may change NMS and more.

So Sponge didnt use the magic ids, instead use a key value pairing, however sponge has a hard time converting minecrafts metadata to its key value pairing, so sponge needs mod developers to add Data manipulators to sponge to convert into the key value pairs.

So here are your options:

  1. Request to CatClearLag to use NMS to gain the sub id and be able to whitelist from that.

  2. Request to CatClearLag to allow to whitelist ids with a select key value pairing and then build a data manipulator for AE2.

  3. Request to AE2 to use different main ids for there items

  4. Request/build your own item removing plugin (for the basics - its actually very easy).

Reasons why the CatClearLag team may reject the request - that i can think of.

  1. dont want to use NMS and break support for none NMS servers

  2. a lot of work for a feature that may not be used

  3. with MC 1.13+, all item ids belong to there own item, mods should follow suit.

Sidenote: While this is not a direct API, it is available without NMS. There is item.toContainer().getInt(DataQuery.of("UnsafeDamage")) - but as the name suggests, that does not indicate whether the value represents actual damage, the sub id or (i think i saw some mods do that) use it as “charge” for the item. The only thing hinting towards that might be item.getType().getTemplate().supports(Keys.ITEM_DURABILITY) iirc.
(Doesn’t change the proposed solutions at all tho)

Now you point it out. That line of code does look familiar, i think i saw it on the forums back when API 4 was a thing. But like you said, doesn’t help the solution. Not to mention that Keys.ITEM_DURABILITY won’t work on modded items as there is no data manipulator for it

1 Like

I am not a Minecraft programmer so I have to look up some of these details you are talking about, like NMS.

As far as I have understood what Bukkit / Sponge are, they are intended to provide a high level abstraction layer on top of what Forge does, dealing with all the complex Forge and Minecraft versioning weirdness so that plugin developers don’t have to.

A consequence is a really old plugin for Bukkit would still work with much newer versions of Minecraft/Forge because the Bukkit abstraction layer hid all the differences, and the old plugins would still work with no changes.

If I follow what you’re saying about making a Sponge plugin but which is also directly interacting with NMS… that apparently negates the whole point of using the Sponge abstraction layer, and the item remover might as well just be written directly as a version-specific Forge mod that does not use Sponge at all…

So NMS stands for Network Minecraft Server and from what your saying it sounds like you understand what we meant by it. Its the code of the minecraft server, no Forge, no Bukkit, no nothing.

Your understanding of bukkit/Sponge is mostly correct. They do do that, but they also do a whole heap of other things, such as plugin loading. Sponge also uses it abstraction layer to interact with Forge as well as minecraft, so if you request all blocks from sponge, sponge will get all Minecraft blocks and all forge blocks.

As for bukkit and its backwards compatibility, its not always the case, a lot of Bukkit plugins use NMS because Bukkit didnt provide a abstraction layer for what they need. Such as spawning in the Human entity, or getting the ping of the player (how much lag they are having). Not to mention that maintaining abstraction layers for past versions of minecraft and keep up with the latest changes is … Well … Impossible unless you can see into the future, so a lot of bukkits abstraction layer slowly disappears, so most older plugins wont work on 1.12.2 bukkit (before bukkit changed the block id system). Sponge doesn’t take the same approach, sponges approach is that if something needs changing to suit the new minecraft changes, then it will change and plugin developers need to adapt to that.

As for your last point, it doesn’t fully negate it, but your right. The reason why it doesnt fully negate it is that you can still use features sponge provides, such as the amazing Scheduler even if you boot in Sponge or Forge.

Im glad you understood me, normally my block of text (in that case a small block of text) normally confuse people with the more in depth stuff, but it seems like you got a lot correct with tiny details gone.

The main issue with using NMS for getting the blocks Sub id is that the sub id system was deprecated a long time ago, meaning mojang could not support it any more and it would be replaced, so why maintain it? - or in this case, allow plugins to interact with it?