• Salut tout le monde
    Je me suis balade sur le fofo quand j’ai vu ce post (http://www.minecraftforgefrance.fr/showthread.php?tid=589&highlight=slider), je me suis dépêché d’aller cherché les deux classes du github de la FFMT Libs, à savoir GuiSliderButton.java et ISliderButton.java. Je n’ai pas compris grand chsoe aux codes j’ai donc essayé de l’incruster dans mon gui, mais manque de chance, il n’apparaît pas et dès qu’on clique dessu on a ce crash-report :

    –-- Minecraft Crash Report ----
    // Don't be sad. I'll do better next time, I promise!
    
    Time: 24/05/15 12:50
    Description: Updating screen events
    
    java.lang.NullPointerException: Updating screen events
    at fr.mrplaigon.musicmc.client.gui.buttons.SliderButton.mousePressed(SliderButton.java:85)
    at net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:465)
    at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:544)
    at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:516)
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:1662)
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1021)
    at net.minecraft.client.Minecraft.run(Minecraft.java:345)
    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 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.mrplaigon.musicmc.client.gui.buttons.SliderButton.mousePressed(SliderButton.java:85)
    at net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:465)
    at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:544)
    at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:516)
    
    -- Affected screen --
    Details:
    Screen name: fr.mrplaigon.musicmc.client.gui.GuiMusicList
    
    -- Affected level --
    Details:
    Level name: MpServer
    All players: 1 total; [EntityPlayerSP['Player765'/159, l='MpServer', x=234,09, y=72,00, z=238,77]]
    Chunk stats: MultiplayerChunkCache: 566, 566
    Level seed: 0
    Level generator: ID 00 - default, ver 1\. Features enabled: false
    Level generator options:
    Level spawn location: 240,00,64,00,248,00 - World: (240,64,248), Chunk: (at 0,4,8 in 15,15; contains blocks 240,0,240 to 255,255,255), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
    Level time: 35924 game time, 35924 day time
    Level dimension: 0
    Level storage version: 0x00000 - Unknown?
    Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
    Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
    Forced entities: 72 total; [EntitySkeleton['Skeleton'/4, l='MpServer', x=158,50, y=28,00, z=288,50], EntityBat['Bat'/6, l='MpServer', x=175,29, y=35,04, z=219,53], EntityCreeper['Creeper'/7, l='MpServer', x=166,50, y=34,00, z=235,50], EntityZombie['Zombie'/12, l='MpServer', x=190,08, y=22,03, z=165,82], EntitySkeleton['Skeleton'/13, l='MpServer', x=188,50, y=42,00, z=166,50], EntityBat['Bat'/14, l='MpServer', x=178,84, y=35,00, z=216,97], EntitySkeleton['Skeleton'/15, l='MpServer', x=182,50, y=34,00, z=211,50], EntitySkeleton['Skeleton'/17, l='MpServer', x=181,50, y=35,00, z=216,50], EntityCreeper['Creeper'/16, l='MpServer', x=180,59, y=34,00, z=213,97], EntitySkeleton['Skeleton'/19, l='MpServer', x=189,16, y=33,00, z=209,50], EntityBat['Bat'/18, l='MpServer', x=175,00, y=36,02, z=221,48], EntityCreeper['Creeper'/21, l='MpServer', x=193,38, y=26,00, z=243,00], EntityBat['Bat'/20, l='MpServer', x=191,84, y=34,01, z=206,38], EntityCreeper['Creeper'/22, l='MpServer', x=176,50, y=13,00, z=311,50], EntityBat['Bat'/28, l='MpServer', x=199,00, y=24,98, z=165,56], EntityZombie['Zombie'/34, l='MpServer', x=192,41, y=25,00, z=179,06], EntityZombie['Zombie'/35, l='MpServer', x=203,69, y=18,61, z=213,50], EntitySkeleton['Skeleton'/32, l='MpServer', x=207,50, y=24,00, z=168,50], EntitySkeleton['Skeleton'/33, l='MpServer', x=190,72, y=42,00, z=164,28], EntityCreeper['Creeper'/38, l='MpServer', x=204,03, y=24,00, z=219,50], EntityBat['Bat'/39, l='MpServer', x=204,97, y=29,10, z=225,25], EntityBat['Bat'/36, l='MpServer', x=191,96, y=25,66, z=193,78], EntitySkeleton['Skeleton'/37, l='MpServer', x=218,47, y=15,00, z=210,88], EntitySkeleton['Skeleton'/42, l='MpServer', x=199,50, y=26,00, z=246,16], EntitySkeleton['Skeleton'/43, l='MpServer', x=195,50, y=26,00, z=243,50], EntityZombie['Zombie'/40, l='MpServer', x=193,03, y=25,00, z=229,53], EntityBat['Bat'/41, l='MpServer', x=214,19, y=28,01, z=243,54], EntityPlayerSP['Player765'/159, l='MpServer', x=234,09, y=72,00, z=238,77], EntitySquid['Squid'/44, l='MpServer', x=200,41, y=57,94, z=289,19], EntityBat['Bat'/50, l='MpServer', x=211,26, y=23,92, z=168,79], EntitySkeleton['Skeleton'/49, l='MpServer', x=217,50, y=25,00, z=170,50], EntitySkeleton['Skeleton'/55, l='MpServer', x=212,71, y=16,53, z=217,69], EntitySkeleton['Skeleton'/54, l='MpServer', x=209,50, y=19,00, z=217,50], EntitySpider['Spider'/53, l='MpServer', x=217,19, y=17,00, z=213,75], EntitySkeleton['Skeleton'/52, l='MpServer', x=222,50, y=26,00, z=175,50], EntitySkeleton['Skeleton'/58, l='MpServer', x=211,53, y=28,00, z=245,44], EntityZombie['Zombie'/57, l='MpServer', x=211,28, y=28,00, z=247,09], EntityZombie['Zombie'/56, l='MpServer', x=212,38, y=16,00, z=216,38], EntitySpider['Spider'/63, l='MpServer', x=222,28, y=25,00, z=168,13], EntitySpider['Spider'/62, l='MpServer', x=232,28, y=26,00, z=171,28], EntitySheep['Sheep'/68, l='MpServer', x=229,03, y=65,00, z=207,00], EntitySpider['Spider'/69, l='MpServer', x=239,34, y=75,00, z=240,66], EntitySpider['Spider'/64, l='MpServer', x=229,50, y=25,00, z=170,50], EntitySkeleton['Skeleton'/65, l='MpServer', x=224,31, y=25,00, z=171,44], EntitySpider['Spider'/66, l='MpServer', x=226,97, y=24,91, z=174,16], EntitySpider['Spider'/67, l='MpServer', x=226,70, y=25,93, z=168,16], EntitySheep['Sheep'/77, l='MpServer', x=249,41, y=63,00, z=279,75], EntitySheep['Sheep'/79, l='MpServer', x=269,53, y=63,00, z=209,75], EntitySheep['Sheep'/85, l='MpServer', x=284,22, y=63,00, z=194,97], EntitySkeleton['Skeleton'/84, l='MpServer', x=262,50, y=15,00, z=272,50], EntitySheep['Sheep'/87, l='MpServer', x=281,50, y=67,00, z=202,03], EntitySheep['Sheep'/86, l='MpServer', x=275,50, y=67,00, z=207,47], EntityZombie['Zombie'/81, l='MpServer', x=269,06, y=13,00, z=267,34], EntitySheep['Sheep'/80, l='MpServer', x=266,03, y=77,00, z=233,94], EntitySkeleton['Skeleton'/83, l='MpServer', x=262,56, y=32,00, z=260,88], EntitySkeleton['Skeleton'/82, l='MpServer', x=262,50, y=32,00, z=262,50], EntityZombie['Zombie'/93, l='MpServer', x=279,50, y=18,00, z=266,50], EntitySkeleton['Skeleton'/92, l='MpServer', x=284,50, y=18,00, z=266,50], EntityEnderman['Enderman'/95, l='MpServer', x=280,22, y=24,00, z=300,47], EntitySkeleton['Skeleton'/94, l='MpServer', x=279,88, y=18,00, z=298,31], EntityEnderman['Enderman'/89, l='MpServer', x=278,50, y=17,00, z=270,50], EntitySheep['Sheep'/88, l='MpServer', x=285,50, y=70,16, z=204,53], EntityBat['Bat'/91, l='MpServer', x=290,60, y=20,92, z=262,44], EntitySkeleton['Skeleton'/90, l='MpServer', x=281,50, y=18,00, z=266,50], EntitySheep['Sheep'/102, l='MpServer', x=296,00, y=75,00, z=230,06], EntityZombie['Zombie'/103, l='MpServer', x=286,94, y=18,00, z=260,63], EntitySheep['Sheep'/100, l='MpServer', x=299,94, y=74,00, z=224,97], EntitySheep['Sheep'/101, l='MpServer', x=289,09, y=76,00, z=226,19], EntityBat['Bat'/234, l='MpServer', x=261,44, y=15,22, z=317,72], EntitySheep['Sheep'/99, l='MpServer', x=294,97, y=75,00, z=222,94], EntitySheep['Sheep'/110, l='MpServer', x=312,59, y=72,00, z=258,72], EntitySheep['Sheep'/111, l='MpServer', x=312,16, y=64,00, z=279,22]]
    Retry entities: 0 total; []
    Server brand: fml,forge
    Server type: Integrated singleplayer server
    Stacktrace:
    at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:350)
    at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2488)
    at net.minecraft.client.Minecraft.run(Minecraft.java:367)
    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 net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
    at GradleStart.main(Unknown Source)
    
    – System Details --
    Details:
    Minecraft Version: 1.8
    Operating System: Windows 7 (amd64) version 6.1
    Java Version: 1.7.0_71, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 678934016 bytes (647 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
    JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
    IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94
    FML: MCP v9.10 FML v8.0.26.1299 Minecraft Forge 11.14.0.1299 4 mods loaded, 4 mods active
    mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    FML{8.0.26.1299} [Forge Mod Loader] (forgeSrc-1.8-11.14.0.1299.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    Forge{11.14.0.1299} [Minecraft Forge] (forgeSrc-1.8-11.14.0.1299.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    musicmcmod{1.0} [MusicMC Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    Launched Version: 1.8
    LWJGL: 2.9.1
    OpenGL: AMD Radeon HD 8570D GL version 4.4.13283 Compatibility Profile Context 14.501.1003.0, ATI Technologies Inc.
    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: No
    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)
    

    Et voici la classe de mon Gui possédant ce slider :

    
    package fr.mrplaigon.musicmc.client.gui;
    
    import net.minecraft.client.gui.GuiButton;
    import net.minecraft.client.gui.GuiScreen;
    import net.minecraft.client.renderer.Tessellator;
    import net.minecraft.client.renderer.WorldRenderer;
    import net.minecraft.util.ResourceLocation;
    import fr.mrplaigon.musicmc.client.gui.buttons.ISliderButton;
    import fr.mrplaigon.musicmc.client.gui.buttons.SliderButton;
    import fr.mrplaigon.musicmc.common.core.MusicMCMod;
    
    public class GuiMusicList extends GuiScreen implements ISliderButton
    { 
    
    public final ResourceLocation texture = new ResourceLocation(MusicMCMod.MODID, "textures/gui/guiMusicList.png"); 
    public final int xSizeOfTexture = 176; //largeur
    public final int ySizeOfTexture = 222; //hauteur
    
    public GuiMusicList()
    {
    
    }
    
        public void drawScreen(int x, int y, float f)
        {
    
        int displayX = (width - xSizeOfTexture) / 2;
            int displayY = (height - ySizeOfTexture) / 2;
            mc.renderEngine.bindTexture(texture);
            drawGuiTexture(displayX, displayY, 0, 0, xSizeOfTexture, ySizeOfTexture);
        }
    
        public void drawGuiTexture(int x, int y, int xDecalage, int yDecalage, int xSize, int ySize)
        {
            float fx = (float)1 / xSize; // 0.00390625 est les résultat de 1 / 256 donc on fait 1 / xSize pour obtenir notre nombre définissant la taille de notre image.
            float fy = (float)1 / ySize; // Idem
            Tessellator tessellator = Tessellator.getInstance();
            WorldRenderer worldrenderer = tessellator.getWorldRenderer();
            worldrenderer.startDrawingQuads();
            worldrenderer.addVertexWithUV(x + 0, y + ySize, zLevel, (float)(xDecalage + 0) * fx, (float)(yDecalage + ySize) * fy);
            worldrenderer.addVertexWithUV(x + xSize, y + ySize, zLevel, (float)(xDecalage + xSize) * fx, (float)(yDecalage + ySize) * fy);
            worldrenderer.addVertexWithUV(x + xSize, y + 0, zLevel, (float)(xDecalage + xSize) * fx, (float)(yDecalage + 0) * fy);
            worldrenderer.addVertexWithUV(x + 0, y + 0, zLevel, (float)(xDecalage + 0) * fx, (float)(yDecalage + 0) * fy);
            tessellator.draw();
        }
    
        public void initGui()
        {
        int posX = (this.width - xSizeOfTexture) / 2;
        int posY = (this.height - ySizeOfTexture) / 2;
    
        this.buttonList.add(new GuiButton(0, posX+ 40, posY + 40, 100, 20, "no use"));
        this.buttonList.add(new SliderButton(this, 1, posX + 80, posY + 40, 50, 50, "test", 1, new ResourceLocation(MusicMCMod.MODID, "textures/gui/pictures/radioIcon.png"), posY + 40));
        }
    
        @Override
        public boolean doesGuiPauseGame()
        {
        return false;
        }
    
        protected void actionPerformed(GuiButton button) 
        {
        switch (button.id)
        {
        case 0:
    
        break;
    
        case 1:
        this.handlerSliderAction(1, 1);
        break;
    
        default:
        }
        }
    
    @Override
    public void handlerSliderAction(int sliderId, float sliderValue) 
    {
    
    }
    
    @Override
    public String getSliderName(int sliderId, float sliderValue) 
    {
    return "test";
    }
    
    }
    
    

    Enfin bref si j’ai oublié de donner des infos dites le moi.
    Merci d’avance

  • Administrateurs Rédacteurs Moddeurs confirmés

        at fr.mrplaigon.musicmc.client.gui.buttons.SliderButton.mousePressed(SliderButton.java:85)
    

    Le problème est dans cette classe. Et un NPE ce n’est pas difficile à corriger …


  • @‘robin4002’:

        at fr.mrplaigon.musicmc.client.gui.buttons.SliderButton.mousePressed(SliderButton.java:85)
    

    Le problème est dans cette classe. Et un NPE ce n’est pas difficile à corriger …

    Bon le crash est réglé mais je ne comprends vraiment rien.
    Le slider n’apparaît pas de + dans mon Gui si j’appuie dessus il ne se passe rien du tout. Peut-être que prendre le GuiSlider de Minecraft serait une meilleure idée …


  • Les sliders sont mal foutus: il faut les dessiner en premier ou réécrire la méthode drawBackground.
    Pourquoi créer un autre bouton pour le slider ?