Jump to content

[1.12.2] Capabilities Vs. NBT: Use-Cases/Performance


SerpentDagger

Recommended Posts

What are the specific differences between Capabilities and NBT data?

For example...

Under what circumstances should I use each?

Which is quicker to access?

How do they store data?

I know from the documentation that Capabilities, particularly the ones already provided by Forge, are very useful in compatibility, so it's clear that they should be used accordingly. It's less clear, however, which to choose for less universal or less openly visible/utilized concepts.

If there's other information that might be interesting or useful that you'd like to share about them, that would also be appreciated.

Thanks in advance.

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Link to comment
Share on other sites

7 minutes ago, SerpentDagger said:

Under what circumstances should I use each?

In an ideal world, everyone would use Capabilities and not mess with the ItemStacks NBTTagCompound at all. So basically always use Capabilities.

8 minutes ago, SerpentDagger said:

Which is quicker to access?

If we are talking computer performance, I think NBTTagCompound just boils down to a HashMap and a Capability is also stored in a HashMap. Capability are easier to read and NBT is sloppy. If we are talking the amount of time to write the code, it comes down to how much information, for small amounts NBT is faster to implement but larger amounts it's typically faster to create a Capability.

11 minutes ago, SerpentDagger said:

How do they store data?

In RAM NBT is a HashMap<String, INBT> where INBT is a single NBT attribute a Compound/HashMap, List/ArrayList, NBTInt/int, etc. Where as in a Capability you define your own object that is attached to a Object(Entity, ItemStack, World, etc) and you store it there in whatever manner you want(not NBT).

On disk everything is converted to NBT and written in Minecraft's custom file format.

  • Thanks 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Thanks, that's exactly what I was looking for. I'll convert my NBT things over to Capabilities, then, since it seems there's no real advantage in using NBT data instead.

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.