Posted September 20, 201312 yr I have an entity that uses a Random to decide where it should move. It appears as if they are desynced from server to client. How would I go about syncing the client with the server?
September 20, 201312 yr 1) Use world.isRemote to determine if the entity is client side, if it is, do nothing. 2) If it is not client side, every time it updates, send any changed data to the client using Packet250CustomPayload 3) Add a packet handler on your client side to handle these packets and update the entity on the client end 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.
September 20, 201312 yr Author I figured that would be the problem. The thing is I don't know how to use packets. Everyone I've talked to says there easy, but no one has ever told me how to do it myself and the tutorial on the forums doesn't make sense
September 22, 201311 yr Use a datawatcher. I do it all the time. In most cases, the server is in control of the entity anyway. Datawatchers are the preferred method to get server data (small) to the client entity. For example, I might use a randInt() in the server to determine an entities color. How to tell the client, so that it can render the proper color? Easy. protected void entityInit() { super.entityInit(); this.butterfly_type = this.worldObj.rand.nextInt(10); this.dataWatcher.addObject(20, Integer.valueOf(this.butterfly_type)); } public void onUpdate() { super.onUpdate(); this.motionY *= 0.6000000238418579D; //Gravity adjustment! if(this.worldObj.isRemote){ this.butterfly_type = this.dataWatcher.getWatchableObjectInt(20); }else{ this.dataWatcher.updateObject(20, Integer.valueOf(this.butterfly_type)); } } Alternately, instead of sending and receiving the value a gazillion times unnecessarily in the update(), you can make a couple functions to set and get the datawatcher object as needed. Or add a little counter and only update once a second. Whichever way you do it, it works. BUT PLEASE NOTE: datawatchers ONLY GO ONE WAY - from server to client. There are different types too, byte, int, and even float. Make sure you don't use anything under 20, as most of those indexes are used by vanilla minecraft. Odds are good I've been programming since before you were born. Yeah. I'm OLD school.
September 22, 201311 yr Also, the client will automatically follow the server movement. Its built in. You don't have to do anything. if(!this.worldObj.isRemote){ this.posX += 0.01f; }else{ //do nothing because this is the client side and it just works } Odds are good I've been programming since before you were born. Yeah. I'm OLD school.
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.