Only send tags early for 1.20.5+ clients, track early send properly in 1.20->1.20.2

This commit is contained in:
Nassim Jahnke 2024-11-17 11:43:19 +01:00
parent c525575d37
commit 5772ee4a93
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
4 changed files with 29 additions and 10 deletions

View File

@ -166,8 +166,8 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol<ClientboundPackets1_1
wrapper.write(Types.VAR_INT_ARRAY_PRIMITIVE, tag.getValue().clone());
}
});
if (w.user().getProtocolInfo().protocolVersion().newerThanOrEqualTo(ProtocolVersion.v1_20_2)) {
// Make sure it's included in the configuration packets
if (w.user().getProtocolInfo().protocolVersion().newerThanOrEqualTo(ProtocolVersion.v1_20_5)) {
// Make sure it's included in the configuration packets as it may already be required for registry data
tagsPacket.send(Protocol1_12_2To1_13.class);
} else {
tagsPacket.scheduleSend(Protocol1_12_2To1_13.class);

View File

@ -77,6 +77,7 @@ public final class Protocol1_20_2To1_20_3 extends AbstractProtocol<ClientboundPa
cancelServerbound(ServerboundPackets1_20_3.CONTAINER_SLOT_STATE_CHANGED);
tagRewriter.registerGeneric(ClientboundPackets1_20_2.UPDATE_TAGS);
tagRewriter.registerGeneric(ClientboundConfigurationPackets1_20_2.UPDATE_TAGS);
final SoundRewriter<ClientboundPacket1_20_2> soundRewriter = new SoundRewriter<>(this);
soundRewriter.registerSound1_19_3(ClientboundPackets1_20_2.SOUND);
@ -307,7 +308,6 @@ public final class Protocol1_20_2To1_20_3 extends AbstractProtocol<ClientboundPa
registerServerbound(ServerboundConfigurationPackets1_20_2.RESOURCE_PACK, resourcePackStatusHandler());
registerClientbound(ClientboundConfigurationPackets1_20_2.RESOURCE_PACK, ClientboundConfigurationPackets1_20_3.RESOURCE_PACK_PUSH, resourcePackHandler(ClientboundConfigurationPackets1_20_3.RESOURCE_PACK_POP));
tagRewriter.registerGeneric(ClientboundConfigurationPackets1_20_2.UPDATE_TAGS);
}
private PacketHandler resourcePackStatusHandler() {

View File

@ -124,11 +124,7 @@ public final class Protocol1_20To1_20_2 extends AbstractProtocol<ClientboundPack
wrapper.resetReader();
wrapper.user().put(new LastTags(wrapper));
});
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.UPDATE_TAGS, wrapper -> {
tagRewriter.handleGeneric(wrapper);
wrapper.resetReader();
wrapper.user().put(new LastTags(wrapper));
});
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.UPDATE_TAGS, this::handleConfigTags);
registerClientbound(ClientboundPackets1_19_4.SET_DISPLAY_OBJECTIVE, wrapper -> {
final byte slot = wrapper.read(Types.BYTE);
@ -229,6 +225,15 @@ public final class Protocol1_20To1_20_2 extends AbstractProtocol<ClientboundPack
});
}
private void handleConfigTags(final PacketWrapper wrapper) {
tagRewriter.handleGeneric(wrapper);
wrapper.resetReader();
final LastTags lastTags = new LastTags(wrapper);
lastTags.setSentDuringConfigPhase(true);
wrapper.user().put(lastTags);
}
private static void sanitizeCustomPayload(final PacketWrapper wrapper) {
final String channel = Key.namespaced(wrapper.get(Types.STRING, 0));
if (channel.equals("minecraft:brand")) {
@ -299,6 +304,7 @@ public final class Protocol1_20To1_20_2 extends AbstractProtocol<ClientboundPack
} else if (unmappedId == ClientboundPackets1_19_4.UPDATE_ENABLED_FEATURES.getId()) {
packetWrapper.setPacketType(ClientboundConfigurationPackets1_20_2.UPDATE_ENABLED_FEATURES);
} else if (unmappedId == ClientboundPackets1_19_4.UPDATE_TAGS.getId()) {
handleConfigTags(packetWrapper); // Manually put through handler
packetWrapper.setPacketType(ClientboundConfigurationPackets1_20_2.UPDATE_TAGS);
} else {
// Not a packet that can be mapped to the configuration protocol
@ -327,9 +333,13 @@ public final class Protocol1_20To1_20_2 extends AbstractProtocol<ClientboundPack
final LastTags lastTags = connection.get(LastTags.class);
if (lastTags != null) {
if (lastTags.sentDuringConfigPhase()) {
lastTags.setSentDuringConfigPhase(false);
} else {
// The server might still follow up with a tags packet, but we wouldn't know
lastTags.sendLastTags(connection);
}
}
if (lastResourcePack != null && connection.getProtocolInfo().protocolVersion() == ProtocolVersion.v1_20_2) {
// The client for some reason drops the resource pack when reentering the configuration state

View File

@ -31,6 +31,7 @@ import java.util.List;
public class LastTags implements StorableObject {
private final List<RegistryTags> registryTags = new ArrayList<>();
private boolean sentDuringConfigPhase;
public LastTags(final PacketWrapper wrapper) {
final int length = wrapper.passthrough(Types.VAR_INT);
@ -65,6 +66,14 @@ public class LastTags implements StorableObject {
packet.send(Protocol1_20To1_20_2.class);
}
public void setSentDuringConfigPhase(final boolean sentDuringConfigPhase) {
this.sentDuringConfigPhase = sentDuringConfigPhase;
}
public boolean sentDuringConfigPhase() {
return sentDuringConfigPhase;
}
private record RegistryTags(String registryKey, List<TagData> tags) {
}
}