Skip to content

Commit

Permalink
Made server auth movement more legit
Browse files Browse the repository at this point in the history
Thanks to @Oryxel for pointing this out
  • Loading branch information
RaphiMC committed Aug 30, 2024
1 parent 2c6d10a commit b1f120d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,26 @@ public void writeMovePlayerPacketToServer(final PacketWrapper wrapper, final Pla
public void sendPlayerAuthInputPacketToServer(final ClientPlayMode playMode) {
if (this.prevPosition == null) this.prevPosition = this.position;
final Position3f positionDelta = this.position.subtract(this.prevPosition);
final Position3f gravityAffectedPositionDelta;

final Position3f velocity;
if (!this.initiallySpawned || this.dimensionChangeInfo != null || this.abilities.getBooleanValue(AbilitiesIndex.Flying)) {
gravityAffectedPositionDelta = positionDelta;
velocity = positionDelta;
} else {
gravityAffectedPositionDelta = positionDelta.subtract(0F, ProtocolConstants.PLAYER_GRAVITY, 0F);
float dx = positionDelta.x() * 0.98F;
float dy = positionDelta.y();
float dz = positionDelta.z() * 0.98F;
final float friction = this.onGround ? ProtocolConstants.BLOCK_FRICTION : 1F;
dx *= friction;
dz *= friction;

if (this.effects.containsKey("minecraft:levitation")) {
dy += (0.05F * (this.effects.get("minecraft:levitation").amplifier() + 1)) * 0.2F;
} else {
dy -= ProtocolConstants.PLAYER_GRAVITY;
}
// Slow falling does not change the velocity when standing still

velocity = new Position3f(dx * 0.91F, dy * 0.98F, dz * 0.91F);
}

this.authInputData.add(PlayerAuthInputPacket_InputData.BlockBreakingDelayEnabled);
Expand Down Expand Up @@ -172,7 +187,7 @@ public void sendPlayerAuthInputPacketToServer(final ClientPlayMode playMode) {
playerAuthInput.write(BedrockTypes.UNSIGNED_VAR_INT, playMode.getValue()); // play mode
playerAuthInput.write(BedrockTypes.UNSIGNED_VAR_INT, NewInteractionModel.Touch.getValue()); // interaction mode
playerAuthInput.write(BedrockTypes.UNSIGNED_VAR_LONG, (long) this.age); // tick
playerAuthInput.write(BedrockTypes.POSITION_3F, gravityAffectedPositionDelta); // position delta
playerAuthInput.write(BedrockTypes.POSITION_3F, velocity); // delta
if (this.authInputData.contains(PlayerAuthInputPacket_InputData.PerformBlockActions)) {
playerAuthInput.write(BedrockTypes.VAR_INT, this.authInputBlockActions.size()); // player block actions count
for (AuthInputBlockAction blockAction : this.authInputBlockActions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ public class ProtocolConstants {
public static final int BEDROCK_COMMAND_VERSION = 41;
public static final byte BEDROCK_REQUEST_CHUNK_RADIUS_MAX_RADIUS = 28;

public static final float PLAYER_GRAVITY = 0.0784F;
public static final float PLAYER_GRAVITY = 0.08F;
public static final float PLAYER_JUMP_HEIGHT = 0.42F;
public static final float BLOCK_FRICTION = 0.6F;

public static StructuredDataContainer createStructuredDataContainer() {
final StructuredDataContainer data = new StructuredDataContainer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,14 +537,6 @@ private static void handleJavaClientGameJoin(final UserConnection user) {
commandsStorage.updateCommandTree();
}

final PacketWrapper updateAttributes = PacketWrapper.create(ClientboundPackets1_21.UPDATE_ATTRIBUTES, user);
updateAttributes.write(Types.VAR_INT, clientPlayer.javaId()); // entity id
updateAttributes.write(Types.VAR_INT, 1); // attribute count
updateAttributes.write(Types.VAR_INT, BedrockProtocol.MAPPINGS.getJavaEntityAttributes().get("minecraft:generic.gravity")); // attribute id
updateAttributes.write(Types.DOUBLE, (double) ProtocolConstants.PLAYER_GRAVITY); // base value
updateAttributes.write(Types.VAR_INT, 0); // modifier count
updateAttributes.send(BedrockProtocol.class);

final PacketWrapper serverDifficulty = PacketWrapper.create(ClientboundPackets1_21.CHANGE_DIFFICULTY, user);
serverDifficulty.write(Types.UNSIGNED_BYTE, (short) joinGameStorage.difficulty().getValue()); // difficulty
serverDifficulty.write(Types.BOOLEAN, false); // locked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"minecraft:saturation",
"minecraft:levitation",
"minecraft:fatal_poison",
"minecraft:slow_falling",
"minecraft:conduit_power",
"minecraft:slow_falling",
"minecraft:bad_omen",
"minecraft:village_hero",
"minecraft:darkness",
Expand Down

0 comments on commit b1f120d

Please sign in to comment.