Convertir Double en Int



  • Bonjour, je voulais convertir un double en Int mais ca crash quand je lance
    Merci 🙂

        int PosX= (int)mc.thePlayer.posX;
        int PosY= (int)mc.thePlayer.posY;
        int PosZ= (int)mc.thePlayer.posZ;
    


  • ah oui, ca vien de l'instance

    package com.extremium.mod;
    
    import cpw.mods.fml.client.FMLClientHandler;
    import cpw.mods.fml.common.Mod.Instance;
    import cpw.mods.fml.common.eventhandler.SubscribeEvent;
    import cpw.mods.fml.relauncher.Side;
    import cpw.mods.fml.relauncher.SideOnly;
    import net.minecraft.client.Minecraft;
    import net.minecraft.client.gui.FontRenderer;
    import net.minecraft.util.Direction;
    import net.minecraft.util.MathHelper;
    import net.minecraftforge.client.event.RenderGameOverlayEvent;
    
    public class EventHandlerMod
    { 
    
        @SideOnly(Side.CLIENT) 
        @SubscribeEvent
        public void onRenderPre(RenderGameOverlayEvent.Pre event)
        {
            if(event.type == RenderGameOverlayEvent.ElementType.DEBUG)
            {
                Minecraft mc = Minecraft.getMinecraft();
                int PosX= (int)mc.thePlayer.posX;
                int PosY= (int)mc.thePlayer.posX;
                int PosZ= (int)mc.thePlayer.posZ;
                event.setCanceled(true);
                this.drawString(Minecraft.getMinecraft().fontRenderer, "Fps : " + mc.debug.split(",", 2)[0], 5, 5, 26666);
                this.drawString(Minecraft.getMinecraft().fontRenderer, "Biome : " + mc.theWorld.getBiomeGenForCoords(5, 15).biomeName, 5, 15, 77777);
                this.drawString(Minecraft.getMinecraft().fontRenderer, "x : " + PosX + " y : " + PosY + " z : " + PosZ, 5, 25, 547444);
                this.drawString(Minecraft.getMinecraft().fontRenderer, Minecraft.getMinecraft().getEntityDebug(), 5, 35, 877778814);
                
                
            }
            
        }
         
        public void drawString(FontRenderer par1FontRenderer, String par2Str, int par3, int par4, int par5)
        {
            par1FontRenderer.drawStringWithShadow(par2Str, par3, par4, par5);
        }
    
        
    }
    
    
    

  • Moddeurs confirmĂ©s ModĂ©rateurs

    Bonjour, merci de nous donner plus d'info, comme le rapport de crash.

    Merci de respecter les règles de la section. Cela fait plusieurs fois que je remarque que tes demandes ne les respectes pas, ton prochain sujet qui ne respecte pas les règles sera sanctionné.

    Cordialement
    Isador34



  • voici le crash report :

    ---- Minecraft Crash Report ----
    // Why did you do that?
    
    Time: 21/09/19 17:03
    Description: Initializing game
    
    java.lang.NullPointerException: Initializing game
    	at com.extremium.mod.EventHandlerMod.<init>(EventHandlerMod.java:17)
    	at com.extremium.mod.Extremium.init(Extremium.java:119)
    	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 cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:532)
    	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 com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
    	at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
    	at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
    	at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
    	at com.google.common.eventbus.EventBus.post(EventBus.java:275)
    	at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:212)
    	at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:190)
    	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 com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
    	at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
    	at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
    	at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
    	at com.google.common.eventbus.EventBus.post(EventBus.java:275)
    	at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:119)
    	at cpw.mods.fml.common.Loader.initializeMods(Loader.java:737)
    	at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:311)
    	at net.minecraft.client.Minecraft.startGame(Minecraft.java:597)
    	at net.minecraft.client.Minecraft.run(Minecraft.java:942)
    	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 com.extremium.mod.EventHandlerMod.<init>(EventHandlerMod.java:17)
    	at com.extremium.mod.Extremium.init(Extremium.java:119)
    	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 cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:532)
    	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 com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
    	at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
    	at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
    	at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
    	at com.google.common.eventbus.EventBus.post(EventBus.java:275)
    	at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:212)
    	at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:190)
    	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 com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
    	at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
    	at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
    	at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
    	at com.google.common.eventbus.EventBus.post(EventBus.java:275)
    	at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:119)
    	at cpw.mods.fml.common.Loader.initializeMods(Loader.java:737)
    	at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:311)
    	at net.minecraft.client.Minecraft.startGame(Minecraft.java:597)
    
    -- Initialization --
    Details:
    Stacktrace:
    	at net.minecraft.client.Minecraft.run(Minecraft.java:942)
    	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)
    
    -- System Details --
    Details:
    	Minecraft Version: 1.7.10
    	Operating System: Windows 10 (amd64) version 10.0
    	Java Version: 1.8.0_181, Oracle Corporation
    	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    	Memory: 624676280 bytes (595 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 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.05 FML v7.10.99.99 Minecraft Forge 10.13.4.1614 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
    	UCHI	mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) 
    	UCHI	FML{7.10.99.99} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.4.1614-1.7.10.jar) 
    	UCHI	Forge{10.13.4.1614} [Minecraft Forge] (forgeSrc-1.7.10-10.13.4.1614-1.7.10.jar) 
    	UCHE	extremium{2.4} [Extremium Mod] (bin) 
    	GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.6.0 NVIDIA 430.86' Renderer: 'GeForce GTX 1050/PCIe/SSE2'
    	Launched Version: 1.7.10
    	LWJGL: 2.9.1
    	OpenGL: GeForce GTX 1050/PCIe/SSE2 GL version 4.6.0 NVIDIA 430.86, NVIDIA Corporation
    	GL Caps: Using GL 1.3 multitexturing.
    Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
    Anisotropic filtering is supported and maximum anisotropy is 16.
    Shaders are available because OpenGL 2.1 is supported.
    
    	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)
    	Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
    	Anisotropic Filtering: Off (1)
    

  • Moddeurs confirmĂ©s ModĂ©rateurs

    je suppose au vu du crash, que ton player n'est pas encore créé au moment où tu le get, d'où la NPE



  • ?? Pas compris. Et sinon, une soluce ?
    Merci encore 🙂


  • Moddeurs confirmĂ©s ModĂ©rateurs

    sais-tu ce qu'est une NPE (NullPointerException)?



  • euuuh non...
    Je suis pas très calé xD
    Merci


  • Moddeurs confirmĂ©s ModĂ©rateurs

    Alors il faudrait penser Ă  apprendre le Java avant de vouloir modder. Tu n'arriveras Ă  rien sinon



  • Merci mais en fait je crois comprendre avc du recul que veut dire Npe xD
    Mais le probleme est que je ne comprends pas oĂą est le bug


  • Moddeurs confirmĂ©s ModĂ©rateurs

    Justement, si tu avais les bases en Java tu saurais où se trouve le problème, et pro-tips, c'est pas ton cast le problème



  • En fait je crois que si car quand j'enleve les 3 lignes ca crash plus


  • Moddeurs confirmĂ©s ModĂ©rateurs

    je t'assure que ça viens pas du cast, laisse ces trois ligne mais sans le cast et tu verras



  • ah oui, ca vien de l'instance

    package com.extremium.mod;
    
    import cpw.mods.fml.client.FMLClientHandler;
    import cpw.mods.fml.common.Mod.Instance;
    import cpw.mods.fml.common.eventhandler.SubscribeEvent;
    import cpw.mods.fml.relauncher.Side;
    import cpw.mods.fml.relauncher.SideOnly;
    import net.minecraft.client.Minecraft;
    import net.minecraft.client.gui.FontRenderer;
    import net.minecraft.util.Direction;
    import net.minecraft.util.MathHelper;
    import net.minecraftforge.client.event.RenderGameOverlayEvent;
    
    public class EventHandlerMod
    { 
    
        @SideOnly(Side.CLIENT) 
        @SubscribeEvent
        public void onRenderPre(RenderGameOverlayEvent.Pre event)
        {
            if(event.type == RenderGameOverlayEvent.ElementType.DEBUG)
            {
                Minecraft mc = Minecraft.getMinecraft();
                int PosX= (int)mc.thePlayer.posX;
                int PosY= (int)mc.thePlayer.posX;
                int PosZ= (int)mc.thePlayer.posZ;
                event.setCanceled(true);
                this.drawString(Minecraft.getMinecraft().fontRenderer, "Fps : " + mc.debug.split(",", 2)[0], 5, 5, 26666);
                this.drawString(Minecraft.getMinecraft().fontRenderer, "Biome : " + mc.theWorld.getBiomeGenForCoords(5, 15).biomeName, 5, 15, 77777);
                this.drawString(Minecraft.getMinecraft().fontRenderer, "x : " + PosX + " y : " + PosY + " z : " + PosZ, 5, 25, 547444);
                this.drawString(Minecraft.getMinecraft().fontRenderer, Minecraft.getMinecraft().getEntityDebug(), 5, 35, 877778814);
                
                
            }
            
        }
         
        public void drawString(FontRenderer par1FontRenderer, String par2Str, int par3, int par4, int par5)
        {
            par1FontRenderer.drawStringWithShadow(par2Str, par3, par4, par5);
        }
    
        
    }
    
    
    

  • Moddeurs confirmĂ©s RĂ©dacteurs Administrateurs

    Bonsoir,

    Si le problème n'est pas résolu (je vois que code ne correspond plus au rapport de crash, tu as changé des choses) il faut ajouter un null check sur la variable qui est null.



  • oui, j'ai rĂ©glĂ© le bug, ca vient du fait que je ne l'ai pas mis dans la fonction RenderGameOverlayEvent



  • @robin4002 et au fait, aurais tu une soluce pour le post du mob invisible que j'ai fait ?


Log in to reply