Skip to content

Commit

Permalink
Relax extensible enum coherence checks for extensible enums without c…
Browse files Browse the repository at this point in the history
…ustom entries
  • Loading branch information
XFactHD committed Oct 23, 2024
1 parent dd989e5 commit c8b24b8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
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

0 comments on commit c8b24b8

Please sign in to comment.