previousProfileSearches = NotEnoughUpdates.INSTANCE.config.hidden.previousProfileSearches;
if (mouseX > x && mouseX < x + 29) {
if (mouseY > y && mouseY < y + 28) {
if (!playerName.equals(Minecraft.getMinecraft().thePlayer.getName().toLowerCase(Locale.ROOT))) {
NotEnoughUpdates.profileViewer.loadPlayerByName(Minecraft.getMinecraft().thePlayer.getName(), profile -> {
profile.resetCache();
NotEnoughUpdates.INSTANCE.openGui = new GuiProfileViewer(profile);
});
}
}
}
previousProfileSearches.removeIf(Objects::isNull);
for (int i = 0; i < previousProfileSearches.size(); i++) {
if (mouseX > x && mouseX < x + 28) {
if (mouseY > y + 28 * (i + 1) && mouseY < y + 28 * (i + 2)) {
if (!playerName.equals(previousProfileSearches.get(i))) {
NotEnoughUpdates.profileViewer.loadPlayerByName(previousProfileSearches.get(i), profile -> {
profile.resetCache();
NotEnoughUpdates.INSTANCE.openGui = new GuiProfileViewer(profile);
});
}
}
}
}
if (mouseX > guiLeft + sizeX - 100 && mouseX < guiLeft + sizeX) {
if (mouseY > guiTop + sizeY + 5 && mouseY < guiTop + sizeY + 25) {
playerNameTextField.mouseClicked(mouseX, mouseY, mouseButton);
inventoryTextField.otherComponentClick();
killDeathSearchTextField.otherComponentClick();
museumTextField.otherComponentClick();
return;
}
}
if (
mouseX > guiLeft + 106 &&
mouseX < guiLeft + 106 + 100 &&
profile != null &&
!profile.getProfileNames().isEmpty() &&
profileName != null
) {
if (mouseY > guiTop + sizeY + 3 && mouseY < guiTop + sizeY + 23) {
String url =
"https://sky.shiiyu.moe/stats/" + getDisplayName() + "/" +
profileName;
Utils.openUrl(url);
Utils.playPressSound();
return;
}
}
if (mouseX > guiLeft && mouseX < guiLeft + 100 && profile != null && !profile.getProfileNames().isEmpty()) {
ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
if (mouseY > guiTop + sizeY + 3 && mouseY < guiTop + sizeY + 23) {
if (scaledResolution.getScaleFactor() >= 4) {
profileDropdownSelected = false;
int profileNum = 0;
for (int index = 0; index < profile.getProfileNames().size(); index++) {
if (profile.getProfileNames().get(index).equals(profileName)) {
profileNum = index;
break;
}
}
if (mouseButton == 0) {
profileNum++;
} else {
profileNum--;
}
if (profileNum >= profile.getProfileNames().size()) profileNum = 0;
if (profileNum < 0) profileNum = profile.getProfileNames().size() - 1;
String newProfileName = profile.getProfileNames().get(profileNum);
if (profileName != null && !profileName.equals(newProfileName)) {
resetCache();
}
profileName = newProfileName;
} else {
profileDropdownSelected = !profileDropdownSelected;
}
} else if (scaledResolution.getScaleFactor() < 4 && profileDropdownSelected) {
int dropdownOptionSize = scaledResolution.getScaleFactor() == 3 ? 10 : 20;
int extraY = mouseY - (guiTop + sizeY + 23);
int index = extraY / dropdownOptionSize;
if (index >= 0 && index < profile.getProfileNames().size()) {
String newProfileName = profile.getProfileNames().get(index);
if (profileName != null && !profileName.equals(newProfileName)) {
resetCache();
}
profileName = newProfileName;
}
}
playerNameTextField.otherComponentClick();
inventoryTextField.otherComponentClick();
killDeathSearchTextField.otherComponentClick();
museumTextField.otherComponentClick();
return;
}
profileDropdownSelected = false;
playerNameTextField.otherComponentClick();
inventoryTextField.otherComponentClick();
killDeathSearchTextField.otherComponentClick();
museumTextField.otherComponentClick();
}
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
super.keyTyped(typedChar, keyCode);
if (pages.containsKey(currentPage)) {
try {
pages.get(currentPage).keyTyped(typedChar, keyCode);
} catch (Exception ex) {
if (currentPage == ProfileViewerPage.CRASH_RECOVERY) throw ex;
pages.put(ProfileViewerPage.CRASH_RECOVERY, new CrashRecoveryPage(this, ex, currentPage));
currentPage = ProfileViewerPage.CRASH_RECOVERY;
}
}
if (playerNameTextField.getFocus()) {
if (keyCode == Keyboard.KEY_RETURN) {
String name = playerNameTextField.getText();
currentPage = ProfileViewerPage.LOADING;
NotEnoughUpdates.profileViewer.loadPlayerByName(
playerNameTextField.getText(),
profile -> { //todo: invalid name
if (profile != null) {
profile.resetCache();
ProfileViewerUtils.saveSearch(name);
}
Minecraft.getMinecraft().displayGuiScreen(new GuiProfileViewer(profile));
}
);
}
playerNameTextField.keyTyped(typedChar, keyCode);
}
}
@Override
protected void mouseReleased(int mouseX, int mouseY, int mouseButton) {
super.mouseReleased(mouseX, mouseY, mouseButton);
if (pages.containsKey(currentPage)) {
pages.get(currentPage).mouseReleased(mouseX, mouseY, mouseButton);
}
}
public void renderXpBar(
String skillName,
ItemStack stack,
int x,
int y,
int xSize,
ProfileViewer.Level levelObj,
int mouseX,
int mouseY
) {
float level = levelObj.level;
int levelFloored = (int) Math.floor(level);
Utils.renderAlignedString(skillName, EnumChatFormatting.WHITE.toString() + levelFloored, x + 14, y - 4, xSize - 20);
if (levelObj.maxed) {
renderGoldBar(x, y + 6, xSize);
} else {
if ((skillName.contains("Catacombs") || Weight.DUNGEON_CLASS_NAMES.stream().anyMatch(e -> skillName
.toLowerCase(Locale.ROOT)
.contains(e))) && levelObj.level >= 50) {
renderGoldBar(x, y + 6, xSize);
} else {
renderBar(x, y + 6, xSize, level % 1);
}
}
if (mouseX > x && mouseX < x + 120) {
if (mouseY > y - 4 && mouseY < y + 13) {
String levelStr;
String totalXpStr = null;
if (skillName.contains("Catacombs")) {
totalXpStr = EnumChatFormatting.GRAY + "Total XP: " + EnumChatFormatting.DARK_PURPLE +
StringUtils.formatNumber(levelObj.totalXp) + EnumChatFormatting.DARK_GRAY + " (" +
StringUtils.formatToTenths(getPercentage(skillName.toLowerCase(Locale.ROOT), levelObj)) + "% to 50)";
}
// Adds overflow level to each level object that is maxed, avoids hotm level as there is no overflow xp for it
if (levelObj.maxed) {
levelStr = !skillName.contains("HOTM") ?
EnumChatFormatting.GOLD + "MAXED!" + EnumChatFormatting.GRAY + " (Overflow level: " + String.format(
"%.2f",
levelObj.level
) + ")" :
EnumChatFormatting.GOLD + "MAXED!";
} else {
if (skillName.contains("Class Average")) {
levelStr = "Progress: " + EnumChatFormatting.DARK_PURPLE + String.format("%.1f", (level % 1 * 100)) + "%";
totalXpStr = "Exact Class Average: " + EnumChatFormatting.WHITE + String.format("%.2f", levelObj.level);
} else {
int maxXp = (int) levelObj.maxXpForLevel;
levelStr =
EnumChatFormatting.DARK_PURPLE +
StringUtils.shortNumberFormat(Math.round((level % 1) * maxXp)) +
"/" +
StringUtils.shortNumberFormat(maxXp) +
// Since catacombs isn't considered 'maxed' at level 50 (since the cap is '99'), we can add
// a conditional here to add the overflow level rather than above
(skillName.contains("Catacombs") && levelObj.level >= 50 ?
EnumChatFormatting.GRAY + " (Overflow level: " + String.format("%.2f", levelObj.level) + ")" : "");
}
}
if (totalXpStr != null) {
tooltipToDisplay = Utils.createList(levelStr, totalXpStr);
} else {
tooltipToDisplay = Utils.createList(levelStr);
}
}
}
NBTTagCompound nbt = new NBTTagCompound(); //Adding NBT Data for Custom Resource Packs
NBTTagCompound display = new NBTTagCompound();
display.setString("Name", skillName);
nbt.setTag("display", display);
stack.setTagCompound(nbt);
GL11.glTranslatef((x), (y - 6f), 0);
GL11.glScalef(0.7f, 0.7f, 1);
Utils.drawItemStackLinear(stack, 0, 0);
GL11.glScalef(1 / 0.7f, 1 / 0.7f, 1);
GL11.glTranslatef(-(x), -(y - 6f), 0);
}
public EntityOtherPlayerMP getEntityPlayer() {
return ((BasicPage) pages.get(ProfileViewerPage.BASIC)).entityPlayer;
}
public void renderGoldBar(float x, float y, float xSize) {
if (!OpenGlHelper.areShadersSupported()) {
renderBar(x, y, xSize, 1);
return;
}
Minecraft.getMinecraft().getTextureManager().bindTexture(icons);
ShaderManager shaderManager = ShaderManager.getInstance();
shaderManager.loadShader("make_gold");
shaderManager.loadData("make_gold", "amount", (startTime - System.currentTimeMillis()) / 10000f);
Utils.drawTexturedRect(x, y, xSize / 2f, 5, 0 / 256f, (xSize / 2f) / 256f, 79 / 256f, 84 / 256f, GL11.GL_NEAREST);
Utils.drawTexturedRect(
x + xSize / 2f,
y,
xSize / 2f,
5,
(182 - xSize / 2f) / 256f,
182 / 256f,
79 / 256f,
84 / 256f,
GL11.GL_NEAREST
);
GL20.glUseProgram(0);
}
public void renderBar(float x, float y, float xSize, float completed) {
Minecraft.getMinecraft().getTextureManager().bindTexture(icons);
completed = Math.round(completed / 0.05f) * 0.05f;
float notCompleted = 1 - completed;
GlStateManager.color(1, 1, 1, 1);
float width;
if (completed < 0.5f) {
width = (0.5f - completed) * xSize;
Utils.drawTexturedRect(
x + xSize * completed,
y,
width,
5,
xSize * completed / 256f,
(xSize / 2f) / 256f,
74 / 256f,
79 / 256f,
GL11.GL_NEAREST
);
}
if (completed < 1f) {
width = Math.min(xSize * notCompleted, xSize / 2f);
Utils.drawTexturedRect(
x + (xSize / 2f) + Math.max(xSize * (completed - 0.5f), 0),
y,
width,
5,
(182 - (xSize / 2f) + Math.max(xSize * (completed - 0.5f), 0)) / 256f,
182 / 256f,
74 / 256f,
79 / 256f,
GL11.GL_NEAREST
);
}
if (completed > 0f) {
width = Math.min(xSize * completed, xSize / 2f);
Utils.drawTexturedRect(x, y, width, 5, 0 / 256f, width / 256f, 79 / 256f, 84 / 256f, GL11.GL_NEAREST);
}
if (completed > 0.5f) {
width = Math.min(xSize * (completed - 0.5f), xSize / 2f);
Utils.drawTexturedRect(
x + (xSize / 2f),
y,
width,
5,
(182 - (xSize / 2f)) / 256f,
(182 - (xSize / 2f) + width) / 256f,
79 / 256f,
84 / 256f,
GL11.GL_NEAREST
);
}
}
public void resetCache() {
pages.values().forEach(GuiProfileViewerPage::resetCache);
}
/**
* 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;
}
private void blurBackground() {
if (!OpenGlHelper.isFramebufferEnabled()) return;
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);
}
}
public float getPercentage(String skillName, ProfileViewer.Level level) {
if (level.maxed) {
return 100;
}
if (skillName.contains("catacombs")) {
return (level.totalXp / DungeonsWeight.CATACOMBS_LEVEL_50_XP) * 100;
} else if (skillName.equalsIgnoreCase("vampire")) {
return (level.totalXp / 2400) * 100;
} else if (Weight.SLAYER_NAMES.contains(skillName)) {
return (level.totalXp / 1000000) * 100;
} else if (skillName.equalsIgnoreCase("social")) {
return (level.totalXp / 272800) * 100;
} else if (skillName.equalsIgnoreCase("garden")) {
return (level.totalXp / 60120) * 100;
} else {
if (level.maxLevel == 60) {
return (level.totalXp / SkillsWeight.SKILLS_LEVEL_60) * 100;
} else {
return (level.totalXp / SkillsWeight.SKILLS_LEVEL_50) * 100;
}
}
}
/**
* 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) {
if (!OpenGlHelper.isFramebufferEnabled()) return;
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();
}
public enum ProfileViewerPage {
LOADING(),
INVALID_NAME(),
NO_SKYBLOCK(),
CRASH_RECOVERY(),
BASIC(0, Items.paper, "§9Skills"),
DUNGEON(1, Item.getItemFromBlock(Blocks.deadbush), "§eDungeoneering"),
EXTRA(2, Items.book, "§7Profile Stats"),
INVENTORIES(3, Item.getItemFromBlock(Blocks.ender_chest), "§bStorage"),
COLLECTIONS(4, Items.painting, "§6Collections"),
PETS(5, Items.bone, "§aPets"),
MINING(6, Items.iron_pickaxe, "§5Heart of the Mountain"),
BINGO(7, Items.filled_map, "§zBingo"),
TROPHY_FISH(8, Items.fishing_rod, "§3Trophy Fish"),
BESTIARY(9, Items.iron_sword, "§cBestiary"),
CRIMSON_ISLE(10, Item.getItemFromBlock(Blocks.netherrack), "§4Crimson Isle"),
MUSEUM(11, Items.leather_chestplate, "§6Museum"),
RIFT(12, Items.ender_eye, "§5Rift"),
GARDEN(13, Item.getItemFromBlock(Blocks.grass), "§2Garden");
public final ItemStack stack;
public final int id;
ProfileViewerPage() {
this(-1, null, null);
}
ProfileViewerPage(int id, Item item, String name) {
this.id = id;
if (item == null) {
stack = null;
} else {
stack = new ItemStack(item);
NBTTagCompound nbt = new NBTTagCompound(); //Adding NBT Data for Custom Resource Packs
NBTTagCompound display = new NBTTagCompound();
display.setString("Name", name);
nbt.setTag("display", display);
stack.setTagCompound(nbt);
}
}
public static ProfileViewerPage getById(int id) {
for (ProfileViewerPage page : values()) {
if (page.id == id) {
return page;
}
}
return null;
}
public boolean isTransient() {
return this == LOADING || this == NO_SKYBLOCK || this == INVALID_NAME || this == CRASH_RECOVERY;
}
public Optional getItem() {
return Optional.ofNullable(stack);
}
}
}