How would I set the X, Y, or Z velocity of the player separately from the other 2?

Started by blahblahbal on

Topic category: Help with modding (Java Edition)

Last seen on 22:47, 4. Nov 2022
Joined Jan 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How would I set the X, Y, or Z velocity of the player separately from the other 2?

Just what the title says. I know you can set the "motion" of the player, but that locks the other 2 directions to 0. Also, is there some sort of documentation on Minecraft methods/method names somewhere? I'm fairly positive I'd have to do some custom code to accomplish this, but I don't know any of the method names or anything.

Last seen on 22:47, 4. Nov 2022
Joined Jan 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Okay, so I think I figured…
Fri, 01/29/2021 - 00:59

Okay, so I think I figured it out; there is setVelocity method that can be used. But there's another issue: How do I make an action "run once" instead of continuing to run while the redstone circuit is powered? I'm trying to make Player Pistons (which push the player), and I'm setting the velocity of the player to a certain value depending on the redstone power level, but if I run into the front of the piston while the circuit is still active, it pushes me again. So how would I make it run the "push" code only once?

Last seen on 02:31, 19. Apr 2024
Joined May 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Just out of curiosity, where…
Sat, 01/30/2021 - 04:56

Just out of curiosity, where is this setVelocity method? I'm trying to find it in MCreator 2021.1 (snapshot), but I don't see it (I'm looking in the procedure blocks, by the way).

Last seen on 22:47, 4. Nov 2022
Joined Jan 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The method is in…
Sat, 01/30/2021 - 16:39

The method is in PlayerEntity I think; I had to edit the procedure's code to use it, but it turns out that ServerPlayerEntity doesn't have setVelocity, so it pseudo crashes your game when on a server. I fixed it by using a combination of getMotion() and setMotion(), using a Vec3d to get the motion and setting the other 2 motion(s) to the getMotion().x or z, like this:

Vec3d v3 = entity.getMotion();
entity.setMotion(v3.x, (double)world.getWorld().getRedstonePowerFromNeighbors(new BlockPos((int)x - 1, (int)y - 1, (int)z)) / 7, v3.z);

This is for the facing up player piston.

Still unsure how to make it only run once though, instead of while the redstone circuit is active, continually power the piston.

Last seen on 14:43, 2. Aug 2022
Joined Nov 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Make it have a nbt variable…
Sat, 01/30/2021 - 17:29

Make it have a nbt variable timer than sets to 200 after it launches you. Every tick you decrease this nbt variable giving a cooldown for the piston. If the cooldown variable is equal to or less than zero allow it to launch you.