Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

 

 

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

  • Author

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.