From dab32bafa1e05fa428c34d45098e354073d5b398 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Wed, 9 Oct 2024 16:37:30 +0200 Subject: [PATCH] Write correct on ground state in 1.20.5->1.21 placement rotation fix (#4170) --- .../configuration/AbstractViaConfig.java | 2 +- .../v1_20_5to1_21/Protocol1_20_5To1_21.java | 4 ++- .../rewriter/BlockItemPacketRewriter1_21.java | 4 ++- .../rewriter/EntityPacketRewriter1_21.java | 33 +++++++++++++++++++ .../storage/OnGroundTracker.java | 33 +++++++++++++++++++ 5 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/storage/OnGroundTracker.java diff --git a/common/src/main/java/com/viaversion/viaversion/configuration/AbstractViaConfig.java b/common/src/main/java/com/viaversion/viaversion/configuration/AbstractViaConfig.java index 7c4c81451..8fa8488c3 100644 --- a/common/src/main/java/com/viaversion/viaversion/configuration/AbstractViaConfig.java +++ b/common/src/main/java/com/viaversion/viaversion/configuration/AbstractViaConfig.java @@ -554,6 +554,6 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf @Override public boolean fix1_21PlacementRotation() { - return false && fix1_21PlacementRotation; // TODO Can't always set onGround to true + return fix1_21PlacementRotation; } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/Protocol1_20_5To1_21.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/Protocol1_20_5To1_21.java index 683131b42..e3f2c57f5 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/Protocol1_20_5To1_21.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/Protocol1_20_5To1_21.java @@ -45,6 +45,7 @@ import com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.BlockItemPacke import com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.ComponentRewriter1_21; import com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.EntityPacketRewriter1_21; import com.viaversion.viaversion.protocols.v1_20_5to1_21.storage.EfficiencyAttributeStorage; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.storage.OnGroundTracker; import com.viaversion.viaversion.rewriter.ComponentRewriter; import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter; @@ -222,6 +223,7 @@ public final class Protocol1_20_5To1_21 extends AbstractProtocol { + wrapper.passthrough(Types.DOUBLE); // X + wrapper.passthrough(Types.DOUBLE); // Y + wrapper.passthrough(Types.DOUBLE); // Z + + wrapper.user().get(OnGroundTracker.class).setOnGround(wrapper.passthrough(Types.BOOLEAN)); + }); + protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_ROT, wrapper -> { + wrapper.passthrough(Types.FLOAT); // Yaw + wrapper.passthrough(Types.FLOAT); // Pitch + + wrapper.user().get(OnGroundTracker.class).setOnGround(wrapper.passthrough(Types.BOOLEAN)); + }); + protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_POS_ROT, wrapper -> { + wrapper.passthrough(Types.DOUBLE); // X + wrapper.passthrough(Types.DOUBLE); // Y + wrapper.passthrough(Types.DOUBLE); // Z + wrapper.passthrough(Types.FLOAT); // Yaw + wrapper.passthrough(Types.FLOAT); // Pitch + + wrapper.user().get(OnGroundTracker.class).setOnGround(wrapper.passthrough(Types.BOOLEAN)); + }); + protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_STATUS_ONLY, wrapper -> { + wrapper.user().get(OnGroundTracker.class).setOnGround(wrapper.passthrough(Types.BOOLEAN)); + }); } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/storage/OnGroundTracker.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/storage/OnGroundTracker.java new file mode 100644 index 000000000..f7a8c3453 --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/storage/OnGroundTracker.java @@ -0,0 +1,33 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * 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.viaversion.protocols.v1_20_5to1_21.storage; + +import com.viaversion.viaversion.api.connection.StorableObject; + +public final class OnGroundTracker implements StorableObject { + + private boolean onGround; + + public boolean onGround() { + return onGround; + } + + public void setOnGround(final boolean onGround) { + this.onGround = onGround; + } +}