public static List gunProperties = new ArrayList();
Which I use to store properties relating to specific ItemStacks. I use this instead of the stacktagcompound because I often need to update it every tick, and I feel that changing an NBTTagCompound every tick is a bad idea (correct me if I am wrong) and it causes problems such as the item highlight (the text that tells you the name of an Item every time you change the item in your hand) not going away.
Anyway, I only ever change this variable server side, but when I need to do rendering on the client side, this variable is not set to anything. I could just send a packet to every client when updating the state server side, but it also seem wrong to send a packet every tick to every player (once again, correct me if I am wrong). What I have noticed, though, is If I change the stacktagcompound of an ItemStack server side, I will be able to read the correct value on client side also. Why is this? Why is the NBTTagCompound readable on the client side when it is only updated server side? And how can I make my variable act like this as well?
To sum up, my main questions are: Is it good to update the stacktagcomound of an item stack every tick? Is sending a packet every tick to every player a bad idea? Why is an NBTTagCompound visible on both client and server side when only updated server side and can I make my variable like that aswell.
Packets, although every tick would be quite an overkill. Why not ONLY send a packet when/if it's changed?
And do you really need to update it every tick and store it only server side?
" send a packet every tick to every player" Yeah in most cases this would be overkill, you should really consider if EVERY player really needs this information.
Since you speak of rendering I would assume only players CLOSE to the player with the item would need this information.
Also you should look into if there are ways for the client to assume the changes ahead of time, so you mayhaps can relax an how often you send packets.
Why is an NBTTagCompound visible on both client and server side
Because code is run on both client and server, it's the same code.
I would definitely agree with not changing NBT tag data every tick, NBT tags are really complex, high level structures that you should probably avoid probing every tick. Often they're hashmaps inside of hashmaps, and while I'm sure it's optimised, it just doesn't seem wise to change constantly.
Don't forget, though, of how variables work. For instance, if you have a reference to a variable inside of an NBT tag, and you change that variable, that it will update what's inside of the tag, cause well that's how references work.
For instance, I have two variables in a tile entity, one is a NBT tag compound which is just a big hashmap of random information. But say, i want to be constantly referencing an array of bytes that is stored several levels down in the tag, if I declare a variable in the initialization phase of the tile entity that directly references the byte array within the tag, they become linked and will always be identical.
Perhaps you could use this fact to make sure your items stay updated.
Either that, or what Mazetar said, packets when the info changes. Good way of doing it, but leaves room for coding errors where upates get missed.
First of all, I need to update every tick for things like gun reload and firing the gun (if it needs to be fired every tick, since onItemRightClick is only fired every 4 ticks). I also need all players to know this, so if a gun is given to them, they can see its reload. Yes, I know that changing a referenced variable will change the actual one, because they are the same thing, but the changes made to the variable made on the server side don't exist on the client, so I see no alternative to using packets. Is it OK, or really bad to be sending a packet every tick to every player. Any possible side effects? As to problems with missing updates, it won't cause much trouble. How do other gun mods store reload?
Ok, I know that there is a method to send updates to all nearby players, but how do I know when a player has come in range and needs to have an update? The updates are only send when an items properties are changing, so if a player from far away comes to get an item that has properties that updated when the player was away, but not when he was close, he will still have the properties of the old item.
What you might be suggesting is to have something like a tick handler that sends updates every now and then (something like 200 ticks, maybe) to always be synchronising the variable. I will try that, and I don't see any problem with single packets being always sent every few seconds as long as a specific item stack exists. Thanks for the help!