Bon au final après avoir regardé du côté des packets du FML j’ai trouvé un truc assez simple pour envoyer des packets avant que le joueur soit entièrement connecté, il m’a suffit d’enregistrer de nouveaux packets.
J’envoie la classe (imparfaite) pour ceux à qui ça pourrait intéresser :
package fr.she3py.mods.zeptopia.network; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Map; import io.netty.channel.Channel; import io.netty.channel.ChannelFutureListener; import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.network.EnumConnectionState; import net.minecraft.network.EnumPacketDirection; import net.minecraft.network.INetHandler; import net.minecraft.network.NetHandlerPlayServer; import net.minecraft.network.Packet; import net.minecraftforge.fml.common.network.FMLNetworkEvent; import net.minecraftforge.fml.common.network.handshake.NetworkDispatcher; import net.minecraftforge.fml.relauncher.ReflectionHelper; import net.minecraftforge.fml.relauncher.ReflectionHelper.UnableToFindMethodException; public class DirectNetworkWrapper { private static final Method REGISTERER; static { try { REGISTERER = ReflectionHelper.findMethod(EnumConnectionState.class, "registerPacket", "a", EnumPacketDirection.class, Class.class); REGISTERER.setAccessible(true); } catch(UnableToFindMethodException | SecurityException e) { throw new RuntimeException("Unable to retrieve the method to register packets", e); } } public static void registerPacket(final EnumPacketDirection direction, final Class <? extends Packet<? >> packetClass) { try { REGISTERER.invoke(EnumConnectionState.PLAY, direction, packetClass); } catch(IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new RuntimeException("Unable to register a packet", e); } } public static void sendThrough(final Channel channel, final Packet<?> packet) { channel.writeAndFlush(packet).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); } public static <E extends FMLNetworkEvent<? extends INetHandler>> void sendToRemote(final E event, final Packet<?> packet) { sendThrough(event.getManager().channel(), packet); } public static <H extends INetHandler> void sendToRemote(final H handler, final Packet<?> packet) { if(handler instanceof NetHandlerPlayServer) sendThrough(((NetHandlerPlayServer) handler).netManager.channel(), packet); else sendThrough(((NetHandlerPlayClient) handler).getNetworkManager().channel(), packet); } }Il faut juste enregistrer les packets customs dans le CommonProxy via registerPacket(direction, packetClass), puis dans un évènement FMLNetworkEvent faire sendToRemote(event, packet), ou sendToRemote(handler, packet) dans un packet.
Cordialement,
ShE3py.