I'm aiming to create a random value that is the same on both the client and server sides.
It needs to be generated during the spawning of an entity.
So I was just wondering is there a way to generate the same value on both client and server or will I need to generate on one and then send the result to the other?
The Meaning of Life, the Universe, and Everything.
Join Date:
1/18/2011
Posts:
256
Minecraft:
Plecks
Member Details
Well, you'll need to use something as a seed that's identical between the server and client. If you need a new number for each entity, then you'll need to use something entity specific, which is also unique for each entity. It's likely you can use the entity ID for this, but I'd check to make sure they're identical between server/client.
When the entity spawns, just use the seed with the random number generator, and as long as the seeds are the same it'll spit out the same number on both sides.
But it needs to generate a different value for each instance of the same entity?
Entity ID is not like block ID or item ID. Each entity currently in the game has a unique ID assigned to it, so no two zombies have the same entity ID.
Entity metadata is sent to the client every updateFrequency ticks (specified during entity registration), or about once every tick if the entity is airborne, or the dataWatcher has been modified.
Do they work in single player?
Can both client and server side update the data they hold? If so I assume server overrides?
Does the data they hold get erased after being read?
Is there a limit to their ID?
Which ID's are taken?
Anything else I should know about them?
...or if anyone just knows where I can read up about them in general that would be great too
It needs to be generated during the spawning of an entity.
So I was just wondering is there a way to generate the same value on both client and server or will I need to generate on one and then send the result to the other?
When the entity spawns, just use the seed with the random number generator, and as long as the seeds are the same it'll spit out the same number on both sides.
Entity ID is not like block ID or item ID. Each entity currently in the game has a unique ID assigned to it, so no two zombies have the same entity ID.
What about dataWatchers?
Are they per entity or per instance?
And how often do they sync to the server?
Do they work in single player?
Can both client and server side update the data they hold? If so I assume server overrides?
Does the data they hold get erased after being read?
Is there a limit to their ID?
Which ID's are taken?
Anything else I should know about them?
...or if anyone just knows where I can read up about them in general that would be great too
Any info on dataWatchers?
The id value for watchable objects ranges between 0 and 31 inclusively.
The server sends changes to the data watcher to the client only, but either can modify the data.
The data they contain should be saved unless the entity is unloaded, in which case you would need to backup any values with NBT.
And they should work in single player.
Thanks for everything!