fix transparent pixel issue in wiki icon screenshitter

This commit is contained in:
George Paton 2025-08-27 13:12:01 +10:00
parent a0451b46a5
commit e5b29e3352

View File

@ -26,12 +26,12 @@ import net.minecraft.util.ResourceLocation;
public class GUIScreenWikiRender extends GuiScreen {
// Basically the same thing as GUIScreenPreview, but will iterate through all provided preview stacks
// taking a screenshot of each, as fast as the game can render them
// Basically the same thing as GUIScreenPreview, but will iterate through all provided preview stacks
// taking a screenshot of each, as fast as the game can render them
protected static final ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/nei/gui_nei.png");
protected ItemStack[] preview;
protected int index = 0;
protected int index = 0;
protected int scale = 1;
protected String saveLocation = "wiki-screenshots";
protected String prefix = "";
@ -52,7 +52,7 @@ public class GUIScreenWikiRender extends GuiScreen {
this.getStackName = getStackName;
}
@Override
@Override
public void drawScreen(int mouseX, int mouseY, float f) {
if(this.mc.theWorld != null) {
GuiScreen.drawRect(0, 0, this.width, this.height, 0xFFC6C6C6);
@ -60,57 +60,64 @@ public class GUIScreenWikiRender extends GuiScreen {
this.drawBackground(0);
}
// Once we've reached the end of the array, immedaitely close this GUI
if(index >= preview.length) {
this.mc.thePlayer.closeScreen();
return;
}
// Once we've reached the end of the array, immedaitely close this GUI
if(index >= preview.length) {
this.mc.thePlayer.closeScreen();
return;
}
this.drawGuiContainerBackgroundLayer();
GL11.glDisable(GL11.GL_LIGHTING);
this.drawGuiContainerForegroundLayer(preview[index]);
GL11.glEnable(GL11.GL_LIGHTING);
ScaledResolution res = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight);
int zoom = scale * res.getScaleFactor();
try {
String slotName = getStackName.apply(preview[index]).replaceAll("§.", "").replaceAll("[^\\w ().-]+", "");
if(!slotName.endsWith(".name")) {
saveScreenshot(Minecraft.getMinecraft().mcDataDir, saveLocation, prefix + slotName + ".png", zoom, zoom, zoom * 16, zoom * 16, 0xFF8B8B8B);
}
} catch (Exception ex) {
// Just skip any failures caused by display name or rendering
}
try {
String slotName = getStackName.apply(preview[index]).replaceAll("§.", "").replaceAll("[^\\w ().-]+", "");
if(!slotName.endsWith(".name")) {
saveScreenshot(Minecraft.getMinecraft().mcDataDir, saveLocation, prefix + slotName + ".png", zoom, zoom, zoom * 16, zoom * 16, 0xFFFF00FF);
}
} catch (Exception ex) {
// Just skip any failures caused by display name or rendering
}
index++;
}
index++;
}
protected void drawGuiContainerBackgroundLayer() {
GL11.glPushMatrix();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(texture);
ScaledResolution res = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight);
GL11.glScaled(scale, scale, scale);
this.drawTexturedModalRect(0, res.getScaledHeight_double() / scale - 18D, 5, 87, 18, 18);
GL11.glPopMatrix();
}
{
public void drawTexturedModalRect(double x, double y, int sourceX, int sourceY, int sizeX, int sizeY) {
double f = 0.00390625D;
double f1 = 0.00390625D;
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.addVertexWithUV((double) (x + 0), (double) (y + sizeY), (double) this.zLevel, (double) ((float) (sourceX + 0) * f), (double) ((float) (sourceY + sizeY) * f1));
tessellator.addVertexWithUV((double) (x + sizeX), (double) (y + sizeY), (double) this.zLevel, (double) ((float) (sourceX + sizeX) * f), (double) ((float) (sourceY + sizeY) * f1));
tessellator.addVertexWithUV((double) (x + sizeX), (double) (y + 0), (double) this.zLevel, (double) ((float) (sourceX + sizeX) * f), (double) ((float) (sourceY + 0) * f1));
tessellator.addVertexWithUV((double) (x + 0), (double) (y + 0), (double) this.zLevel, (double) ((float) (sourceX + 0) * f), (double) ((float) (sourceY + 0) * f1));
tessellator.draw();
ScaledResolution res = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight);
int size = 18;
double y = res.getScaledHeight_double() / scale - 18D;
GL11.glScaled(scale, scale, scale);
GL11.glColor4f(1.0F, 0.0F, 1.0F, 1.0F);
GL11.glDisable(GL11.GL_TEXTURE_2D);
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.addVertex((double) 0, (double) y + size, (double) this.zLevel);
tessellator.addVertex((double) size, (double) y + size, (double) this.zLevel);
tessellator.addVertex((double) size, (double) y, (double) this.zLevel);
tessellator.addVertex((double) 0, (double) y, (double) this.zLevel);
tessellator.draw();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
}
GL11.glPopMatrix();
}
protected void drawGuiContainerForegroundLayer(ItemStack preview) {
if(preview == null) return;
GL11.glPushMatrix();
RenderHelper.enableGUIStandardItemLighting();
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240F, 240F);
@ -119,11 +126,11 @@ public class GUIScreenWikiRender extends GuiScreen {
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glScaled(scale, scale, scale);
ScaledResolution res = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight);
GL11.glTranslated(9D, res.getScaledHeight_double() / scale - 9D, -200);
GL11.glTranslated(9D, res.getScaledHeight_double() / scale - 9D, -200);
this.zLevel = 200.0F;
itemRender.zLevel = 200.0F;
@ -134,7 +141,7 @@ public class GUIScreenWikiRender extends GuiScreen {
itemRender.zLevel = 0.0F;
this.zLevel = 0.0F;
GL11.glPopMatrix();
}