Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 4677452

Browse files
committed
Remove unused imports, fix logic error in checkListPingCompatibilityForClient
1 parent c731f66 commit 4677452

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

patchwork-networking/src/main/java/com/patchworkmc/impl/networking/NetworkVersionManager.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
import java.util.Set;
3030
import java.util.function.BiPredicate;
3131
import java.util.function.Function;
32-
import java.util.stream.Collectors;
3332

34-
import net.minecraftforge.fml.network.NetworkRegistry;
3533
import org.apache.commons.lang3.tuple.Pair;
3634
import org.apache.logging.log4j.LogManager;
3735
import org.apache.logging.log4j.Logger;
@@ -84,7 +82,7 @@ public Map<Identifier, Pair<String, Boolean>> buildChannelVersionsForListPing()
8482
continue;
8583
}
8684

87-
Pair<String, Boolean> version = Pair.of(channel.getNetworkProtocolVersion(), channel.tryClientVersionOnServer(NetworkRegistry.ABSENT));
85+
Pair<String, Boolean> version = Pair.of(channel.getNetworkProtocolVersion(), channel.tryClientVersionOnServer(ABSENT));
8886

8987
channelVersions.put(name, version);
9088
}
@@ -93,11 +91,11 @@ public Map<Identifier, Pair<String, Boolean>> buildChannelVersionsForListPing()
9391
}
9492

9593
public List<String> getServerNonVanillaNetworkMods() {
96-
return validateChannels(identifier -> NetworkRegistry.ACCEPTVANILLA, Origin.VANILLA, VersionedChannel::tryClientVersionOnServer);
94+
return validateChannels(identifier -> ACCEPTVANILLA, Origin.VANILLA, VersionedChannel::tryClientVersionOnServer);
9795
}
9896

9997
public List<String> getClientNonVanillaNetworkMods() {
100-
return validateChannels(identifier -> NetworkRegistry.ACCEPTVANILLA, Origin.VANILLA, VersionedChannel::tryServerVersionOnClient);
98+
return validateChannels(identifier -> ACCEPTVANILLA, Origin.VANILLA, VersionedChannel::tryServerVersionOnClient);
10199
}
102100

103101
/**
@@ -133,8 +131,13 @@ private List<String> validateChannels(final Function<Identifier, String> incomin
133131
List<String> rejected = new ArrayList<>();
134132

135133
for (VersionedChannel channel: channels) {
134+
if (origin == Origin.PING && channel.getChannelName().getNamespace().equals("fml")) {
135+
// FML channels are not checked during the ping process.
136+
continue;
137+
}
138+
136139
final String incomingVersion = incoming.apply(channel.getChannelName());
137-
final boolean accepted = predicate.test(channel, incomingVersion != null ? incomingVersion : NetworkRegistry.ABSENT);
140+
final boolean accepted = predicate.test(channel, incomingVersion != null ? incomingVersion : ABSENT);
138141

139142
if (!accepted) {
140143
rejected.add(channel.getChannelName().toString());
@@ -179,9 +182,6 @@ private List<String> validateChannels(final Function<Identifier, String> incomin
179182
}
180183

181184
public boolean checkListPingCompatibilityForClient(Map<Identifier, Pair<String, Boolean>> incoming) {
182-
// TODO: don't mutate map here, modify the call site instead
183-
incoming.keySet().removeIf(name -> name.getNamespace().equals("fml"));
184-
185185
List<String> rejected = validateChannels(identifier -> {
186186
Pair<String, Boolean> entry = incoming.get(identifier);
187187

@@ -203,7 +203,8 @@ public boolean checkListPingCompatibilityForClient(Map<Identifier, Pair<String,
203203
Identifier channelName = entry.getKey();
204204
boolean required = entry.getValue().getRight();
205205

206-
if (!required || handled.contains(channelName)) {
206+
// We're looking for required and non FML channels that do not exist in our list of channels.
207+
if (!required || channelName.getNamespace().equals("fml") || handled.contains(channelName)) {
207208
continue;
208209
}
209210

0 commit comments

Comments
 (0)