Class NetworkRegistry
java.lang.Object
net.minecraftforge.fmllegacy.network.NetworkRegistry
The network registry. Tracks channels on behalf of mods.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for constructing network channels using a builder style API.static classTracks individual outbound messages for dispatch to clients during login handling. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic StringSpecial value for clientAcceptedVersions and serverAcceptedVersions predicates indicating the other side lacks this channel.static Stringprivate static Map<ResourceLocation,NetworkInstance>private static booleanprivate static org.apache.logging.log4j.Loggerprivate static org.apache.logging.log4j.Marker -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionacceptMissingOr(String protocolVersion)Makes a version predicate that accepts connections to vanilla or without the channel.acceptMissingOr(Predicate<String> versionCheck)Makes a version predicate that accepts connections to vanilla or without the channel.static boolean(package private) static Map<ResourceLocation,String>Construct the Map representation of the channel list, for use during login handshaking(package private) static Map<ResourceLocation,org.apache.commons.lang3.tuple.Pair<String,Boolean>>Construct the Map representation of the channel list, for the client to check against during list pingstatic booleanstatic booleancheckListPingCompatibilityForClient(Map<ResourceLocation,org.apache.commons.lang3.tuple.Pair<String,Boolean>> incoming)private static NetworkInstancecreateInstance(ResourceLocation name, Supplier<String> networkProtocolVersion, Predicate<String> clientAcceptedVersions, Predicate<String> serverAcceptedVersions)Creates the internalNetworkInstancethat tracks the channel data.(package private) static Optional<NetworkInstance>findTarget(ResourceLocation resourceLocation)Find theNetworkInstance, if possible(package private) static List<NetworkRegistry.LoginPayload>gatherLoginPayloads(NetworkDirection direction, boolean isLocal)Retrieve theNetworkRegistry.LoginPayloadlist for dispatch duringFMLHandshakeHandler.tickLogin(Connection)handling.booleanisLocked()listRejectedVanillaMods(BiFunction<NetworkInstance,String,Boolean> testFunction)static voidlock()static EventNetworkChannelnewEventChannel(ResourceLocation name, Supplier<String> networkProtocolVersion, Predicate<String> clientAcceptedVersions, Predicate<String> serverAcceptedVersions)Create a newEventNetworkChannel.static SimpleChannelnewSimpleChannel(ResourceLocation name, Supplier<String> networkProtocolVersion, Predicate<String> clientAcceptedVersions, Predicate<String> serverAcceptedVersions)Create a newSimpleChannel.private static booleanvalidateChannels(Map<ResourceLocation,String> incoming, String originName, BiFunction<NetworkInstance,String,Boolean> testFunction)Tests if the map matches with the supplied predicate tester(package private) static booleanvalidateClientChannels(Map<ResourceLocation,String> channels)Validate the channels from the server on the client.(package private) static booleanvalidateServerChannels(Map<ResourceLocation,String> channels)Validate the channels from the client on the server.
-
Field Details
-
LOGGER
private static final org.apache.logging.log4j.Logger LOGGER -
NETREGISTRY
private static final org.apache.logging.log4j.Marker NETREGISTRY -
instances
-
ABSENT
Special value for clientAcceptedVersions and serverAcceptedVersions predicates indicating the other side lacks this channel. -
ACCEPTVANILLA
-
lock
private static boolean lock
-
-
Constructor Details
-
NetworkRegistry
public NetworkRegistry()
-
-
Method Details
-
acceptMissingOr
Makes a version predicate that accepts connections to vanilla or without the channel.- Parameters:
protocolVersion- The protocol version, which will be matched exactly.- Returns:
- A new predicate with the new conditions.
-
acceptMissingOr
Makes a version predicate that accepts connections to vanilla or without the channel.- Parameters:
versionCheck- The main version predicate, which should check the version number of the protocol.- Returns:
- A new predicate with the new conditions.
-
getServerNonVanillaNetworkMods
-
getClientNonVanillaNetworkMods
-
acceptsVanillaClientConnections
public static boolean acceptsVanillaClientConnections() -
canConnectToVanillaServer
public static boolean canConnectToVanillaServer() -
newSimpleChannel
public static SimpleChannel newSimpleChannel(ResourceLocation name, Supplier<String> networkProtocolVersion, Predicate<String> clientAcceptedVersions, Predicate<String> serverAcceptedVersions)Create a newSimpleChannel.- Parameters:
name- The registry name for this channel. Must be uniquenetworkProtocolVersion- The network protocol version string that will be offered to the remote sideNetworkRegistry.ChannelBuilder.networkProtocolVersion(Supplier)clientAcceptedVersions- Called on the client with the networkProtocolVersion string from the serverNetworkRegistry.ChannelBuilder.clientAcceptedVersions(Predicate)serverAcceptedVersions- Called on the server with the networkProtocolVersion string from the clientNetworkRegistry.ChannelBuilder.serverAcceptedVersions(Predicate)- Returns:
- A new
SimpleChannel - See Also:
newSimpleChannel(ResourceLocation, Supplier, Predicate, Predicate)
-
newEventChannel
public static EventNetworkChannel newEventChannel(ResourceLocation name, Supplier<String> networkProtocolVersion, Predicate<String> clientAcceptedVersions, Predicate<String> serverAcceptedVersions)Create a newEventNetworkChannel.- Parameters:
name- The registry name for this channel. Must be uniquenetworkProtocolVersion- The network protocol version string that will be offered to the remote sideNetworkRegistry.ChannelBuilder.networkProtocolVersion(Supplier)clientAcceptedVersions- Called on the client with the networkProtocolVersion string from the serverNetworkRegistry.ChannelBuilder.clientAcceptedVersions(Predicate)serverAcceptedVersions- Called on the server with the networkProtocolVersion string from the clientNetworkRegistry.ChannelBuilder.serverAcceptedVersions(Predicate)- Returns:
- A new
EventNetworkChannel - See Also:
newEventChannel(ResourceLocation, Supplier, Predicate, Predicate)
-
createInstance
private static NetworkInstance createInstance(ResourceLocation name, Supplier<String> networkProtocolVersion, Predicate<String> clientAcceptedVersions, Predicate<String> serverAcceptedVersions)Creates the internalNetworkInstancethat tracks the channel data.- Parameters:
name- registry namenetworkProtocolVersion- The protocol version stringclientAcceptedVersions- The client accepted predicateserverAcceptedVersions- The server accepted predicate- Returns:
- The
NetworkInstance - Throws:
IllegalArgumentException- if the name already exists
-
findTarget
Find theNetworkInstance, if possible- Parameters:
resourceLocation- The network instance to lookup- Returns:
- The
OptionalNetworkInstance
-
buildChannelVersions
Construct the Map representation of the channel list, for use during login handshaking -
buildChannelVersionsForListPing
static Map<ResourceLocation,org.apache.commons.lang3.tuple.Pair<String,Boolean>> buildChannelVersionsForListPing()Construct the Map representation of the channel list, for the client to check against during list ping -
listRejectedVanillaMods
static List<String> listRejectedVanillaMods(BiFunction<NetworkInstance,String,Boolean> testFunction) -
validateClientChannels
Validate the channels from the server on the client. Tests the client predicates against the server supplied network protocol version.- Parameters:
channels- An @Mapof name->version pairs for testing- Returns:
- true if all channels accept themselves
-
validateServerChannels
Validate the channels from the client on the server. Tests the server predicates against the client supplied network protocol version.- Parameters:
channels- An @Mapof name->version pairs for testing- Returns:
- true if all channels accept themselves
-
validateChannels
private static boolean validateChannels(Map<ResourceLocation,String> incoming, String originName, BiFunction<NetworkInstance,String,Boolean> testFunction)Tests if the map matches with the supplied predicate tester- Parameters:
incoming- An @Mapof name->version pairs for testingoriginName- A label for use in logging (where the version pairs came from)testFunction- The test function to use for testing- Returns:
- true if all channels accept themselves
-
gatherLoginPayloads
static List<NetworkRegistry.LoginPayload> gatherLoginPayloads(NetworkDirection direction, boolean isLocal)Retrieve theNetworkRegistry.LoginPayloadlist for dispatch duringFMLHandshakeHandler.tickLogin(Connection)handling. DispatchesNetworkEvent.GatherLoginPayloadsEventto eachNetworkInstance.- Parameters:
direction- the network direction for the request - only gathers for LOGIN_TO_CLIENT- Returns:
- The
NetworkRegistry.LoginPayloadlist
-
checkListPingCompatibilityForClient
public static boolean checkListPingCompatibilityForClient(Map<ResourceLocation,org.apache.commons.lang3.tuple.Pair<String,Boolean>> incoming) -
isLocked
public boolean isLocked() -
lock
public static void lock()
-