Don't re-enter config state if the dimension registry did not change

This commit is contained in:
Nassim Jahnke 2023-09-19 21:14:45 +10:00
parent fe5646a68c
commit 16f89f2638
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
3 changed files with 22 additions and 27 deletions

View File

@ -133,7 +133,7 @@ public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPack
wrapper.cancel();
final ConfigurationState configurationState = wrapper.user().get(ConfigurationState.class);
if (configurationState.getReenterInfo() == null) {
if (configurationState.bridgePhase() != BridgePhase.REENTERING_CONFIGURATION) {
return;
}
@ -141,8 +141,7 @@ public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPack
configurationState.setBridgePhase(BridgePhase.CONFIGURATION);
final LastResourcePack lastResourcePack = wrapper.user().get(LastResourcePack.class);
sendConfigurationPackets(wrapper.user(), configurationState.getReenterInfo().dimensionRegistry(), lastResourcePack);
configurationState.setReenterInfo(null);
sendConfigurationPackets(wrapper.user(), configurationState.lastDimensionRegistry(), lastResourcePack);
});
cancelServerbound(ServerboundPackets1_20_2.CHUNK_BATCH_RECEIVED);
@ -203,7 +202,6 @@ public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPack
if (!packetWrapper.user().isClientSide() && !Via.getPlatform().isProxy() && unmappedId == ClientboundPackets1_19_4.SYSTEM_CHAT.getId()) {
// Cancelling this on the Vanilla server will cause it to exceptionally resend a message
// Assume that we have already sent the login packet and just let it through
// TODO Maybe just don't wait for the finish config response?
super.transform(direction, State.PLAY, packetWrapper);
return;
}

View File

@ -27,7 +27,6 @@ import com.viaversion.viaversion.api.type.types.version.Types1_20;
import com.viaversion.viaversion.api.type.types.version.Types1_20_2;
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.Protocol1_20_2To1_20;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundConfigurationPackets1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPackets1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.storage.ConfigurationState;
import com.viaversion.viaversion.rewriter.EntityRewriter;
@ -99,17 +98,19 @@ public final class EntityPacketRewriter1_20_2 extends EntityRewriter<Clientbound
// Debug, flat, last death pos, and portal cooldown at the end unchanged
// Send configuration packets first before going into the play protocol state
ConfigurationState configurationBridge = wrapper.user().get(ConfigurationState.class);
final ConfigurationState configurationBridge = wrapper.user().get(ConfigurationState.class);
if (!configurationBridge.setLastDimensionRegistry(dimensionRegistry)) {
// No change, so no need to re-enter the configuration state - just let this one through
return;
}
if (configurationBridge.bridgePhase() == ConfigurationState.BridgePhase.NONE) {
// Reenter the configuration state
final PacketWrapper configurationPacket = wrapper.create(ClientboundPackets1_20_2.START_CONFIGURATION);
configurationPacket.send(Protocol1_20_2To1_20.class);
// TODO The client clears the resource pack when reentering (?)
configurationBridge.setBridgePhase(ConfigurationState.BridgePhase.REENTERING_CONFIGURATION);
configurationBridge.setJoinGamePacket(wrapper);
configurationBridge.setReenterInfo(new ConfigurationState.ReenterInfo(dimensionRegistry));
wrapper.cancel();
return;
}

View File

@ -27,6 +27,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.checkerframework.checker.nullness.qual.Nullable;
public class ConfigurationState implements StorableObject {
@ -35,7 +36,7 @@ public class ConfigurationState implements StorableObject {
private BridgePhase bridgePhase = BridgePhase.NONE;
private QueuedPacket joinGamePacket;
private boolean queuedJoinGame;
private ReenterInfo reenterInfo;
private CompoundTag lastDimensionRegistry;
public BridgePhase bridgePhase() {
return bridgePhase;
@ -45,12 +46,20 @@ public class ConfigurationState implements StorableObject {
this.bridgePhase = bridgePhase;
}
public @Nullable ReenterInfo getReenterInfo() {
return reenterInfo;
public @Nullable CompoundTag lastDimensionRegistry() {
return lastDimensionRegistry;
}
public void setReenterInfo(@Nullable final ReenterInfo reenterInfo) {
this.reenterInfo = reenterInfo;
/**
* Sets the last dimension registry and returns whether it differs from the previously stored one.
*
* @param dimensionRegistry dimension registry to set
* @return whether the dimension registry differs from the previously stored one
*/
public boolean setLastDimensionRegistry(final CompoundTag dimensionRegistry) {
final boolean equals = Objects.equals(this.lastDimensionRegistry, dimensionRegistry);
this.lastDimensionRegistry = dimensionRegistry;
return !equals;
}
public void addPacketToQueue(final PacketWrapper wrapper, final boolean clientbound) throws Exception {
@ -123,7 +132,6 @@ public class ConfigurationState implements StorableObject {
packetQueue.clear();
bridgePhase = BridgePhase.NONE;
queuedJoinGame = false;
reenterInfo = null;
}
public boolean queuedOrSentJoinGame() {
@ -181,16 +189,4 @@ public class ConfigurationState implements StorableObject {
'}';
}
}
public static final class ReenterInfo {
private final CompoundTag dimensionRegistry;
public ReenterInfo(final CompoundTag dimensionRegistry) {
this.dimensionRegistry = dimensionRegistry;
}
public CompoundTag dimensionRegistry() {
return dimensionRegistry;
}
}
}