Résolu Modifier le menu principal
-
Bonjour à tous ! Je cherche pour mon mod en 1.7.2 à modifier le menu principal du jeu, biensûr on ne peut pas modifier les sources avec Forge, donc j’essaie de trouver un moyen de remplacer le menu principal de minecraft dès son chargment. J’ai trouvé ceci, qui semble pouvoir remplacer le TickHandler :
@SubscribeEvent public void onRenderTick(TickEvent event) {}
Cependant et bien premièrement je ne sais pas où je pourrais le mettre dans mon code et puis je me demande comment remplir cette fonction pour qu’elle m’affiche mon menu à la place de l’officiel
Merci d’avance !
spaceDementia
Peut être l’événement GuiOpenEvent ?
-
package com.example.examplemod; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiMainMenu; import net.minecraft.client.gui.GuiScreen; import net.minecraft.init.Blocks; import net.minecraftforge.common.MinecraftForge; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent; import cpw.mods.fml.common.gameevent.TickEvent.Phase; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION) public class ExampleMod { public static final String MODID = "examplemod"; public static final String VERSION = "1.0"; @EventHandler public void init(FMLInitializationEvent event) { // some example code System.out.println("DIRT BLOCK >> " + Blocks.dirt.getUnlocalizedName()); MinecraftForge.EVENT_BUS.register(this); } @SubscribeEvent @SideOnly(Side.CLIENT) public void onTickClient(TickEvent.ClientTickEvent event) { if(event.phase == Phase.END) { Minecraft mc = Minecraft.getMinecraft(); GuiScreen currentScreen = mc.currentScreen; GuiCustomMainMenu customMenu = new GuiCustomMainMenu(); if(currentScreen instanceof GuiMainMenu && !currentScreen.equals(customMenu)) { mc.displayGuiScreen(customMenu); } } } }
Normalement comme ça c’est bon. Tu peux aussi mettre l’event dans une autre classe si tu préfère.
-
Merci robin4002 ! une réponse rapide et précise :), je test ça et je met en résolu si ça marche bien !
-
Bon ça ne marche pas il ne m’affiche pas mon menu custom lors du démarrage de minecraft pourtant j’ai bien recopié ton code.
-
Essaye de remplacer event.phase == Phase.START par event.phase == Phase.END
-
Je viens de tester ça ne marche toujours pas :/___
Bon je pense avoir trouvé mais je me retrouve avec un crash maintenant et je me demande pourquoi lol donc j’ai remplacé :
MinecraftForge.EVENT_BUS.register(this);
par :
FMLCommonHandler.instance().bus().register(this);mais donc apparement maintenant ca fonctionne il crash au chargement du menu en fait lol et le rapport de bug est :
–-- Minecraft Crash Report ---- // This is a token for 1 free hug. Redeem at your nearest Mojangsta: [~~HUG~~] Time: 17/02/14 22:24 Description: Registering texture java.lang.NullPointerException: Registering texture at net.minecraft.client.resources.SimpleReloadableResourceManager.getResource(SimpleReloadableResourceManager.java:63) at net.minecraft.client.renderer.texture.SimpleTexture.loadTexture(SimpleTexture.java:35) at net.minecraft.client.renderer.texture.TextureManager.loadTexture(TextureManager.java:89) at net.minecraft.client.renderer.texture.TextureManager.bindTexture(TextureManager.java:45) at net.minecraft.client.gui.GuiMainMenu.rotateAndBlurSkybox(GuiMainMenu.java:549) at net.minecraft.client.gui.GuiMainMenu.renderSkybox(GuiMainMenu.java:586) at net.minecraft.client.gui.GuiMainMenu.drawScreen(GuiMainMenu.java:616) at helmyriaMod.helmyriaGuiMainMenu.drawScreen(helmyriaGuiMainMenu.java:690) at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1209) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1064) at net.minecraft.client.Minecraft.run(Minecraft.java:951) at net.minecraft.client.main.Main.main(Main.java:112) 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.minecraft.launchwrapper.Launch.launch(Launch.java:134) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) A detailed walkthrough of the error, its code path and all known details is as follows: –------------------------------------------------------------------------------------- -- Head -- Stacktrace: at net.minecraft.client.resources.SimpleReloadableResourceManager.getResource(SimpleReloadableResourceManager.java:63) at net.minecraft.client.renderer.texture.SimpleTexture.loadTexture(SimpleTexture.java:35) -- Resource location being registered -- Details: Resource location: ~~NULL~~ Texture object class: net.minecraft.client.renderer.texture.SimpleTexture Stacktrace: at net.minecraft.client.renderer.texture.TextureManager.loadTexture(TextureManager.java:89) at net.minecraft.client.renderer.texture.TextureManager.bindTexture(TextureManager.java:45) at net.minecraft.client.gui.GuiMainMenu.rotateAndBlurSkybox(GuiMainMenu.java:549) at net.minecraft.client.gui.GuiMainMenu.renderSkybox(GuiMainMenu.java:586) at net.minecraft.client.gui.GuiMainMenu.drawScreen(GuiMainMenu.java:616) at helmyriaMod.helmyriaGuiMainMenu.drawScreen(helmyriaGuiMainMenu.java:690) -- Screen render details -- Details: Screen name: helmyriaMod.helmyriaGuiMainMenu Mouse location: Scaled: (0, 239). Absolute: (0, 0) Screen size: Scaled: (427, 240). Absolute: (854, 480). Scale factor of 2 Stacktrace: at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1209) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1064) at net.minecraft.client.Minecraft.run(Minecraft.java:951) at net.minecraft.client.main.Main.main(Main.java:112) 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.minecraft.launchwrapper.Launch.launch(Launch.java:134) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) -- System Details -- Details: Minecraft Version: 1.7.2 Operating System: Windows 7 (x86) version 6.1 Java Version: 1.7.0_45, Oracle Corporation Java VM Version: Java HotSpot(TM) Client VM (mixed mode), Oracle Corporation Memory: 904294528 bytes (862 MB) / 1060372480 bytes (1011 MB) up to 1060372480 bytes (1011 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP v9.01-pre FML v7.2.116.1024 Minecraft Forge 10.12.0.1024 4 mods loaded, 4 mods active mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available FML{7.2.116.1024} [Forge Mod Loader] (forgeSrc-1.7.2-10.12.0.1024.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available Forge{10.12.0.1024} [Minecraft Forge] (forgeSrc-1.7.2-10.12.0.1024.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available helmyriamod{1.0} [Helmyria] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available Launched Version: 1.6 LWJGL: 2.9.0 OpenGL: Intel 965/963 Graphics Media Accelerator GL version 2.0.0 - Build 8.14.10.1930, Intel Is Modded: Definitely; Client brand changed to 'fml,forge' Type: Client (map_client.txt) Resource Packs: [] Current Language: Français (France) Profiler Position: N/A (disabled) Vec3 Pool Size: ~~ERROR~~ NullPointerException: null Anisotropic Filtering: Off (1)
-
Un NPE sur une des textures. helmyriaGuiMainMenu.java ligne 690, tu as quoi ? (clic sur le java:690 dans le crash, ça te sélectionnera directement la ligne).
-
Alors il me pointe ça :super.drawScreen(par1, par2, par3);
et c’est inséré dans la méthode suivante :public void drawScreen(int par1, int par2, float par3) { GL11.glDisable(GL11.GL_ALPHA_TEST); this.renderSkybox(par1, par2, par3); GL11.glEnable(GL11.GL_ALPHA_TEST); Tessellator tessellator = Tessellator.instance; short short1 = 274; int k = this.width / 2 - short1 / 2; byte b0 = 30; this.drawGradientRect(0, 0, this.width, this.height, -2130706433, 16777215); this.drawGradientRect(0, 0, this.width, this.height, 0, Integer.MIN_VALUE); this.mc.getTextureManager().bindTexture(minecraftTitleTextures); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); if ((double)this.updateCounter < 1.0E-4D) { this.drawTexturedModalRect(k + 0, b0 + 0, 0, 0, 99, 44); this.drawTexturedModalRect(k + 99, b0 + 0, 129, 0, 27, 44); this.drawTexturedModalRect(k + 99 + 26, b0 + 0, 126, 0, 3, 44); this.drawTexturedModalRect(k + 99 + 26 + 3, b0 + 0, 99, 0, 26, 44); this.drawTexturedModalRect(k + 155, b0 + 0, 0, 45, 155, 44); } else { this.drawTexturedModalRect(k + 0, b0 + 0, 0, 0, 155, 44); this.drawTexturedModalRect(k + 155, b0 + 0, 0, 45, 155, 44); } tessellator.setColorOpaque_I(-1); GL11.glPushMatrix(); GL11.glTranslatef((float)(this.width / 2 + 90), 70.0F, 0.0F); GL11.glRotatef(-20.0F, 0.0F, 0.0F, 1.0F); float f1 = 1.8F - MathHelper.abs(MathHelper.sin((float)(Minecraft.getSystemTime() % 1000L) / 1000.0F * (float)Math.PI * 2.0F) * 0.1F); f1 = f1 * 100.0F / (float)(this.fontRendererObj.getStringWidth(this.splashText) + 32); GL11.glScalef(f1, f1, f1); this.drawCenteredString(this.fontRendererObj, this.splashText, 0, -8, -256); GL11.glPopMatrix(); String s = "Minecraft 1.7.2"; if (this.mc.isDemo()) { s = s + " Demo"; } List <string>brandings = Lists.reverse(FMLCommonHandler.instance().getBrandings(true)); for (int i = 0; i < brandings.size(); i++) { String brd = brandings.get(i); if (!Strings.isNullOrEmpty(brd)) { this.drawString(this.fontRendererObj, brd, 2, this.height - ( 10 + i * (this.fontRendererObj.FONT_HEIGHT + 1)), 16777215); } } ForgeHooksClient.renderMainMenu(this, fontRendererObj, width, height); String s1 = "Copyright Mojang AB. Do not distribute!"; this.drawString(this.fontRendererObj, s1, this.width - this.fontRendererObj.getStringWidth(s1) - 2, this.height - 10, -1); if (this.field_92025_p != null && this.field_92025_p.length() > 0) { drawRect(this.field_92022_t - 2, this.field_92021_u - 2, this.field_92020_v + 2, this.field_92019_w - 1, 1428160512); this.drawString(this.fontRendererObj, this.field_92025_p, this.field_92022_t, this.field_92021_u, -1); this.drawString(this.fontRendererObj, this.field_146972_A, (this.width - this.field_92024_r) / 2, ((GuiButton)this.buttonList.get(0)).yPosition - 12, -1); } super.drawScreen(par1, par2, par3); } ```</string>
-
Je pense qu’il ne faut pas faire une classe fille de GuiMainMenu (extends GuiMainMenu) mais uniquement de GuiScreen.
Ça devrait régler (du moins en partie) le problème. -
Oui déjà ça a réglé quelques problèmes, seulement maintenant lorsqu’il crash j’ai comme rapport de bug celui ci :
–-- Minecraft Crash Report ---- // On the bright side, I bought you a teddy bear! Time: 18/02/14 17:48 Description: Rendering screen java.lang.ClassCastException: helmyriaMod.GuiButton cannot be cast to net.minecraft.client.gui.GuiButton at net.minecraft.client.gui.GuiScreen.drawScreen(GuiScreen.java:75) at helmyriaMod.helmyriaGuiMainMenu.drawScreen(helmyriaGuiMainMenu.java:696) at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1209) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1064) at net.minecraft.client.Minecraft.run(Minecraft.java:951) at net.minecraft.client.main.Main.main(Main.java:112) 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.minecraft.launchwrapper.Launch.launch(Launch.java:134) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at net.minecraft.client.gui.GuiScreen.drawScreen(GuiScreen.java:75) at helmyriaMod.helmyriaGuiMainMenu.drawScreen(helmyriaGuiMainMenu.java:696) -- Screen render details -- Details: Screen name: helmyriaMod.helmyriaGuiMainMenu Mouse location: Scaled: (0, 239). Absolute: (0, 0) Screen size: Scaled: (427, 240). Absolute: (854, 480). Scale factor of 2 Stacktrace: at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1209) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1064) at net.minecraft.client.Minecraft.run(Minecraft.java:951) at net.minecraft.client.main.Main.main(Main.java:112) 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.minecraft.launchwrapper.Launch.launch(Launch.java:134) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) -- System Details -- Details: Minecraft Version: 1.7.2 Operating System: Windows 7 (x86) version 6.1 Java Version: 1.7.0_45, Oracle Corporation Java VM Version: Java HotSpot(TM) Client VM (mixed mode), Oracle Corporation Memory: 917667872 bytes (875 MB) / 1060372480 bytes (1011 MB) up to 1060372480 bytes (1011 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP v9.01-pre FML v7.2.116.1024 Minecraft Forge 10.12.0.1024 4 mods loaded, 4 mods active mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available FML{7.2.116.1024} [Forge Mod Loader] (forgeSrc-1.7.2-10.12.0.1024.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available Forge{10.12.0.1024} [Minecraft Forge] (forgeSrc-1.7.2-10.12.0.1024.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available helmyriamod{1.0} [Helmyria] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available Launched Version: 1.6 LWJGL: 2.9.0 OpenGL: Intel 965/963 Graphics Media Accelerator GL version 2.0.0 - Build 8.14.10.1930, Intel Is Modded: Definitely; Client brand changed to 'fml,forge' Type: Client (map_client.txt) Resource Packs: [] Current Language: Français (France) Profiler Position: N/A (disabled) Vec3 Pool Size: ~~ERROR~~ NullPointerException: null Anisotropic Filtering: Off (1)
je me doute que c’est parce que dans la classe de mon Gui j’utilise une class bouton que j’ai recopié mais je ne trouve pas d’autres manières de faire car lorsque je laisse le GuiButton original j’ai deux erreurs sur :
fmlModButton.width = 98;
et sur
minecraftRealmsButton.width = 98;
forcement car dans la classe GuiButton c’est en protected alors est ce qu’il y a un moyen pour ne pas avoir d’erreur ? :)___
Et bien c’est bon j’ai trouvé xD enfin bon j’ai retirer le bouton qui utilisait cela de toute manière il ne m’était pas utile et là tout fonctionne ! encore merci de votre aide et de la rapidité de vos réponses. Je met en résolu -
Vire cette partie du code, elle ne sert que pour le minecraft realms, aucune utilité sur le pack d’un serveur.