Posted June 22, 20241 yr I'm a bit confused as how to get/store custom nbt data in itemstacks on the fly in version 1.21. After a lot of googling I have found that in the past the ItemStack class had the functions getTagCompound() and setTagCompound(), however they seem to have been deprecated? It's unfortunate because that seemed so straight forward and I can't find much info on the subject otherwise. Apologies if this isn't worded nicely as I am still pretty new to minecraft modding. Any help would be appreciated.
June 22, 20241 yr Author Upon further inspection of the wiki I have discovered Capabilities which seems to suit my needs instead. Apologies.
June 22, 20241 yr Item Capabilities haven't been re-implemented in 1.21 yet, you can use Vanilla's Data Components system instead. See DataComponents and the related classes. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 23, 20241 yr Author Okay, so I actually downgraded the mod to 1.20.6 because I did not want to have to deal with vanilla datacomponents. I followed a youtube tutorial and now have a capability I made attach to my modded item. However I am now unsure how to actually retrieve and manipulate the capability of an itemstack. I saw a getCapability function in some tutorials but that seems to have been deprecated...
June 23, 20241 yr The situation is the same in 1.20.6. Data Components were introduced in 1.20.5/1.20.6 and Item Capabilities haven't been re-implemented since then. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 23, 20241 yr Author Okay, I'm glad I made a backup then. I'm confused as to where there is any information on how to work with Data Components. I don't see anything about it on the Forge docs or any tutorials on this in general unless I'm missing it somehow. I can see the DataComponents decompiled class file but I'm not sure how to work with it. Maybe it's beyond my technical expertise?
June 23, 20241 yr I don't think there's any documentation on them yet, I mainly just looked at the Vanilla code when implementing mine. You can see a fairly simple example here: Registration: https://github.com/Choonster-Minecraft-Mods/TestMod3/blob/f3bea10d5f455fa0904056caafd8c844b6fd13ae/src/main/java/choonster/testmod3/init/ModDataComponents.java#L50-L58 Item Registration: https://github.com/Choonster-Minecraft-Mods/TestMod3/blob/f3bea10d5f455fa0904056caafd8c844b6fd13ae/src/main/java/choonster/testmod3/init/ModItems.java#L264-L266 Usage: https://github.com/Choonster-Minecraft-Mods/TestMod3/blob/f3bea10d5f455fa0904056caafd8c844b6fd13ae/src/main/java/choonster/testmod3/world/item/EntityCheckerItem.java Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 23, 20241 yr Author Wow this looks a lot simpler than I thought it would be. Especially compared to the setup I had to do for capabilities. I'll look at all this and update if I have any issues ty
June 23, 20241 yr Author Okay, so I got everything set up and should have my data component registered. However when I try to register my modded item with the data component added to it, I get an error saying that the registry object (for the data component) is not present. I tried changing the order in which things are registered in the mod startup to no avail.
June 24, 20241 yr Forge fires RegisterEvent (which is used internally by DeferredRegister) for each registry in a specific order, so changing the registration order in your code won't help. I haven't actually been able to run my mod since 1.20.6 because I'm waiting on Item Capabilities, so I haven't encountered this error myself. It looks like you can't use your DataComponentType during Item registration, so you probably need to get/add it on demand with getOrDefault and set, instead of in registration. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 24, 20241 yr Author Thanks. I removed the data component from item registration and the game boots fine now. However now when I try to call the set() method on my item stack during the item's useOn method, it still throws an error that the registry object is not present. I have registered the data component along with all of my other modded content in the main mod class, so I am at a genuine loss as to why this is still happening. I am new to these forums, am I allowed to link the github repo?
June 25, 20241 yr Have you registered the DeferredRegister with the mod event bus? You can link your GitHub repo. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 25, 20241 yr Author Yes it should be registered? Here's the link to the github: https://github.com/positivevibes123/MinecraftExplosiveMod hopefully it should be public. I have everything registered in the MyMod.java file. The other java files of interest are ModDataComponents.java and RemoteItem.java
June 26, 20241 yr The repository is private. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 26, 20241 yr https://github.com/positivevibes123/MinecraftExplosiveMod/blob/3dfabe6cd67213db484737c8cce650583dd894f1/src/main/java/com/gmail/damoruso321/bomb/datacomponents/ModDataComponents.java#L19 This should be DATA_COMPONENT_TYPES.register(eventBus), not eventBus.register(DATA_COMPONENT_TYPES). Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
June 26, 20241 yr Author Can’t believe I missed that ty, I’ll update the code when I’m able to hopefully no more issues after that lol
June 26, 20241 yr Author I think I've finally got it working. Thanks for helping with this issue it was quite a learning experience lol
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.