h3tR Posted September 1, 2022 Share Posted September 1, 2022 Hi, I am working on a battery icon on a screen that displays the amount of energy is stored in the related BlockEntity. To do this I made a widget and overrided the render method to fit my needs. I use a separate texture so I don't have to include it in every texture for screens that are supposed to be using it. My problem is that instead of rendering the texture in the scale of itself it renders in the scale of the background (AKA the gui for that menu without the display). I'm not sure what causes this or how to deal with it. Looking at how it gets blitted the code for drawing it is working as intended. I will provide some images and code below for context https://imgur.com/a/dqHJaZS The first Image is the texture file for reference The second image is a screenshot from ingame (The blocky mess next to the arrow is what is supposed to be the display) The render method @Override public void render(@NotNull PoseStack stack, int MouseX, int MouseY, float p_94672_){ RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderTexture(0,RL); Minecraft.getInstance().getTextureManager().bindForSetup(RL); RenderSystem.clearColor(1.0F, 1.0F, 1.0F, 1.0F); //blits the battery Background Minecraft.getInstance().screen.blit(stack,x,y,0,0,this.width,this.height); int energy = menu.getEnergy(); int maxEnergy = menu.getMaxEnergy(); int chargeLevel = (int) Math.ceil((float)energy/maxEnergy*16); //blits the charge Minecraft.getInstance().screen.blit(stack,x+2,y+18-chargeLevel,this.width+(chargeLevel/4-1)*9,16-chargeLevel,9,chargeLevel); } The where the widget gets added (In the screen class) @Override public void render(@NotNull PoseStack stack, int mouseX, int mouseY, float Ptick) { this.addRenderableWidget(new BatteryDisplay(this.getGuiLeft()+82,this.getGuiTop()+37,this.menu)); //... } Thanks for the help! Quote Link to comment Share on other sites More sharing options...
warjort Posted September 1, 2022 Share Posted September 1, 2022 (edited) You say you have different textures and yet you only setShaderTexture() once? Other parts of your code look confused as well. e.g. Why are you doing that bindForSetup() You can replace Minecraft.getInstance().screen.blit() with this.blit() - the current minecraft screen is your Screen instance. You should add widgets in your init(), but I don't see any calls to super.render() which is where the widgets would get drawn. See Screen.render() I also don't see a call to renderBackground() Edited September 1, 2022 by warjort Quote Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post. Link to comment Share on other sites More sharing options...
h3tR Posted September 2, 2022 Author Share Posted September 2, 2022 17 hours ago, warjort said: You say you have different textures and yet you only setShaderTexture() once? Other parts of your code look confused as well. e.g. Why are you doing that bindForSetup() You can replace Minecraft.getInstance().screen.blit() with this.blit() - the current minecraft screen is your Screen instance. You should add widgets in your init(), but I don't see any calls to super.render() which is where the widgets would get drawn. See Screen.render() I also don't see a call to renderBackground() I probably needed to explain some more things because, yeah, from reading my post it is quite confusing. I called the setShaderTexture() twice. Once in the renderBackground() method for the screen and once for the render method for the display class. I did bindForSetup because I didn't know what it did and I saw it being used in another widget so I thought it would be useful (I removed it now though!). I used this.blit() initially but because it wasn't working I thought somehow Minecraft.getInstance().screen.blit() would be something different so I just tried that as a solution (also replaced that now). I now added the widget in the init method for the screen and the super.render() method was already being called in the screen render method however I replaced it in with "//..." because otherwise the post would be pretty long as I'm doing a lot of other things in the method as well. Looking back at it that wasn't very helpful. Just like previously renderBackground() was also being called but I removed it from the post So now to be clear and state the actual problem. Everything is working completely as intended except that the texture is render in an improper scale (1 pixel correlates for many more when rendered for some reason) Thanks again Quote Link to comment Share on other sites More sharing options...
warjort Posted September 2, 2022 Share Posted September 2, 2022 Can you put your code on github so we can see all the relevant context. It should compile and run. You don't even show your updated code, let alone the other relevant code you missed from your first post. Quote Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post. Link to comment Share on other sites More sharing options...
h3tR Posted September 2, 2022 Author Share Posted September 2, 2022 3 hours ago, warjort said: Can you put your code on github so we can see all the relevant context. It should compile and run. You don't even show your updated code, let alone the other relevant code you missed from your first post. Here you go. Github Quote Link to comment Share on other sites More sharing options...
warjort Posted September 3, 2022 Share Posted September 3, 2022 Your issue is you are using the blit method designed for 256x256 images. Since yours is a "nonstandard" size, you need to tell it the size of the image, e.g. this.blit(stack,x,y,0,0,this.width,this.height, 49, 20); 1 Quote Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post. Link to comment Share on other sites More sharing options...
sciwhiz12 Posted September 3, 2022 Share Posted September 3, 2022 Usually, textures should be at the 'minimum' size of 256x256, keeping the space when the content is too small, and expanding only when the content is too large to fit. There is no inherent benefit to sizing textures to exactly fit their contents. It may even be a hindrance if you choose to add more to the texture in the future, as you would need to re-adjust the dimensions in the blit call, and it would break that texture if modified by a resource pack. 1 Quote Link to comment Share on other sites More sharing options...
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.