Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I am triing to create a custom GuiButton, so I created a new class overwrote GuiButton and changed the drawButton method.

Problem is that I dont know how to create a ResourceLocation that is leading into the right package. I want to deposit my texture in the assets.basewars.textures.gui (e.g. assets.basewars.textures.gui.furnace)

Sadly this isnt working

new ResourceLocation("basewars:gui/"+texture); 

Anyone here who knows?

Greetz Fail

Example:

new ResourceLocation("modid:path/to/image/image.png");

That will result in

assets/modid/path/to/image/image.png

.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

  • Author

Thank you, it is working now.

Problem is that the texture seems to scale really strange.

I created the button to be 16x16 pixel big, which is exactly the size of the texture I am using.

 

 

 

Link to the graphic below

http://www.directupload.net/file/d/4018/ima7zxlf_png.htm

 

TexturedButton

public class TexturedButton extends GuiButton{

protected ResourceLocation buttonTextures;

public TexturedButton(int buttonId, int x, int y, int widthIn,
		int heightIn, String buttonText, String texture) {
	super(buttonId, x, y, widthIn, heightIn, buttonText);
	buttonTextures= new ResourceLocation("basewars:textures/gui/"+texture+".png");
}

@Override
public void drawButton(Minecraft mc, int mouseX, int mouseY)
    {
        if (this.visible)
        {
            FontRenderer fontrenderer = mc.fontRendererObj;
            mc.getTextureManager().bindTexture(buttonTextures);
            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
            this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
            int k = this.getHoverState(this.hovered);
            GlStateManager.enableBlend();
            GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
            GlStateManager.blendFunc(770, 771);
            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, mouseX, mouseY);
            int l = 14737632;

            if (packedFGColour != 0)
            {
                l = packedFGColour;
            }
            else if (!this.enabled)
            {
                l = 10526880;
            }
            else if (this.hovered)
            {
                l = 16777120;
            }
        }
    }
}

It is scaling your button image to the size of the gui. To fix this, have your button image in a file that has the same dimensions as your gui.

Hi

You can actually pick where to grab the texture from your file in your code using X and Y coordinates.

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Nope and nope.

 

drawTexturedModalRect always takes 256x256 (resized with resolution, so e.g 512 or 1024) image as Resource.

 

You need to make your button image be insie 256x256 palette and then choose coordinates for it to draw.

 

EDIT

Note - there is also method +"withCustomSize" or something like that. That one allows you to have custom sized png.

 

 

1.7.10 is no longer supported by forge, you are on your own.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.