Résolu Changer le GuiSelectWorld
-
Bonjour,
Comme indiqué dans le titre, je cherche a modifier la Gui de sélection de monde et plus particulièrement les boutons, j’ai créer une nouvelle classe pour les boutons custom (qui fonctionne d’ailleurs parfaitement sur le GuiMainMenu que j’ai également modifié) ainsi que copie de la classe GuiSelectWorld d’origine. celle-ci fonctionne… sauf quand je remplace les boutons par mes boutons custom (le client crash) j’ai cherché une solutions pendant plus d’une semaine et je ne sait plus quoi faire ;-;
j’espère que vois serez déceler le problème, voici ma classe GuiSelectWorld
Merci d’avance
package mod.sao.gui; import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Collections; import java.util.Date; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import net.minecraft.client.AnvilConverterException; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiCreateWorld; import net.minecraft.client.gui.GuiErrorScreen; import net.minecraft.client.gui.GuiRenameWorld; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiSelectWorld; import net.minecraft.client.gui.GuiSlot; import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.client.resources.I18n; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.WorldSettings; import net.minecraft.world.storage.ISaveFormat; import net.minecraft.world.storage.ISaveHandler; import net.minecraft.world.storage.SaveFormatComparator; import net.minecraft.world.storage.WorldInfo; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class GuiSaoSelectWorld extends GuiSelectWorld// implements GuiYesNoCallback { private static final Logger logger = LogManager.getLogger(); private final DateFormat field_146633_h = new SimpleDateFormat(); protected GuiScreen field_146632_a; protected String field_146628_f = "Select world"; private boolean field_146634_i; private int field_146640_r; private java.util.List field_146639_s; //private GuiSelectWorld.List field_146638_t; private String field_146637_u; private String field_146636_v; private String[] field_146635_w = new String[4]; private boolean field_146643_x; private GuiSaoButton field_146642_y; private GuiSaoButton field_146641_z; private GuiSaoButton field_146630_A; private GuiSaoButton field_146631_B; private static final String __OBFID = "CL_00000711"; public GuiSaoSelectWorld(GuiScreen p_i1054_1_) { super(p_i1054_1_); this.field_146632_a = p_i1054_1_; } public void func_146618_g() { this.buttonList.add(this.field_146641_z = new GuiSaoButton(1, this.width / 2 - 154, this.height - 52, 150, 20, I18n.format("selectWorld.select", new Object[0]))); this.buttonList.add(new GuiSaoButton(3, this.width / 2 + 4, this.height - 52, 150, 20, I18n.format("selectWorld.create", new Object[0]))); this.buttonList.add(this.field_146630_A = new GuiSaoButton(6, this.width / 2 - 154, this.height - 28, 72, 20, I18n.format("selectWorld.rename", new Object[0]))); this.buttonList.add(this.field_146642_y = new GuiSaoButton(2, this.width / 2 - 76, this.height - 28, 72, 20, I18n.format("selectWorld.delete", new Object[0]))); this.buttonList.add(this.field_146631_B = new GuiSaoButton(7, this.width / 2 + 4, this.height - 28, 72, 20, I18n.format("selectWorld.recreate", new Object[0]))); this.buttonList.add(new GuiSaoButton(0, this.width / 2 + 82, this.height - 28, 72, 20, I18n.format("gui.cancel", new Object[0]))); this.field_146641_z.enabled = false; this.field_146642_y.enabled = false; this.field_146630_A.enabled = false; this.field_146631_B.enabled = false; } protected void actionPerformed(GuiSaoButton button) throws IOException { if (button.enabled) { if (button.id == 2) { String s = this.func_146614_d(this.field_146640_r); if (s != null) { this.field_146643_x = true; GuiYesNo guiyesno = func_152129_a(this, s, this.field_146640_r); this.mc.displayGuiScreen(guiyesno); } } else if (button.id == 1) { this.func_146615_e(this.field_146640_r); } else if (button.id == 3) { this.mc.displayGuiScreen(new GuiCreateWorld(this)); } else if (button.id == 6) { this.mc.displayGuiScreen(new GuiRenameWorld(this, this.func_146621_a(this.field_146640_r))); } else if (button.id == 0) { this.mc.displayGuiScreen(this.field_146632_a); } else if (button.id == 7) { GuiCreateWorld guicreateworld = new GuiCreateWorld(this); ISaveHandler isavehandler = this.mc.getSaveLoader().getSaveLoader(this.func_146621_a(this.field_146640_r), false); WorldInfo worldinfo = isavehandler.loadWorldInfo(); isavehandler.flush(); guicreateworld.func_146318_a(worldinfo); this.mc.displayGuiScreen(guicreateworld); } else { //this.field_146638_t.actionPerformed(button); } } } }
-
@‘Stevecraft’:
(le client crash)
Et il est où le rapport de crash ?
-
le voici
–-- Minecraft Crash Report ---- // I just don't know what went wrong :( Time: 13/12/15 13:04 Description: Updating screen events java.lang.NullPointerException: Updating screen events at net.minecraft.client.gui.GuiSelectWorld$List.elementClicked(GuiSelectWorld.java:269) at net.minecraft.client.gui.GuiSlot.handleMouseInput(GuiSlot.java:329) at net.minecraft.client.gui.GuiSelectWorld.handleMouseInput(GuiSelectWorld.java:84) at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:572) at net.minecraft.client.Minecraft.runTick(Minecraft.java:1760) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1087) at net.minecraft.client.Minecraft.run(Minecraft.java:376) at net.minecraft.client.main.Main.main(Main.java:117) 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:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) 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.gradle.GradleStartCommon.launch(Unknown Source) at GradleStart.main(Unknown Source) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at net.minecraft.client.gui.GuiSelectWorld$List.elementClicked(GuiSelectWorld.java:269) at net.minecraft.client.gui.GuiSlot.handleMouseInput(GuiSlot.java:329) at net.minecraft.client.gui.GuiSelectWorld.handleMouseInput(GuiSelectWorld.java:84) at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:572) -- Affected screen -- Details: Screen name: mod.sao.gui.GuiSaoSelectWorld Stacktrace: at net.minecraft.client.Minecraft.runTick(Minecraft.java:1760) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1087) at net.minecraft.client.Minecraft.run(Minecraft.java:376) at net.minecraft.client.main.Main.main(Main.java:117) 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:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) 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.gradle.GradleStartCommon.launch(Unknown Source) at GradleStart.main(Unknown Source) -- System Details -- Details: Minecraft Version: 1.8 Operating System: Windows 10 (amd64) version 10.0 Java Version: 1.8.0_65, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 684615800 bytes (652 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP v9.10 FML v8.0.99.99 Minecraft Forge 11.14.4.1563 4 mods loaded, 4 mods active States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored UCHIJA mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) UCHIJA FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.8-11.14.4.1563.jar) UCHIJA Forge{11.14.4.1563} [Minecraft Forge] (forgeSrc-1.8-11.14.4.1563.jar) UCHIJA sao{0.1.0} [Sword Art Online] (bin) Loaded coremods (and transformers): GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.5.0 NVIDIA 359.06' Renderer: 'GeForce GTX 970/PCIe/SSE2' Launched Version: 1.8 LWJGL: 2.9.1 OpenGL: GeForce GTX 970/PCIe/SSE2 GL version 4.5.0 NVIDIA 359.06, NVIDIA Corporation GL Caps: Using GL 1.3 multitexturing. Using GL 1.3 texture combiners. Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported. Shaders are available because OpenGL 2.1 is supported. VBOs are available because OpenGL 1.5 is supported. Using VBOs: Yes Is Modded: Definitely; Client brand changed to 'fml,forge' Type: Client (map_client.txt) Resource Packs: [] Current Language: English (US) Profiler Position: N/A (disabled)
-
Il y a un NPE ici :
at net.minecraft.client.gui.GuiSelectWorld$List.elementClicked(GuiSelectWorld.java:269)
Je suis aller voir, ligne 269 de GuiSelectWorld il y a ça :
GuiSelectWorld.this.field_146641_z.enabled = flag1;La façon dont tu remplaces GuiSelectWorld n’est pas bonne car tu ne la remplace que partiellement.
Je te conseil plutôt d’utiliser l’event GuiInitEvent pour effacer la liste des boutons et la redéfinir avec des propres boutons (ça sera beaucoup plus propre).
Ou alors comme tu veux changer l’apparence des boutons passer par DrawScreenEvent pour redraw les buttons. -
j’ai modifié un des boutons du GuiSelectWorld en passant par l’InitGuiEvent. le client ne crash plus et le bouton est modifié mais il reste un problème.
les boutons d’origine ne sont pas activé par défaut et il s’active quant on clique sur un des mondes.
j’aimerais reproduire cet effet sur mes boutons mais je ne sait pas comment je pourrais savoir si le joueur a cliqué sur un monde ou pas.
voici le code qui modifie les boutons:
@SubscribeEvent public void onInitGuiEvent(InitGuiEvent event){ if(event.gui instanceof GuiSelectWorld){ for (Object b : event.buttonList){ if(((GuiButton) b).id == 1){ //((GuiButton) b).visible = false; //event.buttonList.remove(b); selectButton = (GuiButton) b; } } int width = event.gui.width; int height = event.gui.height; event.buttonList.add(this.select = new GuiSaoButton(8, width / 2 - 154, height - 52, 150, 20, I18n.format("selectWorld.select", new Object[0]))); select.enabled = false; } }
-
Le seul moyen serait de réinitialisé les boutons d’origines
private GuiButton field_146642_y;
private GuiButton field_146641_z;
private GuiButton field_146630_A;
private GuiButton field_146631_B;
via la réflexion. -
Ok, merci de ton aide, je vais me pencher la dessus