Jump to content

Player has no delta movement on Server


Povstalec

Recommended Posts

So I've noticed that if I try to get Player's delta movement, it returns some values on Client, but on Server, the vector is just a bunch of zeros.

I'm guessing this is because Player movement is mainly handled on Client, but I'd like to ask if there's any way to get Player's movement on Server (for example, if there was a block the Player could pass through only at a certain speed along one axis, or if the block would save Player momentum and then set that Player's momentum again when needed).

Link to comment
Share on other sites

  • 2 weeks later...

I already know how to sync it to the Client from the Server, that's not a problem. But I can't get it to sync from the Client to Server with Entity#hurtMarked, that's the problem. If I try to get the delta movement on Server, the vector looks like this: (0.0, 0.0, 0.0) so saving it and then applying it to the Entity just makes it stop.

Are there any other methods Minecraft uses for syncing to Server?

Link to comment
Share on other sites

Alright, so for a second I thought I had a solution when I remembered the old position Entities use for lerping is public

public final Vec3 getPosition(float p_20319_) {
      double d0 = Mth.lerp((double)p_20319_, this.xo, this.getX());
      double d1 = Mth.lerp((double)p_20319_, this.yo, this.getY());
      double d2 = Mth.lerp((double)p_20319_, this.zo, this.getZ());
      return new Vec3(d0, d1, d2);
   }

and while I was able to get the position on server, I found out the old position is identical to the current position (both on client and server), which means if I subtract it from the current position, I still get 0.0, what's up with that? I how can the game lerp motion if the two positions are the same?

Link to comment
Share on other sites

19 hours ago, Povstalec said:

But I can't get it to sync from the Client to Server with Entity#hurtMarked, that's the problem.

That field syncs it from the server to the client.

19 hours ago, Povstalec said:

If I try to get the delta movement on Server, the vector looks like this: (0.0, 0.0, 0.0) so saving it and then applying it to the Entity just makes it stop.

Makes sense since the delta movement is not necessary for syncing, only the position and rotation.

17 hours ago, Povstalec said:

I how can the game lerp motion if the two positions are the same?

You can't, lerping is not supposed to be done on the server anyways as it is meant for handling smoother animations on the client when rendering to the screen. You should just be using the raw position values if you want to use them.

 

Once again, player movement is handled on the client. The only information synced to the server is those that need to be sent to all players, which in terms of movement can typically be boiled down to (as an oversimplification) position and rotation. If you want other values, you'll need to sync them yourself using a packet. Using Entity#hurtMarked will allow you to sync the values you set on the server back to the client afterward.

Link to comment
Share on other sites

22 minutes ago, ChampionAsh5357 said:

You can't, lerping is not supposed to be done on the server anyways as it is meant for handling smoother animations on the client when rendering to the screen.

Oh no, I don't want to do any lerping, I know it's just for client (though I can see why it may have sounded like I do, I should have worded it better). I was just commenting on how baffled I am by the fact that the old values are the same as the new values, since I was expecting them to be different (especially in the case of lerping).

22 minutes ago, ChampionAsh5357 said:

You should just be using the raw position values if you want to use them.

That's what I tried to do when I found out the old values and new values are idetical. Then after some more testing, I realized they're identical only on the server.

 

22 minutes ago, ChampionAsh5357 said:

Using Entity#hurtMarked will allow you to sync the values you set on the server back to the client afterward.

In terms of syncing, I've found ClientboundSetEntityMotionPacket that does the job pretty well.

Edited by Povstalec
Link to comment
Share on other sites

5 hours ago, Povstalec said:

In terms of syncing, I've found ClientboundSetEntityMotionPacket that does the job pretty well.

Yep, that's what Entity#hurtMarked calls.

5 hours ago, Povstalec said:

I was just commenting on how baffled I am by the fact that the old values are the same as the new values, since I was expecting them to be different

It's not necessary on the server as it's handled on the client. Delta movement doesn't need to be known on the server since it doesn't affect anything. When the delta movement is applied to the player on server, it is typically by setting the method I mentioned above which adds the movement to the player on the client.

Link to comment
Share on other sites

  • 7 months later...

I assume that your issue is trying to get the delta movement of the server player and the return result is (0.0, 0.0, 0.0) even though that player is walking around, however, the true delta movement is handled by the client player (or local player) at Minecraft.getInstance().player and you can get the delta movement from this. To get that from another player on the server, you can try using SimpleChannel (read this at Forge Documentation: SimpleImpl). By making the clients with your mod installed send to the server the local player's movement data and making the server send this to other clients, you can get the true delta movement of the players.

Edited by sonnynguyen
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.



×
×
  • Create New...

Important Information

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