MFF

    Minecraft Forge France
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes
    • Forge Events
      • Automatique
      • Foncé
      • Clair
    • S'inscrire
    • Se connecter

    RenderGameOverlayEvent GUI [1.16.5]

    Planifier Épinglé Verrouillé Déplacé Sans suite
    1.16.x
    18 Messages 2 Publieurs 1.5k Vues 2 Watching
    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.
    • robin4002R Hors-ligne
      robin4002 Moddeurs confirmés Rédacteurs Administrateurs
      dernière édition par

      Bonsoir,

      La fonction de l’event RenderGameOverlayEvent n’a pas à être dans une classe héritant de Screen.
      Elle doit par contre être dans une classe enregistré en tant que classe contenant des événements (soit avec MinecraftForge.EVENT_BUS.register soit avec @EventBusSubscriber).

      Tout est expliqué dans ce tutoriel : https://www.minecraftforgefrance.fr/topic/5465/utiliser-les-événements

      devvospeurD 1 réponse Dernière réponse Répondre Citer 0
      • devvospeurD Hors-ligne
        devvospeur @robin4002
        dernière édition par

        @robin4002 Jais essayer de faire comme ça mais se ne marche pas voici le code avec le quelle je vient d’essayer
        Ma classe main :

        
        @Mod(MainM.MODID)
        public class MainM {
            public static final String MODID = "history";
        
            public MainM() {
                FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
                FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup);
        
                IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
                BlockRegister.BLOCK.register(bus);
                ItemRegister.ITEMS.register(bus);
                TileEntityRegister.TILE_ENTITIE.register(bus);
                MinecraftForge.EVENT_BUS.register(this);
                MinecraftForge.EVENT_BUS.register(new WhaterGui());
            }
            private void setup(FMLCommonSetupEvent event) {
            }
        
            private void clientSetup(FMLClientSetupEvent event) {
                Keybinds.register();
            }
        

        et voici le code pour ajouter ma barre d’eau :

        
        package fr.dev.history.Objet.Menu.Whater;
        
        import fr.dev.history.MainM;
        import net.minecraft.client.Minecraft;
        import net.minecraft.util.ResourceLocation;
        import net.minecraft.util.text.ITextComponent;
        import net.minecraftforge.client.event.RenderGameOverlayEvent;
        
        public class WhaterGui {
            public static void render(RenderGameOverlayEvent.Text event){
                if (event.getType() == RenderGameOverlayEvent.ElementType.TEXT){
                    Minecraft mc = Minecraft.getInstance();
                    ResourceLocation GUIA = new ResourceLocation(MainM.MODID, "textures/gui/whater.png");
                    int width = event.getWindow().getScaledHeight();
                    int height = event.getWindow().getScaledWidth();
        
                    mc.fontRenderer.func_243246_a(event.getMatrixStack(), (ITextComponent) GUIA, 200,300,200);
                }
            }
        }
        
        

        Merci de votre réponse

        1 réponse Dernière réponse Répondre Citer 0
        • robin4002R Hors-ligne
          robin4002 Moddeurs confirmés Rédacteurs Administrateurs
          dernière édition par

          Comme expliqué dans le tutoriel, si tu enregistre avec MinecraftForge.EVENT_BUS.register(new WhaterGui()); la fonction ne doit pas être en static.

          Et dans tout les cas pour que ton event fonctionne il faut un @SubscribeEvent au dessus.

          Donc cela devrait être comme ça :

          public class WhaterGui {
              @SubscribeEvent
              public void render(RenderGameOverlayEvent.Text event){
                  if (event.getType() == RenderGameOverlayEvent.ElementType.TEXT){
                      Minecraft mc = Minecraft.getInstance();
                      ResourceLocation GUIA = new ResourceLocation(MainM.MODID, "textures/gui/whater.png");
                      int width = event.getWindow().getScaledHeight();
                      int height = event.getWindow().getScaledWidth();
          
           
                      mc.fontRenderer.func_243246_a(event.getMatrixStack(), (ITextComponent) GUIA, 200,300,200);
                  }
              }
          }
          
          devvospeurD 1 réponse Dernière réponse Répondre Citer 0
          • devvospeurD Hors-ligne
            devvospeur @robin4002
            dernière édition par

            @robin4002 jais essayer je pense que sa fonction mais y’a une erreur quand je vais dans le jeux est je ne comprend pas pourquoi
            L’erreur :

            Time: 04/03/21 21:28
            Description: Unexpected error
            
            java.lang.ClassCastException: net.minecraft.util.ResourceLocation cannot be cast to net.minecraft.util.text.ITextComponent
            	at fr.dev.history.Objet.Menu.Whater.WhaterGui.render(WhaterGui.java:19) ~[main/:?] {re:classloading}
            	at net.minecraftforge.eventbus.ASMEventHandler_4_WhaterGui_render_Text.invoke(.dynamic) ~[?:?] {}
            	at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) ~[eventbus-4.0.0.jar:?] {}
            	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302) ~[eventbus-4.0.0.jar:?] {}
            	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) ~[eventbus-4.0.0.jar:?] {}
            	at net.minecraftforge.client.gui.ForgeIngameGui.renderHUDText(ForgeIngameGui.java:634) ~[forge-1.16.5-36.0.42_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
            	at net.minecraftforge.client.gui.ForgeIngameGui.renderIngameGui(ForgeIngameGui.java:187) ~[forge-1.16.5-36.0.42_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
            	at net.minecraft.client.renderer.GameRenderer.updateCameraAndRender(GameRenderer.java:484) ~[forge-1.16.5-36.0.42_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
            	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1002) ~[forge-1.16.5-36.0.42_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
            	at net.minecraft.client.Minecraft.run(Minecraft.java:612) ~[forge-1.16.5-36.0.42_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
            	at net.minecraft.client.main.Main.main(Main.java:184) ~[forge-1.16.5-36.0.42_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
            	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_282] {}
            	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_282] {}
            	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_282] {}
            	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_282] {}
            	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52) ~[forge-1.16.5-36.0.42_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {}
            	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.0.9.jar:?] {}
            	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.0.9.jar:?] {}
            	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.0.9.jar:?] {}
            	at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.0.9.jar:?] {}
            	at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.0.9.jar:?] {}
            	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:105) [forge-1.16.5-36.0.42_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {}
            
            
            A detailed walkthrough of the error, its code path and all known details is as follows:
            ---------------------------------------------------------------------------------------
            
            -- Head --
            Thread: Render thread
            Stacktrace:
            	at fr.dev.history.Objet.Menu.Whater.WhaterGui.render(WhaterGui.java:19) ~[main/:?] {re:classloading}
            	at net.minecraftforge.eventbus.ASMEventHandler_4_WhaterGui_render_Text.invoke(.dynamic) ~[?:?] {}
            	at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) ~[eventbus-4.0.0.jar:?] {}
            	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302) ~[eventbus-4.0.0.jar:?] {}
            	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) ~[eventbus-4.0.0.jar:?] {}
            	at net.minecraftforge.client.gui.ForgeIngameGui.renderHUDText(ForgeIngameGui.java:634) ~[forge:?] {re:classloading}
            	at net.minecraftforge.client.gui.ForgeIngameGui.renderIngameGui(ForgeIngameGui.java:187) ~[forge:?] {re:classloading}
            -- Affected level --
            Details:
            	All players: 1 total; [ClientPlayerEntity['Dev'/259, l='ClientLevel', x=156.70, y=70.00, z=161.04]]
            	Chunk stats: Client Chunk Cache: 169, 81
            	Level dimension: minecraft:overworld
            	Level spawn location: World: (128,67,128), Chunk: (at 0,4,0 in 8,8; contains blocks 128,0,128 to 143,255,143), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
            	Level time: 76751 game time, 76751 day time
            	Server brand: forge
            	Server type: Integrated singleplayer server
            Stacktrace:
            	at net.minecraft.client.world.ClientWorld.fillCrashReport(ClientWorld.java:465) ~[forge-1.16.5-36.0.42_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
            	at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2091) ~[forge-1.16.5-36.0.42_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
            	at net.minecraft.client.Minecraft.run(Minecraft.java:633) ~[forge-1.16.5-36.0.42_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
            	at net.minecraft.client.main.Main.main(Main.java:184) ~[forge-1.16.5-36.0.42_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
            	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_282] {}
            	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_282] {}
            	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_282] {}
            	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_282] {}
            	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52) ~[forge-1.16.5-36.0.42_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {}
            	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.0.9.jar:?] {}
            	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.0.9.jar:?] {}
            	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.0.9.jar:?] {}
            	at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.0.9.jar:?] {}
            	at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.0.9.jar:?] {}
            	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:105) [forge-1.16.5-36.0.42_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {}
            
            
            -- System Details --
            Details:
            	Minecraft Version: 1.16.5
            	Minecraft Version ID: 1.16.5
            	Operating System: Windows 10 (amd64) version 10.0
            	Java Version: 1.8.0_282, Amazon.com Inc.
            	Java VM Version: OpenJDK 64-Bit Server VM (mixed mode), Amazon.com Inc.
            	Memory: 625605032 bytes (596 MB) / 1105723392 bytes (1054 MB) up to 1873805312 bytes (1787 MB)
            	CPUs: 4
            	JVM Flags: 1 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump
            	ModLauncher: 8.0.9+86+master.3cf110c
            	ModLauncher launch target: fmluserdevclient
            	ModLauncher naming: mcp
            	ModLauncher services: 
            		/mixin-0.8.2.jar mixin PLUGINSERVICE 
            		/eventbus-4.0.0.jar eventbus PLUGINSERVICE 
            		/forge-1.16.5-36.0.42_mapped_snapshot_20201028-1.16.3-launcher.jar object_holder_definalize PLUGINSERVICE 
            		/forge-1.16.5-36.0.42_mapped_snapshot_20201028-1.16.3-launcher.jar runtime_enum_extender PLUGINSERVICE 
            		/accesstransformers-3.0.1.jar accesstransformer PLUGINSERVICE 
            		/forge-1.16.5-36.0.42_mapped_snapshot_20201028-1.16.3-launcher.jar capability_inject_definalize PLUGINSERVICE 
            		/forge-1.16.5-36.0.42_mapped_snapshot_20201028-1.16.3-launcher.jar runtimedistcleaner PLUGINSERVICE 
            		/mixin-0.8.2.jar mixin TRANSFORMATIONSERVICE 
            		/forge-1.16.5-36.0.42_mapped_snapshot_20201028-1.16.3-launcher.jar fml TRANSFORMATIONSERVICE 
            	FML: 36.0
            	Forge: net.minecraftforge:36.0.42
            	FML Language Providers: 
            		javafml@36.0
            		minecraft@1
            	Mod List: 
            		client-extra.jar                                  |Minecraft                     |minecraft                     |1.16.5              |DONE      |a1:d4:5e:04:4f:d3:d6:e0:7b:37:97:cf:77:b0:de:ad:4a:47:ce:8c:96:49:5f:0a:cf:8c:ae:b2:6d:4b:8a:3f
            		forge-1.16.5-36.0.42_mapped_snapshot_20201028-1.16|Forge                         |forge                         |36.0.42             |DONE      |NOSIGNATURE
            		main                                              |SurvivalHistory               |history                       |NONE                |DONE      |NOSIGNATURE
            	Crash Report UUID: 0d3ebc67-c3b0-4d3c-bbf9-c4e35802b945
            	Launched Version: MOD_DEV
            	Backend library: LWJGL version 3.2.2 build 10
            	Backend API: Intel(R) HD Graphics 620 GL version 4.4.0 - Build 21.20.16.4550, Intel
            	GL Caps: Using framebuffer using OpenGL 3.0
            	Using VBOs: Yes
            	Is Modded: Definitely; Client brand changed to 'forge'
            	Type: Client (map_client.txt)
            	Graphics mode: fast
            	Resource Packs: 
            	Current Language: Fran�ais (France)
            	CPU: 4x Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
            [21:28:50] [Render thread/INFO] [STDOUT/]: [net.minecraft.util.registry.Bootstrap:printToSYSOUT:130]: #@!@# Game crashed! Crash report saved to: #@!@# C:\Users\devvospeur\Documents\Mod Adventure History\AdventureHistory\run\.\crash-reports\crash-2021-03-04_21.28.50-client.txt
            AL lib: (EE) alc_cleanup: 1 device not closed
            
            > Task :runClient FAILED
            
            

            et voici mon code :

            package fr.dev.history.Objet.Menu.Whater;
            
            import fr.dev.history.MainM;
            import net.minecraft.client.Minecraft;
            import net.minecraft.util.ResourceLocation;
            import net.minecraft.util.text.ITextComponent;
            import net.minecraftforge.client.event.RenderGameOverlayEvent;
            import net.minecraftforge.eventbus.api.SubscribeEvent;
            
            public class WhaterGui {
            
                @SubscribeEvent
                public void render(RenderGameOverlayEvent.Text event){
                    if (event.getType() == RenderGameOverlayEvent.ElementType.TEXT){
                        Minecraft mc = Minecraft.getInstance();
                        ResourceLocation GUIA = new ResourceLocation(MainM.MODID, "textures/gui/whater.png");
                        int width = event.getWindow().getScaledHeight();
                        int height = event.getWindow().getScaledWidth();
                        mc.fontRenderer.func_243246_a(event.getMatrixStack(), (ITextComponent) GUIA, 15,15,16);
            
                    }
            
                }
            
            }
            
            

            voici ma classe main :

            @Mod(MainM.MODID)
            public class MainM {
                public static final String MODID = "history";
            
                public MainM() {
                    FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
                    FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup);
            
                    IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
                    BlockRegister.BLOCK.register(bus);
                    ItemRegister.ITEMS.register(bus);
                    TileEntityRegister.TILE_ENTITIE.register(bus);
                    MinecraftForge.EVENT_BUS.register(this);
                    MinecraftForge.EVENT_BUS.register(new WhaterGui());
                }
                private void setup(FMLCommonSetupEvent event) {
                }
                private void clientSetup(FMLClientSetupEvent event) {
                    Keybinds.register();
                }
            }
            

            Merci de votre réponse

            1 réponse Dernière réponse Répondre Citer 0
            • robin4002R Hors-ligne
              robin4002 Moddeurs confirmés Rédacteurs Administrateurs
              dernière édition par

              Oui car tu utilises une fonction pour afficher du texte alors que tu essaies d’afficher une image.
              C’est pas bon du tout.

              devvospeurD 1 réponse Dernière réponse Répondre Citer 0
              • devvospeurD Hors-ligne
                devvospeur @robin4002
                dernière édition par

                @robin4002 quelle fonction je dois utiliser ?

                1 réponse Dernière réponse Répondre Citer 0
                • robin4002R Hors-ligne
                  robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                  dernière édition par

                  mc.getTextureManager().bindTexture(GUIA); puis la fonction AbstractGui.blit

                  devvospeurD 1 réponse Dernière réponse Répondre Citer 0
                  • devvospeurD Hors-ligne
                    devvospeur @robin4002
                    dernière édition par

                    @robin4002 Jais essayer de rajouter se code donc voici se que sa donne mais il y a une erreur :

                    public class WhaterGui {
                    
                        @SubscribeEvent
                        public void render(RenderGameOverlayEvent.Text event){
                            if (event.getType() == RenderGameOverlayEvent.ElementType.TEXT){
                                Minecraft mc = Minecraft.getInstance();
                                ResourceLocation GUIA = new ResourceLocation(MainM.MODID, "textures/gui/whater.png");
                                int width = event.getWindow().getScaledHeight();
                                int height = event.getWindow().getScaledWidth();
                                mc.getTextureManager().bindTexture(GUIA);
                                AbstractGui.blit(GUIA, width/2,height/2,0,0,16,16, 16);
                            }
                    
                        }
                    
                    }
                    
                    

                    d0deda5a-2335-4c0d-b0e9-22ac6a11cb71-image.png

                    voila je ne comprend pas pourquoi

                    1 réponse Dernière réponse Répondre Citer 0
                    • robin4002R Hors-ligne
                      robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                      dernière édition par

                      Quelle erreur ?

                      devvospeurD 1 réponse Dernière réponse Répondre Citer 0
                      • devvospeurD Hors-ligne
                        devvospeur @robin4002
                        dernière édition par

                        @robin4002

                        Voici le problème

                        86519b3f-b643-4d58-9462-e36ef25f15d5-image.png

                        1 réponse Dernière réponse Répondre Citer 0
                        • robin4002R Hors-ligne
                          robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                          dernière édition par

                          Le premier argument de la fonction doit être la MatrixStack et non la ResourceLocation que tu veux afficher.

                          Tu peux l’obtenir avec event.getMatrixStack()

                          devvospeurD 1 réponse Dernière réponse Répondre Citer 0
                          • devvospeurD Hors-ligne
                            devvospeur @robin4002
                            dernière édition par

                            @robin4002 a dit dans RenderGameOverlayEvent GUI [1.16.5] :

                            event.getMatrixStack()

                            heuuuu peut tu me dire se que je dois mettre en code car je ne voit pas trop comment faire ?

                            1 réponse Dernière réponse Répondre Citer 0
                            • robin4002R Hors-ligne
                              robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                              dernière édition par robin4002

                              Dans les classes net.minecraft.client.gui.IngameGui et net.minecraftforge.client.gui.ForgeIngameGui la fonction blit est utilisé plusieurs fois, regardes le code des ces derniers pour voir comment l’utiliser.

                              devvospeurD 2 réponses Dernière réponse Répondre Citer 0
                              • devvospeurD Hors-ligne
                                devvospeur @robin4002
                                dernière édition par

                                @robin4002 ok je vais essayer

                                devvospeurD 1 réponse Dernière réponse Répondre Citer 0
                                • devvospeurD Hors-ligne
                                  devvospeur @devvospeur
                                  dernière édition par

                                  @devvospeur jais chercher mais je ne trouve pas peut tu m’expliquer comment faire

                                  1 réponse Dernière réponse Répondre Citer 0
                                  • devvospeurD Hors-ligne
                                    devvospeur @robin4002
                                    dernière édition par

                                    @robin4002 donc ouais jais chercher jais trouver mais je comprend pas comment le rajouter si tu peux m’aider dans le sens à créer le code sa serrai cool

                                    1 réponse Dernière réponse Répondre Citer 0
                                    • robin4002R Hors-ligne
                                      robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                                      dernière édition par

                                      AbstractGui.blit(event.getMatrixStack(), width/2,height/2,0,0,16,16, 16, 16);
                                      Après il faudra peut-être que tu adaptes les paramètres en fonction de ta texture.

                                      1 réponse Dernière réponse Répondre Citer 0
                                      • robin4002R robin4002 a déplacé ce sujet de Support pour les moddeurs sur
                                      • 1 / 1
                                      • Premier message
                                        Dernier message
                                      Design by Woryk
                                      ContactMentions Légales

                                      MINECRAFT FORGE FRANCE © 2024

                                      Powered by NodeBB