Failender Posted June 14, 2015 Posted June 14, 2015 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 Quote
larsgerrits Posted June 14, 2015 Posted June 14, 2015 Example: new ResourceLocation("modid:path/to/image/image.png"); That will result in assets/modid/path/to/image/image.png . Quote 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/
Failender Posted June 14, 2015 Author Posted June 14, 2015 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; } } } } Quote
tiffit Posted June 15, 2015 Posted June 15, 2015 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. Quote
EverythingGames Posted June 18, 2015 Posted June 18, 2015 Hi You can actually pick where to grab the texture from your file in your code using X and Y coordinates. Quote Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]
Ernio Posted June 18, 2015 Posted June 18, 2015 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. Quote 1.7.10 is no longer supported by forge, you are on your own.
Recommended Posts
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.