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

I was trying to do something when the player is moving only to find that player.motionX/Y/Z always seem to be zero on the server. I'm using the following method from within LivingUpdateEvent:

public static boolean isPlayerMoving(EntityPlayer player) {
  player.addChatMessage("Side == client? " + player.worldObj.isRemote);
  // always prints zero on server side; correct values displayed client side
  player.addChatMessage("Player motionX " + player.motionX + ", motionZ " + player.motionZ);
  return player.motionX != 0 || player.motionZ != 0;
}

I looked through NetServerHandler where it handles movement packets, and it uses player.motionX/Y/Z to calculate some things there, suggesting they shouldn't be zero even on the server; I suspect they get reset to zero sometime after the packet is handled, but I can't seem to find where.

EDIT: Looks like it happens in Entity's moveEntity method, which is called directly during the handling of the movement packet.

 

Anyone know a way I can detect if the player is in motion while on the server side?

Hi

 

I don't know of a direct method.  There is a Packet27PlayerInput - Transmit the current state of the player movement - but I think it's only used for riding at the moment.

 

Two suggestions (which might or might not work depending on what you are trying to do and how responsive it needs to be)-

Use the ITickHandler on the server to record the player's position every tick, compare it to the last position to see whether the position has changed much.  But that might not work properly if the network is a bit laggy.  Depending on what you need to know, it might be ok if you can smooth it out (say - over a second).

Alternatively, you could add some code on the client side that sends custom packets to the server when the player moves (when the player is holding down a movement key) and when they stop moving (release all movement keys).

 

-TGG

motionX/Y/Z is no longer used.

 

Use

moveForward and moveStrafing

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

TGG - thanks for the ideas, I'll try checking for the movement keys and send a packet, see how that works.

 

Draco - What do you mean motionX/Y/Z is no longer used? It's still in the code from what I can see (1.6.4). I did try using moveForward/Strafing like you suggested instead of the motion values, but they are still zero on the server, just like motion. Nice idea though.

Draco - What do you mean motionX/Y/Z is no longer used?

 

It's what I've heard, that they were depreciated in favor of move/strafe.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Hi

 

In 1.6.4, moveForward and moveStrafing are only used when you are riding  (Packet27).  They are used to transmit which movement keys the player is pressing.

 

-TGG

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.