Search in sources :

Example 1 with SimpleChannel

use of net.minecraftforge.network.simple.SimpleChannel in project MinecraftForge by MinecraftForge.

the class NetworkInitialization method getHandshakeChannel.

public static SimpleChannel getHandshakeChannel() {
    SimpleChannel handshakeChannel = NetworkRegistry.ChannelBuilder.named(NetworkConstants.FML_HANDSHAKE_RESOURCE).clientAcceptedVersions(a -> true).serverAcceptedVersions(a -> true).networkProtocolVersion(() -> NetworkConstants.NETVERSION).simpleChannel();
    handshakeChannel.messageBuilder(HandshakeMessages.C2SAcknowledge.class, 99, NetworkDirection.LOGIN_TO_SERVER).loginIndex(HandshakeMessages.LoginIndexedMessage::getLoginIndex, HandshakeMessages.LoginIndexedMessage::setLoginIndex).decoder(HandshakeMessages.C2SAcknowledge::decode).encoder(HandshakeMessages.C2SAcknowledge::encode).consumer(HandshakeHandler.indexFirst(HandshakeHandler::handleClientAck)).add();
    handshakeChannel.messageBuilder(HandshakeMessages.S2CModList.class, 1, NetworkDirection.LOGIN_TO_CLIENT).loginIndex(HandshakeMessages.LoginIndexedMessage::getLoginIndex, HandshakeMessages.LoginIndexedMessage::setLoginIndex).decoder(HandshakeMessages.S2CModList::decode).encoder(HandshakeMessages.S2CModList::encode).markAsLoginPacket().consumer(HandshakeHandler.biConsumerFor(HandshakeHandler::handleServerModListOnClient)).add();
    handshakeChannel.messageBuilder(HandshakeMessages.C2SModListReply.class, 2, NetworkDirection.LOGIN_TO_SERVER).loginIndex(HandshakeMessages.LoginIndexedMessage::getLoginIndex, HandshakeMessages.LoginIndexedMessage::setLoginIndex).decoder(HandshakeMessages.C2SModListReply::decode).encoder(HandshakeMessages.C2SModListReply::encode).consumer(HandshakeHandler.indexFirst(HandshakeHandler::handleClientModListOnServer)).add();
    handshakeChannel.messageBuilder(HandshakeMessages.S2CRegistry.class, 3, NetworkDirection.LOGIN_TO_CLIENT).loginIndex(HandshakeMessages.LoginIndexedMessage::getLoginIndex, HandshakeMessages.LoginIndexedMessage::setLoginIndex).decoder(HandshakeMessages.S2CRegistry::decode).encoder(HandshakeMessages.S2CRegistry::encode).buildLoginPacketList(// TODO: Make this non-static, and store a cache on the client.
    RegistryManager::generateRegistryPackets).consumer(HandshakeHandler.biConsumerFor(HandshakeHandler::handleRegistryMessage)).add();
    handshakeChannel.messageBuilder(HandshakeMessages.S2CConfigData.class, 4, NetworkDirection.LOGIN_TO_CLIENT).loginIndex(HandshakeMessages.LoginIndexedMessage::getLoginIndex, HandshakeMessages.LoginIndexedMessage::setLoginIndex).decoder(HandshakeMessages.S2CConfigData::decode).encoder(HandshakeMessages.S2CConfigData::encode).buildLoginPacketList(ConfigSync.INSTANCE::syncConfigs).consumer(HandshakeHandler.biConsumerFor(HandshakeHandler::handleConfigSync)).add();
    return handshakeChannel;
}
Also used : Arrays(java.util.Arrays) List(java.util.List) SimpleChannel(net.minecraftforge.network.simple.SimpleChannel) EventNetworkChannel(net.minecraftforge.network.event.EventNetworkChannel) RegistryManager(net.minecraftforge.registries.RegistryManager) SimpleChannel(net.minecraftforge.network.simple.SimpleChannel) RegistryManager(net.minecraftforge.registries.RegistryManager)

Example 2 with SimpleChannel

use of net.minecraftforge.network.simple.SimpleChannel in project MinecraftForge by MinecraftForge.

the class NetworkInitialization method getPlayChannel.

public static SimpleChannel getPlayChannel() {
    SimpleChannel playChannel = NetworkRegistry.ChannelBuilder.named(NetworkConstants.FML_PLAY_RESOURCE).clientAcceptedVersions(a -> true).serverAcceptedVersions(a -> true).networkProtocolVersion(() -> NetworkConstants.NETVERSION).simpleChannel();
    playChannel.messageBuilder(PlayMessages.SpawnEntity.class, 0).decoder(PlayMessages.SpawnEntity::decode).encoder(PlayMessages.SpawnEntity::encode).consumer(PlayMessages.SpawnEntity::handle).add();
    playChannel.messageBuilder(PlayMessages.OpenContainer.class, 1).decoder(PlayMessages.OpenContainer::decode).encoder(PlayMessages.OpenContainer::encode).consumer(PlayMessages.OpenContainer::handle).add();
    return playChannel;
}
Also used : Arrays(java.util.Arrays) List(java.util.List) SimpleChannel(net.minecraftforge.network.simple.SimpleChannel) EventNetworkChannel(net.minecraftforge.network.event.EventNetworkChannel) RegistryManager(net.minecraftforge.registries.RegistryManager) SimpleChannel(net.minecraftforge.network.simple.SimpleChannel)

Aggregations

Arrays (java.util.Arrays)2 List (java.util.List)2 EventNetworkChannel (net.minecraftforge.network.event.EventNetworkChannel)2 SimpleChannel (net.minecraftforge.network.simple.SimpleChannel)2 RegistryManager (net.minecraftforge.registries.RegistryManager)2