Résolu Afficher une image lors de la connexion.
-
Bonjour,
J’aimerai faire que quand on se connecte on a un gui qui s’ouvre avec une image .
Voilà se que j’ai fais mais a la place de me le mettre en plein milieu de l’écran il me le met a la place de la barre de faim.Voici un screen: http://puu.sh/nagKR/5752dbac45.png
Merci d’avance.
Event:
@SideOnly(Side.CLIENT) @SubscribeEvent public void onRenderGameOverlayEvent(RenderGameOverlayEvent event){ if(!event.isCancelable()){ Minecraft mc = Minecraft.getMinecraft(); if(!mc.thePlayer.capabilities.isCreativeMode) { int width = event.resolution.getScaledWidth(); int height = event.resolution.getScaledHeight(); mc.renderEngine.bindTexture(new ResourceLocation("wl:textures/entity/Equipe.png")); } } }
Main:
@EventHandler public void init(FMLInitializationEvent event) { proxy.init(event); //Register Event: MinecraftForge.EVENT_BUS.register(new Events()); }
Cordialement,
-
Tu veux que ce soit un Gui qui s’affiche ou un GuiScreen ?
@SideOnly(Side.CLIENT) @SubscribeEvent public void onRenderGameOverlayEvent(RenderGameOverlayEvent event){ if(!event.isCancelable()){ // Pourquoi ? Minecraft mc = Minecraft.getMinecraft(); if(!mc.thePlayer.capabilities.isCreativeMode) { int width = event.resolution.getScaledWidth(); int height = event.resolution.getScaledHeight(); mc.renderEngine.bindTexture(new ResourceLocation("wl:textures/entity/Equipe.png")); // Tu bind la texture mais tu la dessines pas } } }
-
Un guiscreen je pense que c’est mieux a voir, pour le draw j’ai oublier effectivement ^^
-
Premièrement, RenderGameOverlayEvent n’est pas un Gui. À moins que tu veules dessiner l’image directement dans l’écran sans que le puisse bouger son curseur. En gros, le RenderGameOverlay permet de dessiner quelque chose sur l’écran sans que le jeu du joueur soit affecté. Ex.: Le menu F3.
Si tu veux que le joueur puisse intéragir avec l’image, tu dois créer un GuiScreen (qui extends Gui donc tu peux aussi utiliser Gui directement) que tu affiches à la connexion du joueur. Tu vas surement avoir des problèmes de NPE quand tu vas arriver à cette étape. Tu ne dois pas utiliser d’events comme EntityJoinWorld ou PlayerLoggedIn, mais un TickHandler avec un boolean que tu mets sur true quand il accepte et que tu remets sur false à sa déconnexion.
EDIT: J’écrivais mon message quand tu as répondu.
-
D’acc merci à toi.
-
A ce moment il faut gérer ça en partie côté serveur et envoyer un paquet pour que le client ouvre le gui si tu veux une synchronisation client/serveur
-
Honnêtement, je ne synchronises jamais mes Gui de connexion avec le serveur. Je stocke une variable isLoaded dans le ClientProxy et je la mets sur true quand il accepte. Ça se passe côté client uniquement.
-
Oui mais si tu veux par exemple que le joueur choisisse quelque chose (imaginons une équipe) lorsqu’il se connecte, il faut le synchronisé avec le serveur pour transmettre l’information
-
J’en suis pas encore la ^^,
J’ai fini mon GuiScreen mais j’ai pas bien compris l’histoire avec le TickHandler vous pouvez m’aider??
Merci. -
Quel tick handler ? L’utilisation des tick handler est très déconseillée
-
Le tick handler est une des seules solutions, sinon, soit tu as un NPE quand tu essaies d’ouvrir le Gui, soit le Gui ne se ouvre simplement pas. D’ailleurs, même robin l’a dit qu’il utilisait un tick handler dans NHG pour faire la même chose.
-
Dans NHG si le kit est null j’ouvre le kit pour choisir le gui.
Je passes par l’event de tick car dans mon cas il est essentiel que le joueur choisisse un kit.
S’il faut juste ouvrir un gui qui affiche un message ou une image à la connexion envoyer un paquet au client depuis l’event PlayerLoginEvent est beaucoup plus propre et moins lourd. -
Chaque fois que j’essayais, ça n’ouvrait pas le Gui, mais je vais réessayer tout à l’heure.
-
Merci de vos réponses mais la je suis bloqué dans le GuiHandler je dois mettre quoi du coup juste return new EquipeGuiScreen??
merci d’avance.
@Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { return null; // Ici ? } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { // TODO Auto-generated method stub return null; // Ici ? } }
-
J’ai aussi une érreur dans mon Packet et dans mon event apparament;
[18:26:15] [main/INFO] [GradleStart]: Extra: [] [18:26:15] [main/INFO] [GradleStart]: Running with arguments: [–userProperties, {}, --assetsDir, C:/Users/Admin/.gradle/caches/minecraft/assets, --assetIndex, 1.8, --accessToken, {REDACTED}, --version, 1.8, --tweakClass, net.minecraftforge.fml.common.launcher.FMLTweaker, --tweakClass, net.minecraftforge.gradle.tweakers.CoremodTweaker] [18:26:15] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.FMLTweaker [18:26:15] [main/INFO] [LaunchWrapper]: Using primary tweak class name net.minecraftforge.fml.common.launcher.FMLTweaker [18:26:15] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.gradle.tweakers.CoremodTweaker [18:26:15] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLTweaker [18:26:15] [main/INFO] [FML]: Forge Mod Loader version 8.0.37.1334 for Minecraft 1.8 loading [18:26:15] [main/INFO] [FML]: Java is Java HotSpot(TM) Client VM, version 1.8.0_45, running on Windows 7:x86:6.1, installed at C:\Program Files (x86)\Java\jdk1.8.0_45\jre [18:26:15] [main/INFO] [FML]: Managed to load a deobfuscated Minecraft name- we are in a deobfuscated environment. Skipping runtime deobfuscation [18:26:15] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.gradle.tweakers.CoremodTweaker [18:26:15] [main/INFO] [GradleStart]: Injecting location in coremod net.minecraftforge.fml.relauncher.FMLCorePlugin [18:26:15] [main/INFO] [GradleStart]: Injecting location in coremod net.minecraftforge.classloading.FMLForgePlugin [18:26:15] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.FMLInjectionAndSortingTweaker [18:26:15] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.FMLDeobfTweaker [18:26:15] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.gradle.tweakers.AccessTransformerTweaker [18:26:15] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLInjectionAndSortingTweaker [18:26:15] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLInjectionAndSortingTweaker [18:26:15] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.relauncher.CoreModManager$FMLPluginWrapper [18:26:15] [main/ERROR] [FML]: The binary patch set is missing. Either you are in a development environment, or things are not going to work! [18:26:16] [main/ERROR] [FML]: FML appears to be missing any signature data. This is not a good thing [18:26:16] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.relauncher.CoreModManager$FMLPluginWrapper [18:26:16] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLDeobfTweaker [18:26:16] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.gradle.tweakers.AccessTransformerTweaker [18:26:16] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.TerminalTweaker [18:26:16] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.TerminalTweaker [18:26:16] [main/INFO] [LaunchWrapper]: Launching wrapped minecraft {net.minecraft.client.main.Main} [18:26:16] [Client thread/INFO]: Setting user: Player571 [18:26:18] [Client thread/INFO]: LWJGL Version: 2.9.1 [18:26:18] [Client thread/INFO] [MinecraftForge]: Attempting early MinecraftForge initialization [18:26:18] [Client thread/INFO] [FML]: MinecraftForge v11.14.1.1334 Initialized [18:26:18] [Client thread/INFO] [FML]: Replaced 204 ore recipies [18:26:18] [Client thread/INFO] [MinecraftForge]: Completed early MinecraftForge initialization [18:26:18] [Client thread/INFO] [FML]: Searching C:\Users\Admin\Desktop\Modding\WasteLand 1.8\eclipse\mods for mods [18:26:18] [Client thread/INFO] [FML]: Forge Mod Loader has identified 4 mods to load [18:26:19] [Client thread/INFO] [FML]: Attempting connection with missing mods [mcp, FML, Forge, wl] at CLIENT [18:26:19] [Client thread/INFO] [FML]: Attempting connection with missing mods [mcp, FML, Forge, wl] at SERVER [18:26:19] [Client thread/INFO]: Reloading ResourceManager: Default, FMLFileResourcePack:Forge Mod Loader, FMLFileResourcePack:Minecraft Forge, FMLFileResourcePack:WasteLand [18:26:19] [Client thread/INFO] [FML]: Processing ObjectHolder annotations [18:26:19] [Client thread/INFO] [FML]: Found 384 ObjectHolder annotations [18:26:19] [Client thread/INFO] [FML]: Configured a dormant chunk cache size of 0 [18:26:19] [Client thread/INFO] [FML]: Applying holder lookups [18:26:19] [Client thread/INFO] [FML]: Holder lookups applied [18:26:19] [Sound Library Loader/INFO]: Starting up SoundSystem… [18:26:19] [Thread-6/INFO]: Initializing LWJGL OpenAL [18:26:19] [Thread-6/INFO]: (The LWJGL binding of OpenAL. For more information, see http://www.lwjgl.org) [18:26:19] [Thread-6/INFO]: OpenAL initialized. [18:26:20] [Sound Library Loader/INFO]: Sound engine started [18:26:20] [Client thread/INFO]: Created: 512x512 textures-atlas [18:26:21] [Client thread/INFO] [FML]: Forge Mod Loader has successfully loaded 4 mods [18:26:21] [Client thread/INFO]: Reloading ResourceManager: Default, FMLFileResourcePack:Forge Mod Loader, FMLFileResourcePack:Minecraft Forge, FMLFileResourcePack:WasteLand [18:26:21] [Client thread/INFO]: SoundSystem shutting down… [18:26:21] [Client thread/WARN]: Author: Paul Lamb, www.paulscode.com [18:26:21] [Sound Library Loader/INFO]: Starting up SoundSystem… [18:26:21] [Thread-8/INFO]: Initializing LWJGL OpenAL [18:26:21] [Thread-8/INFO]: (The LWJGL binding of OpenAL. For more information, see http://www.lwjgl.org) [18:26:21] [Thread-8/INFO]: OpenAL initialized. [18:26:22] [Sound Library Loader/INFO]: Sound engine started [18:26:22] [Client thread/INFO]: Created: 512x512 textures-atlas [18:26:23] [Server thread/INFO]: Starting integrated minecraft server version 1.8 [18:26:23] [Server thread/INFO]: Generating keypair [18:26:24] [Server thread/INFO] [FML]: Injecting existing block and item data into this server instance [18:26:24] [Server thread/INFO] [FML]: Applying holder lookups [18:26:24] [Server thread/INFO] [FML]: Holder lookups applied [18:26:24] [Server thread/INFO] [FML]: Loading dimension 0 (New World) (net.minecraft.server.integrated.IntegratedServer@10ce724) [18:26:24] [Server thread/INFO] [FML]: Loading dimension 1 (New World) (net.minecraft.server.integrated.IntegratedServer@10ce724) [18:26:24] [Server thread/INFO] [FML]: Loading dimension -1 (New World) (net.minecraft.server.integrated.IntegratedServer@10ce724) [18:26:24] [Server thread/INFO]: Preparing start region for level 0 [18:26:25] [Server thread/INFO]: Changing view distance to 16, from 10 [18:26:25] [Netty Local Client IO #0/INFO] [FML]: Server protocol version 1 [18:26:25] [Netty Server IO #1/INFO] [FML]: Client protocol version 1 [18:26:25] [Netty Server IO #1/INFO] [FML]: Client attempting to join with 4 mods : FML@8.0.37.1334,wl@1.0,Forge@11.14.1.1334,mcp@9.05 [18:26:25] [Netty Local Client IO #0/INFO] [FML]: [Netty Local Client IO #0] Client side modded connection established [18:26:25] [Server thread/INFO] [FML]: [Server thread] Server side modded connection established [18:26:25] [Server thread/INFO]: Player571[local:E:1d54938e] logged in with entity id 312 at (179.6984539272894, 77.0, -8.424475937371916) [18:26:25] [Server thread/INFO]: Player571 joined the game [18:26:25] [Server thread/ERROR] [FML]: FMLIndexedMessageCodec exception caught io.netty.handler.codec.EncoderException: java.lang.NullPointerException at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:107) ~[MessageToMessageEncoder.class:4.0.15.Final] at io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:116) ~[MessageToMessageCodec.class:4.0.15.Final] at io.netty.channel.DefaultChannelHandlerContext.invokeWrite(DefaultChannelHandlerContext.java:645) ~[DefaultChannelHandlerContext.class:4.0.15.Final] at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:699) ~[DefaultChannelHandlerContext.class:4.0.15.Final] at io.netty.channel.DefaultChannelHandlerContext.writeAndFlush(DefaultChannelHandlerContext.java:689) ~[DefaultChannelHandlerContext.class:4.0.15.Final] at io.netty.channel.DefaultChannelHandlerContext.writeAndFlush(DefaultChannelHandlerContext.java:718) ~[DefaultChannelHandlerContext.class:4.0.15.Final] at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:893) ~[DefaultChannelPipeline.class:4.0.15.Final] at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:240) ~[AbstractChannel.class:4.0.15.Final] at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.sendToServer(SimpleNetworkWrapper.java:236) [SimpleNetworkWrapper.class:?] at net.armacraft.Utils.Events.PlayerJoin(Events.java:17) [Events.class:?] at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_6_Events_PlayerJoin_PlayerLoggedInEvent.invoke(.dynamic) [?:?] at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:55) [ASMEventHandler.class:?] at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:138) [EventBus.class:?] at net.minecraftforge.fml.common.FMLCommonHandler.firePlayerLoggedIn(FMLCommonHandler.java:591) [FMLCommonHandler.class:?] at net.minecraft.server.management.ServerConfigurationManager.initializeConnectionToPlayer(ServerConfigurationManager.java:192) [ServerConfigurationManager.class:?] at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.completeServerSideConnection(NetworkDispatcher.java:218) [NetworkDispatcher.class:?] at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.access$100(NetworkDispatcher.java:49) [NetworkDispatcher.class:?] at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.update(NetworkDispatcher.java:182) [NetworkDispatcher$1.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:270) [NetworkManager.class:?] at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:208) [NetworkSystem.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:797) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:669) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:171) [IntegratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:540) [MinecraftServer.class:?] at java.lang.Thread.run(Thread.java:745) [?:1.8.0_45] Caused by: java.lang.NullPointerException at net.minecraftforge.fml.common.network.ByteBufUtils.writeUTF8String(ByteBufUtils.java:132) ~[ByteBufUtils.class:?] at net.armacraft.Utils.PacketGUI.toBytes(PacketGUI.java:30) ~[PacketGUI.class:?] at net.minecraftforge.fml.common.network.simpleimpl.SimpleIndexedCodec.encodeInto(SimpleIndexedCodec.java:11) ~[SimpleIndexedCodec.class:?] at net.minecraftforge.fml.common.network.simpleimpl.SimpleIndexedCodec.encodeInto(SimpleIndexedCodec.java:7) ~[SimpleIndexedCodec.class:?] at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.encode(FMLIndexedMessageToMessageCodec.java:55) ~[FMLIndexedMessageToMessageCodec.class:?] at io.netty.handler.codec.MessageToMessageCodec$1.encode(MessageToMessageCodec.java:67) ~[MessageToMessageCodec$1.class:4.0.15.Final] at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:89) ~[MessageToMessageEncoder.class:4.0.15.Final] … 24 more
Packet:
public class PacketGUI implements IMessage { private String text; public PacketGUI() { } public PacketGUI(String text) { this.text = text; } @Override public void fromBytes(ByteBuf buf) { text = ByteBufUtils.readUTF8String(buf); // this class is very useful in general for writing more complex objects } @Override public void toBytes(ByteBuf buf) { ByteBufUtils.writeUTF8String(buf, text);//ICI <-- } public static class Handler implements IMessageHandler <packetgui, imessage="">{ @Override public IMessage onMessage(PacketGUI message, MessageContext ctx) { EntityPlayerMP player = ctx.getServerHandler().playerEntity; player.openGui(WasteLandMod.INSTANCE, 0, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ); ChatComponentText component = new ChatComponentText("test!"); player.addChatComponentMessage(component); return null; // no response in this case } } }
Event:
@SubscribeEvent public void PlayerJoin(PlayerLoggedInEvent event){ EntityPlayerMP player = (EntityPlayerMP) event.player; WasteLandMod.network.sendToServer(new PacketGUI());//ICI } ```</packetgui,>
-
Pourquoi tu fais un gui handler ?
Pourquoi tu as une variable text dans ton paquet alors que tu ne l’utilise pas ? -
La variable text je les pris du tuto sur les packets sinon l’handler je pensé que il en fallait automatiquement à chaque gui .
sinon ça marche toujours pas je comprend pas . -
Pas besoin de gui handler.
Pas besoin de variable text non plus.
La seule chose que tu as à faire c’est envoyer un paquet au client dans l’event PlayerEvent.PlayerLoggedInEvent (donc sendTo et non sendToServer) et ajouter la fonction Minecraft.getMinecraft().displayGuiScreen(new TonGui()); dans l’action du paquet. -
D’acc merci mais j’ai un soucis avec cette ligne de mon packet: EntityPlayerMP player = ctx.getServerHandler().playerEntity;
j’ai essayer getClientHandler mais .playernetity marche pas. -
Dans la fonction onMessage tu dois avoir ça :
Minecraft.getMinecraft().displayGuiScreen(new TonGui());
et rien d’autre.