Résolu Envoi de packets en 1.12.2
-
Bonjour,
je suis actuellement sur un mod en 1.12.2 pour un serveur et je cherche comment utiliser un SimpleNetworkWrapper pour envoyer des packets.
Je pense qu’il y a une histoire de proxy, j’ai créé un SimpleNetworkWrapper init dans l’event de preInit, ensuite c’est la preInit du proxy et le CommonNetworkHandler s’init(c’est une classe classe où j’enregistre des packets) :@SidedProxy(clientSide = References.CLIENT_PROXY, serverSide = References.SERVER_PROXY) public static ExaCommonProxy proxy; public static SimpleNetworkWrapper NETWORK; @EventHandler public void preInit(FMLPreInitializationEvent event) { NETWORK = NetworkRegistry.INSTANCE.newSimpleChannel(References.MODID); proxy.preInit(); CommonNetworkHandler.init(); }
Le CommonNetworkHandler :
public class CommonNetworkHandler { public static void init() { ExaMod.NETWORK.registerMessage(PacketExacarb.PacketExacarbHandler.class, PacketExacarb.class, 1, Side.CLIENT); ExaMod.NETWORK.registerMessage(CPacketMessage.CPacketMessageHandler.class, CPacketMessage.class, 3, Side.CLIENT); ExaMod.NETWORK.registerMessage(CPacketOpenGui.CPacketOpenGuiHandler.class, CPacketOpenGui.class, 5, Side.CLIENT); ExaMod.NETWORK.registerMessage(CPacketOpenGuiGuilds.CPacketOpenGuiGuildsHandler.class,CPacketOpenGuiGuilds.class, 9, Side.CLIENT); ExaMod.NETWORK.registerMessage(PacketSpell.PacketSpellHandler.class, PacketSpell.class, 0, Side.SERVER); } }
Le ClientNetworkHandler(la classe des packets destinés au serveur seulement) :
public class ClientNetworkHandler { public static void init() { ExaMod.NETWORK.registerMessage(SPacketMessage.SPacketMessageHandler.class, SPacketMessage.class, 4, Side.SERVER); ExaMod.NETWORK.registerMessage(SPacketShopBuy.SPacketShopBuyHandler.class, SPacketShopBuy.class, 6, Side.SERVER); ExaMod.NETWORK.registerMessage(SPacketShopSell.SPacketShopSellHandler.class, SPacketShopSell.class, 7, Side.SERVER); ExaMod.NETWORK.registerMessage(SPacketShopNumberItem.SPacketShopNumberItemHandler.class, SPacketShopNumberItem.class, 8, Side.SERVER); } }
Pourrez vous m’aidez svp ?
-
Bonsoir,
Ce tutoriel est valide pour la 1.12.2 : https://www.minecraftforgefrance.fr/topic/1000/1-7-2-le-network
Tes paquets doivent toujours être sur les deux sides, il n’y a aucune raison d’avoir des paquets “serveur uniquement” (à la limiter, c’est l’handler du paquet qui va être exécuté que d’un côté, mais le code du paquet doit être sur les deux, car le client doit savoir comment sérialiser le contenu du paquet)
-
@robin4002 d’accord merci, où je devrais init chaque networkHandler ? Dans le CommonProxy tous les deux ? La classe principale ou le client proxy/server proxy ?
-
Tu ne devrais avoir qu’un seul network handler, qui est initialisé dans ou depuis la classe principale.
-
@robin4002 c’est quand même étrange que quand je lance mon serveur local (Mohist) j’ai un crash au niveau de certains packets(ici un packet qui ouvre un gui lorsqu’il est reçu par le client) :
---- Rapport de plantage de Mohist ---- Temps: 24/11/20 21:17 Description: Erreur dans la boucle de tick du serveur net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from ExaMod (examod) Caused by: java.lang.NoClassDefFoundError: net/minecraft/client/gui/GuiScreen at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Unknown Source) at java.lang.Class.getConstructor0(Unknown Source) at java.lang.Class.newInstance(Unknown Source) at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.instantiate(SimpleNetworkWrapper.java:163) at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.registerMessage(SimpleNetworkWrapper.java:156) at fr.exatium.examod.ExaMod.preInit(ExaMod.java:90) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:632) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91) at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150) at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76) at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399) at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71) at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116) at com.google.common.eventbus.EventBus.post(EventBus.java:217) at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:215) at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:193) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91) at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150) at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76) at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399) at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71) at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116) at com.google.common.eventbus.EventBus.post(EventBus.java:217) at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:132) at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:635) at net.minecraftforge.fml.server.FMLServerHandler.beginServerLoading(FMLServerHandler.java:102) at net.minecraftforge.fml.common.FMLCommonHandler.onServerStart(FMLCommonHandler.java:329) at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(DedicatedServer.java:171) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:593) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.ClassNotFoundException: net.minecraft.client.gui.GuiScreen at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:191) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 43 more Caused by: net.minecraftforge.fml.common.asm.ASMTransformerWrapper$TransformerException: Exception in class transformer net.minecraftforge.fml.common.asm.transformers.SideTransformer@4f7dc426 from coremod FMLCorePlugin at net.minecraftforge.fml.common.asm.ASMTransformerWrapper$TransformerWrapper.transform(ASMTransformerWrapper.java:256) at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:279) at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:176) ... 45 more Caused by: java.lang.RuntimeException: Attempted to load class blk for invalid side SERVER at net.minecraftforge.fml.common.asm.transformers.SideTransformer.transform(SideTransformer.java:60) at net.minecraftforge.fml.common.asm.ASMTransformerWrapper$TransformerWrapper.transform(ASMTransformerWrapper.java:252) ... 47 more Une description détaillée de l'erreur, de son chemin de code et de tous les détails connus suivent: --------------------------------------------------------------------------------------- -- Détails du système -- Details: Version de Mohist: 1.12.2-102 Système d'Exploitation: Windows 10 (amd64) version 10.0 Version de Java: 1.8.0_271, Oracle Corporation Version de Java VM: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Mémoire: 197394624 bytes (188 MB) / 433586176 bytes (413 MB) up to 954728448 bytes (910 MB) Drapeaux JVM: 1 total; -Xmx1G IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 Information de CraftBukkit: Running: Failed to handle CraftCrashReport: craftbukkit not runs FML: MCP 9.42 Powered by Forge 14.23.5.2854 6 mods loaded, 6 mods active States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored | State | ID | Version | Source | Signature | |:----- |:--------- |:------------ |:------------- |:--------- | | LCH | minecraft | 1.12.2 | minecraft.jar | None | | LCH | mcp | 9.42 | minecraft.jar | None | | LCH | mohist | 1.12.2-102 | mohist.jar | None | | LCH | FML | 8.0.99.99 | Mohist.jar | None | | LCH | forge | 14.23.5.2854 | Mohist.jar | None | | LCE | examod | 1.0 | Examod.jar | None | Loaded coremods (and transformers): Profiler Position: N/A (disabled) Is Modded: Definitely; Server brand changed to 'Mohist' Type: Dedicated Server (map_server.txt)
-
Il faut mettre un
SideOnly(Side.CLIENT)
au dessus de la fonction onMessage de ton handler, dans le cas des paquets envoyé au client. -
Merci beaucoup ^^ le problème est résolu !