Skip to content

Commit 67f7a66

Browse files
committed
Fix 1.20.2->1.20 if run on the backend
1 parent 4cba807 commit 67f7a66

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/Protocol1_20To1_20_2.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.viaversion.viaversion.api.minecraft.entities.Entity1_19_4Types;
2828
import com.viaversion.viaversion.api.protocol.packet.Direction;
2929
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
30+
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
3031
import com.viaversion.viaversion.api.protocol.packet.State;
3132
import com.viaversion.viaversion.api.rewriter.EntityRewriter;
3233
import com.viaversion.viaversion.api.rewriter.ItemRewriter;
@@ -44,6 +45,7 @@
4445
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundConfigurationPackets1_20_2;
4546
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundPackets1_20_2;
4647
import java.util.UUID;
48+
import org.checkerframework.checker.nullness.qual.Nullable;
4749

4850
public final class Protocol1_20To1_20_2 extends BackwardsProtocol<ClientboundPackets1_20_2, ClientboundPackets1_19_4, ServerboundPackets1_20_2, ServerboundPackets1_19_4> {
4951

@@ -70,17 +72,18 @@ protected void registerPackets() {
7072
});
7173

7274
registerClientbound(State.LOGIN, ClientboundLoginPackets.GAME_PROFILE.getId(), ClientboundLoginPackets.GAME_PROFILE.getId(), wrapper -> {
73-
final ServerboundLoginPackets ackPacket = ServerboundLoginPackets.LOGIN_ACKNOWLEDGED;
74-
wrapper.create(ackPacket).sendToServer(Protocol1_20To1_20_2.class);
75-
7675
// We can't set the internal state to configuration here as protocols down the line will expect the state to be play
76+
// Add this *before* sending the ack since the server might immediately answer
7777
wrapper.user().put(new ConfigurationPacketStorage());
78+
wrapper.create(ServerboundLoginPackets.LOGIN_ACKNOWLEDGED).sendToServer(Protocol1_20To1_20_2.class);
79+
// TODO Client needs to be set to CONFIGURATION state
7880
});
7981

8082
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.FINISH_CONFIGURATION.getId(), ClientboundConfigurationPackets1_20_2.FINISH_CONFIGURATION.getId(), wrapper -> {
8183
wrapper.cancel();
82-
wrapper.create(ServerboundConfigurationPackets1_20_2.FINISH_CONFIGURATION).sendToServer(Protocol1_20To1_20_2.class);
8384
wrapper.user().get(ConfigurationPacketStorage.class).setFinished(true);
85+
wrapper.create(ServerboundConfigurationPackets1_20_2.FINISH_CONFIGURATION).sendToServer(Protocol1_20To1_20_2.class);
86+
// TODO Client needs to be set to PLAY phase
8487
});
8588

8689
registerServerbound(State.LOGIN, ServerboundLoginPackets.HELLO.getId(), ServerboundLoginPackets.HELLO.getId(), wrapper -> {
@@ -96,6 +99,7 @@ protected void registerPackets() {
9699
// TODO: Check whether all the necessary data for the join game packet is always expected by the client or if we need to cache it from the initial login
97100
final PacketWrapper configAcknowledgedPacket = wrapper.create(ServerboundPackets1_20_2.CONFIGURATION_ACKNOWLEDGED);
98101
configAcknowledgedPacket.sendToServer(Protocol1_20To1_20_2.class);
102+
// TODO Client needs to be set to CONFIGURATION state
99103

100104
wrapper.user().put(new ConfigurationPacketStorage());
101105
});
@@ -159,6 +163,16 @@ public void transform(final Direction direction, final State state, final Packet
159163
}
160164
}
161165

166+
@Override
167+
protected @Nullable ServerboundPackets1_19_4 configurationAcknowledgedPacket() {
168+
return null;
169+
}
170+
171+
@Override
172+
protected @Nullable ServerboundPacketType finishConfigurationPacket() {
173+
return null;
174+
}
175+
162176
@Override
163177
public void init(final UserConnection connection) {
164178
addEntityTracker(connection, new EntityTrackerBase(connection, Entity1_19_4Types.PLAYER));

0 commit comments

Comments
 (0)