capesLocation = new HashMap<>();
private float scroll = 0f;
private int scrollClickedX = -1;
private void drawCapesPage(int mouseX, int mouseY, float partialTicks) {
Minecraft.getMinecraft().getTextureManager().bindTexture(cosmetics_fg);
Utils.drawTexturedRect(guiLeft, guiTop, sizeX, sizeY, GL11.GL_NEAREST);
Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements);
Utils.drawTexturedRect(guiLeft + 15 + 371 * scroll, guiTop + 177, 32, 12,
0, 32 / 256f, 192 / 256f, 204 / 256f, GL11.GL_NEAREST
);
GL11.glEnable(GL11.GL_SCISSOR_TEST);
GL11.glScissor(Minecraft.getMinecraft().displayWidth * (guiLeft + 3) / width, 0,
Minecraft.getMinecraft().displayWidth * (sizeX - 6) / width, Minecraft.getMinecraft().displayHeight
);
int displayingCapes = 0;
for (CapeManager.CapeData capeData : CapeManager.INSTANCE.getCapes()) {
boolean equipable = CapeManager.INSTANCE.getAvailableCapes() == null ||
CapeManager.INSTANCE.getAvailableCapes().contains(capeData.capeName);
if (capeData.canShow() || equipable) {
displayingCapes++;
}
}
float totalNeeded = 91 * displayingCapes;
float totalAvail = sizeX - 20;
float xOffset = scroll * (totalNeeded - totalAvail);
int displayIndex = 0;
for (CapeManager.CapeData capeData : CapeManager.INSTANCE.getCapes()) {
boolean equipable = CapeManager.INSTANCE.getAvailableCapes() == null ||
CapeManager.INSTANCE.getAvailableCapes().contains(capeData.capeName);
if (!capeData.canShow() && !equipable) continue;
if (capeData.capeName.equals(CapeManager.INSTANCE.getCape(Minecraft.getMinecraft().thePlayer
.getUniqueID()
.toString()
.replace("-", "")))) {
GlStateManager.color(250 / 255f, 200 / 255f, 0 / 255f, 1);
Utils.drawGradientRect(guiLeft + 20 + 91 * displayIndex - (int) xOffset, guiTop + 10,
guiLeft + 20 + 91 * displayIndex - (int) xOffset + 81, guiTop + 10 + 108,
new Color(150, 100, 0, 40).getRGB(), new Color(250, 200, 0, 40).getRGB()
);
} else if (capeData.capeName.equals(wantToEquipCape)) {
GlStateManager.color(0, 200 / 255f, 250 / 255f, 1);
Utils.drawGradientRect(guiLeft + 20 + 91 * displayIndex - (int) xOffset, guiTop + 10,
guiLeft + 20 + 91 * displayIndex - (int) xOffset + 81, guiTop + 10 + 108,
new Color(0, 100, 150, 40).getRGB(), new Color(0, 200, 250, 40).getRGB()
);
} else if (CapeManager.INSTANCE.localCape != null &&
CapeManager.INSTANCE.localCape.getRight().equals(capeData.capeName)) {
GlStateManager.color(100 / 255f, 250 / 255f, 150 / 255f, 1);
Utils.drawGradientRect(guiLeft + 20 + 91 * displayIndex - (int) xOffset, guiTop + 10,
guiLeft + 20 + 91 * displayIndex - (int) xOffset + 81, guiTop + 10 + 108,
new Color(50, 100, 75, 40).getRGB(), new Color(100, 250, 150, 40).getRGB()
);
}
Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements);
Utils.drawTexturedRect(guiLeft + 20 + 91 * displayIndex - xOffset, guiTop + 10, 81, 108,
0, 81 / 256f, 84 / 256f, 192 / 256f, GL11.GL_NEAREST
);
GlStateManager.color(1, 1, 1, 1);
Utils.drawTexturedRect(guiLeft + 20 + 91 * displayIndex - xOffset, guiTop + 123, 81, 20,
0, 81 / 256f, 216 / 256f, 236 / 256f, GL11.GL_NEAREST
);
boolean equipPressed = capeData.capeName.equals(wantToEquipCape);
if (!equipable) GlStateManager.color(1, 1, 1, 0.5f);
Utils.drawTexturedRect(
guiLeft + 20 + 91 * displayIndex - xOffset,
guiTop + 149,
81,
20,
equipPressed ? 81 / 256f : 0,
equipPressed ? 0 : 81 / 256f,
equipPressed ? 236 / 256f : 216 / 256f,
equipPressed ? 216 / 256f : 236 / 256f,
GL11.GL_NEAREST
);
Utils.drawStringCenteredScaledMaxWidth(
"Try it out",
guiLeft + 20 + 91 * displayIndex + 81 / 2f - xOffset,
guiTop + 123 + 10,
false,
75,
new Color(100, 250, 150).getRGB()
);
if (equipable) {
Utils.drawStringCenteredScaledMaxWidth(
"Equip",
guiLeft + 20 + 91 * displayIndex + 81 / 2f - xOffset,
guiTop + 149 + 10,
false,
75,
new Color(100, 250, 150).getRGB()
);
} else {
Utils.drawStringCenteredScaledMaxWidth(
"Not Unlocked",
guiLeft + 20 + 91 * displayIndex + 81 / 2f - xOffset,
guiTop + 149 + 10,
false,
75,
new Color(200, 50, 50, 100).getRGB()
);
}
GlStateManager.color(1, 1, 1, 1);
ResourceLocation capeTexture = capesLocation.computeIfAbsent(
capeData.capeName,
k -> new ResourceLocation("notenoughupdates", "capes/" + capeData.capeName + "_preview.png")
);
Minecraft.getMinecraft().getTextureManager().bindTexture(capeTexture);
Utils.drawTexturedRect(guiLeft + 31 + 91 * displayIndex - xOffset, guiTop + 24, 59, 84, GL11.GL_NEAREST);
displayIndex++;
}
GL11.glScissor(0, 0, Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight);
GL11.glDisable(GL11.GL_SCISSOR_TEST);
Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements);
}
Shader blurShaderHorz = null;
Framebuffer blurOutputHorz = null;
Shader blurShaderVert = null;
Framebuffer blurOutputVert = null;
/**
* Creates a projection matrix that projects from our coordinate space [0->width; 0->height] to OpenGL coordinate
* space [-1 -> 1; 1 -> -1] (Note: flipped y-axis).
*
* This is so that we can render to and from the framebuffer in a way that is familiar to us, instead of needing to
* apply scales and translations manually.
*/
private Matrix4f createProjectionMatrix(int width, int height) {
Matrix4f projMatrix = new Matrix4f();
projMatrix.setIdentity();
projMatrix.m00 = 2.0F / (float) width;
projMatrix.m11 = 2.0F / (float) (-height);
projMatrix.m22 = -0.0020001999F;
projMatrix.m33 = 1.0F;
projMatrix.m03 = -1.0F;
projMatrix.m13 = 1.0F;
projMatrix.m23 = -1.0001999F;
return projMatrix;
}
/**
* Renders whatever is currently in the Minecraft framebuffer to our two framebuffers, applying a horizontal
* and vertical blur separately in order to significantly save computation time.
* This is only possible if framebuffers are supported by the system, so this method will exit prematurely
* if framebuffers are not available. (Apple machines, for example, have poor framebuffer support).
*/
private double lastBgBlurFactor = -1;
private void blurBackground() {
int width = Minecraft.getMinecraft().displayWidth;
int height = Minecraft.getMinecraft().displayHeight;
if (blurOutputHorz == null) {
blurOutputHorz = new Framebuffer(width, height, false);
blurOutputHorz.setFramebufferFilter(GL11.GL_NEAREST);
}
if (blurOutputVert == null) {
blurOutputVert = new Framebuffer(width, height, false);
blurOutputVert.setFramebufferFilter(GL11.GL_NEAREST);
}
if (blurOutputHorz.framebufferWidth != width || blurOutputHorz.framebufferHeight != height) {
blurOutputHorz.createBindFramebuffer(width, height);
blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height));
Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false);
}
if (blurOutputVert.framebufferWidth != width || blurOutputVert.framebufferHeight != height) {
blurOutputVert.createBindFramebuffer(width, height);
blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height));
Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false);
}
if (blurShaderHorz == null) {
try {
blurShaderHorz = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur",
Minecraft.getMinecraft().getFramebuffer(), blurOutputHorz
);
blurShaderHorz.getShaderManager().getShaderUniform("BlurDir").set(1, 0);
blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height));
} catch (Exception ignored) {
}
}
if (blurShaderVert == null) {
try {
blurShaderVert = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur",
blurOutputHorz, blurOutputVert
);
blurShaderVert.getShaderManager().getShaderUniform("BlurDir").set(0, 1);
blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height));
} catch (Exception ignored) {
}
}
if (blurShaderHorz != null && blurShaderVert != null) {
if (15 != lastBgBlurFactor) {
blurShaderHorz.getShaderManager().getShaderUniform("Radius").set((float) 15);
blurShaderVert.getShaderManager().getShaderUniform("Radius").set((float) 15);
lastBgBlurFactor = 15;
}
GL11.glPushMatrix();
blurShaderHorz.loadShader(0);
blurShaderVert.loadShader(0);
GlStateManager.enableDepth();
GL11.glPopMatrix();
Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false);
}
}
/**
* Renders a subsection of the blurred framebuffer on to the corresponding section of the screen.
* Essentially, this method will "blur" the background inside the bounds specified by [x->x+blurWidth, y->y+blurHeight]
*/
public void renderBlurredBackground(int width, int height, int x, int y, int blurWidth, int blurHeight) {
float uMin = x / (float) width;
float uMax = (x + blurWidth) / (float) width;
float vMin = (height - y) / (float) height;
float vMax = (height - y - blurHeight) / (float) height;
blurOutputVert.bindFramebufferTexture();
GlStateManager.color(1f, 1f, 1f, 1f);
//Utils.setScreen(width*f, height*f, f);
Utils.drawTexturedRect(x, y, blurWidth, blurHeight, uMin, uMax, vMin, vMax);
//Utils.setScreen(width, height, f);
blurOutputVert.unbindFramebufferTexture();
}
}