diff options
Diffstat (limited to 'src/main/java/io')
9 files changed, 559 insertions, 103 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index f78c7e96..ffd57b41 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -921,8 +921,14 @@ public class NEUManager { if(tag != null && tag.hasKey("ExtraAttributes", 10)) { NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); - if (ea.hasKey("new_year_cake_bag_data", 7)) { - byte[] bytes = ea.getByteArray("new_year_cake_bag_data"); + byte[] bytes = null; + for(String key : ea.getKeySet()) { + if(key.endsWith("backpack_data") || key.equals("new_year_cake_bag_data")) { + bytes = ea.getByteArray(key); + break; + } + } + if(bytes != null) { JsonArray bytesArr = new JsonArray(); for(byte b : bytes) { bytesArr.add(new JsonPrimitive(b)); @@ -1384,6 +1390,10 @@ public class NEUManager { JsonObject petInfo = petnums.get(petname).getAsJsonObject(); if(petInfo.has(tier)) { JsonObject petInfoTier = petInfo.get(tier).getAsJsonObject(); + if(petInfoTier == null || !petInfoTier.has("1") || !petInfoTier.has("100")) { + return replacements; + } + JsonObject min = petInfoTier.get("1").getAsJsonObject(); JsonObject max = petInfoTier.get("100").getAsJsonObject(); @@ -1402,7 +1412,23 @@ public class NEUManager { replacements.put(entry.getKey(), statStr); } } else { + float minMix = (100-level)/99f; + float maxMix = (level-1)/99f; + + JsonArray otherNumsMin = min.get("otherNums").getAsJsonArray(); + JsonArray otherNumsMax = max.get("otherNums").getAsJsonArray(); + for(int i=0; i<otherNumsMax.size(); i++) { + float val = otherNumsMin.get(i).getAsFloat()*minMix + otherNumsMax.get(i).getAsFloat()*maxMix; + replacements.put(""+i, removeUnusedDecimal(Math.floor(val*10)/10f)); + } + for(Map.Entry<String, JsonElement> entry : max.get("statNums").getAsJsonObject().entrySet()) { + float statMax = entry.getValue().getAsFloat(); + float statMin = min.get("statNums").getAsJsonObject().get(entry.getKey()).getAsFloat(); + float val = statMin*minMix + statMax*maxMix; + String statStr = "+"+(int)Math.floor(val); + replacements.put(entry.getKey(), statStr); + } } } } @@ -1461,6 +1487,10 @@ public class NEUManager { } public ItemStack jsonToStack(JsonObject json, boolean useCache) { + return jsonToStack(json, useCache, true); + } + + public ItemStack jsonToStack(JsonObject json, boolean useCache, boolean useReplacements) { if(useCache && itemstackCache.containsKey(json.get("internalname").getAsString())) { return itemstackCache.get(json.get("internalname").getAsString()).copy(); } @@ -1487,13 +1517,17 @@ public class NEUManager { } } - HashMap<String, String> replacements = getLoreReplacements(stack.getTagCompound(), -1); + HashMap<String, String> replacements = new HashMap<>(); + + if(useReplacements) { + replacements = getLoreReplacements(stack.getTagCompound(), -1); - String displayname = json.get("displayname").getAsString(); - for(Map.Entry<String, String> entry : replacements.entrySet()) { - displayname = displayname.replace("{"+entry.getKey()+"}", entry.getValue()); + String displayname = json.get("displayname").getAsString(); + for(Map.Entry<String, String> entry : replacements.entrySet()) { + displayname = displayname.replace("{"+entry.getKey()+"}", entry.getValue()); + } + stack.setStackDisplayName(displayname); } - stack.setStackDisplayName(displayname); if(json.has("lore")) { NBTTagCompound display = new NBTTagCompound(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index 169b6b9f..f5475123 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -29,6 +29,7 @@ import net.minecraft.client.settings.KeyBinding; import net.minecraft.client.shader.Framebuffer; import net.minecraft.client.shader.Shader; import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.event.ClickEvent; import net.minecraft.init.Blocks; import net.minecraft.inventory.ContainerChest; @@ -167,13 +168,17 @@ public class NotEnoughUpdates { }, new SimpleCommand.TabCompleteRunnable() { @Override public List<String> tabComplete(ICommandSender sender, String[] args, BlockPos pos) { - /*if(args.length) { - - }*/ - for(String arg : args) { - System.out.println(arg); + if(args.length != 1) return null; + + String lastArg = args[args.length-1]; + List<String> playerMatches = new ArrayList<>(); + for(EntityPlayer player : Minecraft.getMinecraft().theWorld.playerEntities) { + String playerName = player.getName(); + if(playerName.toLowerCase().startsWith(lastArg.toLowerCase())) { + playerMatches.add(playerName); + } } - return null; + return playerMatches; } }); @@ -705,7 +710,8 @@ public class NotEnoughUpdates { missingRecipe.set(true); } //System.out.println(e.message); - if(isOnSkyblock() && manager.config.streamerMode.value && e.message instanceof ChatComponentText) { + if(unformatted.startsWith("Sending to server") && + isOnSkyblock() && manager.config.streamerMode.value && e.message instanceof ChatComponentText) { String m = e.message.getFormattedText(); String m2 = StreamerMode.filterChat(e.message.getFormattedText()); if(!m.equals(m2)) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/SBAIntegration.java b/src/main/java/io/github/moulberry/notenoughupdates/SBAIntegration.java new file mode 100644 index 00000000..502792df --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/SBAIntegration.java @@ -0,0 +1,196 @@ +package io.github.moulberry.notenoughupdates; + +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.item.ItemStack; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.List; + +public class SBAIntegration { + + private static boolean hasSBA = true; + private static Class<?> skyblockAddonsClass = null; + private static Method skyblockAddons_getInstance = null; + private static Method skyblockAddons_getUtils = null; + private static Class<?> backpackManagerClass = null; + private static Method backpackManager_getFromItem = null; + private static Class<?> backpackClass = null; + private static Method backpackClass_setX= null; + private static Method backpackClass_setY = null; + private static Class<?> utilsClass = null; + private static Method utils_setBackpackToPreview = null; + public static boolean setActiveBackpack(ItemStack stack, int mouseX, int mouseY) { + if(!hasSBA) return false; + try { + if(skyblockAddonsClass == null) { + skyblockAddonsClass = Class.forName("codes.biscuit.skyblockaddons.SkyblockAddons"); + } + if(skyblockAddons_getInstance == null) { + skyblockAddons_getInstance = skyblockAddonsClass.getDeclaredMethod("getInstance"); + } + if(skyblockAddons_getUtils == null) { + skyblockAddons_getUtils = skyblockAddonsClass.getDeclaredMethod("getUtils"); + } + if(backpackManagerClass == null) { + backpackManagerClass = Class.forName("codes.biscuit.skyblockaddons.utils.BackpackManager"); + } + if(backpackManager_getFromItem == null) { + backpackManager_getFromItem = backpackManagerClass.getDeclaredMethod("getFromItem", ItemStack.class); + } + if(backpackClass == null) { + backpackClass = Class.forName("codes.biscuit.skyblockaddons.utils.Backpack"); + } + if(backpackClass_setX == null) { + backpackClass_setX = backpackClass.getDeclaredMethod("setX", int.class); + } + if(backpackClass_setY == null) { + backpackClass_setY = backpackClass.getDeclaredMethod("setY", int.class); + } + if(utilsClass == null) { + utilsClass = Class.forName("codes.biscuit.skyblockaddons.utils.Utils"); + } + if(utils_setBackpackToPreview == null) { + utils_setBackpackToPreview = utilsClass.getDeclaredMethod("setBackpackToPreview", backpackClass); + } + } catch(Exception e) { + e.printStackTrace(); + hasSBA = false; + return false; + } + try { + Object skyblockAddons = skyblockAddons_getInstance.invoke(null); + Object utils = skyblockAddons_getUtils.invoke(skyblockAddons); + if(stack == null) { + utils_setBackpackToPreview.invoke(utils, (Object) null); + } else { + Object backpack = backpackManager_getFromItem.invoke(null, stack); + backpackClass_setX.invoke(backpack, mouseX); + backpackClass_setY.invoke(backpack, mouseY); + utils_setBackpackToPreview.invoke(utils, backpack); + } + } catch(Exception e) { return false; } + return true; + } + + private static Field guiContainerHook_freezeBackpack = null; + public static boolean isFreezeBackpack() { + if(!hasSBA) return false; + try { + if(guiContainerHookClass == null) { + guiContainerHookClass = Class.forName("codes.biscuit.skyblockaddons.asm.hooks.GuiContainerHook"); + } + if(guiContainerHook_freezeBackpack == null) { + guiContainerHook_freezeBackpack = guiContainerHookClass.getDeclaredField("freezeBackpack"); + guiContainerHook_freezeBackpack.setAccessible(true); + } + } catch(Exception e) { + e.printStackTrace(); + hasSBA = false; + return false; + } + try { + return (boolean) guiContainerHook_freezeBackpack.get(null); + } catch(Exception e) { + return false; + } + } + + public static boolean setFreezeBackpack(boolean freezeBackpack) { + if(!hasSBA) return false; + try { + if(guiContainerHookClass == null) { + guiContainerHookClass = Class.forName("codes.biscuit.skyblockaddons.asm.hooks.GuiContainerHook"); + } + if(guiContainerHook_freezeBackpack == null) { + guiContainerHook_freezeBackpack = guiContainerHookClass.getDeclaredField("freezeBackpack"); + guiContainerHook_freezeBackpack.setAccessible(true); + } + } catch(Exception e) { + e.printStackTrace(); + hasSBA = false; + return false; + } + try { + guiContainerHook_freezeBackpack.set(null, freezeBackpack); + return true; + } catch(Exception e) { + return false; + } + } + + private static Method guiContainerHook_keyTyped = null; + private static Method skyblockAddons_getFreezeBackpackKey = null; + public static boolean keyTyped(int keyCode) { + if(!hasSBA) return false; + try { + if(skyblockAddonsClass == null) { + skyblockAddonsClass = Class.forName("codes.biscuit.skyblockaddons.SkyblockAddons"); + } + if(skyblockAddons_getInstance == null) { + skyblockAddons_getInstance = skyblockAddonsClass.getDeclaredMethod("getInstance"); + } + if(skyblockAddons_getFreezeBackpackKey == null) { + skyblockAddons_getFreezeBackpackKey = skyblockAddonsClass.getDeclaredMethod("getFreezeBackpackKey"); + } + if(guiContainerHookClass == null) { + guiContainerHookClass = Class.forName("codes.biscuit.skyblockaddons.asm.hooks.GuiContainerHook"); + } + if(guiContainerHook_keyTyped == null) { + guiContainerHook_keyTyped = guiContainerHookClass.getDeclaredMethod("keyTyped", int.class); + } + } catch(Exception e) { + e.printStackTrace(); + hasSBA = false; + return false; + } + try { + Object skyblockAddons = skyblockAddons_getInstance.invoke(null); + if(!isFreezeBackpack() && ((KeyBinding)skyblockAddons_getFreezeBackpackKey.invoke(skyblockAddons)).getKeyCode() == keyCode) { + setFreezeBackpack(true); + } else { + guiContainerHook_keyTyped.invoke(null, keyCode); + } + } catch(Exception e) { return false; } + return true; + } + + private static Class<?> guiContainerHookClass = null; + private static Method guiContainerHook_drawBackpacks = null; + public static boolean renderActiveBackpack(int mouseX, int mouseY, FontRenderer fontRendererObj) { + if(!hasSBA) return false; + try { + if(guiContainerHookClass == null) { + guiContainerHookClass = Class.forName("codes.biscuit.skyblockaddons.asm.hooks.GuiContainerHook"); + } + if(guiContainerHook_drawBackpacks == null) { + guiContainerHook_drawBackpacks = guiContainerHookClass.getDeclaredMethod("drawBackpacks", + GuiContainer.class, int.class, int.class, FontRenderer.class); + } + } catch(Exception e) { + e.printStackTrace(); + hasSBA = false; + return false; + } + try { + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + + GuiContainer container = new GuiContainer(null) { + protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { + } + }; + container.setWorldAndResolution(Minecraft.getMinecraft(), width, height); + + guiContainerHook_drawBackpacks.invoke(null, container, mouseX, mouseY, fontRendererObj); + } catch(Exception e) { return false; } + return true; + } + +} 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 72baf3a7..07c21304 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java @@ -515,7 +515,7 @@ public class APIManager { if(itemType >= 0 && itemType < categoryItemType.length) { category = categoryItemType[itemType]; } - if(internalname.equals("ENCHANTED_BOOK")) category = "ebook"; + if(internalname.contains("ENCHANTED_BOOK")) category = "ebook"; if(extras.endsWith("Potion")) category = "potion"; if(extras.contains("Rune")) category = "rune"; if(item_lore.split("\n")[0].endsWith("Furniture")) category = "furniture"; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/Options.java b/src/main/java/io/github/moulberry/notenoughupdates/options/Options.java index 8cd82568..0de6cafc 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/Options.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/Options.java @@ -279,6 +279,8 @@ public class Options { public List<Option> getOptions() { List<Option> options = new ArrayList<>(); + //Pane width near top so less scuffed + tryAddOption(paneWidthMult, options); //Buttons tryAddOption(enableItemEditing, options); tryAddOption(onlyShowOnSkyblock, options); @@ -298,7 +300,6 @@ public class Options { tryAddOption(disableItemTabOpen, options); //Sliders tryAddOption(bgBlurFactor, options); - tryAddOption(paneWidthMult, options); tryAddOption(ahNotification, options); tryAddOption(bgOpacity, options); tryAddOption(fgOpacity, options); 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 6aa2a1ab..295bce12 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java @@ -8,6 +8,7 @@ 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.SBAIntegration; import io.github.moulberry.notenoughupdates.cosmetics.ShaderManager; import io.github.moulberry.notenoughupdates.itemeditor.GuiElementTextField; import io.github.moulberry.notenoughupdates.questing.SBScoreboardData; @@ -39,6 +40,7 @@ import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.*; import net.minecraft.util.*; import net.minecraft.world.World; import org.apache.commons.codec.binary.Base64; @@ -51,6 +53,7 @@ import org.lwjgl.opengl.GL14; import org.lwjgl.opengl.GL20; import java.awt.*; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.charset.Charset; import java.text.NumberFormat; @@ -98,8 +101,8 @@ public class GuiProfileViewer extends GuiScreen { INVALID_NAME(null), BASIC(new ItemStack(Items.paper)), INVS(new ItemStack(Item.getItemFromBlock(Blocks.ender_chest))), - COLS(new ItemStack(Items.painting)); - //PETS(new ItemStack(Items.bone)); + COLS(new ItemStack(Items.painting)), + PETS(new ItemStack(Items.bone)); public final ItemStack stack; @@ -127,7 +130,9 @@ public class GuiProfileViewer extends GuiScreen { currentTime = System.currentTimeMillis(); if(startTime == 0) startTime = currentTime; - if(profile == null) currentPage = ProfileViewerPage.INVALID_NAME; + if(profile == null) { + currentPage = ProfileViewerPage.INVALID_NAME; + } if(profileId == null && profile != null && profile.getLatestProfile() != null) { profileId = profile.getLatestProfile(); } @@ -143,13 +148,12 @@ public class GuiProfileViewer extends GuiScreen { blurBackground(); renderBlurredBackground(width, height, guiLeft+2, guiTop+2, sizeX-4, sizeY-4); + GlStateManager.enableDepth(); GlStateManager.translate(0, 0, 5); renderTabs(true); GlStateManager.translate(0, 0, -3); - Minecraft.getMinecraft().getTextureManager().bindTexture(pv_bg); - Utils.drawTexturedRect(guiLeft, guiTop, sizeX, sizeY, GL11.GL_NEAREST); - + GlStateManager.disableDepth(); GlStateManager.translate(0, 0, -2); renderTabs(false); GlStateManager.translate(0, 0, 2); @@ -161,30 +165,8 @@ public class GuiProfileViewer extends GuiScreen { GlStateManager.enableAlpha(); GlStateManager.alphaFunc(516, 0.1F); - switch (currentPage) { - case BASIC: - drawBasicPage(mouseX, mouseY, partialTicks); - break; - case INVS: - drawInvsPage(mouseX, mouseY, partialTicks); - break; - case COLS: - drawColsPage(mouseX, mouseY, partialTicks); - break; - case LOADING: - Utils.drawStringCentered(EnumChatFormatting.YELLOW+"Loading player profiles...", Minecraft.getMinecraft().fontRendererObj, - guiLeft+sizeX/2f, guiTop+101, true, 0); - break; - case INVALID_NAME: - Utils.drawStringCentered(EnumChatFormatting.RED+"Invalid name or API is down!", Minecraft.getMinecraft().fontRendererObj, - guiLeft+sizeX/2f, guiTop+101, true, 0); - break; - //case PETS: - // drawPetsPage(mouseX, mouseY, partialTicks); - // break; - } - - lastTime = currentTime; + Minecraft.getMinecraft().getTextureManager().bindTexture(pv_bg); + Utils.drawTexturedRect(guiLeft, guiTop, sizeX, sizeY, GL11.GL_NEAREST); if(!(currentPage == ProfileViewerPage.LOADING)) { playerNameTextField.render(guiLeft+sizeX-100, guiTop+sizeY+5); @@ -222,6 +204,32 @@ public class GuiProfileViewer extends GuiScreen { } } + GlStateManager.color(1, 1, 1, 1); + switch (currentPage) { + case BASIC: + drawBasicPage(mouseX, mouseY, partialTicks); + break; + case INVS: + drawInvsPage(mouseX, mouseY, partialTicks); + break; + case COLS: + drawColsPage(mouseX, mouseY, partialTicks); + break; + case PETS: + drawPetsPage(mouseX, mouseY, partialTicks); + break; + case LOADING: + Utils.drawStringCentered(EnumChatFormatting.YELLOW+"Loading player profiles...", Minecraft.getMinecraft().fontRendererObj, + guiLeft+sizeX/2f, guiTop+101, true, 0); + break; + case INVALID_NAME: + Utils.drawStringCentered(EnumChatFormatting.RED+"Invalid name or API is down!", Minecraft.getMinecraft().fontRendererObj, + guiLeft+sizeX/2f, guiTop+101, true, 0); + break; + } + + lastTime = currentTime; + if(tooltipToDisplay != null) { List<String> grayTooltip = new ArrayList<>(tooltipToDisplay.size()); for(String line : tooltipToDisplay) { @@ -236,18 +244,6 @@ public class GuiProfileViewer extends GuiScreen { return profile.getProfileInformation(profileId) != null; } - private boolean isCollectionApiEnabled() { - return profile.getCollectionInfo(profileId) != null; - } - - private boolean isInventoryApiEnabled() { - return profile.getInventoryInfo(profileId) != null; - } - - private boolean isSkillsApiEnabled() { - return profile.getSkillInfo(profileId) != null; - } - private void renderTabs(boolean renderPressed) { int ignoredTabs = 0; for(int i=0; i<ProfileViewerPage.values().length; i++) { @@ -265,7 +261,6 @@ public class GuiProfileViewer extends GuiScreen { private void renderTab(ItemStack stack, int xIndex, boolean pressed) { GlStateManager.disableLighting(); - GlStateManager.enableDepth(); GlStateManager.enableBlend(); GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); GlStateManager.enableAlpha(); @@ -277,7 +272,7 @@ public class GuiProfileViewer extends GuiScreen { float uMin = 0; float uMax = 28/256f; float vMin = 20/256f; - float vMax = 52/256f; + float vMax = 51/256f; if(pressed) { vMin = 52/256f; vMax = 84/256f; @@ -293,14 +288,15 @@ public class GuiProfileViewer extends GuiScreen { } GlStateManager.disableLighting(); - GlStateManager.enableDepth(); GlStateManager.enableBlend(); GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); GlStateManager.enableAlpha(); GlStateManager.alphaFunc(516, 0.1F); Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements); - Utils.drawTexturedRect(x, y, 28, 32, uMin, uMax, vMin, vMax, GL11.GL_NEAREST); + Utils.drawTexturedRect(x, y, 28, pressed?32:31, uMin, uMax, vMin, vMax, GL11.GL_NEAREST); + + GlStateManager.enableDepth(); Utils.drawItemStack(stack, x+6, y+9); } @@ -339,6 +335,26 @@ public class GuiProfileViewer extends GuiScreen { return; } } + break; + case PETS: + JsonObject petsInfo = profile.getPetsInfo(profileId); + if(petsInfo == null) break; + JsonArray pets = petsInfo.get("pets").getAsJsonArray(); + for(int i=petsPage*20; i<Math.min(petsPage*20+20, pets.size()); i++) { + int xIndex = i % COLLS_XCOUNT; + int yIndex = i / COLLS_XCOUNT; + + float x = 5 + COLLS_XPADDING + (COLLS_XPADDING + 20) * xIndex; + float y = 7 + COLLS_YPADDING + (COLLS_YPADDING + 20) * yIndex; + + if(mouseX > guiLeft+x && mouseX < guiLeft+x+20) { + if(mouseY > guiTop+y && mouseY < guiTop+y+20) { + selectedPet = pets.get(i).getAsJsonObject(); + return; + } + } + } + break; } if(mouseX > guiLeft+sizeX-100 && mouseX < guiLeft+sizeX) { if(mouseY > guiTop+sizeY+5 && mouseY < guiTop+sizeY+25) { @@ -375,7 +391,7 @@ public class GuiProfileViewer extends GuiScreen { } else { profileDropdownSelected = !profileDropdownSelected; } - } else if(scaledResolution.getScaleFactor() != 4) { + } else if(scaledResolution.getScaleFactor() != 4 && profileDropdownSelected) { int dropdownOptionSize = scaledResolution.getScaleFactor()==3?10:20; int extraY = mouseY - (guiTop+sizeY+23); int index = extraY/dropdownOptionSize; @@ -399,6 +415,7 @@ public class GuiProfileViewer extends GuiScreen { @Override protected void keyTyped(char typedChar, int keyCode) throws IOException { super.keyTyped(typedChar, keyCode); + SBAIntegration.keyTyped(keyCode); switch (currentPage) { case INVS: keyTypedInvs(typedChar, keyCode); @@ -551,6 +568,31 @@ public class GuiProfileViewer extends GuiScreen { } } + public int getLevel(JsonArray levels, int offset, float exp) { + float xpTotal = 0; + int level = 1; + + for(int i=offset; i<offset+99; i++) { + xpTotal += levels.get(i).getAsFloat(); + + if(xpTotal > exp) { + break; + } else { + level += 1; + } + } + + if(level <= 0) { + level = 1; + } else if(level > 100) { + level = 100; + } + return level; + } + + private JsonObject selectedPet = null; + private int petsPage = 0; + private List<JsonObject> sortedPets = null; private static HashMap<String, String> minionRarityToNumMap = new HashMap<>(); static { minionRarityToNumMap.put("COMMON", "0"); @@ -560,33 +602,154 @@ public class GuiProfileViewer extends GuiScreen { minionRarityToNumMap.put("LEGENDARY", "4"); } private void drawPetsPage(int mouseX, int mouseY, float partialTicks) { + JsonObject petsInfo = profile.getPetsInfo(profileId); + if(petsInfo == null) return; + JsonObject petsJson = Utils.getConstant("pets"); + if(petsJson == null) return; + + String location = null; + JsonObject status = profile.getPlayerStatus(); + if(status != null && status.has("mode")) { + location = status.get("mode").getAsString(); + } + + backgroundRotation += (currentTime - lastTime)/400f; + backgroundRotation %= 360; + + String panoramaIdentifier = "day"; + if(SBScoreboardData.getInstance().currentTimeDate != null) { + if(SBScoreboardData.getInstance().currentTimeDate.getHours() <= 6 || + SBScoreboardData.getInstance().currentTimeDate.getHours() >= 20) { + panoramaIdentifier = "night"; + } + } + + Panorama.drawPanorama(-backgroundRotation, guiLeft+212, guiTop+44, 81, 108, -0.37f, 0.6f, + getPanoramasForLocation(location==null?"dynamic":location, panoramaIdentifier)); + Minecraft.getMinecraft().getTextureManager().bindTexture(pv_pets); Utils.drawTexturedRect(guiLeft, guiTop, sizeX, sizeY, GL11.GL_NEAREST); - JsonObject petsInfo = profile.getPetsInfo(profileId); - if(petsInfo == null) return; + Utils.drawStringCentered(EnumChatFormatting.DARK_PURPLE+"Pets", Minecraft.getMinecraft().fontRendererObj, + guiLeft+100, guiTop+14, true, 4210752); + GlStateManager.color(1, 1, 1, 1); JsonArray pets = petsInfo.get("pets").getAsJsonArray(); - for(int i=0; i<pets.size(); i++) { - JsonObject pet = pets.get(i).getAsJsonObject(); - } + if(sortedPets == null) { + sortedPets = new ArrayList<>(); + for(int i=0; i<pets.size(); i++) { + sortedPets.add(pets.get(i).getAsJsonObject()); + } + sortedPets.sort((pet1, pet2) -> { + String tier1 = pet1.get("tier").getAsString(); + String tierNum1 = minionRarityToNumMap.get(tier1); + int tierNum1I = Integer.parseInt(tierNum1); + float exp1 = pet1.get("exp").getAsFloat(); + + String tier2 = pet2.get("tier").getAsString(); + String tierNum2 = minionRarityToNumMap.get(tier2); + int tierNum2I = Integer.parseInt(tierNum2); + float exp2 = pet2.get("exp").getAsFloat(); + + if(tierNum1I != tierNum2I) { + return tierNum2I - tierNum1I; + } else { + return (int)(exp2 - exp1); + } + }); + } + + for(int i=petsPage*20; i<Math.min(petsPage*20+20, sortedPets.size()); i++) { + JsonObject pet = sortedPets.get(i); + if(pet != null) { + String petname = pet.get("type").getAsString(); + String tier = pet.get("tier").getAsString(); + String tierNum = minionRarityToNumMap.get(tier); + float exp = pet.get("exp").getAsFloat(); + if(tierNum == null) continue; + + int petRarityOffset = petsJson.get("pet_rarity_offset").getAsJsonObject().get(tier).getAsInt(); + JsonArray levelsArr = petsJson.get("pet_levels").getAsJsonArray(); + + int level = getLevel(levelsArr, petRarityOffset, exp); + + JsonObject petItem = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(petname+";"+tierNum); + ItemStack stack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(petItem, false, false); + HashMap<String, String> replacements = NotEnoughUpdates.INSTANCE.manager.getLoreReplacements(petname, tier, level); + + NBTTagCompound tag = stack.getTagCompound()==null?new NBTTagCompound():stack.getTagCompound(); + if(tag.hasKey("display", 10)) { + NBTTagCompound display = tag.getCompoundTag("display"); + if(display.hasKey("Lore", 9)) { + NBTTagList newLore = new NBTTagList(); + NBTTagList lore = display.getTagList("Lore", 8); + for(int j=0; j<lore.tagCount(); j++) { + String line = lore.getStringTagAt(j); + for(Map.Entry<String, String> replacement : replacements.entrySet()) { + line = line.replace("{"+replacement.getKey()+"}", replacement.getValue()); + } + newLore.appendTag(new NBTTagString(line)); + } + display.setTag("Lore", newLore); + } + if(display.hasKey("Name", 8)) { + String displayName = display.getString("Name"); + for(Map.Entry<String, String> replacement : replacements.entrySet()) { + displayName = displayName.replace("{"+replacement.getKey()+"}", replacement.getValue()); + } + display.setTag("Name", new NBTTagString(displayName)); + } + tag.setTag("display", display); + } + stack.setTagCompound(tag); - /*if(minions != null) { - for (int i = 0; i < minions.size(); i++) { - String minion = minions.get(i); - if (minion != null) { - JsonObject minionJson = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(minion + "_GENERATOR_1"); - if (minionJson != null) { - int xIndex = i % COLLS_XCOUNT; - int yIndex = i / COLLS_XCOUNT; - - float x = 231 + COLLS_XPADDING + (COLLS_XPADDING + 20) * xIndex; - float y = 7 + COLLS_YPADDING + (COLLS_YPADDING + 20) * yIndex; + int xIndex = i % COLLS_XCOUNT; + int yIndex = i / COLLS_XCOUNT; + + float x = 5 + COLLS_XPADDING + (COLLS_XPADDING + 20) * xIndex; + float y = 7 + COLLS_YPADDING + (COLLS_YPADDING + 20) * yIndex; + + Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements); + if(pet == selectedPet) { + GlStateManager.color(1, 185/255f, 0, 1); + Utils.drawTexturedRect(guiLeft+x, guiTop+y, 20, 20, + 0, 20/256f, 0, 20/256f, GL11.GL_NEAREST); + } else { + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft+x, guiTop+y, 20, 20, + 0, 20/256f, 0, 20/256f, GL11.GL_NEAREST); + } + + Utils.drawItemStack(stack, guiLeft+(int)x+2, guiTop+(int)y+2); + + if(mouseX > guiLeft+x && mouseX < guiLeft+x+20) { + if(mouseY > guiTop+y && mouseY < guiTop+y+20) { + tooltipToDisplay = stack.getTooltip(Minecraft.getMinecraft().thePlayer, false); } } } - }*/ + } + + if(selectedPet != null) { + String type = selectedPet.get("type").getAsString(); + + for(int i=0; i<4; i++) { + JsonObject item = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(type+";"+i); + if(item != null) { + int x = guiLeft+280; + float y = guiTop+67+15*(float)Math.sin(((currentTime-startTime)/800f)%(2*Math.PI)); + GlStateManager.translate(x, y, 0); + ItemStack stack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(item); + GlStateManager.scale(-3.5f, 3.5f, 1); + GlStateManager.enableDepth(); + Utils.drawItemStack(stack, 0, 0); + GlStateManager.scale(-1/3.5f, 1/3.5f, 1); + GlStateManager.translate(-x, -y, 0); + break; + } + } + } } private String[] romans = new String[]{"I","II","III","IV","V","VI","VII","VIII","IX","X","XI", @@ -937,7 +1100,29 @@ public class GuiProfileViewer extends GuiScreen { continue; } - items[yIndex][xIndex] = NotEnoughUpdates.INSTANCE.manager.jsonToStack(jsonInv.get(j).getAsJsonObject(), false); + JsonObject item = jsonInv.get(j).getAsJsonObject(); + ItemStack stack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(item, false); + if(item.has("item_contents")) { + JsonArray bytesArr = item.get("item_contents").getAsJsonArray(); + byte[] bytes = new byte[bytesArr.size()]; + for(int bytesArrI=0; bytesArrI<bytesArr.size(); bytesArrI++) { + bytes[bytesArrI] = bytesArr.get(bytesArrI).getAsByte(); + } + //byte[] bytes2 = null; + NBTTagCompound tag = stack.getTagCompound(); + if(tag != null && tag.hasKey("ExtraAttributes", 10)) { + NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); + for(String key : ea.getKeySet()) { + if(key.endsWith("backpack_data") || key.equals("new_year_cake_bag_data")) { + ea.setTag(key, new NBTTagByteArray(bytes)); + break; + } + } + tag.setTag("ExtraAttributes", ea); + stack.setTagCompound(tag); + } + } + items[yIndex][xIndex] = stack; } inventories[i] = items; } @@ -957,7 +1142,9 @@ public class GuiProfileViewer extends GuiScreen { private int greenCandyCount = -1; private int purpleCandyCount = -1; private GuiElementTextField inventoryTextField = new GuiElementTextField("", GuiElementTextField.SCALE_TEXT); - + private ItemStack lastBackpack; + private int lastBackpackX; + private int lastBackpackY; private void drawInvsPage(int mouseX, int mouseY, float partialTicks) { Minecraft.getMinecraft().getTextureManager().bindTexture(pv_invs); Utils.drawTexturedRect(guiLeft, guiTop, sizeX, sizeY, GL11.GL_NEAREST); @@ -1132,6 +1319,7 @@ public class GuiProfileViewer extends GuiScreen { fontRendererObj.drawString(Utils.cleanColour(invNameToDisplayMap.get(selectedInventory).getDisplayName()), x+8, y+6, 4210752); + ItemStack stackToRender = null; int overlay = new Color(0, 0, 0, 100).getRGB(); for(int yIndex=0; yIndex<inventory.length; yIndex++) { if(inventory[yIndex] == null) continue; @@ -1152,8 +1340,39 @@ public class GuiProfileViewer extends GuiScreen { if(mouseX >= x+8+xIndex*18 && mouseX <= x+8+xIndex*18+16) { if(mouseY >= y+18+yIndex*18 && mouseY <= y+18+yIndex*18+16) { - tooltipToDisplay = stack.getTooltip(Minecraft.getMinecraft().thePlayer, false); + stackToRender = stack; + } + } + } + } + if(stackToRender == null && !SBAIntegration.isFreezeBackpack()) lastBackpack = null; + if(SBAIntegration.isFreezeBackpack()) { + if(lastBackpack != null) { + SBAIntegration.setActiveBackpack(lastBackpack, lastBackpackX, lastBackpackY); + GlStateManager.translate(0, 0, 100); + SBAIntegration.renderActiveBackpack(mouseX, mouseY, fontRendererObj); + GlStateManager.translate(0, 0, -100); + } + } else { + if(stackToRender != null) { + String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stackToRender); + boolean renderedBackpack; + if(internalname != null && (internalname.endsWith("BACKPACK") || internalname.equals("NEW_YEAR_CAKE_BAG"))) { + lastBackpack = stackToRender; + lastBackpackX = mouseX; + lastBackpackY = mouseY; + renderedBackpack = SBAIntegration.setActiveBackpack(lastBackpack, lastBackpackX, lastBackpackY); + if(renderedBackpack) { + GlStateManager.translate(0, 0, 100); + renderedBackpack = SBAIntegration.renderActiveBackpack(mouseX, mouseY, fontRendererObj); + GlStateManager.translate(0, 0, -100); } + } else { + renderedBackpack = false; + } + if(!renderedBackpack) { + lastBackpack = null; + tooltipToDisplay = stackToRender.getTooltip(Minecraft.getMinecraft().thePlayer, false); } } } @@ -1313,7 +1532,7 @@ public class GuiProfileViewer extends GuiScreen { } } - Panorama.drawPanorama(-backgroundRotation-extraRotation, guiLeft+23, guiTop+44, 81, 108, + Panorama.drawPanorama(-backgroundRotation-extraRotation, guiLeft+23, guiTop+44, 81, 108, 0.37f, 0.8f, getPanoramasForLocation(location==null?"unknown":location, panoramaIdentifier)); Minecraft.getMinecraft().getTextureManager().bindTexture(pv_basic); @@ -1398,7 +1617,7 @@ public class GuiProfileViewer extends GuiScreen { if(location != null) { JsonObject misc = Utils.getConstant("misc"); if(misc != null) { - locationStr = Utils.getElementAsString(Utils.getElement(misc, "area_names."+location), "Unknown Location"); + locationStr = Utils.getElementAsString(Utils.getElement(misc, "area_names."+location), "Unknown"); } } } @@ -1409,11 +1628,6 @@ public class GuiProfileViewer extends GuiScreen { Utils.drawStringCentered(statusStr, fr, guiLeft+63, guiTop+160, true, 0); } - if(!isLoadedProfile()) { - //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); @@ -1454,10 +1668,12 @@ public class GuiProfileViewer extends GuiScreen { } else { if(inventoryInfo != null && inventoryInfo.has("inv_armor")) { JsonArray items = inventoryInfo.get("inv_armor").getAsJsonArray(); - for(int i=0; i<entityPlayer.inventory.armorInventory.length; i++) { - JsonElement itemElement = items.get(i); - if(itemElement != null && itemElement.isJsonObject()) { - entityPlayer.inventory.armorInventory[i] = NotEnoughUpdates.INSTANCE.manager.jsonToStack(itemElement.getAsJsonObject(), false); + if(items != null && items.size() == 4) { + for(int i=0; i<entityPlayer.inventory.armorInventory.length; i++) { + JsonElement itemElement = items.get(i); + if(itemElement != null && itemElement.isJsonObject()) { + entityPlayer.inventory.armorInventory[i] = NotEnoughUpdates.INSTANCE.manager.jsonToStack(itemElement.getAsJsonObject(), false); + } } } } @@ -1502,6 +1718,7 @@ public class GuiProfileViewer extends GuiScreen { GlStateManager.translate(x, y, 0); ItemStack stack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(item); GlStateManager.scale(-1.5f, 1.5f, 1); + GlStateManager.enableDepth(); Utils.drawItemStack(stack, 0, 0); GlStateManager.scale(-1/1.5f, 1/1.5f, 1); GlStateManager.translate(-x, -y, 0); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/Panorama.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/Panorama.java index 74ffb4b8..fa585f1e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/Panorama.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/Panorama.java @@ -23,9 +23,8 @@ public class Panorama { 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) { + public static void drawPanorama(float angle, int x, int y, int width, int height, float yOffset, float zOffset, ResourceLocation[] panoramas) { Minecraft.getMinecraft().getFramebuffer().unbindFramebuffer(); - //GlStateManager.viewport(0, 0, 1024, 1024); ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); @@ -56,7 +55,7 @@ public class Panorama { GlStateManager.pushMatrix(); - GlStateManager.translate(0, 0.37f, 0.8f); + GlStateManager.translate(0, yOffset, zOffset); GlStateManager.rotate(angle, 0.0F, 1.0F, 0.0F); 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 d45fd82b..dac93e6f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java @@ -354,7 +354,6 @@ public class PlayerStats { stats.addStat(DEFENCE, 2.5f); } if(internalname.equals("NEW_YEAR_CAKE_BAG") && item.has("item_contents")) { - JsonArray bytesArr = item.get("item_contents").getAsJsonArray(); byte[] bytes = new byte[bytesArr.size()]; for(int i=0; i<bytesArr.size(); i++) { 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 c703bc9e..d463f87e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java @@ -322,17 +322,20 @@ public class ProfileViewer { for (int i = 0; i < playerInformation.size(); i++) { JsonObject profile = playerInformation.get(i).getAsJsonObject(); - String cute_name = profile.get("cute_name").getAsString(); - - profileIds.add(cute_name); - - if (backup == null) backup = cute_name; if (!profile.has("members")) continue; JsonObject members = profile.get("members").getAsJsonObject(); if (members.has(uuid)) { JsonObject member = members.get(uuid).getAsJsonObject(); + + if(member.has("coop_invitation")) { + continue; + } + + String cute_name = profile.get("cute_name").getAsString(); + if (backup == null) backup = cute_name; + profileIds.add(cute_name); if (member.has("last_save")) { long last_save = member.get("last_save").getAsLong(); if (last_save > backupLastSave) { @@ -340,6 +343,7 @@ public class ProfileViewer { backup = cute_name; } } + } } if (runnable != null) runnable.run(); |