• S'inscrire
    • Se connecter
    • Recherche
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes

    Résolu Open Gui via Keybind

    1.7.x
    1.7.10
    3
    6
    1393
    Charger plus de messages
    • Du plus ancien au plus récent
    • Du plus récent au plus ancien
    • Les plus votés
    Répondre
    • Répondre à l'aide d'un nouveau sujet
    Se connecter pour répondre
    Ce sujet a été supprimé. Seuls les utilisateurs avec les droits d'administration peuvent le voir.
    • P
      PotTime dernière édition par

      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 😄

      1 réponse Dernière réponse Répondre Citer 0
      • Deleted
        Deleted dernière édition par

        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());

        1 réponse Dernière réponse Répondre Citer 0
        • P
          PotTime dernière édition par

          Génial ! ;D

          Le seul problème c’est qu’il pense que il n’y a pas de de texture, regarde la photo

          http://prntscr.com/ffh5hr

          1 réponse Dernière réponse Répondre Citer 0
          • Deleted
            Deleted dernière édition par

            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.

            1 réponse Dernière réponse Répondre Citer 1
            • P
              PotTime dernière édition par

              C’est bon, merci, j’ai trouvé !!!
              😄

              D 1 réponse Dernière réponse Répondre Citer 0
              • D
                DarkEros @PotTime dernière édition par

                Ce message a été supprimé !
                1 réponse Dernière réponse Répondre Citer 0
                • 1 / 1
                • Premier message
                  Dernier message
                Design by Woryk
                Contact / Mentions Légales

                MINECRAFT FORGE FRANCE © 2018

                Powered by NodeBB