Package net.minecraftforge.fml.network
Class NetworkRegistry
- java.lang.Object
-
- net.minecraftforge.fml.network.NetworkRegistry
-
public class NetworkRegistry extends java.lang.Object
The network registry. Tracks channels on behalf of mods.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
NetworkRegistry.ChannelBuilder
Builder for constructing network channels using a builder style API.static class
NetworkRegistry.LoginPayload
Tracks individual outbound messages for dispatch to clients during login handling.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ABSENT
Special value for clientAcceptedVersions and serverAcceptedVersions predicates indicating the other side lacks this channel.static java.lang.String
ACCEPTVANILLA
private static java.util.Map<ResourceLocation,NetworkInstance>
instances
private static boolean
lock
private static org.apache.logging.log4j.Logger
LOGGER
private static org.apache.logging.log4j.Marker
NETREGISTRY
-
Constructor Summary
Constructors Constructor Description NetworkRegistry()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.util.function.Predicate<java.lang.String>
acceptMissingOr(java.lang.String protocolVersion)
Makes a version predicate that accepts connections to vanilla or without the channel.static java.util.function.Predicate<java.lang.String>
acceptMissingOr(java.util.function.Predicate<java.lang.String> versionCheck)
Makes a version predicate that accepts connections to vanilla or without the channel.static boolean
acceptsVanillaClientConnections()
(package private) static java.util.Map<ResourceLocation,java.lang.String>
buildChannelVersions()
Construct the Map representation of the channel list, for use during login handshaking(package private) static java.util.Map<ResourceLocation,org.apache.commons.lang3.tuple.Pair<java.lang.String,java.lang.Boolean>>
buildChannelVersionsForListPing()
Construct the Map representation of the channel list, for the client to check against during list pingstatic boolean
canConnectToVanillaServer()
static boolean
checkListPingCompatibilityForClient(java.util.Map<ResourceLocation,org.apache.commons.lang3.tuple.Pair<java.lang.String,java.lang.Boolean>> incoming)
private static NetworkInstance
createInstance(ResourceLocation name, java.util.function.Supplier<java.lang.String> networkProtocolVersion, java.util.function.Predicate<java.lang.String> clientAcceptedVersions, java.util.function.Predicate<java.lang.String> serverAcceptedVersions)
Creates the internalNetworkInstance
that tracks the channel data.(package private) static java.util.Optional<NetworkInstance>
findTarget(ResourceLocation resourceLocation)
Find theNetworkInstance
, if possible(package private) static java.util.List<NetworkRegistry.LoginPayload>
gatherLoginPayloads(NetworkDirection direction, boolean isLocal)
Retrieve theNetworkRegistry.LoginPayload
list for dispatch duringFMLHandshakeHandler.tickLogin(NetworkManager)
handling.static java.util.List<java.lang.String>
getClientNonVanillaNetworkMods()
static java.util.List<java.lang.String>
getServerNonVanillaNetworkMods()
boolean
isLocked()
(package private) static java.util.List<java.lang.String>
listRejectedVanillaMods(java.util.function.BiFunction<NetworkInstance,java.lang.String,java.lang.Boolean> testFunction)
static void
lock()
static EventNetworkChannel
newEventChannel(ResourceLocation name, java.util.function.Supplier<java.lang.String> networkProtocolVersion, java.util.function.Predicate<java.lang.String> clientAcceptedVersions, java.util.function.Predicate<java.lang.String> serverAcceptedVersions)
Create a newEventNetworkChannel
.static SimpleChannel
newSimpleChannel(ResourceLocation name, java.util.function.Supplier<java.lang.String> networkProtocolVersion, java.util.function.Predicate<java.lang.String> clientAcceptedVersions, java.util.function.Predicate<java.lang.String> serverAcceptedVersions)
Create a newSimpleChannel
.private static boolean
validateChannels(java.util.Map<ResourceLocation,java.lang.String> incoming, java.lang.String originName, java.util.function.BiFunction<NetworkInstance,java.lang.String,java.lang.Boolean> testFunction)
Tests if the map matches with the supplied predicate tester(package private) static boolean
validateClientChannels(java.util.Map<ResourceLocation,java.lang.String> channels)
Validate the channels from the server on the client.(package private) static boolean
validateServerChannels(java.util.Map<ResourceLocation,java.lang.String> channels)
Validate the channels from the client on the server.
-
-
-
Field Detail
-
LOGGER
private static final org.apache.logging.log4j.Logger LOGGER
-
NETREGISTRY
private static final org.apache.logging.log4j.Marker NETREGISTRY
-
instances
private static java.util.Map<ResourceLocation,NetworkInstance> instances
-
ABSENT
public static java.lang.String ABSENT
Special value for clientAcceptedVersions and serverAcceptedVersions predicates indicating the other side lacks this channel.
-
ACCEPTVANILLA
public static java.lang.String ACCEPTVANILLA
-
lock
private static boolean lock
-
-
Method Detail
-
acceptMissingOr
public static java.util.function.Predicate<java.lang.String> acceptMissingOr(java.lang.String protocolVersion)
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
public static java.util.function.Predicate<java.lang.String> acceptMissingOr(java.util.function.Predicate<java.lang.String> versionCheck)
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
public static java.util.List<java.lang.String> getServerNonVanillaNetworkMods()
-
getClientNonVanillaNetworkMods
public static java.util.List<java.lang.String> getClientNonVanillaNetworkMods()
-
acceptsVanillaClientConnections
public static boolean acceptsVanillaClientConnections()
-
canConnectToVanillaServer
public static boolean canConnectToVanillaServer()
-
newSimpleChannel
public static SimpleChannel newSimpleChannel(ResourceLocation name, java.util.function.Supplier<java.lang.String> networkProtocolVersion, java.util.function.Predicate<java.lang.String> clientAcceptedVersions, java.util.function.Predicate<java.lang.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, java.util.function.Supplier<java.lang.String> networkProtocolVersion, java.util.function.Predicate<java.lang.String> clientAcceptedVersions, java.util.function.Predicate<java.lang.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, java.util.function.Supplier<java.lang.String> networkProtocolVersion, java.util.function.Predicate<java.lang.String> clientAcceptedVersions, java.util.function.Predicate<java.lang.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:
java.lang.IllegalArgumentException
- if the name already exists
-
findTarget
static java.util.Optional<NetworkInstance> findTarget(ResourceLocation resourceLocation)
Find theNetworkInstance
, if possible- Parameters:
resourceLocation
- The network instance to lookup- Returns:
- The
Optional
NetworkInstance
-
buildChannelVersions
static java.util.Map<ResourceLocation,java.lang.String> buildChannelVersions()
Construct the Map representation of the channel list, for use during login handshaking
-
buildChannelVersionsForListPing
static java.util.Map<ResourceLocation,org.apache.commons.lang3.tuple.Pair<java.lang.String,java.lang.Boolean>> buildChannelVersionsForListPing()
Construct the Map representation of the channel list, for the client to check against during list ping
-
listRejectedVanillaMods
static java.util.List<java.lang.String> listRejectedVanillaMods(java.util.function.BiFunction<NetworkInstance,java.lang.String,java.lang.Boolean> testFunction)
-
validateClientChannels
static boolean validateClientChannels(java.util.Map<ResourceLocation,java.lang.String> channels)
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
static boolean validateServerChannels(java.util.Map<ResourceLocation,java.lang.String> channels)
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(java.util.Map<ResourceLocation,java.lang.String> incoming, java.lang.String originName, java.util.function.BiFunction<NetworkInstance,java.lang.String,java.lang.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 java.util.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(java.util.Map<ResourceLocation,org.apache.commons.lang3.tuple.Pair<java.lang.String,java.lang.Boolean>> incoming)
-
isLocked
public boolean isLocked()
-
lock
public static void lock()
-
-