diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java index 27285a85..678bd123 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java @@ -26,6 +26,7 @@ import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.ComponentRewr import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.EntityPacketRewriter1_21_2; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.InventoryStateIdStorage; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.ItemTagStorage; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.SneakingStorage; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; @@ -149,6 +150,7 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol { + wrapper.passthrough(Types.VAR_INT); + final int action = wrapper.passthrough(Types.VAR_INT); + if (action == 0) { + wrapper.user().get(SneakingStorage.class).setPlayerCommandTrackedSneaking(true); + } else if (action == 1) { + wrapper.user().get(SneakingStorage.class).setPlayerCommandTrackedSneaking(false); + } + }); + // Now also sent by the player if not in a vehicle, but we can't emulate that here, and otherwise only used in predicates - // TODO Why leaving vehicle no worky protocol.registerServerbound(ServerboundPackets1_20_5.PLAYER_INPUT, wrapper -> { final float sideways = wrapper.read(Types.FLOAT); final float forward = wrapper.read(Types.FLOAT); final byte flags = wrapper.read(Types.BYTE); byte updatedFlags = 0; - if (forward < 0) { + if (forward > 0) { updatedFlags |= 1; - } else if (forward > 0) { + } else if (forward < 0) { updatedFlags |= 1 << 1; } @@ -203,16 +214,29 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/SneakingStorage.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/SneakingStorage.java new file mode 100644 index 00000000..2ab7cd9a --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/SneakingStorage.java @@ -0,0 +1,34 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * Copyright (C) 2016-2024 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage; + +import com.viaversion.viaversion.api.connection.StorableObject; + +public final class SneakingStorage implements StorableObject { + private boolean playerCommandTrackedSneaking; + + public void setPlayerCommandTrackedSneaking(final boolean playerCommandTrackedSneaking) { + this.playerCommandTrackedSneaking = playerCommandTrackedSneaking; + } + + public boolean setSneaking(final boolean sneaking) { + final boolean changed = this.playerCommandTrackedSneaking != sneaking; + this.playerCommandTrackedSneaking = sneaking; + return changed; + } +}