Jump to content

[1.7.10] Entity sync position


nos951

Recommended Posts

Hi everyone,

I have a problem with my entity.

 

My entity move on a path with .setPosition(), but it happens that the position don't match between server and client.

 

If the spawn my entity and that start moving, the position is the same or approximately. But if I go out and return in the game, when the entity is moving, the position is more different, like 1 cube, and then I have difficulty to interact with them.

 

The code for setPosition() is running on both side, otherwise the entity doesn't move or is not smooth(stop and go), only the "speed" is synced with datawatcher.

 

I’ve see the code of Minecart but I don’t understand how it does it, considering that in the client side make only setPosition(this.posX, this.posY, this.posZ).

 

I think I miss something.

 

There is my code simplified:

Entity:

 

 

Public class MyEntity extends Entity{

private int Tick=0;

private float speed;

 

//For setPositionAndRotation2

private double newPosX;

private double newPosY;

private double newPosZ;

private double newRotationYaw;

private double newRotationPitch;

private int newPosRotationIncrements;

 

public MyEntity (World world) {

super(world);

this.setSize(1F, 1F);

}

 

public MyEntity (World world, double x, int y, double z) {

this(world);

this.setPosition(x, y, z);

}

 

// Copied from EntityLivingBase for smooth movement

    @SideOnly(Side.CLIENT)

    public void setPositionAndRotation2(double p_70056_1_, double p_70056_3_, double p_70056_5_, float p_70056_7_, float p_70056_8_, int p_70056_9_)

    {

        this.yOffset = 0.0F;

        this.newPosX = p_70056_1_;

        this.newPosY = p_70056_3_;

        this.newPosZ = p_70056_5_;

        this.newRotationYaw = (double)p_70056_7_;

        this.newRotationPitch = (double)p_70056_8_;

        this.newPosRotationIncrements = p_70056_9_;

    }

   

    @Override

    protected void entityInit()

    {

        this.dataWatcher.addObject(19, new Float(0.0F));

    }

   

    public void onUpdate(){

    if(++Tick>400){

    this.kill();

    }

    if(!worldObj.isRemote){

    this.speed = 0.05F;

    this.dataWatcher.updateObject(19, speed);

    }

    else{

    speed = this.dataWatcher.getWatchableObjectFloat(19);

    }

   

this.setPosition(((double)this.posX+speed), this.posY, this.posZ);

System.out.println(this.posX + " " + worldObj.isRemote);

    }

}

 

 

 

Register Entity in preInit()

 

 

int randomId = EntityRegistry.findGlobalUniqueEntityId();

EntityRegistry.registerGlobalEntityID(MyEntity.class, "MyMod", randomId);

EntityRegistry.registerModEntity(MyEntity.class, "MyEntity", randomId, MyMod.MODID, 64, 1, true);

 

 

 

Someone knows what is the problem or what I missing?

 

Thanks and sorry for my english,

Nos951

 

 

Link to comment
Share on other sites

I'm assuming you have a more complicated version where the speed actually changes, otherwise, that is a waste.

 

Set the speed to one value and skip the data watcher for now and see if it changes anything for you.

 

Why are you putting in a randomId when you register your mob?

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

Yes my real entity change speed and move on different axis, but for this problem I've create this simplified entity for find a solution, and I saw that have the same problem.

 

I've tried to set on both side the same speed, always for test, but the desync when I load the game, while the entity is moving, the two position are different.

 

For the randomId I've never changed after following a guide a long time ago. Ok I've saw now, but if I put for example 0 the result doesn't change. Thank for letting me know.

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.