Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12.2] Capabilities Vs. NBT: Use-Cases/Performance
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 1
SerpentDagger

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

By SerpentDagger, October 5 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

SerpentDagger    16

SerpentDagger

SerpentDagger    16

  • Creeper Killer
  • SerpentDagger
  • Members
  • 16
  • 127 posts
Posted October 5

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.

  • Quote

Share this post


Link to post
Share on other sites

Animefan8888    677

Animefan8888

Animefan8888    677

  • Reality Controller
  • Animefan8888
  • Forge Modder
  • 677
  • 5746 posts
Posted October 5
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
  • Quote

Share this post


Link to post
Share on other sites

SerpentDagger    16

SerpentDagger

SerpentDagger    16

  • Creeper Killer
  • SerpentDagger
  • Members
  • 16
  • 127 posts
Posted October 5

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.

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Oliviafrostpaw
      [1.14.4] Injecting into Existing Loot Tables, Blocks

      By Oliviafrostpaw · Posted 7 minutes ago

      Ah, thank you very very much. Having attempted to look and find the correct bus/subscriber and or examples for its usage I found no instance of @Mod.EventBusSubscriber on the classes, is this necessary or am I just looking in the wrong places? Any Guidance would be appreciated 
    • bluey418
      Error with running modpack on twitch

      By bluey418 · Posted 19 minutes ago

      I have opened up minecraft for the first time in a while, and I wanted to run a modpack off of the twitch launcher. Every time I try to run MC, and I've tried this for a few modpacks, I get the following error in my game output tab:   OpenJDK 64-Bit Server VM warning: Ignoring option PermSize; support was removed in 8.0 Error: Could not find or load main class = Caused by: java.lang.ClassNotFoundException: =   Any idea what is causing this? I am running on a Mac, FYI.   Thanks!
    • Draco18s
      [1.14.4] Injecting into Existing Loot Tables, Blocks

      By Draco18s · Posted 44 minutes ago

      @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)   That is not the correct bus for that event.
    • Draco18s
      [1.14.4] Dimensions

      By Draco18s · Posted 47 minutes ago

      When you create a dimension, you have to pass a DimensionType to DimensionManager.registerDimension()   Why not...hold onto it?   If you have access to the world, you can also query that world for its dimension information, which includes the DimensionType.
    • Draco18s
      CORAL TOMBSTONE MOD NOT WORKS

      By Draco18s · Posted 50 minutes ago

      Talk to the mod author. Those of us here have no idea what that mod is, where the problem could be, or how to fix it. This is the Forge forums. We deal with Forge.
  • Topics

    • Oliviafrostpaw
      10
      [1.14.4] Injecting into Existing Loot Tables, Blocks

      By Oliviafrostpaw
      Started December 8

    • bluey418
      0
      Error with running modpack on twitch

      By bluey418
      Started 19 minutes ago

    • RaphGamingz
      2
      [1.14.4] Dimensions

      By RaphGamingz
      Started Yesterday at 07:45 AM

    • martingabrixx
      1
      CORAL TOMBSTONE MOD NOT WORKS

      By martingabrixx
      Started 4 hours ago

    • Edivad99
      1
      Minecraft Forge for 1.15

      By Edivad99
      Started 1 hour ago

  • Who's Online (See full list)

    • geekles
    • J0WAY
    • bluey418
    • Skyriis
    • PrinceRaiden
    • Kerman
    • LexManos
    • ErdbeerbaerLP
    • Draco18s
    • Edivad99
    • hohserg
    • Oliviafrostpaw
    • LilyStag
    • Nuxache
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12.2] Capabilities Vs. NBT: Use-Cases/Performance
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community