Some questions about multiconnect api
plusls opened this issue · 2 comments
I use MultiConnectAPI.instance().addServerboundIdentifierCustomPayloadListener
to my callback function, and call ultiConnectAPI.instance().forceSendCustomPayload(channel, data);
to send my packet to low version server.
forceSendCustomPayload
use MinecraftClient.getInstance().getNetworkHandler()
to get ClientPlayNetworkHandler
. But sometimes, getNetworkHandler()
return null but connect is established, and multiconnect will block some packet.
Some mod use some trick to bypass MinecraftClient.getInstance().getNetworkHandler()
and get real getNetworkHandler, such as bbor:
((ClientPlayNetworkHandler) netHandlerPlayClient).sendPacket(SubscribeToServer.getPayload().build());
I don't how to solve this problem elegantly. I use while loop
to do this.
@Override
public void onCustomPayload(int protocol, Identifier channel, PacketByteBuf data) {
while (true) {
try {
if (channel.equals(ServerNetworkHandler.REQUEST_BLOCK_ENTITY) || channel.equals(ServerNetworkHandler.REQUEST_ENTITY)) {
MasaGadgetMod.LOGGER.debug("forceSendCustomPayload: masagadget");
MultiConnectAPI.instance().forceSendCustomPayload(channel, data);
} else if (channel.equals(new Identifier("bbor:subscribe"))) {
MasaGadgetMod.LOGGER.debug("forceSendCustomPayload: bbor");
MultiConnectAPI.instance().forceSendCustomPayload(channel, data);
}
} catch (IllegalStateException e) {
// MinecraftClient.getInstance().getNetworkHandler() 在游戏刚连接时会返回 null
// 由于 multiconnect mixin 了 ClientPlayNetworkHandler.sendPacket
// 因此只能用死循环来缓解这个问题
// 不知道有没有优雅的解决方案
continue;
}
break;
}
}
I want to know how to solve this problem elegantly.
MinecraftClient.getInstance().getNetworkHandler()
can be null before the GameJoinS2CPacket
has been processed. Multiconnect really shouldn't be using MinecraftClient.getNetworkHandler
in this way. I'll work on a fix for this.