Skip to content

Commit ead2c6f

Browse files
committed
Send sneaking command on vehicle exit in 1.21.2->1.21.1
Fixes #1001
1 parent 1a972da commit ead2c6f

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,7 @@ public void register() {
316316

317317
// Player input no longer sets the sneaking state on the server
318318
// Send the change separately if needed (= when in a vehicle and player commands aren't sent by the old client)
319-
final PlayerStorage sneakingStorage = wrapper.user().get(PlayerStorage.class);
320-
if (sneakingStorage.setSneaking(sneaking)) {
321-
final PacketWrapper playerCommandPacket = wrapper.create(ServerboundPackets1_21_2.PLAYER_COMMAND);
322-
playerCommandPacket.write(Types.VAR_INT, tracker(wrapper.user()).clientEntityId());
323-
playerCommandPacket.write(Types.VAR_INT, sneaking ? 0 : 1); // Start/stop sneaking
324-
playerCommandPacket.write(Types.VAR_INT, 0); // Data
325-
playerCommandPacket.sendToServer(Protocol1_21_2To1_21.class);
326-
}
319+
sendSneakingPlayerCommand(wrapper, sneaking);
327320
});
328321

329322
protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_POS, wrapper -> {
@@ -416,6 +409,7 @@ public void register() {
416409
final ClientVehicleStorage storage = wrapper.user().get(ClientVehicleStorage.class);
417410
if (storage != null && vehicleId == storage.vehicleId()) {
418411
wrapper.user().remove(ClientVehicleStorage.class);
412+
sendSneakingPlayerCommand(wrapper, false);
419413
}
420414

421415
final int clientEntityId = tracker(wrapper.user()).clientEntityId();
@@ -436,6 +430,7 @@ public void register() {
436430
for (final int entityId : entityIds) {
437431
if (entityId == vehicleStorage.vehicleId()) {
438432
wrapper.user().remove(ClientVehicleStorage.class);
433+
sendSneakingPlayerCommand(wrapper, false);
439434
break;
440435
}
441436
}
@@ -561,6 +556,17 @@ private void handleRelativeArguments(
561556
}
562557
}
563558

559+
private void sendSneakingPlayerCommand(final PacketWrapper wrapper, final boolean sneaking) {
560+
final PlayerStorage sneakingStorage = wrapper.user().get(PlayerStorage.class);
561+
if (sneakingStorage.setSneaking(sneaking)) {
562+
final PacketWrapper playerCommandPacket = wrapper.create(ServerboundPackets1_21_2.PLAYER_COMMAND);
563+
playerCommandPacket.write(Types.VAR_INT, tracker(wrapper.user()).clientEntityId());
564+
playerCommandPacket.write(Types.VAR_INT, sneaking ? 0 : 1); // Start/stop sneaking
565+
playerCommandPacket.write(Types.VAR_INT, 0); // Data
566+
playerCommandPacket.sendToServer(Protocol1_21_2To1_21.class);
567+
}
568+
}
569+
564570
private int boatTypeFromEntityType(final EntityType type) {
565571
if (type == EntityTypes1_21_2.OAK_BOAT) {
566572
return 0;

0 commit comments

Comments
 (0)