Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.21.3] Relax extensible enum coherence checks for extensible enums without custom entries #1622

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,41 +75,41 @@ public static void handleClientboundPayload(ExtensibleEnumDataPayload payload, I
Map<String, EnumEntry> localEnumEntries = getEnumEntries();
Map<String, EnumEntry> remoteEnumEntries = payload.enumEntries();

Set<String> keyDiff = Sets.symmetricDifference(localEnumEntries.keySet(), remoteEnumEntries.keySet());
if (!keyDiff.isEmpty()) {
context.disconnect(Component.translatable("neoforge.network.extensible_enums.enum_set_mismatch"));
return;
}

Map<String, Mismatch> mismatched = new HashMap<>();
for (EnumEntry localEntry : localEnumEntries.values()) {
EnumEntry remoteEntry = remoteEnumEntries.get(localEntry.className);
if (!localEntry.isExtended() && !remoteEntry.isExtended()) {
for (String className : Sets.union(localEnumEntries.keySet(), remoteEnumEntries.keySet())) {
EnumEntry localEntry = localEnumEntries.get(className);
EnumEntry remoteEntry = remoteEnumEntries.get(className);
if ((localEntry == null && remoteEntry.isExtended()) || (remoteEntry == null && localEntry.isExtended())) {
mismatched.put(className, Mismatch.EXTENSIBILITY);
continue;
}

if ((localEntry == null || !localEntry.isExtended()) && (remoteEntry == null || !remoteEntry.isExtended())) {
continue;
}

if (localEntry.networkCheck != remoteEntry.networkCheck) {
mismatched.put(localEntry.className, Mismatch.NETWORK_CHECK);
mismatched.put(className, Mismatch.NETWORK_CHECK);
continue;
}

if (localEntry.isExtended() != remoteEntry.isExtended()) {
mismatched.put(localEntry.className, Mismatch.EXTENSION);
mismatched.put(className, Mismatch.EXTENSION);
continue;
}

ExtensionData localData = localEntry.data.orElseThrow();
ExtensionData remoteData = remoteEntry.data.orElseThrow();
if (localData.vanillaCount != remoteData.vanillaCount || localData.totalCount != remoteData.totalCount) {
mismatched.put(localEntry.className, Mismatch.ENTRY_COUNT);
mismatched.put(className, Mismatch.ENTRY_COUNT);
continue;
}

List<String> localValues = localData.entries;
List<String> remoteValues = remoteData.entries;
for (int i = 0; i < localData.totalCount - localData.vanillaCount; i++) {
if (!localValues.get(i).equals(remoteValues.get(i))) {
mismatched.put(localEntry.className, Mismatch.ENTRY_MISMATCH);
mismatched.put(className, Mismatch.ENTRY_MISMATCH);
break;
}
}
Expand All @@ -122,6 +122,13 @@ public static void handleClientboundPayload(ExtensibleEnumDataPayload payload, I
String enumClass = entry.getKey();
message.append("\n").append(enumClass).append(": ");
switch (entry.getValue()) {
case EXTENSIBILITY -> {
if (remoteEnumEntries.containsKey(enumClass)) {
message.append("Enum is extensible on the server but not on the client");
} else {
message.append("Enum is extensible on the client but not on the server");
}
}
case NETWORK_CHECK -> message.append("Mismatched NetworkCheck (server: ")
.append(remoteEnumEntries.get(enumClass).networkCheck)
.append(", client: ")
Expand Down Expand Up @@ -258,6 +265,7 @@ public record ExtensionData(int vanillaCount, int totalCount, List<String> entri
}

private enum Mismatch {
EXTENSIBILITY,
NETWORK_CHECK,
EXTENSION,
ENTRY_COUNT,
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/assets/neoforge/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@
"neoforge.network.data_maps.missing_their": "Cannot connect to server as it has mandatory registry data maps not present on the client: %s",

"neoforge.network.extensible_enums.no_vanilla_server": "This client does not support vanilla servers as it has extended enums used in serverbound networking",
"neoforge.network.extensible_enums.enum_set_mismatch": "The set of extensible enums on the client and server do not match. Make sure you are using the same NeoForge version as the server",
"neoforge.network.extensible_enums.enum_entry_mismatch": "The set of values added to extensible enums on the client and server do not match. Make sure you are using the same mod and NeoForge versions as the server. See the log for more details",

"neoforge.attribute.debug.base": "[Entity: %s | Item: %s]",
Expand Down