mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 16:54:22 +00:00
Let NetworkInstance.isRemotePresent check minecraft:register for channel IDs. (#8921)
This commit is contained in:
1 parent
874ff1bba2
commit
983c119477
3 files changed
+20
-1
No files matched your search
@@ -32,12 +32,14 @@ public class MCRegisterPacketHandler
|
||||
|
||||
public static class ChannelList {
|
||||
private Set<ResourceLocation> locations = new HashSet<>();
|
||||
private Set<ResourceLocation> remoteLocations = Set.of();
|
||||
|
||||
public void updateFrom(final Supplier<NetworkEvent.Context> source, FriendlyByteBuf buffer, final NetworkEvent.RegistrationChangeType changeType) {
|
||||
byte[] data = new byte[Math.max(buffer.readableBytes(), 0)];
|
||||
buffer.readBytes(data);
|
||||
Set<ResourceLocation> oldLocations = this.locations;
|
||||
this.locations = bytesToResLocation(data);
|
||||
this.remoteLocations = Set.copyOf(this.locations);
|
||||
// ensure all locations receive updates, old and new.
|
||||
oldLocations.addAll(this.locations);
|
||||
oldLocations.stream()
|
||||
@@ -76,6 +78,14 @@ public class MCRegisterPacketHandler
|
||||
}
|
||||
return rl;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the unmodifiable set of channel locations sent by the remote side}
|
||||
* This is useful for interacting with other modloaders via the network to inspect registered network channel IDs.
|
||||
*/
|
||||
public Set<ResourceLocation> getRemoteLocations() {
|
||||
return this.remoteLocations;
|
||||
}
|
||||
}
|
||||
|
||||
public void addChannels(Set<ResourceLocation> locations, Connection manager) {
|
||||
|
||||
@@ -231,4 +231,10 @@ public class NetworkHooks
|
||||
{
|
||||
return mgr.channel().attr(NetworkConstants.FML_MOD_MISMATCH_DATA).get();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static MCRegisterPacketHandler.ChannelList getChannelList(Connection mgr)
|
||||
{
|
||||
return mgr.channel().attr(NetworkConstants.FML_MC_REGISTRY).get();
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,9 @@ public class NetworkInstance
|
||||
|
||||
public boolean isRemotePresent(Connection manager) {
|
||||
ConnectionData connectionData = NetworkHooks.getConnectionData(manager);
|
||||
return connectionData != null && connectionData.getChannels().containsKey(channelName);
|
||||
MCRegisterPacketHandler.ChannelList channelList = NetworkHooks.getChannelList(manager);
|
||||
return (connectionData != null && connectionData.getChannels().containsKey(channelName))
|
||||
// if it's not in the fml connection data, let's check if it's sent by another modloader.
|
||||
|| (channelList != null && channelList.getRemoteLocations().contains(channelName));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user