Posted February 23, 20214 yr Hello, I am having a problem with creating a button for my gui. The button actually does get created and gets added to the screen, the problem is that it has no texture. I have double-triple checked the coords of the texture from my file, and I've looked at other modders code and I'm not seeing what they have done that I haven't relating to this issue. The BlockScreen code: public class ExperienceBlockScreen extends ContainerScreen<BaseContainer> { private static final ResourceLocation BACKGROUND_TEXTURE = new ResourceLocation(Constants.MOD_ID, "textures/gui/experience_block_gui.png"); // Coords for the graphical elements of the gui // Arrow Coords // B/G final static int ARROW_BAR_XPOS = 199; final static int ARROW_BAR_YPOS = 4; // Exp Bar Coords // B/G final static int EXP_BAR_XPOS = 8; final static int EXP_BAR_YPOS = 78; // Width and Height final static int EXP_BAR_SPACING_X = 21; final static int EXP_BAR_SPACING_Y = 72; // F/G final static int EXP_BAR_TEX_U = 177; final static int EXP_BAR_TEX_V = 75; // Buttons // Single Plus final static int SINGLE_PLUS_BUTTON_XPOS = 115; final static int SINGLE_PLUS_BUTTON_YPOS = 28; // Double Plus final static int DOUBLE_PLUS_BUTTON_XPOS = 129; final static int DOUBLE_PLUS_BUTTON_YPOS = 28; // Single Minus final static int SINGLE_MINUS_BUTTON_XPOS = 115; final static int SINGLE_MINUS_BUTTON_YPOS = 40; // Double Minus final static int DOUBLE_MINUS_BUTTON_XPOS = 129; final static int DOUBLE_MINUS_BUTTON_YPOS = 41; // Button Spacings final static int SINGLE_SPACING_X = 11; final static int SINGLE_SPACING_Y = 11; final static int DOUBLE_SPACING_X = 17; final static int DOUBLE_SPACING_Y = 9; public ExperienceBlockScreen(BaseContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) { super(screenContainer, inv, titleIn); xSize = 176; ySize = 166; } // @Override // protected void init() { // // super.init(); // // //this.buttons.clear(); // // } @Override public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { this.renderBackground(matrixStack); super.render(matrixStack, mouseX, mouseY, partialTicks); this.renderHoveredTooltip(matrixStack, mouseX, mouseY); } @Override protected void drawGuiContainerForegroundLayer(MatrixStack matrixStack, int x, int y) { // final float LABEL_XPOS = 5; // final float FONT_Y_SPACING = 12; // final float EXP_BLOCK_LABEL_YPOS = ExperienceBlockContainer.TILE_INV_YPOS - FONT_Y_SPACING; // this.font.func_243248_b(matrixStack, this.title, LABEL_XPOS, EXP_BLOCK_LABEL_YPOS, Color.darkGray.getRGB()); // // final float PLAYER_INV_LABEL_YPOS = ExperienceBlockContainer.PLAYER_INV_YPOS - FONT_Y_SPACING; // this.font.func_243248_b(matrixStack, this.playerInventory.getDisplayName(), LABEL_XPOS, PLAYER_INV_LABEL_YPOS, Color.darkGray.getRGB()); } @Override protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int x, int y) { this.minecraft.getTextureManager().bindTexture(BACKGROUND_TEXTURE); RenderSystem.color4f(1.0f, 1.0f,1.0f,1.0f); int edgeSpacingX = (this.width - this.xSize)/2; int edgeSpacingY = (this.height - this.ySize)/2; // Drawing the main gui element this.blit(matrixStack, edgeSpacingX, edgeSpacingY, 0, 0, this.xSize, this.ySize); // Drawing the button for single minus // (x,y) this can be the (0,0) of the gui element, then the offsets to get the texture, then the width and height // this.blit(matrixStack, edgeSpacingX + SINGLE_MINUS_BUTTON_XPOS, edgeSpacingY + SINGLE_MINUS_BUTTON_YPOS, // SINGLE_MINUS_BUTTON_XPOS, SINGLE_MINUS_BUTTON_YPOS, // SINGLE_SPACING_X, SINGLE_SPACING_Y); this.addButton(new SingleMinusButton(guiLeft + SINGLE_MINUS_BUTTON_XPOS, guiTop + SINGLE_MINUS_BUTTON_YPOS, new TranslationTextComponent(""), (press)->{})); // Drawing the ExpBar this.blit(matrixStack, edgeSpacingX + EXP_BAR_XPOS, edgeSpacingY + EXP_BAR_YPOS - 17, EXP_BAR_TEX_U, EXP_BAR_TEX_V - 17, EXP_BAR_SPACING_X, EXP_BAR_SPACING_Y); } } And the SingleMinusButton code: public class SingleMinusButton extends Button { private static final ResourceLocation BACKGROUND_TEXTURE = new ResourceLocation(Constants.MOD_ID, "textures/gui/experience_block_gui.png"); private int xSize; private int ySize; public SingleMinusButton(int x, int y, ITextComponent title, IPressable pressedAction) { super(x, y, 11, 11, title, pressedAction); xSize = 176; ySize = 166; } @Override public void renderButton(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { int textureX = (this.width - xSize) / 2; int textureY = (this.height - ySize) / 2; // Where the button should be on the gui final int SINGLE_MINUS_BUTTON_XPOS = 115; final int SINGLE_MINUS_BUTTON_YPOS = 40; //Coords to base button final int SINGLE_MINUS_BUTTON_BASE_U = 216; final int SINGLE_MINUS_BUTTON_BASE_V = 68; // Coords to the texture of hovered button texture final int SINGLE_MINUS_BUTTON_HOV_U = 216; final int SINGLE_MINUS_BUTTON_HOV_V = 17; // Coords to the texture of the selected button texture final int SINGLE_MINUS_BUTTON_SEL_U = 216; final int SINGLE_MINUS_BUTTON_SEL_V = 42; Minecraft minecraft = Minecraft.getInstance(); minecraft.getTextureManager().bindTexture(BACKGROUND_TEXTURE); RenderSystem.color4f(1.0f, 1.0f,1.0f,1.0f); this.blit(matrixStack, textureX + SINGLE_MINUS_BUTTON_XPOS, textureY + SINGLE_MINUS_BUTTON_YPOS, SINGLE_MINUS_BUTTON_BASE_U, SINGLE_MINUS_BUTTON_BASE_V, width, height); } private static boolean inBounds(int x, int y, int xSize, int ySize, double mouseX, double mouseY) { return ((mouseX >= x && mouseX <= x + xSize) && (mouseY >= y && mouseY <= y + ySize)); } } If there's a call to a method that I'm missing, then the help would be wonderful. The issue I think is with the actual texture file if the button is being created, but it works for the main gui so I don't understand. Thank you for the help in advance.
February 23, 20214 yr Author That's me being stupid and not thinking stuff through. That actually fixed it tho, so thank you very much. Updated code in case someone in the future needs it: public class SingleMinusButton extends Button { private static final ResourceLocation BACKGROUND_TEXTURE = new ResourceLocation(Constants.MOD_ID, "textures/gui/experience_block_gui.png"); public SingleMinusButton(int x, int y, ITextComponent title, IPressable pressedAction) { super(x, y, 11, 11, title, pressedAction); } @Override public void renderButton(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { //Coords to base button final int SINGLE_MINUS_BUTTON_BASE_U = 216; final int SINGLE_MINUS_BUTTON_BASE_V = 68; // Coords to the texture of hovered button texture final int SINGLE_MINUS_BUTTON_HOV_U = 216; final int SINGLE_MINUS_BUTTON_HOV_V = 17; // Coords to the texture of the selected button texture final int SINGLE_MINUS_BUTTON_SEL_U = 216; final int SINGLE_MINUS_BUTTON_SEL_V = 42; Minecraft minecraft = Minecraft.getInstance(); minecraft.getTextureManager().bindTexture(BACKGROUND_TEXTURE); RenderSystem.color4f(1.0f, 1.0f,1.0f,1.0f); this.blit(matrixStack, x, y, SINGLE_MINUS_BUTTON_BASE_U, SINGLE_MINUS_BUTTON_BASE_V, width, height); } private static boolean inBounds(int x, int y, int xSize, int ySize, double mouseX, double mouseY) { return ((mouseX >= x && mouseX <= x + xSize) && (mouseY >= y && mouseY <= y + ySize)); } } Is there anything else I'm being stupid on btw? Might help me next time
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.