GThoro Posted January 24, 2021 Posted January 24, 2021 I've started working on a mod and it's been a bit of a bumpy ride. Mostly due to lack of recent and decent information, examples or simple know-how about internal workings. Finding outdated tutorials doesn't help either, and from what I've already read and seen in code (looking at 1.16 mods at github was mostly helpful) I got a bit confused. So please help me understand few things. Here's my questions: I want to attach some simple data to some ItemStack and TileEntity, is using getOrCreateTag() for ItemStack and getTileData() for TileEntity the way to go? or should I use capabilities for it? If I'm setting tag for ItemStack or TileEntity, should I do this on server side only or both? I wanted to play a sound during onItemUse and I've used context.getPlayer().playSound() which is ran on render and server thread, but only player using item is hearing the sound, according to Forge documentation this method on render thread should play for current player (and it does) and on server side it should send play message to all other players (this doesn't work) If I want to store some custom "world" data that isn't specific to any block/item/chunk I should use capabilities and attach it to the world? Quote
Draco18s Posted January 24, 2021 Posted January 24, 2021 52 minutes ago, GThoro said: I want to attach some simple data to some ItemStack and TileEntity, is using getOrCreateTag() for ItemStack and getTileData() for TileEntity the way to go? or should I use capabilities for it? Capabilities. 52 minutes ago, GThoro said: If I want to store some custom "world" data that isn't specific to any block/item/chunk I should use capabilities and attach it to the world? Yes. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
GThoro Posted January 24, 2021 Author Posted January 24, 2021 32 minutes ago, Draco18s said: Capabilities. Even if it's like simple string or int value? For example I have an item that user can right click and his player UUID should be "stored in" the item, this should use capabilities too? What's NBT for then? Quote
Draco18s Posted January 24, 2021 Posted January 24, 2021 (edited) Yes, use Capabilities. The NBT system is what vanilla uses and half the functions available don't do what you think they do. getTileData() for instance doesn't let you store data in the tile entity, it is the NBT representation of the tile entity so it can be stored in an ItemStack. NBT is a serialized data format meant to store the (whatever) on disk. Its not meant to be run-time modified left and right. Vanilla uses it for arbitrary data storage on ItemStacks because Mojang doesn't have a better method. Edited January 24, 2021 by Draco18s Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
Draco18s Posted January 24, 2021 Posted January 24, 2021 3 minutes ago, diesieben07 said: this is not true. Well darn. What is it for, then? I know that the various functions don't do what one expects half the time, looks like I messed that one up again. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
Recommended Posts
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.