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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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