Package net.minecraftforge.fml.network
Class NetworkRegistry
java.lang.Object
net.minecraftforge.fml.network.NetworkRegistry
The network registry. Tracks channels on behalf of mods.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Builder for constructing network channels using a builder style API.static class
Tracks individual outbound messages for dispatch to clients during login handling. -
Field Summary
Modifier and TypeFieldDescriptionstatic String
Special value for clientAcceptedVersions and serverAcceptedVersions predicates indicating the other side lacks this channel.static String
private static Map<ResourceLocation,
NetworkInstance> private static boolean
private static final org.apache.logging.log4j.Logger
private static final org.apache.logging.log4j.Marker
-
Constructor Summary
-
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 boolean
static boolean
checkListPingCompatibilityForClient
(Map<ResourceLocation, org.apache.commons.lang3.tuple.Pair<String, Boolean>> incoming) private static NetworkInstance
createInstance
(ResourceLocation name, Supplier<String> networkProtocolVersion, Predicate<String> clientAcceptedVersions, Predicate<String> serverAcceptedVersions) Creates the internalNetworkInstance
that 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.LoginPayload
list for dispatch duringFMLHandshakeHandler.tickLogin(NetworkManager)
handling.boolean
isLocked()
listRejectedVanillaMods
(BiFunction<NetworkInstance, String, Boolean> testFunction) static void
lock()
static EventNetworkChannel
newEventChannel
(ResourceLocation name, Supplier<String> networkProtocolVersion, Predicate<String> clientAcceptedVersions, Predicate<String> serverAcceptedVersions) Create a newEventNetworkChannel
.static SimpleChannel
newSimpleChannel
(ResourceLocation name, Supplier<String> networkProtocolVersion, Predicate<String> clientAcceptedVersions, Predicate<String> serverAcceptedVersions) Create a newSimpleChannel
.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(package private) static boolean
validateClientChannels
(Map<ResourceLocation, String> channels) Validate the channels from the server on the client.(package private) static boolean
validateServerChannels
(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:
-
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:
-
createInstance
private static NetworkInstance createInstance(ResourceLocation name, Supplier<String> networkProtocolVersion, Predicate<String> clientAcceptedVersions, Predicate<String> serverAcceptedVersions) Creates the internalNetworkInstance
that 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
Optional
NetworkInstance
-
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, buildChannelVersionsForListPing()Boolean>> 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 @Map
of 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 @Map
of 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 @Map
of 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.LoginPayload
list for dispatch duringFMLHandshakeHandler.tickLogin(NetworkManager)
handling. DispatchesNetworkEvent.GatherLoginPayloadsEvent
to eachNetworkInstance
.- Parameters:
direction
- the network direction for the request - only gathers for LOGIN_TO_CLIENT- Returns:
- The
NetworkRegistry.LoginPayload
list
-
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()
-