Posted June 14, 201510 yr 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
June 14, 201510 yr 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/
June 14, 201510 yr 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; } } } }
June 15, 201510 yr 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.
June 18, 201510 yr 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]
June 18, 201510 yr 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.