diff options
Diffstat (limited to 'src/main/java/io')
16 files changed, 940 insertions, 259 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java index 200569df..d0301b2c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java @@ -170,7 +170,7 @@ public class GuiItemRecipe extends GuiScreen { @Override public void handleKeyboardInput() throws IOException { - super.handleKeyboardInput(); //TODO: r and u + super.handleKeyboardInput(); ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); int width = scaledResolution.getScaledWidth(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index edf1d31c..b879c383 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -1079,8 +1079,6 @@ public class NEUManager { } if(craftMatrices.size() > 0) { - Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C0DPacketCloseWindow( - Minecraft.getMinecraft().thePlayer.openContainer.windowId)); Minecraft.getMinecraft().displayGuiScreen(new GuiItemRecipe("Item Usages", craftMatrices, results, this)); return true; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index a33c13b3..25b27cc5 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -96,7 +96,6 @@ public class NEUOverlay extends Gui { private JsonObject[] searchedItemsArr = null; private boolean itemPaneOpen = false; - private boolean hoveringItemPaneToggle = false; private int page = 0; @@ -1636,21 +1635,16 @@ public class NEUOverlay extends Gui { int rightSide = leftSide+paneWidth-getBoxPadding()-getItemBoxXPadding(); //Tab - Minecraft.getMinecraft().getTextureManager().bindTexture(itemPaneTabArrow); - GlStateManager.color(1f, 1f, 1f, 0.3f); - Utils.drawTexturedRect(width-itemPaneTabOffset.getValue(), height/2 - 50, 20, 100); - GlStateManager.bindTexture(0); + if(!manager.config.disableItemTabOpen.value) { + Minecraft.getMinecraft().getTextureManager().bindTexture(itemPaneTabArrow); + GlStateManager.color(1f, 1f, 1f, 0.3f); + Utils.drawTexturedRect(width-itemPaneTabOffset.getValue(), height/2 - 50, 20, 100); + GlStateManager.bindTexture(0); - if(mouseX > width-itemPaneTabOffset.getValue() && mouseY > height/2 - 50 - && mouseY < height/2 + 50) { - if(!hoveringItemPaneToggle) { - if(!manager.config.disableItemTabOpen.value) { - itemPaneOpen = !itemPaneOpen; - } - hoveringItemPaneToggle = true; + if(!itemPaneOpen && mouseX > width-itemPaneTabOffset.getValue() && mouseY > height/2 - 50 + && mouseY < height/2 + 50) { + itemPaneOpen = true; } - } else { - hoveringItemPaneToggle = false; } //Atomic reference used so that below lambda doesn't complain about non-effectively-final variable diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index a7a30233..734f7ca1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -14,7 +14,7 @@ import io.github.moulberry.notenoughupdates.infopanes.CosmeticsInfoPane; import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; import io.github.moulberry.notenoughupdates.questing.GuiQuestLine; -import io.github.moulberry.notenoughupdates.questing.NEUQuesting; +import io.github.moulberry.notenoughupdates.questing.SBScoreboardData; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; @@ -31,20 +31,15 @@ import net.minecraft.inventory.ContainerChest; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.scoreboard.ScoreObjective; import net.minecraft.scoreboard.Scoreboard; import net.minecraft.util.ChatComponentText; -import net.minecraft.util.ChatStyle; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.Session; import net.minecraftforge.client.ClientCommandHandler; -import net.minecraftforge.client.event.ClientChatReceivedEvent; -import net.minecraftforge.client.event.GuiOpenEvent; -import net.minecraftforge.client.event.GuiScreenEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.client.event.*; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.fml.client.registry.ClientRegistry; @@ -139,10 +134,13 @@ public class NotEnoughUpdates { if(args.length != 1) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "idiot.")); + } else { + profileViewer.getProfileByName(args[0], profile -> { + profile.resetCache(); + openGui = new GuiProfileViewer(profile); + }); } - profileViewer.getProfileByName(args[0], profile -> { - openGui = new GuiProfileViewer(profile); - }); + //openGui = new GuiProfileViewer(null); } }); @@ -398,7 +396,7 @@ public class NotEnoughUpdates { joinedSB = false; } } - //NEUQuesting.getInstance().tick(); + SBScoreboardData.getInstance().tick(); //GuiQuestLine.questLine.tick(); } if(currChatMessage != null && System.currentTimeMillis() - lastChatMessage > CHAT_MSG_COOLDOWN) { @@ -473,6 +471,15 @@ public class NotEnoughUpdates { } } + @SubscribeEvent(priority=EventPriority.HIGHEST) + public void onRenderEntitySpecials(RenderLivingEvent.Specials.Pre event) { + if(Minecraft.getMinecraft().currentScreen instanceof GuiProfileViewer) { + if(((GuiProfileViewer)Minecraft.getMinecraft().currentScreen).getEntityPlayer() == event.entity) { + event.setCanceled(true); + } + } + } + @SubscribeEvent public void onRenderGameOverlay(RenderGameOverlayEvent event) { if(event.type != null && event.type.equals(RenderGameOverlayEvent.ElementType.BOSSHEALTH) && diff --git a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java index 65f6545e..53cc4639 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java @@ -168,7 +168,9 @@ public class APIManager { args.put("uuid", ""+uuid); manager.hypixelApi.getHypixelApiAsync(manager.config.apiKey.value, "skyblock/profiles", args, jsonObject -> { - if(jsonObject.has("success") && jsonObject.get("success").getAsBoolean()) { + if(jsonObject == null) return; + + if(jsonObject.has("success") && jsonObject.get("success").getAsBoolean()) { incPlayerInfoVersion(); playerInformation = jsonObject.get("profiles").getAsJsonArray(); if(playerInformation == null) return; @@ -366,7 +368,9 @@ public class APIManager { args.put("page", ""+page); manager.hypixelApi.getHypixelApiAsync(manager.config.apiKey.value, "skyblock/auctions", args, jsonObject -> { - if (jsonObject.get("success").getAsBoolean()) { + if(jsonObject == null) return; + + if (jsonObject.get("success").getAsBoolean()) { totalPages = jsonObject.get("totalPages").getAsInt(); activeAuctions = jsonObject.get("totalAuctions").getAsInt(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/auction/CustomAH.java b/src/main/java/io/github/moulberry/notenoughupdates/auction/CustomAH.java index 17ce216e..77fa8425 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/CustomAH.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/CustomAH.java @@ -103,7 +103,7 @@ public class CustomAH extends Gui { private Category CATEGORY_TRAVEL_SCROLLS = new Category("travelscroll", "Travel Scrolls", "map"); private Category CATEGORY_REFORGE_STONES = new Category("reforgestone", "Reforge Stones", "anvil"); - private Category CATEGORY_RUNES = new Category("rune", "Runes", "end_portal_frame"); + private Category CATEGORY_RUNES = new Category("rune", "Runes", "magma_cream"); private Category CATEGORY_FURNITURE = new Category("furniture", "Furniture", "armor_stand"); private Category CATEGORY_COMBAT = new Category("weapon", "Combat", "golden_sword", CATEGORY_SWORD, diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java index 81ecc9b4..9607a888 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java @@ -1,5 +1,6 @@ package io.github.moulberry.notenoughupdates.profileviewer; +import com.google.common.base.Splitter; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -7,35 +8,49 @@ import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.authlib.properties.Property; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.cosmetics.ShaderManager; +import io.github.moulberry.notenoughupdates.questing.SBScoreboardData; import io.github.moulberry.notenoughupdates.util.TexLoc; import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityOtherPlayerMP; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.network.NetworkPlayerInfo; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.texture.TextureUtil; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.resources.DefaultPlayerSkin; +import net.minecraft.client.resources.IResourceManager; +import net.minecraft.client.resources.IResourceManagerReloadListener; import net.minecraft.client.resources.SkinManager; +import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockPos; import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.Charsets; +import org.luaj.vm2.ast.Str; import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL14; +import org.lwjgl.opengl.GL20; import java.awt.*; +import java.io.IOException; import java.nio.charset.Charset; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.UUID; +import java.util.*; +import java.util.List; public class GuiProfileViewer extends GuiScreen { @@ -48,6 +63,14 @@ public class GuiProfileViewer extends GuiScreen { private int guiLeft; private int guiTop; + private float backgroundRotation = 0; + + private long currentTime = 0; + private long lastTime = 0; + private long startTime = 0; + + private List<String> tooltipToDisplay = null; + public enum ProfileViewerPage { BASIC } @@ -58,6 +81,9 @@ public class GuiProfileViewer extends GuiScreen { @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { + currentTime = System.currentTimeMillis(); + if(startTime == 0) startTime = currentTime; + super.drawScreen(mouseX, mouseY, partialTicks); drawDefaultBackground(); @@ -67,6 +93,12 @@ public class GuiProfileViewer extends GuiScreen { break; } + lastTime = currentTime; + + if(tooltipToDisplay != null) { + Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, Minecraft.getMinecraft().fontRendererObj); + tooltipToDisplay = null; + } } private String niceUuid(String uuidStr) { @@ -85,33 +117,196 @@ public class GuiProfileViewer extends GuiScreen { return niceAucId.toString(); } + public EntityOtherPlayerMP getEntityPlayer() { + return entityPlayer; + } + private EntityOtherPlayerMP entityPlayer = null; private ResourceLocation playerLocationSkin = null; private ResourceLocation playerLocationCape = null; private String skinType = null; - TexLoc tl = new TexLoc(0, 0, Keyboard.KEY_M); - TexLoc tl2 = new TexLoc(0, 0, Keyboard.KEY_B); - TexLoc tl3 = new TexLoc(0, 0, Keyboard.KEY_J); + private HashMap<String, ResourceLocation[]> panoramasMap = new HashMap<>(); + + public ResourceLocation[] getPanoramasForLocation(String location, String identifier) { + if(panoramasMap.containsKey(location)) return panoramasMap.get(location); + try { + ResourceLocation[] panoramasArray = new ResourceLocation[6]; + for(int i=0; i<6; i++) { + panoramasArray[i] = new ResourceLocation("notenoughupdates:panoramas/"+location+"_"+identifier+"/panorama_"+i+".png"); + Minecraft.getMinecraft().getResourceManager().getResource(panoramasArray[i]); + } + panoramasMap.put(location, panoramasArray); + return panoramasArray; + } catch(IOException e) { + try { + ResourceLocation[] panoramasArray = new ResourceLocation[6]; + for(int i=0; i<6; i++) { + panoramasArray[i] = new ResourceLocation("notenoughupdates:panoramas/"+location+"/panorama_"+i+".png"); + Minecraft.getMinecraft().getResourceManager().getResource(panoramasArray[i]); + } + panoramasMap.put(location, panoramasArray); + return panoramasArray; + } catch(IOException e2) { + ResourceLocation[] panoramasArray = new ResourceLocation[6]; + for(int i=0; i<6; i++) { + panoramasArray[i] = new ResourceLocation("notenoughupdates:panoramas/unknown/panorama_"+i+".png"); + } + panoramasMap.put(location, panoramasArray); + return panoramasArray; + } + } + } + + private int backgroundClickedX = -1; + + private static char[] c = new char[]{'k', 'm', 'b', 't'}; + + public static String shortNumberFormat(double n, int iteration) { + double d = ((long) n / 100) / 10.0; + boolean isRound = (d * 10) %10 == 0; + return (d < 1000? + ((d > 99.9 || isRound || (!isRound && d > 9.99)? + (int) d * 10 / 10 : d + "" + ) + "" + c[iteration]) + : shortNumberFormat(d, iteration+1)); + } + private void drawBasicPage(int mouseX, int mouseY, float partialTicks) { + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + this.sizeX = 431; this.sizeY = 202; this.guiLeft = (this.width-this.sizeX)/2; this.guiTop = (this.height-this.sizeY)/2; + String location = null; + JsonObject status = profile.getPlayerStatus(); + if(status != null && status.has("mode")) { + location = status.get("mode").getAsString(); + } + + int extraRotation = 0; + if(Mouse.isButtonDown(0)) { + if(backgroundClickedX == -1) { + if(mouseX > guiLeft+23 && mouseX < guiLeft+23+81) { + if(mouseY > guiTop+44 && mouseY < guiTop+44+108) { + backgroundClickedX = mouseX; + } + } + } + } else { + if(backgroundClickedX != -1) { + backgroundRotation += mouseX - backgroundClickedX; + backgroundClickedX = -1; + } + } + if(backgroundClickedX == -1) { + backgroundRotation += (currentTime - lastTime)/400f; + } else { + extraRotation = mouseX - backgroundClickedX; + } + backgroundRotation %= 360; + + String panoramaIdentifier = "day"; + if(SBScoreboardData.getInstance().currentTimeDate != null) { + if(SBScoreboardData.getInstance().currentTimeDate.before(new Date(0, 0, 0, 6, 0, 0))) { + if(SBScoreboardData.getInstance().currentTimeDate.after(new Date(0, 0, 0, 20, 0, 0))) { + panoramaIdentifier = "night"; + } + } + } + + Panorama.drawPanorama(-backgroundRotation-extraRotation, guiLeft+23, guiTop+44, 81, 108, + getPanoramasForLocation(location==null?"unknown":location, panoramaIdentifier)); + Minecraft.getMinecraft().getTextureManager().bindTexture(pv_basic); Utils.drawTexturedRect(guiLeft, guiTop, sizeX, sizeY, GL11.GL_NEAREST); - tl.handleKeyboardInput(); - tl2.handleKeyboardInput(); - tl3.handleKeyboardInput(); + if(entityPlayer != null && profile.getHypixelProfile() != null) { + String rank = Utils.getElementAsString(profile.getHypixelProfile().get("rank"), Utils.getElementAsString(profile.getHypixelProfile().get("newPackageRank"), "NONE")); + EnumChatFormatting rankPlusColorECF = EnumChatFormatting.getValueByName(Utils.getElementAsString(profile.getHypixelProfile().get("rankPlusColor"), "WHITE")); + String rankPlusColor = EnumChatFormatting.WHITE.toString(); + if(rankPlusColorECF != null) { + rankPlusColor = rankPlusColorECF.toString(); + } + + JsonObject misc = Utils.getConstant("misc"); + if(misc != null) { + if(misc.has("ranks")) { + String rankName = Utils.getElementAsString(Utils.getElement(misc, "ranks."+rank+".tag"), null); + String rankColor = Utils.getElementAsString(Utils.getElement(misc, "ranks."+rank+".color"), "7"); + String rankPlus = Utils.getElementAsString(Utils.getElement(misc, "ranks."+rank+".plus"), ""); + + String name = entityPlayer.getName(); + + if(misc.has("special_bois")) { + JsonArray special_bois = misc.get("special_bois").getAsJsonArray(); + for(int i=0; i<special_bois.size(); i++) { + if(special_bois.get(i).getAsString().equals(profile.getUuid())) { + name = Utils.chromaString(name); + break; + } + } + } + + String playerName = EnumChatFormatting.GRAY.toString() + name; + if(rankName != null) { + StringBuilder sb = new StringBuilder(); + sb.append("\u00A7"+rankColor); + sb.append("["); + sb.append(rankName); + sb.append(rankPlusColor); + sb.append(rankPlus); + sb.append("\u00A7"+rankColor); + sb.append("] "); + sb.append(name); + playerName = sb.toString(); + } + + int rankPrefixLen = fr.getStringWidth(playerName); + int halfRankPrefixLen = rankPrefixLen/2; + + int x = guiLeft+63; + int y = guiTop+54; + + drawRect(x-halfRankPrefixLen-1, y-1, x+halfRankPrefixLen+1, y+8, new Color(0, 0, 0, 64).getRGB()); + + fr.drawString(playerName, x-halfRankPrefixLen, y, 0, true); + } + } + } + + if(status != null) { + JsonElement onlineElement = Utils.getElement(status, "online"); + boolean online = onlineElement != null && onlineElement.isJsonPrimitive() && onlineElement.getAsBoolean(); + String statusStr = online ? EnumChatFormatting.GREEN + "ONLINE" : EnumChatFormatting.RED + "OFFLINE"; + String locationStr = null; + if(profile.getUuid().equals("20934ef9488c465180a78f861586b4cf")) { + locationStr = "Ignoring DMs"; + } else { + if(location != null) { + JsonObject misc = Utils.getConstant("misc"); + if(misc != null) { + locationStr = Utils.getElementAsString(Utils.getElement(misc, "area_names."+location), "Unknown Location"); + } + } + } + if(locationStr != null) { + statusStr += EnumChatFormatting.GRAY+" - "+EnumChatFormatting.GREEN+locationStr; + } + + Utils.drawStringCentered(statusStr, fr, guiLeft+63, guiTop+160, true, 0); + } + + if(profile.getPlayerInformation(null) == null) { + //TODO: "Downloading player information" + return; + } if(entityPlayer == null) { UUID playerUUID = UUID.fromString(niceUuid(profile.getUuid())); GameProfile fakeProfile = Minecraft.getMinecraft().getSessionService().fillProfileProperties(new GameProfile(playerUUID, "CoolGuy123"), false); - for(Property prop : fakeProfile.getProperties().get("textures")) { - System.out.println(new String(Base64.decodeBase64(prop.getValue()), Charsets.UTF_8)); - } entityPlayer = new EntityOtherPlayerMP(Minecraft.getMinecraft().theWorld, fakeProfile) { public ResourceLocation getLocationSkin() { return playerLocationSkin == null ? DefaultPlayerSkin.getDefaultSkin(this.getUniqueID()) : playerLocationSkin; @@ -125,6 +320,10 @@ public class GuiProfileViewer extends GuiScreen { return skinType == null ? DefaultPlayerSkin.getSkinType(this.getUniqueID()) : skinType; } }; + entityPlayer.setAlwaysRenderNameTag(false); + entityPlayer.setCustomNameTag(""); + } else { + entityPlayer.refreshDisplayName(); } JsonObject profileInfo = profile.getProfileInformation(null); @@ -132,7 +331,7 @@ public class GuiProfileViewer extends GuiScreen { JsonObject skillInfo = profile.getSkillInfo(null); JsonObject inventoryInfo = profile.getInventoryInfo(null); - JsonObject collectionInfo =profile. getCollectionInfo(null); + JsonObject collectionInfo = profile. getCollectionInfo(null); if(inventoryInfo != null && inventoryInfo.has("inv_armor")) { JsonArray items = inventoryInfo.get("inv_armor").getAsJsonArray(); @@ -165,122 +364,176 @@ public class GuiProfileViewer extends GuiScreen { } catch(Exception e){} } - drawEntityOnScreen(guiLeft+63, guiTop+129, 30, guiLeft+63-mouseX, guiTop+129-mouseY, entityPlayer); + GlStateManager.color(1, 1, 1, 1); + drawEntityOnScreen(guiLeft+63, guiTop+128+7, 36, guiLeft+63-mouseX, guiTop+129-mouseY, entityPlayer); PlayerStats.Stats stats = profile.getStats(null); - for(int i=0; i<PlayerStats.defaultStatNames.length; i++) { - String statName = PlayerStats.defaultStatNames[i]; - String statNamePretty = PlayerStats.defaultStatNamesPretty[i]; - int val = Math.round(stats.get(statName)); + if(stats != null) { + Splitter splitter = Splitter.on(" ").omitEmptyStrings().limit(2); + for(int i=0; i<PlayerStats.defaultStatNames.length; i++) { + String statName = PlayerStats.defaultStatNames[i]; + String statNamePretty = PlayerStats.defaultStatNamesPretty[i]; + int val = Math.round(stats.get(statName)); + GlStateManager.color(1, 1, 1, 1); + GlStateManager.enableBlend(); + GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); + for(int xOff=-2; xOff<=2; xOff++) { + for(int yOff=-2; yOff<=2; yOff++) { + if(Math.abs(xOff) != Math.abs(yOff)) { + Utils.drawStringCenteredScaledMaxWidth(Utils.cleanColourNotModifiers(statNamePretty) + " " + val, Minecraft.getMinecraft().fontRendererObj, + guiLeft+172f+xOff/2f, guiTop+36+12.5f*i+yOff/2f, false, 80, new Color(0, 0, 0, + 200/Math.max(Math.abs(xOff), Math.abs(yOff))).getRGB()); + } + } + } - for(int xOff=-1; xOff<=1; xOff++) { - for(int yOff=-1; yOff<=1; yOff++) { - if(Math.abs(xOff) != Math.abs(yOff)) { - //Utils.drawStringCenteredScaledMaxWidth(Utils.cleanColourNotModifiers(statNamePretty) + " " + val, Minecraft.getMinecraft().fontRendererObj, - // guiLeft+172f+xOff, guiTop+36+12.5f*i+yOff, false, 85, new Color(100, 100, 100, 100).getRGB()); + GlStateManager.color(1, 1, 1, 1); + Utils.drawStringCenteredScaledMaxWidth(statNamePretty + " " + EnumChatFormatting.WHITE + val, Minecraft.getMinecraft().fontRendererObj, + guiLeft+172f, guiTop+36+12.5f*i, false, 80, 4210752); + + + if(mouseX > guiLeft+132 && mouseX < guiLeft+212) { + if(mouseY > guiTop+32+12.5f*i && mouseY < guiTop+40+12.5f*i) { + List<String> split = splitter.splitToList(statNamePretty); + PlayerStats.Stats baseStats = PlayerStats.getBaseStats(); + tooltipToDisplay = new ArrayList<>(); + tooltipToDisplay.add(statNamePretty); + int base = Math.round(baseStats.get(statName)); + tooltipToDisplay.add(EnumChatFormatting.GRAY+"Base "+split.get(1)+": "+EnumChatFormatting.GREEN+base+" "+split.get(0)); + int passive = Math.round(profile.getPassiveStats(null).get(statName)-baseStats.get(statName)); + tooltipToDisplay.add(EnumChatFormatting.GRAY+"Passive "+split.get(1)+" Bonus: +"+EnumChatFormatting.YELLOW+passive+" "+split.get(0)); + int itemBonus = Math.round(stats.get(statName)-profile.getPassiveStats(null).get(statName)); + tooltipToDisplay.add(EnumChatFormatting.GRAY+"Item "+split.get(1)+" Bonus: +"+EnumChatFormatting.DARK_PURPLE+itemBonus+" "+split.get(0)); + int finalStat = Math.round(stats.get(statName)); + tooltipToDisplay.add(EnumChatFormatting.GRAY+"Final "+split.get(1)+": +"+EnumChatFormatting.RED+finalStat+" "+split.get(0)); } } } - - GlStateManager.color(1, 1, 1, 1); - Utils.drawStringCenteredScaledMaxWidth(statNamePretty + " " + EnumChatFormatting.WHITE + val, Minecraft.getMinecraft().fontRendererObj, - guiLeft+172f, guiTop+36+12.5f*i, true, 85, Color.BLACK.getRGB()); + } else { + //"stats not enabled in api" } - int position = 0; - for(Map.Entry<String, String> entry : skillToSkillNameMap.entrySet()) { - int yPosition = position % 7; - int xPosition = position / 7; + if(skillInfo != null) { + int position = 0; + for(Map.Entry<String, ItemStack> entry : ProfileViewer.getSkillToSkillDisplayMap().entrySet()) { + int yPosition = position % 7; + int xPosition = position / 7; - String skillName = entry.getValue(); + String skillName = entry.getValue().getDisplayName(); - float level = (int)skillInfo.get(entry.getKey()).getAsFloat(); + float level = Utils.getElementAsFloat(skillInfo.get("level_"+entry.getKey()), 0); + int levelFloored = (int)Math.floor(level); - for(int xOff=-1; xOff<=1; xOff++) { - for(int yOff=-1; yOff<=1; yOff++) { - if(Math.abs(xOff) != Math.abs(yOff)) { - //Utils.drawStringCenteredScaledMaxWidth(Utils.cleanColourNotModifiers(skillName) + " " + level, Minecraft.getMinecraft().fontRendererObj, - // guiLeft+tl.x+tl2.x*xPosition+xOff, guiTop+tl.y+tl2.y*yPosition+yOff, false, 85, new Color(100, 100, 100, 100).getRGB()); + int x = guiLeft+237+86*xPosition; + int y = guiTop+31+21*yPosition; + + for(int xOff=-2; xOff<=2; xOff++) { + for(int yOff=-2; yOff<=2; yOff++) { + if(Math.abs(xOff) != Math.abs(yOff)) { + Utils.drawStringCenteredYScaledMaxWidth(Utils.cleanColourNotModifiers(skillName) + " " + levelFloored, Minecraft.getMinecraft().fontRendererObj, + x+14+xOff/2f, y+yOff/2f, false, 60, new Color(0, 0, 0, + 200/Math.max(Math.abs(xOff), Math.abs(yOff))).getRGB()); + } } } - } - GlStateManager.color(1, 1, 1, 1); - Utils.drawStringCenteredScaledMaxWidth(skillName + " " + EnumChatFormatting.WHITE + level, Minecraft.getMinecraft().fontRendererObj, - guiLeft+277+86*xPosition, guiTop+36+21*yPosition, true, 85, Color.BLACK.getRGB()); + GlStateManager.color(1, 1, 1, 1); + Utils.drawStringCenteredYScaledMaxWidth(EnumChatFormatting.WHITE + skillName + " " + EnumChatFormatting.WHITE + levelFloored, Minecraft.getMinecraft().fontRendererObj, + x+14, y, false, 60, 4210752); - position++; + if(skillInfo.get("maxed_"+entry.getKey()).getAsBoolean()) { + renderGoldBar(x, y+6, 80); + } else { + renderBar(x, y+6, 80, level%1); + } + + if(mouseX > x && mouseX < x+80) { + if(mouseY > y+4 && mouseY < y+13) { + String levelStr; + if(skillInfo.get("maxed_"+entry.getKey()).getAsBoolean()) { + levelStr = EnumChatFormatting.GOLD+"MAXED!"; + } else { + int maxXp = (int)skillInfo.get("maxxp_"+entry.getKey()).getAsFloat(); + levelStr = EnumChatFormatting.DARK_PURPLE.toString() + shortNumberFormat(Math.round((level%1)*maxXp), 0) + "/" + shortNumberFormat(maxXp, 0); + } + + tooltipToDisplay = Utils.createList(levelStr); + } + } + + GL11.glTranslatef((x), (y-8*0.7f), 0); + GL11.glScalef(0.7f, 0.7f, 1); + Utils.drawItemStackLinear(entry.getValue(), 0, 0); + GL11.glScalef(1/0.7f, 1/0.7f, 1); + GL11.glTranslatef(-(x), -(y-8*0.7f), 0); + + position++; + } + } else { + //api not enabled } } - private static final LinkedHashMap<String, String> skillToSkillNameMap = new LinkedHashMap<>(); - static { - skillToSkillNameMap.put("level_skill_taming", "Taming"); - skillToSkillNameMap.put("level_skill_mining", "Mining"); - skillToSkillNameMap.put("level_skill_foraging", "Foraging"); - skillToSkillNameMap.put("level_skill_enchanting", "Enchanting"); - skillToSkillNameMap.put("level_skill_carpentry", "Carpentry"); - skillToSkillNameMap.put("level_skill_farming", "Farming"); - skillToSkillNameMap.put("level_skill_combat", "Combat"); - skillToSkillNameMap.put("level_skill_fishing", "Fishing"); - skillToSkillNameMap.put("level_skill_alchemy", "Alchemy"); - skillToSkillNameMap.put("level_skill_runecrafting", "Runecrafting"); - skillToSkillNameMap.put("level_slayer_zombie", "Revenant Slayer"); - skillToSkillNameMap.put("level_slayer_spider", "Tarantula Slayer"); - skillToSkillNameMap.put("level_slayer_wolf", "Sven Slayer"); - } + private void renderGoldBar(float x, float y, float xSize) { - /*private void renderBar(float x, float y, float xSize, float ySize, float completed) { - this.mc.getTextureManager().bindTexture(Gui.icons); + Minecraft.getMinecraft().getTextureManager().bindTexture(Gui.icons); + ShaderManager shaderManager = ShaderManager.getInstance(); + shaderManager.loadShader("make_gold"); + shaderManager.loadData("make_gold", "amount", (startTime-System.currentTimeMillis())/10000f); - float yScale = ySize/5; + 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); + } - if (i > 0) - { - int j = 182; - int k = (int)(this.mc.thePlayer.experience * (float)(j + 1)); - int l = p_175176_1_.getScaledHeight() - 32 + 3; + private void renderBar(float x, float y, float xSize, float completed) { + Minecraft.getMinecraft().getTextureManager().bindTexture(Gui.icons); - Utils.drawTexturedRect(x, y, xSize, ); + completed = Math.round(completed/0.05f)*0.05f; - this.drawTexturedModalRect(p_175176_2_, l, 0, 64, j, 5); + float notcompleted = 1-completed; - if (k > 0) - { - this.drawTexturedModalRect(p_175176_2_, l, 0, 69, k, 5); - } + int displayNum = 0;//tl.x%5; + + GlStateManager.color(1, 1, 1, 1); + float width = 0; + + if(completed < 0.5f && (displayNum == 1 || displayNum == 0)) { + 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 && (displayNum == 2 || displayNum == 0)) { + 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 (this.mc.thePlayer.experienceLevel > 0) - { - this.mc.mcProfiler.startSection("expLevel"); - int k1 = 8453920; - String s = "" + this.mc.thePlayer.experienceLevel; - int l1 = (p_175176_1_.getScaledWidth() - this.getFontRenderer().getStringWidth(s)) / 2; - int i1 = p_175176_1_.getScaledHeight() - 31 - 4; - int j1 = 0; - this.getFontRenderer().drawString(s, l1 + 1, i1, 0); - this.getFontRenderer().drawString(s, l1 - 1, i1, 0); - this.getFontRenderer().drawString(s, l1, i1 + 1, 0); - this.getFontRenderer().drawString(s, l1, i1 - 1, 0); - this.getFontRenderer().drawString(s, l1, i1, k1); - this.mc.mcProfiler.endSection(); + if(completed > 0f && (displayNum == 3 || displayNum == 0)) { + 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 && (displayNum == 4 || displayNum == 0)) { + width = Math.max(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); + } + } + private static final ResourceLocation shadowTextures = new ResourceLocation("textures/misc/shadow.png"); public static void drawEntityOnScreen(int posX, int posY, int scale, float mouseX, float mouseY, EntityLivingBase ent) { GlStateManager.enableColorMaterial(); GlStateManager.pushMatrix(); GlStateManager.translate((float)posX, (float)posY, 50.0F); GlStateManager.scale((float)(-scale), (float)scale, (float)scale); GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F); - float f = ent.renderYawOffset; + float renderYawOffset = ent.renderYawOffset; float f1 = ent.rotationYaw; float f2 = ent.rotationPitch; float f3 = ent.prevRotationYawHead; @@ -288,19 +541,54 @@ public class GuiProfileViewer extends GuiScreen { GlStateManager.rotate(135.0F, 0.0F, 1.0F, 0.0F); RenderHelper.enableStandardItemLighting(); GlStateManager.rotate(-135.0F, 0.0F, 1.0F, 0.0F); - GlStateManager.rotate(-((float)Math.atan((double)(mouseY / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F); + GlStateManager.rotate(25, 1.0F, 0.0F, 0.0F); ent.renderYawOffset = (float)Math.atan((double)(mouseX / 40.0F)) * 20.0F; ent.rotationYaw = (float)Math.atan((double)(mouseX / 40.0F)) * 40.0F; ent.rotationPitch = -((float)Math.atan((double)(mouseY / 40.0F))) * 20.0F; ent.rotationYawHead = ent.rotationYaw; ent.prevRotationYawHead = ent.rotationYaw; - GlStateManager.translate(0.0F, 0.0F, 0.0F); RenderManager rendermanager = Minecraft.getMinecraft().getRenderManager(); rendermanager.setPlayerViewY(180.0F); rendermanager.setRenderShadow(false); rendermanager.renderEntityWithPosYaw(ent, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F); - rendermanager.setRenderShadow(true); - ent.renderYawOffset = f; + + /*{ + GlStateManager.enableBlend(); + GlStateManager.blendFunc(770, 771); + rendermanager.renderEngine.bindTexture(shadowTextures); + GlStateManager.depthMask(false); + float f = 0.5f; + + if (ent instanceof EntityLiving) { + EntityLiving entityliving = (EntityLiving)ent; + f *= entityliving.getRenderSizeModifier(); + + if (entityliving.isChild()) + { + f *= 0.5F; + } + } + + /*Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); + + GlStateManager.color(1, 1, 1, 0.5f); + Utils.drawTexturedRect(-0.5f*tl.x, -0.5f*tl.x, 1*tl.x, 1*tl.x); + + /*for (BlockPos blockpos : BlockPos.getAllInBoxMutable(new BlockPos(i, k, i1), new BlockPos(j, l, j1))) { + Block block = world.getBlockState(blockpos.down()).getBlock(); + + if (block.getRenderType() != -1 && world.getLightFromNeighbors(blockpos) > 3) { + this.func_180549_a(block, x, y, z, blockpos, shadowAlpha, f, d2, d3, d4); + } + } + + GlStateManager.disableBlend(); + GlStateManager.depthMask(true); + }*/ + + ent.renderYawOffset = renderYawOffset; ent.rotationYaw = f1; ent.rotationPitch = f2; ent.prevRotationYawHead = f3; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/Panorama.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/Panorama.java new file mode 100644 index 00000000..bf49e616 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/Panorama.java @@ -0,0 +1,151 @@ +package io.github.moulberry.notenoughupdates.profileviewer; + +import io.github.moulberry.notenoughupdates.util.TexLoc; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.texture.DynamicTexture; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.glu.Project; + +public class Panorama { + + private static TexLoc tl = new TexLoc(97, 19, Keyboard.KEY_P); + private static TexLoc tl2 = new TexLoc(37, 80, Keyboard.KEY_L); + + private static ResourceLocation backgroundTexture = null; + + private static int lastWidth = 0; + private static int lastHeight = 0; + + public static void drawPanorama(float angle, int x, int y, int width, int height, ResourceLocation[] panoramas) { + Minecraft.getMinecraft().getFramebuffer().unbindFramebuffer(); + //GlStateManager.viewport(0, 0, 1024, 1024); + + ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); + + GL11.glViewport(0, 0, width*scaledresolution.getScaleFactor(), height*scaledresolution.getScaleFactor()); + + tl.handleKeyboardInput(); + tl2.handleKeyboardInput(); + float fov = 97; + + { + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + GlStateManager.matrixMode(5889); + GlStateManager.pushMatrix(); + GlStateManager.loadIdentity(); + Project.gluPerspective(fov, (float)height/width, 0.05F, 10.0F); + GlStateManager.matrixMode(5888); + GlStateManager.pushMatrix(); + GlStateManager.loadIdentity(); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.rotate(180F, 1.0F, 0.0F, 0.0F); + GlStateManager.rotate(90, 0.0F, 0.0F, 1.0F); + GlStateManager.rotate(19, 1.0F, 0.0F, 0.0F); + //GlStateManager.rotate(tl.x, 0.0F, 0.0F, 1.0F); + GlStateManager.enableBlend(); + GlStateManager.disableAlpha(); + GlStateManager.disableCull(); + GlStateManager.depthMask(false); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + + GlStateManager.pushMatrix(); + + GlStateManager.translate(0, 0.37f, 0.8f); + + //GlStateManager.rotate(MathHelper.sin(currentTime/1.6f) * 5.0F, 1.0F, 0.0F, 0.0F); + GlStateManager.rotate(angle, 0.0F, 1.0F, 0.0F); + + + for (int k = 0; k < 6; ++k) { + GlStateManager.pushMatrix(); + + switch (k) { + case 1: + GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F); break; + case 2: + GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F); break; + case 3: + GlStateManager.rotate(-90.0F, 0.0F, 1.0F, 0.0F); break; + case 4: + GlStateManager.rotate(90.0F, 1.0F, 0.0F, 0.0F); break; + case 5: + GlStateManager.rotate(-90.0F, 1.0F, 0.0F, 0.0F); break; + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(panoramas[k]); + float splits = 0.1f; + for(float x1=0; x1<1; x1+=splits) { + for(float y1=0; y1<1; y1+=splits) { + worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); + + for(int i=0; i<4; i++) { + float x2 = (i == 0 || i == 3) ? x1 : x1+splits; + float y2 = (i >= 2) ? y1 : y1+splits; + + float xr = x2*2-1; + float yr = y2*2-1; + + float distSq = xr*xr+yr*yr+1; + float scale = (float)Math.sqrt(3/distSq); + + worldrenderer.pos(xr*scale , yr*scale , scale).tex(x2, y2).color(255, 255, 255, 255).endVertex(); + + } + + tessellator.draw(); + } + } + + GlStateManager.popMatrix(); + } + + GlStateManager.popMatrix(); + GlStateManager.colorMask(true, true, true, false); + + worldrenderer.setTranslation(0.0D, 0.0D, 0.0D); + GlStateManager.colorMask(true, true, true, true); + GlStateManager.matrixMode(5889); + GlStateManager.popMatrix(); + GlStateManager.matrixMode(5888); + GlStateManager.popMatrix(); + GlStateManager.depthMask(true); + GlStateManager.enableCull(); + GlStateManager.enableDepth(); + } + + if(backgroundTexture == null || lastWidth != width*scaledresolution.getScaleFactor() || lastHeight != height*scaledresolution.getScaleFactor()) { + DynamicTexture viewportTexture = new DynamicTexture(width*scaledresolution.getScaleFactor(), height*scaledresolution.getScaleFactor()); + backgroundTexture = Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation("background", viewportTexture); + lastWidth = width*scaledresolution.getScaleFactor(); + lastHeight = height*scaledresolution.getScaleFactor(); + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(backgroundTexture); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); + GL11.glCopyTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, 0, 0, width*scaledresolution.getScaleFactor(), height*scaledresolution.getScaleFactor()); + + Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(true); + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX); + worldrenderer.pos(x, y+height, 0) + .tex(0, 1).endVertex(); + worldrenderer.pos(x+width, y+height, 0) + .tex(0, 0).endVertex(); + worldrenderer.pos(x+width, y, 0) + .tex(1, 0).endVertex(); + worldrenderer.pos(x, y, 0) + .tex(1, 1).endVertex(); + tessellator.draw(); + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java index 25b7356d..d0d1e5fc 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java @@ -114,7 +114,7 @@ public class PlayerStats { return stats; } - public static Stats getFairyBonus(int fairyExchanges) { + private static Stats getFairyBonus(int fairyExchanges) { Stats bonus = new Stats(); bonus.addStat(SPEED, fairyExchanges/10); @@ -128,7 +128,7 @@ public class PlayerStats { return bonus; } - public static Stats getSkillBonus(JsonObject skillInfo) { + private static Stats getSkillBonus(JsonObject skillInfo) { JsonObject bonuses = Utils.getConstant("bonuses"); if(bonuses == null) return null; @@ -155,7 +155,7 @@ public class PlayerStats { return skillBonus; } - public static Stats getPetBonus(JsonObject profile) { + private static Stats getPetBonus(JsonObject profile) { JsonObject bonuses = Utils.getConstant("bonuses"); if(bonuses == null) return null; @@ -192,7 +192,7 @@ public class PlayerStats { return petBonus; } - public static float harpBonus(JsonObject profile) { + private static float harpBonus(JsonObject profile) { String talk_to_melody = Utils.getElementAsString(Utils.getElement(profile, "objectives.talk_to_melody.status"), "INCOMPLETE"); if(talk_to_melody.equalsIgnoreCase("COMPLETE")) { return 26; @@ -205,7 +205,6 @@ public class PlayerStats { public static Stats getPassiveBonuses(JsonObject skillInfo, JsonObject profile) { Stats passiveBonuses = new Stats(); - //TODO: null checking Stats fairyBonus = getFairyBonus((int)Utils.getElementAsFloat(Utils.getElement(profile, "fairy_exchanges"), 0)); Stats skillBonus = getSkillBonus(skillInfo); Stats petBonus = getPetBonus(profile); @@ -220,7 +219,7 @@ public class PlayerStats { return passiveBonuses; } - public static String getFullset(JsonArray armor, int ignore) { + private static String getFullset(JsonArray armor, int ignore) { String fullset = null; for(int i=0; i<armor.size(); i++) { if(i == ignore) continue; @@ -247,7 +246,7 @@ public class PlayerStats { return fullset; } - public static Stats getSetBonuses(Stats stats, JsonObject inventoryInfo, JsonObject collectionInfo, JsonObject skillInfo, JsonObject profile) { + private static Stats getSetBonuses(Stats stats, JsonObject inventoryInfo, JsonObject collectionInfo, JsonObject skillInfo, JsonObject profile) { JsonArray armor = Utils.getElement(inventoryInfo, "inv_armor").getAsJsonArray(); Stats bonuses = new Stats(); @@ -320,7 +319,7 @@ public class PlayerStats { private static String[] rarityArr = new String[] { "COMMON", "UNCOMMON", "RARE", "EPIC", "LEGENDARY", "MYTHIC", "SPECIAL", "VERY SPECIAL", }; - public static int checkItemType(JsonArray lore, boolean contains, String... typeMatches) { + private static int checkItemType(JsonArray lore, boolean contains, String... typeMatches) { for(int i=lore.size()-1; i>=0; i--) { String line = lore.get(i).getAsString(); for(String rarity : rarityArr) { @@ -365,7 +364,7 @@ public class PlayerStats { STAT_PATTERN_MAP.put("intelligence", INTELLIGENCE_PATTERN); STAT_PATTERN_MAP.put("sea_creature_chance", SCC_PATTERN); } - public static Stats getStatForItem(String internalname, JsonObject item, JsonArray lore) { + private static Stats getStatForItem(String internalname, JsonObject item, JsonArray lore) { Stats stats = new Stats(); for(int i=0; i<lore.size(); i++) { String line = lore.get(i).getAsString(); @@ -413,7 +412,7 @@ public class PlayerStats { } return stats; } - public static Stats getItemBonuses(boolean talismanOnly, JsonArray... inventories) { + private static Stats getItemBonuses(boolean talismanOnly, JsonArray... inventories) { JsonObject misc = Utils.getConstant("misc"); if(misc == null) return null; JsonElement talisman_upgrades_element = misc.get("talisman_upgrades"); @@ -431,7 +430,7 @@ public class PlayerStats { if(itemBonuses.containsKey(internalname)) { continue; } - if(!talismanOnly || checkItemType(item.get("lore").getAsJsonArray(), true, "ACCESSORY") >= 0) { + if(!talismanOnly || checkItemType(item.get("lore").getAsJsonArray(), true, "ACCESSORY", "HATCCESSORY") >= 0) { Stats itemBonus = getStatForItem(internalname, item, item.get("lore").getAsJsonArray()); itemBonuses.put(internalname, itemBonus); @@ -457,7 +456,7 @@ public class PlayerStats { return itemBonusesStats; } - public static float getStatMult(JsonObject inventoryInfo) { + private static float getStatMult(JsonObject inventoryInfo) { float mult = 1f; JsonArray armor = Utils.getElement(inventoryInfo, "inv_armor").getAsJsonArray(); @@ -485,7 +484,7 @@ public class PlayerStats { return mult; } - public static void applyLimits(Stats stats, JsonObject inventoryInfo) { + private static void applyLimits(Stats stats, JsonObject inventoryInfo) { //>0 JsonArray armor = Utils.getElement(inventoryInfo, "inv_armor").getAsJsonArray(); @@ -508,6 +507,8 @@ public class PlayerStats { } public static Stats getStats(JsonObject skillInfo, JsonObject inventoryInfo, JsonObject collectionInfo, JsonObject profile) { + if(skillInfo == null || inventoryInfo == null || collectionInfo == null || profile == null) return null; + JsonArray armor = Utils.getElement(inventoryInfo, "inv_armor").getAsJsonArray(); JsonArray inventory = Utils.getElement(inventoryInfo, "inv_contents").getAsJsonArray(); JsonArray talisman_bag = Utils.getElement(inventoryInfo, "talisman_bag").getAsJsonArray(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java index db90cca8..5706dee9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java @@ -9,17 +9,20 @@ import io.github.moulberry.notenoughupdates.NEUManager; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; -import java.util.Base64; -import java.util.HashMap; -import java.util.List; +import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; import java.util.regex.Matcher; @@ -33,6 +36,27 @@ public class ProfileViewer { this.manager = manager; } + private static final LinkedHashMap<String, ItemStack> skillToSkillDisplayMap = new LinkedHashMap<>(); + static { + skillToSkillDisplayMap.put("skill_taming", Utils.createItemStack(Items.spawn_egg, EnumChatFormatting.LIGHT_PURPLE+"Taming")); + skillToSkillDisplayMap.put("skill_mining", Utils.createItemStack(Items.stone_pickaxe, EnumChatFormatting.GRAY+"Mining")); + skillToSkillDisplayMap.put("skill_foraging", Utils.createItemStack(Item.getItemFromBlock(Blocks.sapling), EnumChatFormatting.DARK_GREEN+"Foraging")); + skillToSkillDisplayMap.put("skill_enchanting", Utils.createItemStack(Item.getItemFromBlock(Blocks.enchanting_table), EnumChatFormatting.GREEN+"Enchanting")); + skillToSkillDisplayMap.put("skill_carpentry", Utils.createItemStack(Item.getItemFromBlock(Blocks.crafting_table), EnumChatFormatting.DARK_RED+"Carpentry")); + skillToSkillDisplayMap.put("skill_farming", Utils.createItemStack(Items.golden_hoe, EnumChatFormatting.YELLOW+"Farming")); + skillToSkillDisplayMap.put("skill_combat", Utils.createItemStack(Items.stone_sword, EnumChatFormatting.RED+"Combat")); + skillToSkillDisplayMap.put("skill_fishing", Utils.createItemStack(Items.fishing_rod, EnumChatFormatting.AQUA+"Fishing")); + skillToSkillDisplayMap.put("skill_alchemy", Utils.createItemStack(Items.brewing_stand, EnumChatFormatting.BLUE+"Alchemy")); + skillToSkillDisplayMap.put("skill_runecrafting", Utils.createItemStack(Items.magma_cream, EnumChatFormatting.DARK_PURPLE+"Runecrafting")); + skillToSkillDisplayMap.put("slayer_zombie", Utils.createItemStack(Items.rotten_flesh, EnumChatFormatting.GOLD+"Rev Slayer")); + skillToSkillDisplayMap.put("slayer_spider", Utils.createItemStack(Items.spider_eye, EnumChatFormatting.GOLD+"Tara Slayer")); + skillToSkillDisplayMap.put("slayer_wolf", Utils.createItemStack(Items.bone, EnumChatFormatting.GOLD+"Sven Slayer")); + } + + public static Map<String, ItemStack> getSkillToSkillDisplayMap() { + return Collections.unmodifiableMap(skillToSkillDisplayMap); + } + public class Profile { private final String uuid; private String latestProfile = null; @@ -44,13 +68,38 @@ public class ProfileViewer { private final HashMap<String, JsonObject> skillInfoMap = new HashMap<>(); private final HashMap<String, JsonObject> inventoryInfoMap = new HashMap<>(); private final HashMap<String, JsonObject> collectionInfoMap = new HashMap<>(); + private JsonObject playerStatus = null; private PlayerStats.Stats stats = null; + private PlayerStats.Stats passiveStats = null; public Profile(String uuid) { this.uuid = uuid; } private AtomicBoolean updatingPlayerInfoState = new AtomicBoolean(false); + private AtomicBoolean updatingPlayerStatusState = new AtomicBoolean(false); + + public JsonObject getPlayerStatus() { + if(playerStatus != null) return playerStatus; + if(updatingPlayerStatusState.get()) return null; + + updatingPlayerStatusState.set(true); + + HashMap<String, String> args = new HashMap<>(); + args.put("uuid", ""+uuid); + manager.hypixelApi.getHypixelApiAsync(manager.config.apiKey.value, "status", + args, jsonObject -> { + if(jsonObject == null) return; + + updatingPlayerStatusState.set(false); + if(jsonObject.has("success") && jsonObject.get("success").getAsBoolean()) { + playerStatus = jsonObject.get("session").getAsJsonObject(); + } + }, () -> updatingPlayerStatusState.set(false) + ); + + return null; + } public JsonArray getPlayerInformation(Runnable runnable) { if(playerInformation != null) return playerInformation; @@ -62,6 +111,8 @@ public class ProfileViewer { args.put("uuid", ""+uuid); manager.hypixelApi.getHypixelApiAsync(manager.config.apiKey.value, "skyblock/profiles", args, jsonObject -> { + if(jsonObject == null) return; + updatingPlayerInfoState.set(false); if(jsonObject.has("success") && jsonObject.get("success").getAsBoolean()) { playerInformation = jsonObject.get("profiles").getAsJsonArray(); @@ -79,17 +130,21 @@ public class ProfileViewer { if(members.has(uuid)) { JsonObject member = members.get(uuid).getAsJsonObject(); - long last_save = member.get("last_save").getAsLong(); - if(last_save > backupLastSave) { - backupLastSave = last_save; - backup = cute_name; + if(member.has("last_save")) { + long last_save = member.get("last_save").getAsLong(); + if(last_save > backupLastSave) { + backupLastSave = last_save; + backup = cute_name; + } } } } System.out.println("accepting runnable"); - runnable.run(); + if(runnable != null) runnable.run(); latestProfile = backup; } + }, () -> { + updatingPlayerInfoState.set(false); } ); @@ -103,6 +158,10 @@ public class ProfileViewer { if(profileMap.containsKey(profileId)) return profileMap.get(profileId); for(int i=0; i<playerInformation.size(); i++) { + if(!playerInformation.get(i).isJsonObject()) { + playerInformation = null; + return null; + } JsonObject profile = playerInformation.get(i).getAsJsonObject(); if(profile.get("cute_name").getAsString().equalsIgnoreCase(profileId)) { if(!profile.has("members")) return null; @@ -125,22 +184,41 @@ public class ProfileViewer { public void resetCache() { playerInformation = null; basicInfo = null; + playerStatus = null; profileMap.clear(); skillInfoMap.clear(); inventoryInfoMap.clear(); collectionInfoMap.clear(); } - public float getLevel(JsonArray levelingArray, float xp) { + private class Level { + private float level = 0; + private float maxXpForLevel = 0; + private boolean maxed = false; + } + + public Level getLevel(JsonArray levelingArray, float xp, boolean cumulative) { + Level levelObj = new Level(); for(int level=0; level<levelingArray.size(); level++) { float levelXp = levelingArray.get(level).getAsFloat(); if(levelXp > xp) { - return level + xp/levelXp; + if(cumulative) { + float previous = 0; + if(level > 0) previous = levelingArray.get(level-1).getAsFloat(); + levelObj.maxXpForLevel = (levelXp-previous); + levelObj.level = 1 + level + (xp-levelXp)/levelObj.maxXpForLevel; + } else { + levelObj.maxXpForLevel = levelXp; + levelObj.level = level + xp/levelXp; + } + return levelObj; } else { - xp -= levelXp; + if(!cumulative) xp -= levelXp; } } - return levelingArray.size(); + levelObj.level = levelingArray.size(); + levelObj.maxed = true; + return levelObj; } public JsonObject getSkillInfo(String profileId) { @@ -164,7 +242,7 @@ public class ProfileViewer { float experience_slayer_zombie = Utils.getElementAsFloat(Utils.getElement(profileInfo, "slayer_bosses.zombie.xp"), 0); float experience_slayer_spider = Utils.getElementAsFloat(Utils.getElement(profileInfo, "slayer_bosses.spider.xp"), 0); - float experience_slayer_wolf = Utils.getElementAsFloat(Utils.getElement(profileInfo, "slayer_bosses.zombie.xp"), 0); + float experience_slayer_wolf = Utils.getElementAsFloat(Utils.getElement(profileInfo, "slayer_bosses.wolf.xp"), 0); float totalSkillXP = experience_skill_taming + experience_skill_mining + experience_skill_foraging + experience_skill_enchanting + experience_skill_carpentry + experience_skill_farming @@ -193,20 +271,65 @@ public class ProfileViewer { skillInfo.addProperty("experience_slayer_spider", experience_slayer_spider); skillInfo.addProperty("experience_slayer_wolf", experience_slayer_wolf); - skillInfo.addProperty("level_skill_taming", getLevel(Utils.getElement(leveling, "leveling_xp").getAsJsonArray(), experience_skill_taming)); - skillInfo.addProperty("level_skill_mining", getLevel(Utils.getElement(leveling, "leveling_xp").getAsJsonArray(), experience_skill_mining)); - skillInfo.addProperty("level_skill_foraging", getLevel(Utils.getElement(leveling, "leveling_xp").getAsJsonArray(), experience_skill_foraging)); - skillInfo.addProperty("level_skill_enchanting", getLevel(Utils.getElement(leveling, "leveling_xp").getAsJsonArray(), experience_skill_enchanting)); - skillInfo.addProperty("level_skill_carpentry", getLevel(Utils.getElement(leveling, "leveling_xp").getAsJsonArray(), experience_skill_carpentry)); - skillInfo.addProperty("level_skill_farming", getLevel(Utils.getElement(leveling, "leveling_xp").getAsJsonArray(), experience_skill_farming)); - skillInfo.addProperty("level_skill_combat", getLevel(Utils.getElement(leveling, "leveling_xp").getAsJsonArray(), experience_skill_combat)); - skillInfo.addProperty("level_skill_fishing", getLevel(Utils.getElement(leveling, "leveling_xp").getAsJsonArray(), experience_skill_fishing)); - skillInfo.addProperty("level_skill_alchemy", getLevel(Utils.getElement(leveling, "leveling_xp").getAsJsonArray(), experience_skill_alchemy)); - skillInfo.addProperty("level_skill_runecrafting", getLevel(Utils.getElement(leveling, "leveling_xp").getAsJsonArray(), experience_skill_runecrafting)); - - skillInfo.addProperty("level_slayer_zombie", getLevel(Utils.getElement(leveling, "slayer_xp.zombie").getAsJsonArray(), experience_slayer_zombie)); - skillInfo.addProperty("level_slayer_spider", getLevel(Utils.getElement(leveling, "slayer_xp.spider").getAsJsonArray(), experience_slayer_spider)); - skillInfo.addProperty("level_slayer_wolf", getLevel(Utils.getElement(leveling, "slayer_xp.wolf").getAsJsonArray(), experience_slayer_wolf)); + Level level_skill_taming = getLevel(Utils.getElement(leveling, "leveling_xp").getAsJsonArray(), experience_skill_taming, false); + Level level_skill_mining = getLevel(Utils.getElement(leveling, "leveling_xp").getAsJsonArray(), experience_skill_mining, false); + Level level_skill_foraging = getLevel(Utils.getElement(leveling, "leveling_xp").getAsJsonArray(), experience_skill_foraging, false); + Level level_skill_enchanting = getLevel(Utils.getElement(leveling, "leveling_xp").getAsJsonArray(), experience_skill_enchanting, false); + Level level_skill_carpentry = getLevel(Utils.getElement(leveling, "leveling_xp").getAsJsonArray(), experience_skill_carpentry, false); + Level level_skill_farming = getLevel(Utils.getElement(leveling, "leveling_xp").getAsJsonArray(), experience_skill_farming, false); + Level level_skill_combat = getLevel(Utils.getElement(leveling, "leveling_xp").getAsJsonArray(), experience_skill_combat, false); + Level level_skill_fishing = getLevel(Utils.getElement(leveling, "leveling_xp").getAsJsonArray(), experience_skill_fishing, false); + Level level_skill_alchemy = getLevel(Utils.getElement(leveling, "leveling_xp").getAsJsonArray(), experience_skill_alchemy, false); + Level level_skill_runecrafting = getLevel(Utils.getElement(leveling, "runecrafting_xp").getAsJsonArray(), experience_skill_runecrafting, false); + + Level level_slayer_zombie = getLevel(Utils.getElement(leveling, "slayer_xp.zombie").getAsJsonArray(), experience_slayer_zombie, true); + Level level_slayer_spider = getLevel(Utils.getElement(leveling, "slayer_xp.spider").getAsJsonArray(), experience_slayer_spider, true); + Level level_slayer_wolf = getLevel(Utils.getElement(leveling, "slayer_xp.wolf").getAsJsonArray(), experience_slayer_wolf, true); + + skillInfo.addProperty("level_skill_taming", level_skill_taming.level); + skillInfo.addProperty("level_skill_mining", level_skill_mining.level); + skillInfo.addProperty("level_skill_foraging", level_skill_foraging.level); + skillInfo.addProperty("level_skill_enchanting", level_skill_enchanting.level); + skillInfo.addProperty("level_skill_carpentry", level_skill_carpentry.level); + skillInfo.addProperty("level_skill_farming", level_skill_farming.level); + skillInfo.addProperty("level_skill_combat", level_skill_combat.level); + skillInfo.addProperty("level_skill_fishing", level_skill_fishing.level); + skillInfo.addProperty("level_skill_alchemy", level_skill_alchemy.level); + skillInfo.addProperty("level_skill_runecrafting", level_skill_runecrafting.level); + + skillInfo.addProperty("level_slayer_zombie", level_slayer_zombie.level); + skillInfo.addProperty("level_slayer_spider", level_slayer_spider.level); + skillInfo.addProperty("level_slayer_wolf", level_slayer_wolf.level); + + skillInfo.addProperty("maxed_skill_taming", level_skill_taming.maxed); + skillInfo.addProperty("maxed_skill_mining", level_skill_mining.maxed); + skillInfo.addProperty("maxed_skill_foraging", level_skill_foraging.maxed); + skillInfo.addProperty("maxed_skill_enchanting", level_skill_enchanting.maxed); + skillInfo.addProperty("maxed_skill_carpentry", level_skill_carpentry.maxed); + skillInfo.addProperty("maxed_skill_farming", level_skill_farming.maxed); + skillInfo.addProperty("maxed_skill_combat", level_skill_combat.maxed); + skillInfo.addProperty("maxed_skill_fishing", level_skill_fishing.maxed); + skillInfo.addProperty("maxed_skill_alchemy", level_skill_alchemy.maxed); + skillInfo.addProperty("maxed_skill_runecrafting", level_skill_runecrafting.maxed); + + skillInfo.addProperty("maxed_slayer_zombie", level_slayer_zombie.maxed); + skillInfo.addProperty("maxed_slayer_spider", level_slayer_spider.maxed); + skillInfo.addProperty("maxed_slayer_wolf", level_slayer_wolf.maxed); + + skillInfo.addProperty("maxxp_skill_taming", level_skill_taming.maxXpForLevel); + skillInfo.addProperty("maxxp_skill_mining", level_skill_mining.maxXpForLevel); + skillInfo.addProperty("maxxp_skill_foraging", level_skill_foraging.maxXpForLevel); + skillInfo.addProperty("maxxp_skill_enchanting", level_skill_enchanting.maxXpForLevel); + skillInfo.addProperty("maxxp_skill_carpentry", level_skill_carpentry.maxXpForLevel); + skillInfo.addProperty("maxxp_skill_farming", level_skill_farming.maxXpForLevel); + skillInfo.addProperty("maxxp_skill_combat", level_skill_combat.maxXpForLevel); + skillInfo.addProperty("maxxp_skill_fishing", level_skill_fishing.maxXpForLevel); + skillInfo.addProperty("maxxp_skill_alchemy", level_skill_alchemy.maxXpForLevel); + skillInfo.addProperty("maxxp_skill_runecrafting", level_skill_runecrafting.maxXpForLevel); + + skillInfo.addProperty("maxxp_slayer_zombie", level_slayer_zombie.maxXpForLevel); + skillInfo.addProperty("maxxp_slayer_spider", level_slayer_spider.maxXpForLevel); + skillInfo.addProperty("maxxp_slayer_wolf", level_slayer_wolf.maxXpForLevel); return skillInfo; } @@ -300,10 +423,24 @@ public class ProfileViewer { return collectionInfo; } + public PlayerStats.Stats getPassiveStats(String profileId) { + if(passiveStats != null) return passiveStats; + JsonObject profileInfo = getProfileInformation(profileId); + if(profileInfo == null) return null; + + passiveStats = PlayerStats.getPassiveBonuses(getSkillInfo(profileId), profileInfo); + + if(passiveStats != null) { + passiveStats.add(PlayerStats.getBaseStats()); + } + + return passiveStats; + } + public PlayerStats.Stats getStats(String profileId) { if(stats != null) return stats; JsonObject profileInfo = getProfileInformation(profileId); - if(profileInfo == null) return PlayerStats.getBaseStats(); + if(profileInfo == null) return null; stats = PlayerStats.getStats(getSkillInfo(profileId), getInventoryInfo(profileId), getCollectionInfo(profileId), profileInfo); return stats; @@ -328,7 +465,9 @@ public class ProfileViewer { args.put("name", ""+name); manager.hypixelApi.getHypixelApiAsync(manager.config.apiKey.value, "player", args, jsonObject -> { - if(jsonObject.has("success") && jsonObject.get("success").getAsBoolean()) { + if(jsonObject == null) return; + + if(jsonObject.has("success") && jsonObject.get("success").getAsBoolean()) { nameToHypixelProfile.put(name, jsonObject.get("player").getAsJsonObject()); uuidToHypixelProfile.put(jsonObject.get("player").getAsJsonObject().get("uuid").getAsString(), jsonObject.get("player").getAsJsonObject()); if(callback != null) callback.accept(jsonObject); @@ -339,14 +478,15 @@ public class ProfileViewer { public Profile getProfileByName(String name, Consumer<Profile> callback) { if(nameToHypixelProfile.containsKey(name)) { - return getProfileReset(nameToHypixelProfile.get(name).get("uuid").getAsString(), callback); + Profile profile = getProfileReset(nameToHypixelProfile.get(name).get("uuid").getAsString(), ignored -> {}); + callback.accept(profile); + return profile; } else { getHypixelProfile(name, jsonObject -> { - System.out.println("getting profile with callback"); - getProfileReset(jsonObject.get("player").getAsJsonObject().get("uuid").getAsString(), callback); + callback.accept(getProfileReset(jsonObject.get("player").getAsJsonObject().get("uuid").getAsString(), ignored -> {})); }); - return null; } + return null; } public Profile getProfile(String uuid, Consumer<Profile> callback) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/questing/NEUQuesting.java b/src/main/java/io/github/moulberry/notenoughupdates/questing/NEUQuesting.java deleted file mode 100644 index 8be12c95..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/questing/NEUQuesting.java +++ /dev/null @@ -1,67 +0,0 @@ -package io.github.moulberry.notenoughupdates.questing; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.scoreboard.Score; -import net.minecraft.scoreboard.ScoreObjective; -import net.minecraft.scoreboard.ScorePlayerTeam; -import net.minecraft.scoreboard.Scoreboard; -import net.minecraft.util.EnumChatFormatting; - -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class NEUQuesting { - - private static final NEUQuesting INSTANCE = new NEUQuesting(); - - private static final Pattern locationPattern = Pattern.compile("(\\u00a7)(?!.*\\u00a7).+"); - private static final Pattern timePattern = Pattern.compile(".+(am|pm)"); - - public String location = ""; - public String date = ""; - public String time = ""; - - public static NEUQuesting getInstance() { - return INSTANCE; - } - - public void tick() { - Scoreboard scoreboard = Minecraft.getMinecraft().thePlayer.getWorldScoreboard(); - - ScoreObjective sidebarObjective = scoreboard.getObjectiveInDisplaySlot(1); //§707/14/20 - - List<Score> scores = new ArrayList<>(); - for(Score score : scoreboard.getSortedScores(sidebarObjective)) { - scores.add(score); - } - List<String> lines = new ArrayList<>(); - for(int i=scores.size()-1; i>=0; i--) { - Score score = scores.get(i); - ScorePlayerTeam scoreplayerteam1 = scoreboard.getPlayersTeam(score.getPlayerName()); - String line = ScorePlayerTeam.formatPlayerName(scoreplayerteam1, score.getPlayerName()); - line = Utils.cleanDuplicateColourCodes(line); - lines.add(line); - } - if(lines.size() >= 5) { - date = Utils.cleanColour(lines.get(2)).trim(); - //§74:40am - Matcher matcher = timePattern.matcher(lines.get(3)); - if(matcher.find()) { - time = Utils.cleanColour(matcher.group()).trim(); - } - matcher = locationPattern.matcher(lines.get(4)); - if(matcher.find()) { - location = Utils.cleanColour(matcher.group()).trim(); - } - } - //System.out.println(date + ":" + time + ":" + location); - } - -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/questing/SBScoreboardData.java b/src/main/java/io/github/moulberry/notenoughupdates/questing/SBScoreboardData.java new file mode 100644 index 00000000..89ec44cc --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/questing/SBScoreboardData.java @@ -0,0 +1,76 @@ +package io.github.moulberry.notenoughupdates.questing; + +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.scoreboard.Score; +import net.minecraft.scoreboard.ScoreObjective; +import net.minecraft.scoreboard.ScorePlayerTeam; +import net.minecraft.scoreboard.Scoreboard; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class SBScoreboardData { + + private static final SBScoreboardData INSTANCE = new SBScoreboardData(); + + private static final Pattern locationPattern = Pattern.compile("(\\u00a7)(?!.*\\u00a7).+"); + private static final Pattern timePattern = Pattern.compile(".+(am|pm)"); + + public String location = ""; + public String date = ""; + public String time = ""; + + public Date currentTimeDate = null; + + + public static SBScoreboardData getInstance() { + return INSTANCE; + } + + public void tick() { + try { + Scoreboard scoreboard = Minecraft.getMinecraft().thePlayer.getWorldScoreboard(); + + ScoreObjective sidebarObjective = scoreboard.getObjectiveInDisplaySlot(1); //§707/14/20 + + List<Score> scores = new ArrayList<>(); + for(Score score : scoreboard.getSortedScores(sidebarObjective)) { + scores.add(score); + } + List<String> lines = new ArrayList<>(); + for(int i=scores.size()-1; i>=0; i--) { + Score score = scores.get(i); + ScorePlayerTeam scoreplayerteam1 = scoreboard.getPlayersTeam(score.getPlayerName()); + String line = ScorePlayerTeam.formatPlayerName(scoreplayerteam1, score.getPlayerName()); + line = Utils.cleanDuplicateColourCodes(line); + lines.add(line); + } + if(lines.size() >= 5) { + date = Utils.cleanColour(lines.get(2)).trim(); + //§74:40am + Matcher matcher = timePattern.matcher(lines.get(3)); + if(matcher.find()) { + time = Utils.cleanColour(matcher.group()).trim(); + + try { + String timeSpace = time.replace("am", " am").replace("pm", " pm"); + SimpleDateFormat parseFormat = new SimpleDateFormat("hh:mm a"); + currentTimeDate = parseFormat.parse(timeSpace); + } catch (ParseException e) {} + } + matcher = locationPattern.matcher(lines.get(4)); + if(matcher.find()) { + location = Utils.cleanColour(matcher.group()).trim(); + } + } + } catch(Exception e) {} + //System.out.println(date + ":" + time + ":" + location); + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/RequirementApi.java b/src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/RequirementApi.java index 27f9f293..a53ed56b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/RequirementApi.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/RequirementApi.java @@ -3,10 +3,8 @@ package io.github.moulberry.notenoughupdates.questing.requirements; import com.google.common.base.Splitter; import com.google.gson.*; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.questing.NEUQuesting; import java.util.List; -import java.util.Map; public class RequirementApi extends Requirement { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/RequirementIslandType.java b/src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/RequirementIslandType.java index 5ee005f5..319bc1b6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/RequirementIslandType.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/RequirementIslandType.java @@ -1,6 +1,6 @@ package io.github.moulberry.notenoughupdates.questing.requirements; -import io.github.moulberry.notenoughupdates.questing.NEUQuesting; +import io.github.moulberry.notenoughupdates.questing.SBScoreboardData; public class RequirementIslandType extends Requirement { @@ -14,6 +14,6 @@ public class RequirementIslandType extends Requirement { @Override public void updateRequirement() { - completed = islandType.equalsIgnoreCase(NEUQuesting.getInstance().location); + completed = islandType.equalsIgnoreCase(SBScoreboardData.getInstance().location); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java b/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java index 133619ae..05351629 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java @@ -27,24 +27,28 @@ public class HypixelApi { private ExecutorService es = Executors.newCachedThreadPool(); public void getHypixelApiAsync(String apiKey, String method, HashMap<String, String> args, Consumer<JsonObject> consumer) { - getHypixelApiAsync(generateApiUrl(apiKey.trim(), method, args), consumer); + getHypixelApiAsync(apiKey, method, args, consumer, () -> {}); } - public void getHypixelApiAsync(String urlS, Consumer<JsonObject> consumer) { + public void getHypixelApiAsync(String apiKey, String method, HashMap<String, String> args, Consumer<JsonObject> consumer, Runnable error) { + getHypixelApiAsync(generateApiUrl(apiKey.trim(), method, args), consumer, error); + } + + public void getHypixelApiAsync(String urlS, Consumer<JsonObject> consumer, Runnable error) { es.submit(() -> { - consumer.accept(getHypixelApiSync(urlS)); + try { + consumer.accept(getHypixelApiSync(urlS)); + } catch(IOException e) { + error.run(); + } }); } - public JsonObject getHypixelApiSync(String urlS) { - URLConnection connection; - try { - URL url = new URL(urlS); - connection = url.openConnection(); - connection.setConnectTimeout(3000); - } catch(IOException e) { - return null; - } + public JsonObject getHypixelApiSync(String urlS) throws IOException { + + URL url = new URL(urlS); + URLConnection connection = url.openConnection(); + connection.setConnectTimeout(3000); try(BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) { StringBuilder builder = new StringBuilder(); @@ -56,8 +60,6 @@ public class HypixelApi { JsonObject json = gson.fromJson(response, JsonObject.class); return json; - } catch(IOException e) { - return null; } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java index 66400c00..5fe96aae 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -13,13 +13,18 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.audio.SoundHandler; import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.block.model.ItemCameraTransforms; import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.client.renderer.texture.DynamicTexture; +import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.client.resources.model.IBakedModel; import net.minecraft.event.ClickEvent; import net.minecraft.event.HoverEvent; import net.minecraft.inventory.Slot; @@ -33,6 +38,7 @@ import net.minecraft.util.*; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL14; +import org.lwjgl.util.glu.Project; import javax.swing.*; import java.awt.*; @@ -89,6 +95,80 @@ public class Utils { RenderHelper.disableStandardItemLighting(); } + private static final EnumChatFormatting[] rainbow = new EnumChatFormatting[]{ + EnumChatFormatting.RED, + EnumChatFormatting.GOLD, + EnumChatFormatting.YELLOW, + EnumChatFormatting.GREEN, + EnumChatFormatting.AQUA, + EnumChatFormatting.LIGHT_PURPLE, + EnumChatFormatting.DARK_PURPLE + }; + + public static String chromaString(String str) { + long currentTimeMillis = System.currentTimeMillis(); + + StringBuilder rainbowText = new StringBuilder(); + for(int i=0; i<str.length(); i++) { + char c = str.charAt(i); + int index = (int)(i-currentTimeMillis/100)%rainbow.length; + if(index < 0) index += rainbow.length; + rainbowText.append(rainbow[index]).append(c); + } + return rainbowText.toString(); + } + + public static void drawItemStackLinear(ItemStack stack, int x, int y) { + if(stack == null)return; + + RenderItem itemRender = Minecraft.getMinecraft().getRenderItem(); + + RenderHelper.enableGUIStandardItemLighting(); + itemRender.zLevel = -145; //Negates the z-offset of the below method. + + IBakedModel ibakedmodel = itemRender.getItemModelMesher().getItemModel(stack); + GlStateManager.pushMatrix(); + Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture); + Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture).setBlurMipmap(true, true); + GlStateManager.enableRescaleNormal(); + GlStateManager.enableAlpha(); + GlStateManager.alphaFunc(516, 0.1F); + GlStateManager.enableBlend(); + GlStateManager.blendFunc(770, 771); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + setupGuiTransform(x, y, ibakedmodel.isGui3d()); + ibakedmodel = net.minecraftforge.client.ForgeHooksClient.handleCameraTransforms(ibakedmodel, ItemCameraTransforms.TransformType.GUI); + itemRender.renderItem(stack, ibakedmodel); + GlStateManager.disableAlpha(); + GlStateManager.disableRescaleNormal(); + GlStateManager.disableLighting(); + GlStateManager.popMatrix(); + Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture); + Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture).restoreLastBlurMipmap(); + + itemRender.renderItemOverlays(Minecraft.getMinecraft().fontRendererObj, stack, x, y); + itemRender.zLevel = 0; + RenderHelper.disableStandardItemLighting(); + } + + private static void setupGuiTransform(int xPosition, int yPosition, boolean isGui3d) { + GlStateManager.translate((float)xPosition, (float)yPosition, 5); + GlStateManager.translate(8.0F, 8.0F, 0.0F); + GlStateManager.scale(1.0F, 1.0F, -1.0F); + GlStateManager.scale(0.5F, 0.5F, 0.5F); + + if (isGui3d) { + GlStateManager.scale(40.0F, 40.0F, 40.0F); + GlStateManager.rotate(210.0F, 1.0F, 0.0F, 0.0F); + GlStateManager.rotate(-135.0F, 0.0F, 1.0F, 0.0F); + GlStateManager.enableLighting(); + } else { + GlStateManager.scale(64.0F, 64.0F, 64.0F); + GlStateManager.rotate(180.0F, 1.0F, 0.0F, 0.0F); + GlStateManager.disableLighting(); + } + } + public static Method getMethod(Class<?> clazz, Class<?>[] params, String... methodNames) { for(String methodName : methodNames) { try { @@ -281,6 +361,15 @@ public class Utils { drawStringScaled(str, fr, x, y-fontHeight/2, shadow, colour, factor); } + public static void drawStringCenteredYScaledMaxWidth(String str, FontRenderer fr, float x, float y, boolean shadow, int len, int colour) { + int strLen = fr.getStringWidth(str); + float factor = len/(float)strLen; + factor = Math.min(1, factor); + float fontHeight = 8*factor; + + drawStringScaled(str, fr, x, y-fontHeight/2, shadow, colour, factor); + } + public static int renderStringTrimWidth(String str, FontRenderer fr, boolean shadow, int x, int y, int len, int colour, int maxLines) { return renderStringTrimWidth(str, fr, shadow, x, y, len, colour, maxLines, 1); } |