Jump to content

Another Question About Sides, Sorry


Syric

Recommended Posts

I'm having a strange issue where I want to move an entity with entity.setDeltaMovement. Since this has nothing to do with rendering, I would assume it should be run on the server side only. However, when I do that, it doesn't appear to work: ingame, when I trigger this code (and I can confirm that it is triggering), I do not appear to move.

if (!level.isClientSide()) {
                entity.setDeltaMovement(vec3.x * mult, vert, vec3.z*mult);
            }

That said, the server certainly thinks it's moved me - I set up some nearby blocks to log when they detect an entity within them, along with the side, and when I use setDeltaMovement on the server side they report detecting an entity on the server side but not the client side.

However, when I invert the if statement:

if (level.isClientSide()) {
                entity.setDeltaMovement(vec3.x * mult, vert, vec3.z*mult);
            }

then the player does appear to move when I trigger this code in-game, and the detector blocks register an entity inside them on both logical sides.

Setting the code to run on both sides produces problems, however. Namely, I have code so that this movement happens only once: when the entity is moved, they're also given the Slowness effect, and they're not moved if they already have it. If the code runs on both sides, sometimes the server side runs first and applies Slowness, which then prevents the client side from moving the entity.

I believe that I could make my code appear to work by using the second variation, only running the code on the client side. However, this answer is counterintuitive enough that I'm suspicious of it, so I'm coming here to ask for advice. Is running this code on the client side only really a valid way to handle this issue? How should I deal with this problem?

Link to comment
Share on other sites

I've seen this before.

The issue is movement changes normally start from the client (the user pressing keys) which sends a message to the server.

The server then broadcasts the change to all nearby players. However, it doesn't send the message to the player itself, it kind of assumes it already knows.

If you want the gory details look at the ChunkMap.TrackedEntity and how the seenBy set works.

There's a couple of places in the code where minecraft does use setDeltaMovement() on the server.

In those cases it checks if the entity is a player and sends the player a ClientBoundSetEntityMotionPacket without going through the TrackedEntity stuff, so the player knows what is happening.

if (entity instanceof ServerPlayer) {
    ((ServerPlayer) entity).connection.send(new ClientboundSetEntityMotionPacket(entity));
}

 

Edited by warjort
  • Thanks 1

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

So I should use setDeltaMovement() on the server side only, and update the client with the code you posted? I'll give that a shot.

Edit: seems to be working, thank you!

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