Package net.minecraftforge.fml.network
Class NetworkRegistry
- java.lang.Object
-
- net.minecraftforge.fml.network.NetworkRegistry
-
public class NetworkRegistry extends java.lang.ObjectThe network registry. Tracks channels on behalf of mods.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classNetworkRegistry.ChannelBuilderBuilder for constructing network channels using a builder style API.static classNetworkRegistry.LoginPayloadTracks individual outbound messages for dispatch to clients during login handling.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringABSENTSpecial value for clientAcceptedVersions and serverAcceptedVersions predicates indicating the other side lacks this channel.static java.lang.StringACCEPTVANILLAprivate static java.util.Map<ResourceLocation,NetworkInstance>instancesprivate static booleanlockprivate static org.apache.logging.log4j.LoggerLOGGERprivate static org.apache.logging.log4j.MarkerNETREGISTRY
-
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 booleanacceptsVanillaClientConnections()(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 booleancanConnectToVanillaServer()static booleancheckListPingCompatibilityForClient(java.util.Map<ResourceLocation,org.apache.commons.lang3.tuple.Pair<java.lang.String,java.lang.Boolean>> incoming)private static NetworkInstancecreateInstance(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 internalNetworkInstancethat 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.LoginPayloadlist for dispatch duringFMLHandshakeHandler.tickLogin(NetworkManager)handling.static java.util.List<java.lang.String>getClientNonVanillaNetworkMods()static java.util.List<java.lang.String>getServerNonVanillaNetworkMods()booleanisLocked()(package private) static java.util.List<java.lang.String>listRejectedVanillaMods(java.util.function.BiFunction<NetworkInstance,java.lang.String,java.lang.Boolean> testFunction)static voidlock()static EventNetworkChannelnewEventChannel(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 SimpleChannelnewSimpleChannel(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 booleanvalidateChannels(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 booleanvalidateClientChannels(java.util.Map<ResourceLocation,java.lang.String> channels)Validate the channels from the server on the client.(package private) static booleanvalidateServerChannels(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 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:
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
OptionalNetworkInstance
-
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 @Mapof 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 @Mapof 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 @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 java.util.List<NetworkRegistry.LoginPayload> gatherLoginPayloads(NetworkDirection direction, boolean isLocal)
Retrieve theNetworkRegistry.LoginPayloadlist for dispatch duringFMLHandshakeHandler.tickLogin(NetworkManager)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(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()
-
-