Revert "Send registry data before finish configuration in 1.20.5->1.20.3 (#778)"

This reverts commit e93e30c235.
This commit is contained in:
Nassim Jahnke 2024-06-08 19:58:14 +02:00
parent 7bd43e0234
commit bfbc086f44
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
2 changed files with 30 additions and 9 deletions

View File

@ -41,7 +41,6 @@ import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.rewriter.CommandRewriter1_19_4;
import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundConfigurationPackets1_20_2;
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundConfigurationPackets1_20_3;
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundPacket1_20_3;
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundPackets1_20_3;
@ -55,6 +54,7 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundCon
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.BannerPatternStorage;
import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundConfigurationPackets1_20_2;
import com.viaversion.viaversion.rewriter.ComponentRewriter.ReadType;
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;
@ -78,16 +78,17 @@ public final class Protocol1_20_5To1_20_3 extends BackwardsProtocol<ClientboundP
super.registerPackets();
tagRewriter.registerGeneric(ClientboundPackets1_20_5.UPDATE_TAGS);
tagRewriter.registerGeneric(ClientboundConfigurationPackets1_20_5.UPDATE_TAGS);
registerClientbound(ClientboundPackets1_20_5.START_CONFIGURATION, wrapper -> wrapper.user().get(RegistryDataStorage.class).clear());
registerClientbound(ClientboundConfigurationPackets1_20_5.UPDATE_TAGS, wrapper -> {
// Send off registry data first, needed for tags
sendRegistryData(wrapper.user());
tagRewriter.getGenericHandler().handle(wrapper);
});
registerClientbound(ClientboundConfigurationPackets1_20_5.FINISH_CONFIGURATION, wrapper -> {
// Send off registry data first
final PacketWrapper registryDataPacket = wrapper.create(ClientboundConfigurationPackets1_20_3.REGISTRY_DATA);
registryDataPacket.write(Types.COMPOUND_TAG, wrapper.user().get(RegistryDataStorage.class).registryData().copy());
registryDataPacket.send(Protocol1_20_5To1_20_3.class);
// In case the server for some reason does not send tags
sendRegistryData(wrapper.user());
});
registerClientbound(ClientboundPackets1_20_5.START_CONFIGURATION, wrapper -> wrapper.user().get(RegistryDataStorage.class).clear());
final SoundRewriter<ClientboundPacket1_20_5> soundRewriter = new SoundRewriter<>(this);
soundRewriter.registerSound1_19_3(ClientboundPackets1_20_5.SOUND);
@ -182,6 +183,16 @@ public final class Protocol1_20_5To1_20_3 extends BackwardsProtocol<ClientboundP
cancelClientbound(ClientboundPackets1_20_5.DEBUG_SAMPLE);
}
private void sendRegistryData(final UserConnection connection) {
final RegistryDataStorage registryDataStorage = connection.get(RegistryDataStorage.class);
if (!registryDataStorage.sentRegistryData()) {
final PacketWrapper registryDataPacket = PacketWrapper.create(ClientboundConfigurationPackets1_20_3.REGISTRY_DATA, connection);
registryDataPacket.write(Types.COMPOUND_TAG, registryDataStorage.registryData().copy());
registryDataPacket.send(Protocol1_20_5To1_20_3.class);
registryDataStorage.setSentRegistryData();
}
}
private void handleStoreCookie(final PacketWrapper wrapper) {
wrapper.cancel();

View File

@ -17,19 +17,28 @@
*/
package com.viaversion.viabackwards.protocol.v1_20_5to1_20_3.storage;
import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.api.connection.StorableObject;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class RegistryDataStorage implements StorableObject {
private final CompoundTag registryData = new CompoundTag();
private String[] dimensionKeys;
private boolean sentRegistryData;
public CompoundTag registryData() {
return registryData;
}
public boolean sentRegistryData() {
return sentRegistryData;
}
public void setSentRegistryData() {
this.sentRegistryData = true;
}
public String @Nullable [] dimensionKeys() {
return dimensionKeys;
}
@ -41,5 +50,6 @@ public final class RegistryDataStorage implements StorableObject {
public void clear() {
registryData.clear();
dimensionKeys = null;
sentRegistryData = false;
}
}