Jump to content

Entity not syncing between server and client


tlr38usd

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.