Résolu Open Gui via Keybind
-
Bonjour,
Je débute en Java, dévellopement Minecraft.Je souhaite lorsque que je clique sur RSHIFT un gui s’ouvre.
Voici mon code pour le GUI :
package fr.pottime.gui; import java.io.IOException; import javax.swing.JOptionPane; import org.lwjgl.opengl.GL11; import net.minecraft.client.gui.GuiScreen; import net.minecraft.util.ResourceLocation; public class OpenGui extends GuiScreen { private static final ResourceLocation texture = new ResourceLocation("textures/gui/BackgroundMod.png"); private int xSize; private int ySize; public void drawScreen(int i, int j, float f) { xSize = 176; ySize = 166; int k = (width - xSize) / 2; int l = (height - ySize) / 2; GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glColor3f(1.0F, 1.0F, 1.0F); try { drawBackgroundImage(); } catch (IOException e) { e.printStackTrace(); } super.drawScreen(i, j, f); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glDisable(GL11.GL_LIGHTING); } private void drawBackgroundImage() throws IOException { int displayX = (width - xSize) / 2; int displayY = (height - ySize) / 2; this.mc.getTextureManager().bindTexture(texture); drawTexturedModalRect(displayX, displayY , 0, 0, xSize, ySize); } @Override public boolean doesGuiPauseGame() { return false; } }
Et le code pour le lancée :
package fr.pottime.proxy; import org.lwjgl.input.Keyboard; import cpw.mods.fml.client.registry.ClientRegistry; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.settings.KeyBinding; public class ClientProxy extends CommonProxy { private static final Object OpenGui = fr.pottime.gui.OpenGui.class; private static KeyBinding keyBinding; public ClientProxy() { FMLCommonHandler.instance().bus().register(this); keyBinding = new KeyBinding(".Gui", Keyboard.KEY_RSHIFT, "key.categories.gameplay"); ClientRegistry.registerKeyBinding(keyBinding); } @SubscribeEvent public void onEvent(KeyInputEvent event) { if(keyBinding.isPressed()) { keyPressed(); } } private void keyPressed() { Minecraft.getMinecraft().displayGuiScreen((GuiScreen) OpenGui); }
Ce code est dans le ClientProxy.
J’ai bien sùr fait le @SidedProxy
@SidedProxy(clientSide = Reference.CLIENT_PROXY, serverSide = Reference.SERVER_PROXY)Si vous voulez ; le code de Reference
public class Reference { public static final String MODID = "FakeGui"; public static final String MOD_NAME = "FakeGui"; public static final String VERSION = "1.0"; public static final String CLIENT_PROXY = "fr.pottime.proxy.ClientProxy"; public static final String SERVER_PROXY = "fr.pottime.proxy.CommonProxy"; }
Voilà, si vous voulez plus de choses répondez moi sur ce topic ou en mp
J’allais oublié le plus important ! :‘( :’(
Les erreurs! :@java.lang.ClassCastException: java.lang.Class cannot be cast to net.minecraft.client.gui.GuiScreen at fr.pottime.proxy.ClientProxy.keyPressed(ClientProxy.java:42) at fr.pottime.proxy.ClientProxy.onEvent(ClientProxy.java:36) at cpw.mods.fml.common.eventhandler.ASMEventHandler_0_ClientProxy_onEvent_KeyInputEvent.invoke(.dynamic) at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:140) at cpw.mods.fml.common.FMLCommonHandler.fireKeyInput(FMLCommonHandler.java:540) at net.minecraft.client.Minecraft.runTick(Minecraft.java:1964) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039) at net.minecraft.client.Minecraft.run(Minecraft.java:962) at net.minecraft.client.main.Main.main(Main.java:164) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) 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 fr.pottime.proxy.ClientProxy.keyPressed(ClientProxy.java:42) at fr.pottime.proxy.ClientProxy.onEvent(ClientProxy.java:36) at cpw.mods.fml.common.eventhandler.ASMEventHandler_0_ClientProxy_onEvent_KeyInputEvent.invoke(.dynamic) at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:140) at cpw.mods.fml.common.FMLCommonHandler.fireKeyInput(FMLCommonHandler.java:540)
J’espère avoir des réponses le plus vite possible
-
Salut,
Le paramètre de la fonction Minecraft#displayGuiScreen est censé être une instance d’une classe fille de GuiScreen, or toi tu rentres un paramètre de type Class. Il faudrait plutôt faire un displayGuiScreen(new OpenGui()); -
Génial ! ;D
Le seul problème c’est qu’il pense que il n’y a pas de de texture, regarde la photo
-
Ton objet ResourceLocation est en effet incorrect. Tu dois rajouter un autre argument qui est le modid de ton mod. Si tu ne saisis pas, regarde le tutoriel sur un mob basique, dans la partie “Rendu” à la fin.
-
C’est bon, merci, j’ai trouvé !!!
-
Ce message a été supprimé !