Custom Bouton



  • Salut,

    J'aimerais faire un GuiButton personnalisé pour afficher le texte à gauche du bouton et non centré, j'ai inspecté le code et je pense savoir ce qu'il faut modifier seulement, lorsque je copie colle et personifie un peu le code ça ne marche toujours pas voici mes classes :

    package net.minecraft.client.gui;
    
    import cpw.mods.fml.relauncher.Side;
    import cpw.mods.fml.relauncher.SideOnly;
    import net.minecraft.client.renderer.OpenGlHelper;
    import net.minecraft.client.renderer.Tessellator;
    import net.minecraft.util.IIcon;
    import net.minecraft.util.ResourceLocation;
    import org.lwjgl.opengl.GL11;
    
    @SideOnly(Side.CLIENT)
    public class Gui
    {
        public static final ResourceLocation optionsBackground = new ResourceLocation("textures/gui/options_background.png");
        public static final ResourceLocation statIcons = new ResourceLocation("textures/gui/container/stats_icons.png");
        public static final ResourceLocation icons = new ResourceLocation("textures/gui/icons.png");
        protected float zLevel;
        private static final String __OBFID = "CL_00000662";
    
        protected void drawHorizontalLine(int p_73730_1_, int p_73730_2_, int p_73730_3_, int p_73730_4_)
        {
            if (p_73730_2_ < p_73730_1_)
            {
                int i1 = p_73730_1_;
                p_73730_1_ = p_73730_2_;
                p_73730_2_ = i1;
            }
    
            drawRect(p_73730_1_, p_73730_3_, p_73730_2_ + 1, p_73730_3_ + 1, p_73730_4_);
        }
    
        protected void drawVerticalLine(int p_73728_1_, int p_73728_2_, int p_73728_3_, int p_73728_4_)
        {
            if (p_73728_3_ < p_73728_2_)
            {
                int i1 = p_73728_2_;
                p_73728_2_ = p_73728_3_;
                p_73728_3_ = i1;
            }
    
            drawRect(p_73728_1_, p_73728_2_ + 1, p_73728_1_ + 1, p_73728_3_, p_73728_4_);
        }
    
        /**
         * Draws a solid color rectangle with the specified coordinates and color. Args: x1, y1, x2, y2, color
         */
        public static void drawRect(int p_73734_0_, int p_73734_1_, int p_73734_2_, int p_73734_3_, int p_73734_4_)
        {
            int j1;
    
            if (p_73734_0_ < p_73734_2_)
            {
                j1 = p_73734_0_;
                p_73734_0_ = p_73734_2_;
                p_73734_2_ = j1;
            }
    
            if (p_73734_1_ < p_73734_3_)
            {
                j1 = p_73734_1_;
                p_73734_1_ = p_73734_3_;
                p_73734_3_ = j1;
            }
    
            float f3 = (float)(p_73734_4_ >> 24 & 255) / 255.0F;
            float f = (float)(p_73734_4_ >> 16 & 255) / 255.0F;
            float f1 = (float)(p_73734_4_ >> 8 & 255) / 255.0F;
            float f2 = (float)(p_73734_4_ & 255) / 255.0F;
            Tessellator tessellator = Tessellator.instance;
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glDisable(GL11.GL_TEXTURE_2D);
            OpenGlHelper.glBlendFunc(770, 771, 1, 0);
            GL11.glColor4f(f, f1, f2, f3);
            tessellator.startDrawingQuads();
            tessellator.addVertex((double)p_73734_0_, (double)p_73734_3_, 0.0D);
            tessellator.addVertex((double)p_73734_2_, (double)p_73734_3_, 0.0D);
            tessellator.addVertex((double)p_73734_2_, (double)p_73734_1_, 0.0D);
            tessellator.addVertex((double)p_73734_0_, (double)p_73734_1_, 0.0D);
            tessellator.draw();
            GL11.glEnable(GL11.GL_TEXTURE_2D);
            GL11.glDisable(GL11.GL_BLEND);
        }
    
        /**
         * Draws a rectangle with a vertical gradient between the specified colors.
         */
        protected void drawGradientRect(int p_73733_1_, int p_73733_2_, int p_73733_3_, int p_73733_4_, int p_73733_5_, int p_73733_6_)
        {
            float f = (float)(p_73733_5_ >> 24 & 255) / 255.0F;
            float f1 = (float)(p_73733_5_ >> 16 & 255) / 255.0F;
            float f2 = (float)(p_73733_5_ >> 8 & 255) / 255.0F;
            float f3 = (float)(p_73733_5_ & 255) / 255.0F;
            float f4 = (float)(p_73733_6_ >> 24 & 255) / 255.0F;
            float f5 = (float)(p_73733_6_ >> 16 & 255) / 255.0F;
            float f6 = (float)(p_73733_6_ >> 8 & 255) / 255.0F;
            float f7 = (float)(p_73733_6_ & 255) / 255.0F;
            GL11.glDisable(GL11.GL_TEXTURE_2D);
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glDisable(GL11.GL_ALPHA_TEST);
            OpenGlHelper.glBlendFunc(770, 771, 1, 0);
            GL11.glShadeModel(GL11.GL_SMOOTH);
            Tessellator tessellator = Tessellator.instance;
            tessellator.startDrawingQuads();
            tessellator.setColorRGBA_F(f1, f2, f3, f);
            tessellator.addVertex((double)p_73733_3_, (double)p_73733_2_, (double)this.zLevel);
            tessellator.addVertex((double)p_73733_1_, (double)p_73733_2_, (double)this.zLevel);
            tessellator.setColorRGBA_F(f5, f6, f7, f4);
            tessellator.addVertex((double)p_73733_1_, (double)p_73733_4_, (double)this.zLevel);
            tessellator.addVertex((double)p_73733_3_, (double)p_73733_4_, (double)this.zLevel);
            tessellator.draw();
            GL11.glShadeModel(GL11.GL_FLAT);
            GL11.glDisable(GL11.GL_BLEND);
            GL11.glEnable(GL11.GL_ALPHA_TEST);
            GL11.glEnable(GL11.GL_TEXTURE_2D);
        }
    
        /**
         * Renders the specified text to the screen, center-aligned.
         */
        public void drawCenteredString(FontRenderer p_73732_1_, String p_73732_2_, int p_73732_3_, int p_73732_4_, int p_73732_5_)
        {
            p_73732_1_.drawStringWithShadow(p_73732_2_, p_73732_3_ - p_73732_1_.getStringWidth(p_73732_2_) / 2, p_73732_4_, p_73732_5_);
        }
    
        /**
         * Renders the specified text to the screen.
         */
        public void drawString(FontRenderer p_73731_1_, String p_73731_2_, int p_73731_3_, int p_73731_4_, int p_73731_5_)
        {
            p_73731_1_.drawStringWithShadow(p_73731_2_, p_73731_3_, p_73731_4_, p_73731_5_);
        }
    
        /**
         * Draws a textured rectangle at the stored z-value. Args: x, y, u, v, width, height
         */
        public void drawTexturedModalRect(int p_73729_1_, int p_73729_2_, int p_73729_3_, int p_73729_4_, int p_73729_5_, int p_73729_6_)
        {
            float f = 0.00390625F;
            float f1 = 0.00390625F;
            Tessellator tessellator = Tessellator.instance;
            tessellator.startDrawingQuads();
            tessellator.addVertexWithUV((double)(p_73729_1_ + 0), (double)(p_73729_2_ + p_73729_6_), (double)this.zLevel, (double)((float)(p_73729_3_ + 0) * f), (double)((float)(p_73729_4_ + p_73729_6_) * f1));
            tessellator.addVertexWithUV((double)(p_73729_1_ + p_73729_5_), (double)(p_73729_2_ + p_73729_6_), (double)this.zLevel, (double)((float)(p_73729_3_ + p_73729_5_) * f), (double)((float)(p_73729_4_ + p_73729_6_) * f1));
            tessellator.addVertexWithUV((double)(p_73729_1_ + p_73729_5_), (double)(p_73729_2_ + 0), (double)this.zLevel, (double)((float)(p_73729_3_ + p_73729_5_) * f), (double)((float)(p_73729_4_ + 0) * f1));
            tessellator.addVertexWithUV((double)(p_73729_1_ + 0), (double)(p_73729_2_ + 0), (double)this.zLevel, (double)((float)(p_73729_3_ + 0) * f), (double)((float)(p_73729_4_ + 0) * f1));
            tessellator.draw();
        }
    
        public void drawTexturedModelRectFromIcon(int p_94065_1_, int p_94065_2_, IIcon p_94065_3_, int p_94065_4_, int p_94065_5_)
        {
            Tessellator tessellator = Tessellator.instance;
            tessellator.startDrawingQuads();
            tessellator.addVertexWithUV((double)(p_94065_1_ + 0), (double)(p_94065_2_ + p_94065_5_), (double)this.zLevel, (double)p_94065_3_.getMinU(), (double)p_94065_3_.getMaxV());
            tessellator.addVertexWithUV((double)(p_94065_1_ + p_94065_4_), (double)(p_94065_2_ + p_94065_5_), (double)this.zLevel, (double)p_94065_3_.getMaxU(), (double)p_94065_3_.getMaxV());
            tessellator.addVertexWithUV((double)(p_94065_1_ + p_94065_4_), (double)(p_94065_2_ + 0), (double)this.zLevel, (double)p_94065_3_.getMaxU(), (double)p_94065_3_.getMinV());
            tessellator.addVertexWithUV((double)(p_94065_1_ + 0), (double)(p_94065_2_ + 0), (double)this.zLevel, (double)p_94065_3_.getMinU(), (double)p_94065_3_.getMinV());
            tessellator.draw();
        }
    
        public static void func_146110_a(int p_146110_0_, int p_146110_1_, float p_146110_2_, float p_146110_3_, int p_146110_4_, int p_146110_5_, float p_146110_6_, float p_146110_7_)
        {
            float f4 = 1.0F / p_146110_6_;
            float f5 = 1.0F / p_146110_7_;
            Tessellator tessellator = Tessellator.instance;
            tessellator.startDrawingQuads();
            tessellator.addVertexWithUV((double)p_146110_0_, (double)(p_146110_1_ + p_146110_5_), 0.0D, (double)(p_146110_2_ * f4), (double)((p_146110_3_ + (float)p_146110_5_) * f5));
            tessellator.addVertexWithUV((double)(p_146110_0_ + p_146110_4_), (double)(p_146110_1_ + p_146110_5_), 0.0D, (double)((p_146110_2_ + (float)p_146110_4_) * f4), (double)((p_146110_3_ + (float)p_146110_5_) * f5));
            tessellator.addVertexWithUV((double)(p_146110_0_ + p_146110_4_), (double)p_146110_1_, 0.0D, (double)((p_146110_2_ + (float)p_146110_4_) * f4), (double)(p_146110_3_ * f5));
            tessellator.addVertexWithUV((double)p_146110_0_, (double)p_146110_1_, 0.0D, (double)(p_146110_2_ * f4), (double)(p_146110_3_ * f5));
            tessellator.draw();
        }
    
        public static void func_152125_a(int p_152125_0_, int p_152125_1_, float p_152125_2_, float p_152125_3_, int p_152125_4_, int p_152125_5_, int p_152125_6_, int p_152125_7_, float p_152125_8_, float p_152125_9_)
        {
            float f4 = 1.0F / p_152125_8_;
            float f5 = 1.0F / p_152125_9_;
            Tessellator tessellator = Tessellator.instance;
            tessellator.startDrawingQuads();
            tessellator.addVertexWithUV((double)p_152125_0_, (double)(p_152125_1_ + p_152125_7_), 0.0D, (double)(p_152125_2_ * f4), (double)((p_152125_3_ + (float)p_152125_5_) * f5));
            tessellator.addVertexWithUV((double)(p_152125_0_ + p_152125_6_), (double)(p_152125_1_ + p_152125_7_), 0.0D, (double)((p_152125_2_ + (float)p_152125_4_) * f4), (double)((p_152125_3_ + (float)p_152125_5_) * f5));
            tessellator.addVertexWithUV((double)(p_152125_0_ + p_152125_6_), (double)p_152125_1_, 0.0D, (double)((p_152125_2_ + (float)p_152125_4_) * f4), (double)(p_152125_3_ * f5));
            tessellator.addVertexWithUV((double)p_152125_0_, (double)p_152125_1_, 0.0D, (double)(p_152125_2_ * f4), (double)(p_152125_3_ * f5));
            tessellator.draw();
        }
    }
    
    package fr.altiscraft.altiscraft.common;
    
    import org.lwjgl.opengl.GL11;
    
    import cpw.mods.fml.relauncher.Side;
    import cpw.mods.fml.relauncher.SideOnly;
    import net.minecraft.client.Minecraft;
    import net.minecraft.client.audio.PositionedSoundRecord;
    import net.minecraft.client.audio.SoundHandler;
    import net.minecraft.client.gui.FontRenderer;
    import net.minecraft.client.gui.Gui;
    import net.minecraft.client.renderer.OpenGlHelper;
    import net.minecraft.util.ResourceLocation;
    
    @SideOnly(Side.CLIENT)
    public class GuiBouton extends Gui {
    protected static final ResourceLocation buttonTextures = new ResourceLocation("textures/gui/widgets.png");
    /** Button width in pixels */
    public int width;
    /** Button height in pixels */
    public int height;
    /** The x position of this control. */
    public int xPosition;
    /** The y position of this control. */
    public int yPosition;
    /** The string displayed on this control. */
    public String displayString;
    public int id;
    /** True if this control is enabled, false to disable. */
    public boolean enabled;
    /** Hides the button completely if false. */
    public boolean visible;
    protected boolean field_146123_n;
    public int packedFGColour;
    
    public GuiBouton(int p_i1020_1_, int p_i1020_2_, int p_i1020_3_, String p_i1020_4_) {
    this(p_i1020_1_, p_i1020_2_, p_i1020_3_, 200, 20, p_i1020_4_);
    }
    
    public GuiBouton(int p_i1021_1_, int p_i1021_2_, int p_i1021_3_, int p_i1021_4_, int p_i1021_5_,
    String p_i1021_6_) {
    this.width = 200;
    this.height = 20;
    this.enabled = true;
    this.visible = true;
    this.id = p_i1021_1_;
    this.xPosition = p_i1021_2_;
    this.yPosition = p_i1021_3_;
    this.width = p_i1021_4_;
    this.height = p_i1021_5_;
    this.displayString = p_i1021_6_;
    }
    
    /**
    * Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over
    * this button and 2 if it IS hovering over this button.
    */
    public int getHoverState(boolean p_146114_1_) {
    byte b0 = 1;
    
    if (!this.enabled) {
    b0 = 0;
    } else if (p_146114_1_) {
    b0 = 2;
    }
    
    return b0;
    }
    
    /**
    * Draws this button to the screen.
    */
    public void drawButton(Minecraft p_146112_1_, int p_146112_2_, int p_146112_3_) {
    if (this.visible) {
    FontRenderer fontrenderer = p_146112_1_.fontRenderer;
    p_146112_1_.getTextureManager().bindTexture(buttonTextures);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    this.field_146123_n = p_146112_2_ >= this.xPosition && p_146112_3_ >= this.yPosition
    && p_146112_2_ < this.xPosition + this.width && p_146112_3_ < this.yPosition + this.height;
    int k = this.getHoverState(this.field_146123_n);
    GL11.glEnable(GL11.GL_BLEND);
    OpenGlHelper.glBlendFunc(770, 771, 1, 0);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + k * 20, this.width / 2, this.height);
    this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2,
    46 + k * 20, this.width / 2, this.height);
    this.mouseDragged(p_146112_1_, p_146112_2_, p_146112_3_);
    int l = 14737632;
    
    if (packedFGColour != 0) {
    l = packedFGColour;
    } else if (!this.enabled) {
    l = 10526880;
    } else if (this.field_146123_n) {
    l = 16777120;
    }
    
    this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2,
    this.yPosition + (this.height - 8) / 2, l);
    }
    }
    
    /**
    * Fired when the mouse button is dragged. Equivalent of
    * MouseListener.mouseDragged(MouseEvent e).
    */
    protected void mouseDragged(Minecraft p_146119_1_, int p_146119_2_, int p_146119_3_) {
    }
    
    /**
    * Fired when the mouse button is released. Equivalent of
    * MouseListener.mouseReleased(MouseEvent e).
    */
    public void mouseReleased(int p_146118_1_, int p_146118_2_) {
    }
    
    /**
    * Returns true if the mouse has been pressed on this control. Equivalent of
    * MouseListener.mousePressed(MouseEvent e).
    */
    public boolean mousePressed(Minecraft p_146116_1_, int p_146116_2_, int p_146116_3_) {
    return this.enabled && this.visible && p_146116_2_ >= this.xPosition && p_146116_3_ >= this.yPosition
    && p_146116_2_ < this.xPosition + this.width && p_146116_3_ < this.yPosition + this.height;
    }
    
    public boolean func_146115_a() {
    return this.field_146123_n;
    }
    
    public void func_146111_b(int p_146111_1_, int p_146111_2_) {
    }
    
    public void func_146113_a(SoundHandler p_146113_1_) {
    p_146113_1_.playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
    }
    
    public int getButtonWidth() {
    return this.width;
    }
    
    public int func_154310_c() {
    return this.height;
    }
    }
    

    Crash:

    –-- Minecraft Crash Report ----
    // Don't be sad. I'll do better next time, I promise!

    Time: 05/12/15 15:00
    Description: Rendering screen

    java.lang.ClassCastException: fr.altiscraft.altiscraft.common.GuiAC10 cannot be cast to net.minecraft.client.gui.GuiButton
    at net.minecraft.client.gui.GuiScreen.drawScreen(GuiScreen.java:63)
    at fr.altiscraft.altiscraft.common.GuiInv.drawScreen(GuiInv.java:83)
    at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1137)
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1067)
    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:497)
    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 net.minecraft.client.gui.GuiScreen.drawScreen(GuiScreen.java:63)
    at fr.altiscraft.altiscraft.common.GuiInv.drawScreen(GuiInv.java:83)

    -- Screen render details --
    Details:
    Screen name: fr.altiscraft.altiscraft.common.GuiInv
    Mouse location: Scaled: (240, 125). Absolute: (960, 500)
    Screen size: Scaled: (480, 251). Absolute: (1920, 1001). Scale factor of 4

    -- Affected level --
    Details:
    Level name: MpServer
    All players: 1 total; [EntityClientPlayerMP['Player721'/141, l='MpServer', x=78,28, y=5,62, z=157,82]]
    Chunk stats: MultiplayerChunkCache: 240, 240
    Level seed: 0
    Level generator: ID 01 - flat, ver 0. Features enabled: false
    Level generator options: 
    Level spawn location: World: (-125,4,-212), Chunk: (at 3,0,12 in -8,-14; contains blocks -128,0,-224 to -113,255,-209), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1)
    Level time: 135511 game time, 135511 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: 97 total; [EntityVehicle['Quad'/259, l='MpServer', x=102,50, y=4,63, z=142,50], EntitySeat['entity.Seat.name'/289, l='MpServer', x=82,30, y=3,62, z=144,60], EntitySeat['entity.Seat.name'/290, l='MpServer', x=81,80, y=3,81, z=144,60], EntityWheel['entity.Wheel.name'/291, l='MpServer', x=83,42, y=3,07, z=145,66], EntityWheel['entity.Wheel.name'/292, l='MpServer', x=83,42, y=3,06, z=143,66], EntitySeat['entity.Seat.name'/293, l='MpServer', x=89,76, y=2,63, z=145,63], EntitySeat['entity.Seat.name'/294, l='MpServer', x=90,26, y=2,81, z=145,63], EntityWheel['entity.Wheel.name'/295, l='MpServer', x=92,13, y=2,00, z=146,57], EntityWheel['entity.Wheel.name'/296, l='MpServer', x=92,13, y=2,00, z=144,57], EntityWheel['entity.Wheel.name'/297, l='MpServer', x=88,63, y=2,08, z=144,57], EntityWheel['entity.Wheel.name'/298, l='MpServer', x=88,63, y=2,00, z=146,57], EntitySeat['entity.Seat.name'/299, l='MpServer', x=89,93, y=3,64, z=155,34], EntitySeat['entity.Seat.name'/300, l='MpServer', x=90,43, y=3,81, z=155,35], EntityWheel['entity.Wheel.name'/301, l='MpServer', x=92,28, y=3,05, z=156,32], EntityWheel['entity.Wheel.name'/302, l='MpServer', x=92,32, y=3,00, z=154,32], EntityWheel['entity.Wheel.name'/303, l='MpServer', x=88,82, y=3,09, z=154,25], EntityWheel['entity.Wheel.name'/304, l='MpServer', x=88,78, y=3,09, z=156,25], EntitySeat['entity.Seat.name'/305, l='MpServer', x=94,71, y=4,63, z=146,65], EntitySeat['entity.Seat.name'/306, l='MpServer', x=95,21, y=4,81, z=146,62], EntityWheel['entity.Wheel.name'/307, l='MpServer', x=97,14, y=4,06, z=147,45], EntityWheel['entity.Wheel.name'/308, l='MpServer', x=97,03, y=4,06, z=145,45], EntityWheel['entity.Wheel.name'/309, l='MpServer', x=93,53, y=4,07, z=145,65], EntityWheel['entity.Wheel.name'/310, l='MpServer', x=93,64, y=4,07, z=147,65], EntitySeat['entity.Seat.name'/311, l='MpServer', x=94,91, y=4,63, z=150,58], EntitySeat['entity.Seat.name'/312, l='MpServer', x=95,41, y=4,81, z=150,61], EntityWheel['entity.Wheel.name'/313, l='MpServer', x=97,21, y=4,06, z=151,69], EntityWheel['entity.Wheel.name'/314, l='MpServer', x=97,36, y=4,06, z=149,69], EntityWheel['entity.Wheel.name'/315, l='MpServer', x=93,87, y=4,07, z=149,43], EntityWheel['entity.Wheel.name'/316, l='MpServer', x=93,72, y=4,07, z=151,43], EntitySeat['entity.Seat.name'/317, l='MpServer', x=92,94, y=4,88, z=154,79], EntitySeat['entity.Seat.name'/318, l='MpServer', x=92,75, y=4,88, z=155,90], EntityWheel['entity.Wheel.name'/319, l='MpServer', x=91,49, y=3,46, z=154,03], EntityWheel['entity.Wheel.name'/320, l='MpServer', x=91,12, y=3,46, z=156,12], EntityWheel['entity.Wheel.name'/321, l='MpServer', x=94,10, y=4,46, z=156,65], EntityWheel['entity.Wheel.name'/322, l='MpServer', x=94,47, y=4,46, z=154,55], EntitySeat['entity.Seat.name'/323, l='MpServer', x=94,12, y=4,63, z=159,53], EntitySeat['entity.Seat.name'/324, l='MpServer', x=94,62, y=4,81, z=159,48], EntityWheel['entity.Wheel.name'/325, l='MpServer', x=96,56, y=4,06, z=160,27], EntityWheel['entity.Wheel.name'/326, l='MpServer', x=96,40, y=4,06, z=158,27], EntityWheel['entity.Wheel.name'/327, l='MpServer', x=92,91, y=4,07, z=158,56], EntityWheel['entity.Wheel.name'/328, l='MpServer', x=93,07, y=4,07, z=160,55], EntitySeat['entity.Seat.name'/329, l='MpServer', x=82,31, y=4,81, z=136,08], EntitySeat['entity.Seat.name'/330, l='MpServer', x=82,19, y=4,81, z=134,96], EntityWheel['entity.Wheel.name'/331, l='MpServer', x=84,22, y=4,07, z=136,39], EntityWheel['entity.Wheel.name'/332, l='MpServer', x=84,01, y=4,07, z=134,28], EntityWheel['entity.Wheel.name'/333, l='MpServer', x=80,84, y=4,07, z=134,60], EntityWheel['entity.Wheel.name'/334, l='MpServer', x=81,05, y=4,07, z=136,71], EntitySeat['entity.Seat.name'/335, l='MpServer', x=101,59, y=4,63, z=147,12], EntitySeat['entity.Seat.name'/336, l='MpServer', x=101,57, y=4,81, z=146,62], EntityWheel['entity.Wheel.name'/337, l='MpServer', x=102,42, y=4,06, z=144,71], EntityWheel['entity.Wheel.name'/338, l='MpServer', x=100,43, y=4,06, z=144,79], EntityWheel['entity.Wheel.name'/339, l='MpServer', x=100,58, y=4,06, z=148,29], EntityWheel['entity.Wheel.name'/340, l='MpServer', x=102,57, y=4,06, z=148,21], EntitySeat['entity.Seat.name'/341, l='MpServer', x=98,60, y=4,63, z=152,12], EntitySeat['entity.Seat.name'/342, l='MpServer', x=98,57, y=4,81, z=151,62], EntityWheel['entity.Wheel.name'/343, l='MpServer', x=99,40, y=4,06, z=149,69], EntityWheel['entity.Wheel.name'/344, l='MpServer', x=97,40, y=4,06, z=149,81], EntityWheel['entity.Wheel.name'/345, l='MpServer', x=97,60, y=4,06, z=153,31], EntityWheel['entity.Wheel.name'/346, l='MpServer', x=99,60, y=4,06, z=153,19], EntitySeat['entity.Seat.name'/347, l='MpServer', x=100,42, y=4,63, z=138,88], EntitySeat['entity.Seat.name'/348, l='MpServer', x=100,43, y=4,81, z=139,38], EntityWheel['entity.Wheel.name'/349, l='MpServer', x=99,56, y=4,06, z=141,28], EntityWheel['entity.Wheel.name'/350, l='MpServer', x=101,56, y=4,06, z=141,22], EntityWheel['entity.Wheel.name'/351, l='MpServer', x=101,44, y=4,06, z=137,72], EntityWheel['entity.Wheel.name'/352, l='MpServer', x=99,44, y=4,06, z=137,78], EntitySeat['entity.Seat.name'/353, l='MpServer', x=103,13, y=4,63, z=142,47], EntitySeat['entity.Seat.name'/354, l='MpServer', x=102,63, y=4,81, z=142,44], EntityWheel['entity.Wheel.name'/355, l='MpServer', x=100,81, y=4,06, z=141,40], EntityWheel['entity.Wheel.name'/356, l='MpServer', x=100,69, y=4,06, z=143,39], EntityWheel['entity.Wheel.name'/357, l='MpServer', x=104,19, y=4,06, z=143,60], EntityWheel['entity.Wheel.name'/358, l='MpServer', x=104,31, y=4,06, z=141,60], EntityCamera['inconnu'/361, l='MpServer', x=81,67, y=3,64, z=144,66], EntityCamera['inconnu'/363, l='MpServer', x=90,39, y=2,64, z=145,57], EntityCamera['inconnu'/365, l='MpServer', x=90,55, y=3,64, z=155,29], EntityCamera['inconnu'/367, l='MpServer', x=95,33, y=4,64, z=146,55], EntityCamera['inconnu'/369, l='MpServer', x=95,54, y=4,64, z=150,56], EntityCamera['inconnu'/371, l='MpServer', x=92,67, y=4,64, z=155,31], EntityCamera['inconnu'/391, l='MpServer', x=94,73, y=4,64, z=159,41], EntityCamera['inconnu'/393, l='MpServer', x=82,50, y=4,64, z=135,50], EntityClientPlayerMP['Player721'/141, l='MpServer', x=78,28, y=5,62, z=157,82], EntityVehicle['Quad'/145, l='MpServer', x=81,67, y=3,63, z=144,66], EntityCamera['inconnu'/401, l='MpServer', x=101,50, y=4,64, z=146,50], EntityCamera['inconnu'/403, l='MpServer', x=98,50, y=4,64, z=151,50], EntityWheel['entity.Wheel.name'/148, l='MpServer', x=79,92, y=3,07, z=143,66], EntityWheel['entity.Wheel.name'/149, l='MpServer', x=79,92, y=3,07, z=145,66], EntityVehicle['Quad'/152, l='MpServer', x=90,39, y=2,63, z=145,57], EntityVehicle['Quad'/159, l='MpServer', x=90,55, y=3,63, z=155,29], EntityCamera['inconnu'/418, l='MpServer', x=100,50, y=4,64, z=139,50], EntityCamera['inconnu'/420, l='MpServer', x=102,50, y=4,64, z=142,50], EntityVehicle['Quad'/166, l='MpServer', x=95,33, y=4,63, z=146,55], EntityVehicle['Quad'/173, l='MpServer', x=95,54, y=4,63, z=150,56], EntityVehicle['Dogde Ram'/180, l='MpServer', x=92,67, y=4,63, z=155,31], EntityVehicle['Quad'/205, l='MpServer', x=94,73, y=4,63, z=159,41], EntityVehicle['Dogde Ram'/212, l='MpServer', x=82,50, y=4,63, z=135,50], EntityVehicle['Quad'/225, l='MpServer', x=101,50, y=4,63, z=146,50], EntityVehicle['Quad'/232, l='MpServer', x=98,50, y=4,63, z=151,50], EntityVehicle['Quad'/252, l='MpServer', x=100,50, y=4,63, z=139,50]]
    Retry entities: 0 total; []
    Server brand: fml,forge
    Server type: Integrated singleplayer server
    Stacktrace:
    at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415)
    at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2566)
    at net.minecraft.client.Minecraft.run(Minecraft.java:984)
    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:497)
    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_60, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 766864464 bytes (731 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.1492 9 mods loaded, 9 mods active
    States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
    UCHIJAAAA mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) 
    UCHIJAAAA FML{7.10.99.99} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.4.1492-1.7.10.jar) 
    UCHIJAAAA Forge{10.13.4.1492} [Minecraft Forge] (forgeSrc-1.7.10-10.13.4.1492-1.7.10.jar) 
    UCHIJAAAA CarpentersBlocks{0.0.1 Beta} [AltisCraft.fr] (bin) 
    UCHIJAAAA flansmod{@VERSION@} [Flan's Mod] (bin) 
    UCHIJAAAA thirstmod{1.8.14} [Thirst Mod] (bin) 
    UCHIJAAAA t4pro{1.0.1} [Project] (bin) 
    UCHIJAAAA altiscraft.MODID{1.0.0} [AltisCraft.fr] (bin) 
    UCHIJAAAA ffmtlibs{1.5.0.113} [FFMT Library] (FFMT-libs-1.5.0.113-mc1.7.10-dev.jar) 
    GL info: ' Vendor: 'Intel' Version: '4.3.0 - Build 10.18.15.4256' Renderer: 'Intel(R) HD Graphics 4600'
    Launched Version: 1.7.10
    LWJGL: 2.9.1
    OpenGL: Intel(R) HD Graphics 4600 GL version 4.3.0 - Build 10.18.15.4256, Intel
    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: Français (France)
    Profiler Position: N/A (disabled)
    Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
    Anisotropic Filtering: Off (1)


  • Rédacteurs

    java.lang.ClassCastException: fr.altiscraft.altiscraft.common.GuiAC10 cannot be cast to net.minecraft.client.gui.GuiButton

    Regarde un peu …


  • Administrateurs

    Pour faire un bouton custom il faut faire une classe extends GuiButton. Sinon tu aura forcement des problèmes de cast…



  • D'accord mais si je met ça,

    public class GuiBouton extends GuiButton

    il y a des problèmes au niveau des constructeurs 😕

    public GuiBouton(int p_i1021_1_, int p_i1021_2_, int p_i1021_3_, int p_i1021_4_, int p_i1021_5_,
    String p_i1021_6_) {
    this.width = 200;
    this.height = 20;
    this.enabled = true;
    this.visible = true;
    this.id = p_i1021_1_;
    this.xPosition = p_i1021_2_;
    this.yPosition = p_i1021_3_;
    this.width = p_i1021_4_;
    this.height = p_i1021_5_;
    this.displayString = p_i1021_6_;
    }
    

    (Implicit super constructor GuiButton() is undefined. Must explictly invoke another constructor) 😕


  • Rédacteurs

    Tu doit faire un super(arg1, arg2, arg3, arg4, arg5, arg6)



  • Merci maintenant j'ai ces classes :

    package fr.altiscraft.altiscraft.common;
    
    import org.lwjgl.opengl.GL11;
    
    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.client.gui.GuiButton;
    import net.minecraft.client.renderer.OpenGlHelper;
    import net.minecraft.util.ResourceLocation;
    
    @SideOnly(Side.CLIENT)
    public class GuiAC10 extends GuiBouton {
    
    protected static final ResourceLocation buttonTextures = new ResourceLocation(ModAltisCraft.MODID,
    "textures/gui/widgets3.png");
    
        public GuiAC10(int id, int xPosition, int yPosition, String nomdubouton)
        {
            super(id, xPosition, yPosition, 65, 10, nomdubouton);
        }
    
      public void drawButton(Minecraft mc, int x, int y) {
    if (this.visible) {
    FontRenderer fontrenderer = mc.fontRenderer;
    mc.getTextureManager().bindTexture(buttonTextures);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    this.field_146123_n = x >= this.xPosition && y >= this.yPosition
    && x < this.xPosition + this.width && y < this.yPosition + this.height;
    int k = this.getHoverState(this.field_146123_n);
    GL11.glEnable(GL11.GL_BLEND);
    OpenGlHelper.glBlendFunc(770, 771, 1, 0);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + k * 20, this.width / 2, this.height);
    this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2,
    46 + k * 20, this.width / 2, this.height);
    this.mouseDragged(mc, x, y);
    int l = 14737632;
    
    if (packedFGColour != 0) {
    l = packedFGColour;
    } else if (!this.enabled) {
    l = 10526880;
    } else if (this.field_146123_n) {
    l = 16777120;
    }
    
    this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2,
    this.yPosition + (this.height - 8) / 2, l);
    }
    }
    
    }
    
    package fr.altiscraft.altiscraft.common;
    
    import org.lwjgl.opengl.GL11;
    
    import cpw.mods.fml.relauncher.Side;
    import cpw.mods.fml.relauncher.SideOnly;
    import net.minecraft.client.Minecraft;
    import net.minecraft.client.audio.PositionedSoundRecord;
    import net.minecraft.client.audio.SoundHandler;
    import net.minecraft.client.gui.FontRenderer;
    import net.minecraft.client.gui.GuiButton;
    import net.minecraft.client.renderer.OpenGlHelper;
    import net.minecraft.util.ResourceLocation;
    
    @SideOnly(Side.CLIENT)
    public class GuiBouton extends GuiButton {
    protected static final ResourceLocation buttonTextures = new ResourceLocation("textures/gui/widgets.png");
    /** Button width in pixels */
    public int width;
    /** Button height in pixels */
    public int height;
    /** The x position of this control. */
    public int xPosition;
    /** The y position of this control. */
    public int yPosition;
    /** The string displayed on this control. */
    public String displayString;
    public int id;
    /** True if this control is enabled, false to disable. */
    public boolean enabled;
    /** Hides the button completely if false. */
    public boolean visible;
    protected boolean field_146123_n;
    public int packedFGColour;
    
    public GuiBouton(int x, int y, int z, String str) {
    this(x, y, z, 200, 20, str);
    }
    
    public GuiBouton(int x, int y, int z, int hx, int hz,
    String str) {
    super(x,y,z,hx,hz,str);
    this.width = 200;
    this.height = 20;
    this.enabled = true;
    this.visible = true;
    this.id = x;
    this.xPosition = y;
    this.yPosition = z;
    this.width = hx;
    this.height = hz;
    this.displayString = str;
    }
    
    /**
    * Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over
    * this button and 2 if it IS hovering over this button.
    */
    public int getHoverState(boolean p_146114_1_) {
    byte b0 = 1;
    
    if (!this.enabled) {
    b0 = 0;
    } else if (p_146114_1_) {
    b0 = 2;
    }
    
    return b0;
    }
    
    /**
    * Draws this button to the screen.
    */
    public void drawButton(Minecraft p_146112_1_, int p_146112_2_, int p_146112_3_) {
    if (this.visible) {
    FontRenderer fontrenderer = p_146112_1_.fontRenderer;
    p_146112_1_.getTextureManager().bindTexture(buttonTextures);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    this.field_146123_n = p_146112_2_ >= this.xPosition && p_146112_3_ >= this.yPosition
    && p_146112_2_ < this.xPosition + this.width && p_146112_3_ < this.yPosition + this.height;
    int k = this.getHoverState(this.field_146123_n);
    GL11.glEnable(GL11.GL_BLEND);
    OpenGlHelper.glBlendFunc(770, 771, 1, 0);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + k * 20, this.width / 2, this.height);
    this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2,
    46 + k * 20, this.width / 2, this.height);
    this.mouseDragged(p_146112_1_, p_146112_2_, p_146112_3_);
    int l = 14737632;
    
    if (packedFGColour != 0) {
    l = packedFGColour;
    } else if (!this.enabled) {
    l = 10526880;
    } else if (this.field_146123_n) {
    l = 16777120;
    }
    
    this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2,
    this.yPosition + (this.height - 8) / 2, l);
    }
    }
    
    /**
    * Fired when the mouse button is dragged. Equivalent of
    * MouseListener.mouseDragged(MouseEvent e).
    */
    protected void mouseDragged(Minecraft p_146119_1_, int p_146119_2_, int p_146119_3_) {
    }
    
    /**
    * Fired when the mouse button is released. Equivalent of
    * MouseListener.mouseReleased(MouseEvent e).
    */
    public void mouseReleased(int p_146118_1_, int p_146118_2_) {
    }
    
    /**
    * Returns true if the mouse has been pressed on this control. Equivalent of
    * MouseListener.mousePressed(MouseEvent e).
    */
    public boolean mousePressed(Minecraft p_146116_1_, int p_146116_2_, int p_146116_3_) {
    return this.enabled && this.visible && p_146116_2_ >= this.xPosition && p_146116_3_ >= this.yPosition
    && p_146116_2_ < this.xPosition + this.width && p_146116_3_ < this.yPosition + this.height;
    }
    
    public boolean func_146115_a() {
    return this.field_146123_n;
    }
    
    public void func_146111_b(int p_146111_1_, int p_146111_2_) {
    }
    
    public void func_146113_a(SoundHandler p_146113_1_) {
    p_146113_1_.playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
    }
    
    public int getButtonWidth() {
    return this.width;
    }
    
    public int func_154310_c() {
    return this.height;
    }
    }
    

    Et j'aimerais fais que le texte soit à gauche et non au centre du bouton je change des paramètres en debug mais j'ai l'impression que je ne peux pas modifier la priorité du centre du extends GuiButton 😕

    Des idées ? 🙂

    Je voudrais arriver à ça:

    Sachant que j'ai ça pour l'instant:


  • Rédacteurs

    Ligne 49 remplace :

    this.drawCenteredString(….)
    

    par :

    this.drawString(...)
    


  • Merci à tous pour votre soutient ! 🙂 #JePasseEnRésolu