diff options
Diffstat (limited to 'src/main/java/io')
35 files changed, 2623 insertions, 320 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/AccessoryBagOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/AccessoryBagOverlay.java index 65d4efc7..1011f3cc 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/AccessoryBagOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/AccessoryBagOverlay.java @@ -1,11 +1,13 @@ package io.github.moulberry.notenoughupdates; import com.google.gson.JsonArray; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.profileviewer.PlayerStats; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.gui.inventory.GuiChest; import net.minecraft.client.gui.inventory.GuiContainer; @@ -41,6 +43,7 @@ public class AccessoryBagOverlay { private static final int TAB_BONUS = 2; private static final int TAB_DUP = 3; private static final int TAB_MISSING = 4; + private static final int TAB_OPTIMIZER = 5; private static final ItemStack[] TAB_STACKS = new ItemStack[] { Utils.createItemStack(Items.dye, EnumChatFormatting.DARK_AQUA+"Basic Information", @@ -53,6 +56,8 @@ public class AccessoryBagOverlay { 8), Utils.createItemStack(Item.getItemFromBlock(Blocks.barrier), EnumChatFormatting.DARK_AQUA+"Missing", 0), + Utils.createItemStack(Item.getItemFromBlock(Blocks.redstone_block), EnumChatFormatting.DARK_AQUA+"Optimizer", + 0), }; private static int currentTab = TAB_BASIC; @@ -82,6 +87,36 @@ public class AccessoryBagOverlay { if(currentTab > TAB_MISSING) currentTab = TAB_MISSING; } + if(currentTab == TAB_OPTIMIZER) { + int x = guiLeft+xSize+3; + int y = guiTop; + + if(mouseY > y+92 && mouseY < y+103) { + if(mouseX > x+5 && mouseX < x+75) { + mainWeapon = (int)Math.floor((mouseX-x-5)/70f*9); + if(mainWeapon < 1) { + mainWeapon = 1; + } else if(mainWeapon > 9) { + mainWeapon = 9; + } + } + } + + if(mouseX > x+5 && mouseX < x+35 || mouseX > x+45 && mouseX < x+75) { + boolean set = mouseX > x+5 && mouseX < x+35; + + if(mouseY > y+32 && mouseY < y+43) { + forceCC = set; + } else if(mouseY > y+52 && mouseY < y+63) { + forceAS = set; + } else if(mouseY > y+72 && mouseY < y+83) { + useGodPot = set; + } else if(mouseY > y+92 && mouseY < y+103) { + allowShaded = set; + } + } + } + return true; } catch(Exception e) { return false; @@ -94,6 +129,8 @@ public class AccessoryBagOverlay { talismanCountRarity = null; totalStats = null; reforgeStats = null; + duplicates = null; + missing = null; } private static Set<ItemStack> accessoryStacks = new HashSet<>(); @@ -116,7 +153,7 @@ public class AccessoryBagOverlay { } } - Utils.drawStringCenteredScaledMaxWidth("# By Rarity", Minecraft.getMinecraft().fontRendererObj, x+40, y+12, true, 70, + Utils.drawStringCenteredScaledMaxWidth("# By Rarity", Minecraft.getMinecraft().fontRendererObj, x+40, y+12, false, 70, new Color(80, 80, 80).getRGB()); int yIndex = 0; @@ -137,7 +174,7 @@ public class AccessoryBagOverlay { } } - Utils.drawStringCenteredScaledMaxWidth("Total Stats", Minecraft.getMinecraft().fontRendererObj, x+40, y+12, true, 70, + Utils.drawStringCenteredScaledMaxWidth("Total Stats", Minecraft.getMinecraft().fontRendererObj, x+40, y+12, false, 70, new Color(80, 80, 80).getRGB()); int yIndex = 0; for(int i=0; i<PlayerStats.defaultStatNames.length; i++) { @@ -166,7 +203,7 @@ public class AccessoryBagOverlay { } } - Utils.drawStringCenteredScaledMaxWidth("Reforge Stats", Minecraft.getMinecraft().fontRendererObj, x+40, y+12, true, 70, + Utils.drawStringCenteredScaledMaxWidth("Reforge Stats", Minecraft.getMinecraft().fontRendererObj, x+40, y+12, false, 70, new Color(80, 80, 80).getRGB()); int yIndex = 0; for(int i=0; i<PlayerStats.defaultStatNames.length; i++) { @@ -186,13 +223,241 @@ public class AccessoryBagOverlay { } } - private static Set<ItemStack> duplicates = new HashSet<>(); + private static Set<ItemStack> duplicates = null; public static void renderDuplicatesOverlay(int x, int y) { - Utils.drawStringCenteredScaledMaxWidth("Duplicates", Minecraft.getMinecraft().fontRendererObj, x+40, y+12, true, 70, - new Color(80, 80, 80).getRGB()); + if(duplicates == null) { + JsonObject misc = Utils.getConstant("misc"); + if(misc == null) { + Utils.drawStringCenteredScaledMaxWidth("Duplicates: ERROR", Minecraft.getMinecraft().fontRendererObj, x+40, y+12, false, 70, + new Color(80, 80, 80).getRGB()); + return; + } + JsonElement talisman_upgrades_element = misc.get("talisman_upgrades"); + if(talisman_upgrades_element == null) { + Utils.drawStringCenteredScaledMaxWidth("Duplicates: ERROR", Minecraft.getMinecraft().fontRendererObj, x+40, y+12, false, 70, + new Color(80, 80, 80).getRGB()); + return; + } + JsonObject talisman_upgrades = talisman_upgrades_element.getAsJsonObject(); + + duplicates = new HashSet<>(); + + Set<String> prevInternalnames = new HashSet<>(); + for(ItemStack stack : accessoryStacks) { + String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); + + if(prevInternalnames.contains(internalname)) { + duplicates.add(stack); + continue; + } + prevInternalnames.add(internalname); + + if(talisman_upgrades.has(internalname)) { + JsonArray upgrades = talisman_upgrades.get(internalname).getAsJsonArray(); + for(ItemStack stack2 : accessoryStacks) { + if(stack != stack2) { + String internalname2 = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack2); + for(int j=0; j<upgrades.size(); j++) { + String upgrade = upgrades.get(j).getAsString(); + if(internalname2.equals(upgrade)) { + duplicates.add(stack); + break; + } + } + } + } + } + } + } + if(duplicates.isEmpty()) { + Utils.drawStringCenteredScaledMaxWidth("No Duplicates", Minecraft.getMinecraft().fontRendererObj, x+40, y+12, false, 70, + new Color(80, 80, 80).getRGB()); + } else { + Utils.drawStringCenteredScaledMaxWidth("Duplicates: " + duplicates.size(), Minecraft.getMinecraft().fontRendererObj, x+40, y+12, false, 70, + new Color(80, 80, 80).getRGB()); + + int yIndex = 0; + for(ItemStack duplicate : duplicates) { + renderAlignedString(duplicate.getDisplayName(), "", x+5, y+20+11*yIndex, 70); + if(duplicates.size() > 11) { + if(++yIndex >= 10) break; + } else { + if(++yIndex >= 11) break; + } + } + + if(duplicates.size() > 11) { + Utils.drawStringCenteredScaledMaxWidth("+" + (duplicates.size()-10) + " More", + Minecraft.getMinecraft().fontRendererObj, x+40, y+16+121, false, 70, + new Color(80, 80, 80).getRGB()); + } + } } + private static List<ItemStack> missing = null; public static void renderMissingOverlay(int x, int y) { + if(missing == null) { + JsonObject misc = Utils.getConstant("misc"); + if(misc == null) { + Utils.drawStringCenteredScaledMaxWidth("Duplicates: ERROR", Minecraft.getMinecraft().fontRendererObj, x+40, y+12, false, 70, + new Color(80, 80, 80).getRGB()); + return; + } + JsonElement talisman_upgrades_element = misc.get("talisman_upgrades"); + if(talisman_upgrades_element == null) { + Utils.drawStringCenteredScaledMaxWidth("Duplicates: ERROR", Minecraft.getMinecraft().fontRendererObj, x+40, y+12, false, 70, + new Color(80, 80, 80).getRGB()); + return; + } + JsonObject talisman_upgrades = talisman_upgrades_element.getAsJsonObject(); + + missing = new ArrayList<>(); + + List<String> missingInternal = new ArrayList<>(); + for(Map.Entry<String, JsonObject> entry : NotEnoughUpdates.INSTANCE.manager.getItemInformation().entrySet()) { + if(entry.getValue().has("lore")) { + if(checkItemType(entry.getValue().get("lore").getAsJsonArray(), "ACCESSORY", "HATCCESSORY") >= 0) { + missingInternal.add(entry.getKey()); + } + } + } + + for(ItemStack stack : accessoryStacks) { + String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); + missingInternal.remove(internalname); + + for(Map.Entry<String, JsonElement> talisman_upgrade_element : talisman_upgrades.entrySet()) { + JsonArray upgrades = talisman_upgrade_element.getValue().getAsJsonArray(); + for(int j=0; j<upgrades.size(); j++) { + String upgrade = upgrades.get(j).getAsString(); + if(internalname.equals(upgrade)) { + missingInternal.remove(talisman_upgrade_element.getKey()); + break; + } + } + } + } + + missingInternal.sort(getItemComparator()); + + for(String internal : missingInternal) { + missing.add(NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(internal))); + } + } + if(missing.isEmpty()) { + Utils.drawStringCenteredScaledMaxWidth("No Missing", Minecraft.getMinecraft().fontRendererObj, x+40, y+12, false, 70, + new Color(80, 80, 80).getRGB()); + } else { + Utils.drawStringCenteredScaledMaxWidth("Missing: " + missing.size(), Minecraft.getMinecraft().fontRendererObj, x+40, y+12, false, 70, + new Color(80, 80, 80).getRGB()); + + int yIndex = 0; + for(ItemStack missingStack : missing) { + renderAlignedString(missingStack.getDisplayName(), "", x+5, y+20+11*yIndex, 70); + if(missing.size() > 11) { + if(++yIndex >= 10) break; + } else { + if(++yIndex >= 11) break; + } + } + + if(missing.size() > 11) { + Utils.drawStringCenteredScaledMaxWidth("+" + (missing.size()-10) + " More", + Minecraft.getMinecraft().fontRendererObj, x+40, y+16+121, false, 70, + new Color(80, 80, 80).getRGB()); + } + } + } + + private static boolean forceCC = false; + private static boolean forceAS = false; + private static boolean useGodPot = true; + private static boolean allowShaded = true; + private static int mainWeapon = 1; + + public static void renderOptimizerOverlay(int x, int y) { + Utils.drawStringCenteredScaledMaxWidth("Optimizer", Minecraft.getMinecraft().fontRendererObj, x+40, y+12, false, 70, + new Color(80, 80, 80).getRGB()); + + int light = new Color(220, 220, 220).getRGB(); + int dark = new Color(170, 170, 170).getRGB(); + + Gui.drawRect(x+5, y+32, x+35, y+43, forceCC?dark:light); + Gui.drawRect(x+45, y+32, x+75, y+43, forceCC?light:dark); + + Gui.drawRect(x+5, y+52, x+35, y+63, forceAS?dark:light); + Gui.drawRect(x+45, y+52, x+75, y+63, forceAS?light:dark); + + Gui.drawRect(x+5, y+72, x+35, y+83, useGodPot?dark:light); + Gui.drawRect(x+45, y+72, x+75, y+83, useGodPot?light:dark); + + Gui.drawRect(x+5, y+92, x+35, y+103, allowShaded?dark:light); + Gui.drawRect(x+45, y+92, x+75, y+103, allowShaded?light:dark); + + Gui.drawRect(x+5, y+102, x+75, y+113, light); + Gui.drawRect(x+5+(int)((mainWeapon-1)/9f*70), y+102, x+5+(int)(mainWeapon/9f*70), y+113, dark); + + Utils.drawStringCenteredScaledMaxWidth("Force 100% CC", Minecraft.getMinecraft().fontRendererObj, x+40, y+27, false, 70, + new Color(80, 80, 80).getRGB()); + Utils.drawStringCenteredScaledMaxWidth((forceCC?EnumChatFormatting.GREEN:EnumChatFormatting.GRAY)+"YES", + Minecraft.getMinecraft().fontRendererObj, x+20, y+37, + true, 30, new Color(80, 80, 80).getRGB()); + Utils.drawStringCenteredScaledMaxWidth((forceCC?EnumChatFormatting.GRAY:EnumChatFormatting.RED)+"NO", Minecraft.getMinecraft().fontRendererObj, x+60, y+37, + true, 30, new Color(80, 80, 80).getRGB()); + + Utils.drawStringCenteredScaledMaxWidth("Force 100% ATKSPEED", Minecraft.getMinecraft().fontRendererObj, x+40, y+47, false, 70, + new Color(80, 80, 80).getRGB()); + Utils.drawStringCenteredScaledMaxWidth((forceAS?EnumChatFormatting.GREEN:EnumChatFormatting.GRAY)+"YES", Minecraft.getMinecraft().fontRendererObj, x+20, y+57, + true, 30, new Color(80, 80, 80).getRGB()); + Utils.drawStringCenteredScaledMaxWidth((forceAS?EnumChatFormatting.GRAY:EnumChatFormatting.RED)+"NO", Minecraft.getMinecraft().fontRendererObj, x+60, y+57, + true, 30, new Color(80, 80, 80).getRGB()); + + Utils.drawStringCenteredScaledMaxWidth("Use God Potion", Minecraft.getMinecraft().fontRendererObj, x+40, y+67, false, 70, + new Color(80, 80, 80).getRGB()); + Utils.drawStringCenteredScaledMaxWidth((useGodPot?EnumChatFormatting.GREEN:EnumChatFormatting.GRAY)+"YES", Minecraft.getMinecraft().fontRendererObj, x+20, y+77, + true, 30, new Color(80, 80, 80).getRGB()); + Utils.drawStringCenteredScaledMaxWidth((useGodPot?EnumChatFormatting.GRAY:EnumChatFormatting.RED)+"NO", Minecraft.getMinecraft().fontRendererObj, x+60, y+77, + true, 30, new Color(80, 80, 80).getRGB()); + + Utils.drawStringCenteredScaledMaxWidth("Use God Potion", Minecraft.getMinecraft().fontRendererObj, x+40, y+87, false, 70, + new Color(80, 80, 80).getRGB()); + Utils.drawStringCenteredScaledMaxWidth((allowShaded?EnumChatFormatting.GREEN:EnumChatFormatting.GRAY)+"YES", + Minecraft.getMinecraft().fontRendererObj, x+20, y+97, + true, 30, new Color(80, 80, 80).getRGB()); + Utils.drawStringCenteredScaledMaxWidth((allowShaded?EnumChatFormatting.GRAY:EnumChatFormatting.RED)+"NO", + Minecraft.getMinecraft().fontRendererObj, x+60, y+97, + true, 30, new Color(80, 80, 80).getRGB()); + + Utils.drawStringCenteredScaledMaxWidth("Main Weapon", Minecraft.getMinecraft().fontRendererObj, x+40, y+107, false, 70, + new Color(80, 80, 80).getRGB()); + Utils.drawStringCenteredScaled("1 2 3 4 5 6 7 8 9", + Minecraft.getMinecraft().fontRendererObj, x+40, y+117, + true, 70, new Color(80, 80, 80).getRGB()); + } + + private static Comparator<String> getItemComparator() { + return (o1, o2) -> { + float cost1; + JsonObject o1Auc = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(o1); + if(o1Auc != null && o1Auc.has("price")) { + cost1 = o1Auc.get("price").getAsFloat(); + } else { + cost1 = NotEnoughUpdates.INSTANCE.manager.auctionManager.getCraftCost(o1).craftCost; + } + float cost2; + JsonObject o2Auc = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(o2); + if(o2Auc != null && o2Auc.has("price")) { + cost2 = o2Auc.get("price").getAsFloat(); + } else { + cost2 = NotEnoughUpdates.INSTANCE.manager.auctionManager.getCraftCost(o2).craftCost; + } + + + if(cost1 < cost2) return -1; + if(cost1 > cost2) return 1; + + return o1.compareTo(o2); + }; } public static void renderOverlay() { @@ -276,6 +541,11 @@ public class AccessoryBagOverlay { Minecraft.getMinecraft().getTextureManager().bindTexture(accessory_bag_overlay); Utils.drawTexturedRect(guiLeft+xSize+3, guiTop, 80, 149, 0, 80/256f, 0, 149/256f, GL11.GL_NEAREST); + if(pagesVisited.size() < 1) { + renderVisitOverlay(guiLeft+xSize+3, guiTop); + return; + } + Minecraft.getMinecraft().getTextureManager().bindTexture(accessory_bag_overlay); Utils.drawTexturedRect(guiLeft+xSize+80, guiTop+20*currentTab, 28, 22, 80/256f, 108/256f, 22/256f, 44/256f, GL11.GL_NEAREST); @@ -292,6 +562,8 @@ public class AccessoryBagOverlay { renderDuplicatesOverlay(guiLeft+xSize+3, guiTop); return; case TAB_MISSING: renderMissingOverlay(guiLeft+xSize+3, guiTop); return; + case TAB_OPTIMIZER: + renderOptimizerOverlay(guiLeft+xSize+3, guiTop); return; } } catch(Exception e) { e.printStackTrace(); @@ -500,6 +772,20 @@ public class AccessoryBagOverlay { } return -1; } + private static int checkItemType(JsonArray lore, String... typeMatches) { + for(int i=lore.size()-1; i>=0; i--) { + String line = lore.get(i).getAsString(); + + for(String rarity : rarityArr) { + for(int j=0; j<typeMatches.length; j++) { + if(line.trim().endsWith(rarity + " " + typeMatches[j])) { + return j; + } + } + } + } + return -1; + } public static boolean isAccessory(ItemStack stack) { return checkItemType(stack, false, "ACCESSORY", "HATCCESSORY") >= 0; @@ -523,5 +809,4 @@ public class AccessoryBagOverlay { } return -1; } - } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/BetterContainers.java b/src/main/java/io/github/moulberry/notenoughupdates/BetterContainers.java index b17c84a0..6a876201 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/BetterContainers.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/BetterContainers.java @@ -1,5 +1,6 @@ package io.github.moulberry.notenoughupdates; +import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.util.TexLoc; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; @@ -14,22 +15,30 @@ import net.minecraft.inventory.ContainerChest; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; import org.lwjgl.input.Keyboard; import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; +import java.io.*; +import java.nio.charset.StandardCharsets; import java.util.Random; public class BetterContainers { + private static final ResourceLocation TOGGLE_OFF = new ResourceLocation("notenoughupdates:dynamic_54/toggle_off.png"); + private static final ResourceLocation TOGGLE_ON = new ResourceLocation("notenoughupdates:dynamic_54/toggle_on.png"); + private static final ResourceLocation DYNAMIC_54_BASE = new ResourceLocation("notenoughupdates:dynamic_54/style1/dynamic_54.png"); private static final ResourceLocation DYNAMIC_54_SLOT = new ResourceLocation("notenoughupdates:dynamic_54/style1/dynamic_54_slot_ctm.png"); private static final ResourceLocation DYNAMIC_54_BUTTON = new ResourceLocation("notenoughupdates:dynamic_54/style1/dynamic_54_button_ctm.png"); private static final ResourceLocation rl = new ResourceLocation("notenoughupdates:dynamic_chest_inventory.png"); private static boolean loaded = false; private static DynamicTexture texture = null; + private static int textColour = 4210752; private static int lastClickedSlot = 0; private static int clickedSlot = 0; @@ -62,6 +71,15 @@ public class BetterContainers { textureManager.bindTexture(location); } + public static boolean isAh() { + if(!isChestOpen()) return false; + + GuiChest eventGui = (GuiChest) Minecraft.getMinecraft().currentScreen; + ContainerChest cc = (ContainerChest) eventGui.inventorySlots; + String containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText(); + return containerName.trim().startsWith("Auctions Browser") || containerName.trim().startsWith("Wardrobe"); + } + public static boolean isOverriding() { return isChestOpen() && loaded && texture != null && !Keyboard.isKeyDown(Keyboard.KEY_B); } @@ -71,21 +89,66 @@ public class BetterContainers { stack.getDisplayName() != null && stack.getDisplayName().trim().isEmpty(); } + public static boolean shouldRenderStack(ItemStack stack) { + return !isBlankStack(stack) && !isToggleOff(stack) && !isToggleOn(stack); + } + public static boolean isButtonStack(ItemStack stack) { return stack != null && stack.getItem() != Item.getItemFromBlock(Blocks.stained_glass_pane) - && NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack) == null; + && NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack) == null && !isToggleOn(stack) && !isToggleOff(stack); + } + + public static int getTextColour() { + return textColour; + } + + public static boolean isToggleOn(ItemStack stack) { + if(stack != null && stack.getTagCompound() != null && stack.getTagCompound().hasKey("display", 10) && + stack.getTagCompound().getCompoundTag("display").hasKey("Lore", 9)) { + NBTTagList lore = stack.getTagCompound().getCompoundTag("display").getTagList("Lore", 8); + if(lore.tagCount() == 1 && lore.getStringTagAt(0).equalsIgnoreCase(EnumChatFormatting.GRAY+"click to disable!")) { + return true; + } + } + return false; + } + + public static boolean isToggleOff(ItemStack stack) { + if(stack != null && stack.getTagCompound() != null && stack.getTagCompound().hasKey("display", 10) && + stack.getTagCompound().getCompoundTag("display").hasKey("Lore", 9)) { + NBTTagList lore = stack.getTagCompound().getCompoundTag("display").getTagList("Lore", 8); + if(lore.tagCount() == 1 && lore.getStringTagAt(0).equalsIgnoreCase(EnumChatFormatting.GRAY+"click to enable!")) { + return true; + } + } + return false; } private static void generateTex(ResourceLocation location) { if(!hasItem()) return; loaded = true; Container container = ((GuiChest)Minecraft.getMinecraft().currentScreen).inventorySlots; + + int backgroundStyle = NotEnoughUpdates.INSTANCE.manager.config.dynamicMenuBackgroundStyle.value.intValue(); + backgroundStyle = Math.max(1, Math.min(10, backgroundStyle)); + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(Minecraft.getMinecraft().getResourceManager().getResource( + new ResourceLocation("notenoughupdates:dynamic_54/style"+ backgroundStyle+"/dynamic_config.json")).getInputStream(), StandardCharsets.UTF_8)); + JsonObject json = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(reader, JsonObject.class); + String textColourS = json.get("text-colour").getAsString(); + textColour = (int)Long.parseLong(textColourS, 16); + } catch(Exception e) { + textColour = 4210752; + e.printStackTrace(); + } + if(hasNullPane() && container instanceof ContainerChest) { try { + BufferedImage bufferedImageOn = ImageIO.read(Minecraft.getMinecraft().getResourceManager().getResource(TOGGLE_ON).getInputStream()); + BufferedImage bufferedImageOff = ImageIO.read(Minecraft.getMinecraft().getResourceManager().getResource(TOGGLE_OFF).getInputStream()); + BufferedImage bufferedImageBase = ImageIO.read(Minecraft.getMinecraft().getResourceManager().getResource(DYNAMIC_54_BASE).getInputStream()); try { - int backgroundStyle = NotEnoughUpdates.INSTANCE.manager.config.dynamicMenuBackgroundStyle.value.intValue(); - backgroundStyle = Math.max(1, Math.min(10, backgroundStyle)); bufferedImageBase = ImageIO.read(Minecraft.getMinecraft().getResourceManager().getResource( new ResourceLocation("notenoughupdates:dynamic_54/style"+ backgroundStyle+"/dynamic_54.png")).getInputStream()); } catch(Exception e) {} @@ -117,8 +180,7 @@ public class BetterContainers { boolean[][] buttons = new boolean[9][size/9]; for (int index = 0; index < size; index++) { ItemStack stack = lower.getStackInSlot(index); - buttons[index%9][index/9] = stack != null && stack.getItem() != Item.getItemFromBlock(Blocks.stained_glass_pane) - && NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack) == null; + buttons[index%9][index/9] = isButtonStack(stack); if(buttons[index%9][index/9] && getClickedSlot() == index) { buttons[index%9][index/9] = false; @@ -128,12 +190,30 @@ public class BetterContainers { } } for (int index = 0; index < size; index++) { + ItemStack stack = lower.getStackInSlot(index); int xi = index%9; int yi = index/9; if(slots[xi][yi] || buttons[xi][yi]) { int x = 7*horzTexMult + xi*18*horzTexMult; int y = 17*vertTexMult + yi*18*vertTexMult; + boolean on = isToggleOn(stack); + boolean off = isToggleOff(stack); + + if(on || off) { + for(int x2=0; x2<18; x2++) { + for(int y2=0; y2<18; y2++) { + BufferedImage toggle = on ? bufferedImageOn : bufferedImageOff; + Color c = new Color(toggle.getRGB(x2, y2), true); + if(c.getAlpha() < 10) { + continue; + } + bufferedImageNew.setRGB(x+x2, y+y2, c.getRGB()); + } + } + continue; + } + if(buttons[xi][yi]) { boolean up = yi > 0 && buttons[xi][yi-1]; boolean right = xi < buttons.length-1 && buttons[xi+1][yi]; @@ -149,6 +229,7 @@ public class BetterContainers { int[] rgbs = bufferedImageButton.getRGB((ctmIndex%12)*19*horzTexMult, (ctmIndex/12)*19*vertTexMult, 18*horzTexMult, 18*vertTexMult, null, 0, 18*vertTexMult); bufferedImageNew.setRGB(x, y, 18*horzTexMult, 18*vertTexMult, rgbs, 0, 18*vertTexMult); + } else { boolean up = yi > 0 && slots[xi][yi-1]; boolean right = xi < slots.length-1 && slots[xi+1][yi]; @@ -179,6 +260,7 @@ public class BetterContainers { loaded = false; clickedSlot = -1; clickedSlotMillis = 0; + textColour = 4210752; } private static boolean isChestOpen() { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/CustomItemEffects.java b/src/main/java/io/github/moulberry/notenoughupdates/CustomItemEffects.java index 9d3c1c2f..cc94981f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/CustomItemEffects.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/CustomItemEffects.java @@ -1,5 +1,6 @@ package io.github.moulberry.notenoughupdates; +import io.github.moulberry.notenoughupdates.util.SpecialColour; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.Minecraft; @@ -24,6 +25,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent; import org.lwjgl.opengl.GL11; import org.lwjgl.util.vector.Vector3f; +import java.awt.*; import java.util.HashSet; import java.util.LinkedList; @@ -185,7 +187,7 @@ public class CustomItemEffects { drawSelectionBoundingBox(block.getSelectedBoundingBox(Minecraft.getMinecraft().theWorld, candidate) .expand(0.001D, 0.001D, 0.001D).offset(-d0, -d1, -d2), - random ? 0.1f : 0.2f); + random ? 0.5f : 1f); } } } @@ -199,7 +201,8 @@ public class CustomItemEffects { } public static void drawSelectionBoundingBox(AxisAlignedBB p_181561_0_, float alpha) { - GlStateManager.color(64/255f, 224/255f, 208/255f, alpha); + Color c = new Color(SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.manager.config.treecapOverlayColour.value), true); + GlStateManager.color(c.getRed()/255f, c.getGreen()/255f, c.getBlue()/255f, c.getAlpha()/255f*alpha); Tessellator tessellator = Tessellator.getInstance(); WorldRenderer worldrenderer = tessellator.getWorldRenderer(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/DungeonBlocks.java b/src/main/java/io/github/moulberry/notenoughupdates/DungeonBlocks.java new file mode 100644 index 00000000..29f5edc7 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/DungeonBlocks.java @@ -0,0 +1,315 @@ +package io.github.moulberry.notenoughupdates; + +import io.github.moulberry.notenoughupdates.questing.SBInfo; +import io.github.moulberry.notenoughupdates.util.SpecialColour; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.*; +import net.minecraft.client.renderer.texture.*; +import net.minecraft.client.resources.IResourceManager; +import net.minecraft.client.resources.IResourceManagerReloadListener; +import net.minecraft.client.shader.Framebuffer; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.BufferUtils; +import org.lwjgl.opengl.*; + +import java.nio.IntBuffer; +import java.util.HashMap; +import java.util.Map; + +public class DungeonBlocks implements IResourceManagerReloadListener { + + //public static Framebuffer framebuffer = null; + private static int textureId = -1; + private static IntBuffer intbuffer = null; + private static HashMap<String, Integer> modified = new HashMap<>(); + + @Override + public void onResourceManagerReload(IResourceManager resourceManager) { + reset(); + } + + public static boolean textureExists() { + return textureId != -1 && isInDungeons(); + } + + public static void bindTextureIfExists() { + if(textureExists()) { + GlStateManager.bindTexture(textureId); + } + } + + public static boolean isInDungeons() { + return NotEnoughUpdates.INSTANCE.manager.config.dungeonBlocksEverywhere.value || + (SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("dungeon")); + } + + public static void reset() { + textureId = -1; + intbuffer = null; + for(int tex : modified.values()) { + GlStateManager.deleteTexture(tex); + } + modified.clear(); + } + + public static int getModifiedTexture(ResourceLocation location, int colour) { + String id = location.getResourceDomain()+":"+location.getResourcePath(); + if(modified.containsKey(id)) { + return modified.get(id); + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(location); + int mipmapLevels = GL11.glGetTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL); + int w = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_WIDTH); + int h = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_HEIGHT); + + if(intbuffer == null || intbuffer.capacity() < w*h) intbuffer = BufferUtils.createIntBuffer(w*h); + + int textureId = TextureUtil.glGenTextures(); + GlStateManager.bindTexture(textureId); + + if (mipmapLevels >= 0) { + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, mipmapLevels); + GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MIN_LOD, 0.0F); + GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LOD, (float)mipmapLevels); + GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0.0F); + } + + for (int i = 0; i <= mipmapLevels; ++i) { + GL11.glTexImage2D(GL11.GL_TEXTURE_2D, i, GL11.GL_RGBA, w >> i, h >> i, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, (IntBuffer)((IntBuffer)null)); + } + + GlStateManager.bindTexture(textureId); + + GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); + GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); + + for (int level = 0; level <= mipmapLevels; level++) { + int w2 = w >> level; + int h2 = h >> level; + + Minecraft.getMinecraft().getTextureManager().bindTexture(location); + GL11.glGetTexImage(GL11.GL_TEXTURE_2D, level, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intbuffer); + + for(int x=0; x<w2; x++) { + for(int y=0; y<h2; y++) { + int index = x+y*w2; + + int newCol = colour; + float newAlpha = ((newCol >> 24) & 0xFF)/255f; + float newRed = ((newCol >> 16) & 0xFF)/255f; + float newGreen = ((newCol >> 8) & 0xFF)/255f; + float newBlue = (newCol & 0xFF)/255f; + + int oldCol = intbuffer.get(index); + int oldAlpha = (oldCol >> 24) & 0xFF; + float oldRed = ((oldCol >> 16) & 0xFF)/255f; + float oldGreen = ((oldCol >> 8) & 0xFF)/255f; + float oldBlue = (oldCol & 0xFF)/255f; + + int r = (int)((newRed*newAlpha + oldRed*(1-newAlpha))*255); + int g = (int)((newGreen*newAlpha + oldGreen*(1-newAlpha))*255); + int b = (int)((newBlue*newAlpha + oldBlue*(1-newAlpha))*255); + + intbuffer.put(index, oldAlpha << 24 | r << 16 | g << 8 | b); + } + } + + GlStateManager.bindTexture(textureId); + GL11.glTexImage2D(GL11.GL_TEXTURE_2D, level, GL11.GL_RGBA, w2, h2, + 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intbuffer); + } + + modified.put(id, textureId); + return textureId; + } + + public static void tick() { + if(textureId == -1) { + int locationBlocksId = Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture).getGlTextureId(); + + GlStateManager.bindTexture(locationBlocksId); + int mipmapLevels = GL11.glGetTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL); + int w = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_WIDTH); + int h = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_HEIGHT); + + if(intbuffer == null || intbuffer.capacity() < w*h) intbuffer = BufferUtils.createIntBuffer(w*h); + + if(textureId == -1) { + textureId = TextureUtil.glGenTextures(); + GlStateManager.bindTexture(textureId); + + if (mipmapLevels >= 0) { + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, mipmapLevels); + GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MIN_LOD, 0.0F); + GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LOD, (float)mipmapLevels); + GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0.0F); + } + + for (int i = 0; i <= mipmapLevels; ++i) { + GL11.glTexImage2D(GL11.GL_TEXTURE_2D, i, GL11.GL_RGBA, w >> i, h >> i, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, (IntBuffer)((IntBuffer)null)); + } + } + GlStateManager.bindTexture(textureId); + + GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); + GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); + + HashMap<TextureAtlasSprite, Integer> spriteMap = new HashMap<>(); + spriteMap.put(Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("minecraft:blocks/stonebrick_cracked"), + SpecialColour.specialToSimpleRGB(NotEnoughUpdates.INSTANCE.manager.config.dungCrackedColour.value)); + spriteMap.put(Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("minecraft:blocks/dispenser_front_horizontal"), + SpecialColour.specialToSimpleRGB(NotEnoughUpdates.INSTANCE.manager.config.dungDispenserColour.value)); + spriteMap.put(Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("minecraft:blocks/lever"), + SpecialColour.specialToSimpleRGB(NotEnoughUpdates.INSTANCE.manager.config.dungLeverColour.value)); + spriteMap.put(Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("minecraft:blocks/trip_wire"), + SpecialColour.specialToSimpleRGB(NotEnoughUpdates.INSTANCE.manager.config.dungTripWireColour.value)); + + for (int level = 0; level <= mipmapLevels; level++) { + int w2 = w >> level; + int h2 = h >> level; + + GlStateManager.bindTexture(locationBlocksId); + GL11.glGetTexImage(GL11.GL_TEXTURE_2D, level, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intbuffer); + + for(Map.Entry<TextureAtlasSprite, Integer> entry : spriteMap.entrySet()) { + TextureAtlasSprite tas = entry.getKey(); + for(int x=(int)(w2*tas.getMinU()); x<w2*tas.getMaxU(); x++) { + for(int y=(int)(h2*tas.getMinV()); y<h2*tas.getMaxV(); y++) { + int index = x+y*w2; + + int newCol = entry.getValue(); + float newAlpha = ((newCol >> 24) & 0xFF)/255f; + float newRed = ((newCol >> 16) & 0xFF)/255f; + float newGreen = ((newCol >> 8) & 0xFF)/255f; + float newBlue = (newCol & 0xFF)/255f; + + /*int oldCol = intbuffer.get(index); + int oldAlpha = (oldCol >> 24) & 0xFF; + float oldRed = ((oldCol >> 16) & 0xFF)/255f; + float oldGreen = ((oldCol >> 8) & 0xFF)/255f; + float oldBlue = (oldCol & 0xFF)/255f; + + int r = (int)((newRed*newAlpha + oldRed*(1-newAlpha))*255); + int g = (int)((newGreen*newAlpha + oldGreen*(1-newAlpha))*255); + int b = (int)((newBlue*newAlpha + oldBlue*(1-newAlpha))*255);*/ + + intbuffer.put(index, newCol); + } + } + } + + GlStateManager.bindTexture(textureId); + GL11.glTexImage2D(GL11.GL_TEXTURE_2D, level, GL11.GL_RGBA, w2, h2, + 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intbuffer); + } + } + /*if(framebuffer == null || true) { + Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture); + int w = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_WIDTH); + int h = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_HEIGHT); + + framebuffer = checkFramebufferSizes(framebuffer, w, h); + + try { + int locationBlocksId = Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture).getGlTextureId(); + + //framebuffer2.bindFramebufferTexture(); + //GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, w, h, 0, GL11.GL_RGBA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, ((ByteBuffer)null)); + + //textureId = GlStateManager.generateTexture(); + //GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, w, h, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, ((ByteBuffer)null)); + + GL11.glPushMatrix(); + + GlStateManager.matrixMode(5889); + GlStateManager.loadIdentity(); + GlStateManager.ortho(0.0D, w, h, 0.0D, 1000.0D, 3000.0D); + GlStateManager.matrixMode(5888); + GlStateManager.loadIdentity(); + GlStateManager.translate(0.0F, 0.0F, -2000.0F); + + framebuffer.bindFramebufferTexture(); + if (Minecraft.getMinecraft().gameSettings.mipmapLevels >= 0) { + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, Minecraft.getMinecraft().gameSettings.mipmapLevels); + GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MIN_LOD, 0.0F); + GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LOD, (float)Minecraft.getMinecraft().gameSettings.mipmapLevels); + GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0.0F); + } + + for (int i = 0; i <= Minecraft.getMinecraft().gameSettings.mipmapLevels; ++i) { + GL11.glTexImage2D(GL11.GL_TEXTURE_2D, i, GL11.GL_RGBA, w >> i, h >> i, + 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, ((IntBuffer)null)); + } + + //framebuffer.framebufferClear(); + framebuffer.bindFramebuffer(true); + GlStateManager.clearColor(1, 1, 1, 0); + GlStateManager.clear(GL11.GL_COLOR_BUFFER_BIT); + GL11.glClearColor(1, 1, 1, 0); + + Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(0, 0, w, h, 0, 1, 1, 0, GL11.GL_LINEAR); + + framebuffer.bindFramebufferTexture(); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, Minecraft.getMinecraft().gameSettings.mipmapLevels); + GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MIN_LOD, 0.0F); + GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LOD, (float)Minecraft.getMinecraft().gameSettings.mipmapLevels); + GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0.0F); + GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); + + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + GlStateManager.matrixMode(5889); + GlStateManager.loadIdentity(); + GlStateManager.ortho(0.0D, scaledResolution.getScaledWidth_double(), scaledResolution.getScaledHeight_double(), + 0.0D, 1000.0D, 3000.0D); + GlStateManager.matrixMode(5888); + GlStateManager.loadIdentity(); + GlStateManager.translate(0.0F, 0.0F, -2000.0F); + + GL11.glPopMatrix(); + + Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(true); + + + /*framebuffer.bindFramebufferTexture(); + if(Keyboard.isKeyDown(Keyboard.KEY_B)) Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture); + Utils.drawTexturedRect(0, 0, w, h, GL11.GL_NEAREST);*/ + + /*GlStateManager.bindTexture(textureId); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); + GlStateManager.enableBlend(); + GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); + + //GlStateManager.enableTexture2D(); + //GlStateManager.enableBlend(); + //GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); + + + //GlStateManager.disableBlend(); + + Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(true); + } catch(Exception e) { + e.printStackTrace(); + } + }*/ + } + + private static Framebuffer checkFramebufferSizes(Framebuffer framebuffer, int width, int height) { + if(framebuffer == null || framebuffer.framebufferWidth != width || framebuffer.framebufferHeight != height) { + if(framebuffer == null) { + framebuffer = new Framebuffer(width, height, false); + framebuffer.framebufferColor[0] = 1f; + framebuffer.framebufferColor[1] = 0f; + framebuffer.framebufferColor[2] = 0f; + framebuffer.framebufferColor[3] = 0; + } else { + framebuffer.createBindFramebuffer(width, height); + } + framebuffer.setFramebufferFilter(GL11.GL_NEAREST); + } + return framebuffer; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/DungeonMap.java b/src/main/java/io/github/moulberry/notenoughupdates/DungeonMap.java new file mode 100644 index 00000000..aac7726a --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/DungeonMap.java @@ -0,0 +1,416 @@ +package io.github.moulberry.notenoughupdates; + +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.block.material.MapColor; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.texture.DynamicTexture; +import net.minecraft.item.ItemMap; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.storage.MapData; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.lwjgl.opengl.GL11; + +import java.awt.*; +import java.awt.image.BufferedImage; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +public class DungeonMap { + + private int[] mapTextureData = null; + private DynamicTexture dynamicTexture = new DynamicTexture(128, 128); + private ResourceLocation dynamicRL = new ResourceLocation("notenoughupdates:dynamic_dungeonmap.png"); + + private void setMapRGB(int x, int y, int rgb) { + if(mapTextureData != null) { + mapTextureData[x+y*128] = rgb; + } + } + + private class RoomOffset { + int x; + int y; + + public RoomOffset(int x, int y) { + this.x = x; + this.y = y; + } + + public RoomOffset left() { + return new RoomOffset(x-1, y); + } + + public RoomOffset right() { + return new RoomOffset(x+1, y); + } + + public RoomOffset up() { + return new RoomOffset(x, y-1); + } + + public RoomOffset down() { + return new RoomOffset(x, y+1); + } + + public RoomOffset[] getNeighbors() { + return new RoomOffset[]{left(), right(), up(), down()}; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + RoomOffset that = (RoomOffset) o; + return x == that.x && y == that.y; + } + + @Override + public int hashCode() { + return Objects.hash(x, y); + } + } + + private enum RoomConnectionType { + NONE, WALL, CORRIDOR, ROOM_DIVIDER + } + + private class RoomConnection { + RoomConnectionType type; + Color colour; + + public RoomConnection(RoomConnectionType type, Color colour) { + this.type = type; + this.colour = colour; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + RoomConnection that = (RoomConnection) o; + return type == that.type && + Objects.equals(colour, that.colour); + } + + @Override + public int hashCode() { + return Objects.hash(type, colour); + } + } + + private class Room { + Color colour = new Color(0, 0, 0, 0); + + RoomConnection left = new RoomConnection(RoomConnectionType.NONE, new Color(0, true)); + RoomConnection up = new RoomConnection(RoomConnectionType.NONE, new Color(0, true)); + RoomConnection right = new RoomConnection(RoomConnectionType.NONE, new Color(0, true)); + RoomConnection down = new RoomConnection(RoomConnectionType.NONE, new Color(0, true)); + + public void render(int roomSize, int connectorSize) { + Gui.drawRect(0, 0, roomSize, roomSize, colour.getRGB()); + } + } + + public void render(int[] renderTo, int x, int y, int rgb) { + int i = x+y*128; + if(i >= 0 && i < renderTo.length) { + renderTo[i] = rgb; + } + } + + public void render(RoomOffset roomOffset, int[] renderTo, int startOffsetX, int startOffsetY) { + /*for(Map.Entry<RoomOffset, Room> entry : roomMap.entrySet()) { + + }*/ + if(roomMap.containsKey(roomOffset)) { + Room room = roomMap.get(roomOffset); + + for(int xo=0; xo<16; xo++) { + for(int yo=0; yo<16; yo++) { + int x = (roomOffset.x-startOffsetX)*20+xo; + int y = (roomOffset.y-startOffsetY)*20+yo; + + render(renderTo, x, y, room.colour.getRGB()); + } + } + + for(int k=0; k<4; k++) { + RoomConnection connection; + if(k == 0) { + connection = room.up; + } else if(k == 1) { + connection = room.right; + } else if(k == 2) { + connection = room.down; + } else { + connection = room.left; + } + if(connection.type == RoomConnectionType.NONE || connection.type == RoomConnectionType.WALL) continue; + for(int o1=1; o1<=4; o1++) { + int min = 0; + int max = 16; + if(connection.type == RoomConnectionType.CORRIDOR) { + min = 6; + max = 10; + } + for (int o2 = min; o2 < max; o2++) { + int x; + int y; + + if(k == 0) { + x = (roomOffset.x-startOffsetX)*20+o2; + y = (roomOffset.y-startOffsetY)*20-o1; + } else if(k == 1) { + x = (roomOffset.x-startOffsetX)*20+15+o1; + y = (roomOffset.y-startOffsetY)*20+o2; + } else if(k == 2) { + x = (roomOffset.x-startOffsetX)*20+o2; + y = (roomOffset.y-startOffsetY)*20+15+o1; + } else { + x = (roomOffset.x-startOffsetX)*20-o1; + y = (roomOffset.y-startOffsetY)*20+o2; + } + + render(renderTo, x, y, connection.colour.getRGB()); + } + } + } + } + + } + + private HashMap<RoomOffset, Room> roomMap = new HashMap<>(); + private Color[][] colourMap = new Color[128][128]; + private int startRoomX = -1; + private int startRoomY = -1; + private int connectorSize = 5; + private int roomSize = 0; + + public void updateRoomConnections(RoomOffset roomOffset) { + if(roomMap.containsKey(roomOffset)) { + Room room = roomMap.get(roomOffset); + + for(int k=0; k<4; k++) { + int totalFilled = 0; + for(int i=0; i<roomSize; i++) { + for(int j=1; j<=connectorSize; j++) { + int x = startRoomX + roomOffset.x*(roomSize+connectorSize); + int y = startRoomY + roomOffset.y*(roomSize+connectorSize); + + if(k == 0) { + x += i; + y -= j; + } else if(k == 1) { + x += roomSize+j-1; + y += i; + } else if(k == 2) { + x += i; + y += roomSize+j-1; + } else { + x -= j; + y += i; + } + + if(x < colourMap.length && y < colourMap[x].length) { + if(colourMap[x][y].equals(room.colour)) { + totalFilled++; + } + } + } + } + float proportionFilled = (float)totalFilled/roomSize/connectorSize; + + RoomConnectionType type = RoomConnectionType.WALL; + if(proportionFilled > 0.8) { + type = RoomConnectionType.ROOM_DIVIDER; + } else if(proportionFilled > 0.1) { + type = RoomConnectionType.CORRIDOR; + } + if(k == 0) { + room.up = new RoomConnection(type, room.colour); + } else if(k == 1) { + room.right = new RoomConnection(type, room.colour); + } else if(k == 2) { + room.down = new RoomConnection(type, room.colour); + } else { + room.left = new RoomConnection(type, room.colour); + } + } + } + } + + public void loadNeighbors(RoomOffset room) { + if(!roomMap.containsKey(room)) { + roomMap.put(room, new Room()); + } + for(RoomOffset neighbor : room.getNeighbors()) { + if(!roomMap.containsKey(neighbor)) { + int x = startRoomX + neighbor.x*(roomSize+connectorSize); + int y = startRoomY + neighbor.y*(roomSize+connectorSize); + + if(x > 0 && y > 0 && x+roomSize < colourMap.length && y+roomSize < colourMap[x].length) { + roomMap.put(neighbor, new Room()); + loadNeighbors(neighbor); + } + } + } + } + + public void updateRoomColours() { + for(Map.Entry<RoomOffset, Room> entry : roomMap.entrySet()) { + int x = startRoomX + entry.getKey().x*(roomSize+connectorSize); + int y = startRoomY + entry.getKey().y*(roomSize+connectorSize); + + try { + entry.getValue().colour = colourMap[x][y]; + } catch(Exception e) {} + } + } + + @SubscribeEvent + public void onRenderOverlay(RenderGameOverlayEvent event) { + //System.out.println("render overlayw"); + if(event.type == RenderGameOverlayEvent.ElementType.ALL) { + ItemStack stack = Minecraft.getMinecraft().thePlayer.inventory.mainInventory[8]; + if(NotEnoughUpdates.INSTANCE.colourMap != null || stack != null && stack.getItem() instanceof ItemMap) { + if(mapTextureData == null) { + mapTextureData = dynamicTexture.getTextureData(); + } + + if(NotEnoughUpdates.INSTANCE.colourMap != null) { + colourMap = NotEnoughUpdates.INSTANCE.colourMap; + } else { + ItemMap map = (ItemMap) stack.getItem(); + MapData mapData = map.getMapData(stack, Minecraft.getMinecraft().theWorld); + + if(mapData == null) return; + + for (int i = 0; i < 16384; ++i) { + int x = i % 128; + int y = i / 128; + + int j = mapData.colors[i] & 255; + + Color c; + if (j / 4 == 0) { + c = new Color((i + i / 128 & 1) * 8 + 16 << 24, true); + } else { + c = new Color(MapColor.mapColorArray[j / 4].func_151643_b(j & 3), true); + } + + colourMap[x][y] = c; + } + } + + for(int x=0; x<colourMap.length; x++) { + for(int y=0; y<colourMap[x].length; y++) { + Color c = colourMap[x][y]; + if(c.getAlpha() > 80) { + if(startRoomX < 0 && startRoomY < 0 && c.getRed() == 0 && c.getGreen() == 124 && c.getBlue() == 0) { + roomSize = 0; + out: + for(int xd=0; xd<=20; xd++) { + for(int yd=0; yd<=20; yd++) { + if(x+xd >= colourMap.length || y+yd >= colourMap[x+xd].length) continue; + Color c2 = colourMap[x+xd][y+yd]; + + if(c2.getGreen() != 124 || c2.getAlpha() <= 80) { + if(xd < 10 && yd < 10) { + break out; + } + } else { + roomSize = Math.max(roomSize, Math.min(xd+1, yd+1)); + } + if(xd == 20 && yd == 20) { + if(roomSize == 0) roomSize = 20; + startRoomX = x; + startRoomY = y; + } + } + } + } + } + } + } + + for(int i=0; i<roomSize; i++) { + for(int k=0; k<4; k++) { + for(int j=1; j<8; j++) { + int x; + int y; + + if(k == 0) { + x = startRoomX+i; + y = startRoomY-j; + } else if(k == 1) { + x = startRoomX+roomSize+j-1; + y = startRoomY+i; + } else if(k == 2) { + x = startRoomX+i; + y = startRoomY+roomSize+j-1; + } else { + x = startRoomX-j; + y = startRoomY+i; + } + + if(x < colourMap.length && y < colourMap[x].length) { + if(colourMap[x][y].getAlpha() > 80) { + if(j == 1) { + break; + } + connectorSize = Math.min(connectorSize, j-1); + } + } + } + } + } + + loadNeighbors(new RoomOffset(0, 0)); + updateRoomColours(); + for(RoomOffset offset : roomMap.keySet()) { + updateRoomConnections(offset); + } + + //System.out.println("room x: " + startRoomX + "room y: " + startRoomY + " size: " + roomSize + " connector: " + connectorSize); + + //rendering + for (int i = 0; i < 16384; ++i) { + mapTextureData[i] = 0; + } + + if(!roomMap.isEmpty()) { + int minRoomX = 999; + int minRoomY = 999; + int maxRoomX = -999; + int maxRoomY = -999; + for(RoomOffset offset : roomMap.keySet()) { + minRoomX = Math.min(offset.x, minRoomX); + minRoomY = Math.min(offset.y, minRoomY); + maxRoomX = Math.max(offset.x, maxRoomX); + maxRoomY = Math.max(offset.y, maxRoomY); + } + + for(RoomOffset offset : roomMap.keySet()) { + render(offset, mapTextureData, minRoomX, minRoomY); + } + + //process + + dynamicTexture.updateDynamicTexture(); + Minecraft.getMinecraft().getTextureManager().loadTexture(dynamicRL, dynamicTexture); + + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(dynamicRL); + Utils.drawTexturedRect(0, 0, 128, 128, GL11.GL_NEAREST); + } + } + } + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/GuiEnchantColour.java b/src/main/java/io/github/moulberry/notenoughupdates/GuiEnchantColour.java index 8e14598f..6e25e7fd 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/GuiEnchantColour.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/GuiEnchantColour.java @@ -2,6 +2,7 @@ package io.github.moulberry.notenoughupdates; import com.google.common.base.Splitter; import io.github.moulberry.notenoughupdates.itemeditor.GuiElementTextField; +import io.github.moulberry.notenoughupdates.util.LerpingInteger; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; @@ -9,6 +10,7 @@ import net.minecraft.client.renderer.GlStateManager; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import java.io.IOException; @@ -34,6 +36,8 @@ public class GuiEnchantColour extends GuiScreen { private HashMap<Integer, String> comparators = new HashMap<>(); private List<GuiElementTextField[]> guiElementTextFields = new ArrayList<>(); + private LerpingInteger scroll = new LerpingInteger(0, 100); + @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { drawDefaultBackground(); @@ -42,7 +46,21 @@ public class GuiEnchantColour extends GuiScreen { ySize = 53+25*enchantColours.size(); guiLeft = (width-xSize)/2; - guiTop = (height-ySize)/2; + + if(ySize > height) { + if(scroll.getTarget() > 0) { + scroll.setTarget(0); + } else if(scroll.getTarget() < height-ySize) { + scroll.setTarget(height-ySize); + } + scroll.tick(); + guiTop = scroll.getValue(); + } else { + guiTop = (height-ySize)/2; + scroll.setValue(0); + scroll.resetTimer(); + } + NotEnoughUpdates.INSTANCE.manager.loadConfig(); @@ -151,6 +169,21 @@ public class GuiEnchantColour extends GuiScreen { } @Override + public void handleMouseInput() throws IOException { + super.handleMouseInput(); + + int dWheel = Mouse.getEventDWheel(); + + if(dWheel < 0) { + scroll.setTarget(scroll.getTarget()-50); + scroll.resetTimer(); + } else if(dWheel > 0) { + scroll.setTarget(scroll.getTarget()+50); + scroll.resetTimer(); + } + } + + @Override protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { super.mouseClicked(mouseX, mouseY, mouseButton); for(int yIndex=0; yIndex<guiElementTextFields.size(); yIndex++) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java b/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java index fb8671cb..c9ca87fd 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java @@ -25,6 +25,12 @@ public class GuiTextures { public static final ResourceLocation item_haschild = new ResourceLocation("notenoughupdates:item_haschild.png"); public static final ResourceLocation button_tex = new ResourceLocation("notenoughupdates:button.png"); + public static final ResourceLocation button_white = new ResourceLocation("notenoughupdates:button_white.png"); + public static final ResourceLocation colour_selector_dot = new ResourceLocation("notenoughupdates:colour_selector_dot.png"); + public static final ResourceLocation colour_selector_bar = new ResourceLocation("notenoughupdates:colour_selector_bar.png"); + public static final ResourceLocation colour_selector_bar_alpha = new ResourceLocation("notenoughupdates:colour_selector_bar_alpha.png"); + public static final ResourceLocation colour_selector_chroma = new ResourceLocation("notenoughupdates:colour_selector_chroma.png"); + public static final ResourceLocation accessory_bag_overlay = new ResourceLocation("notenoughupdates:accessory_bag_overlay.png"); public static final ResourceLocation quickcommand_background = new ResourceLocation("notenoughupdates:quickcommand_background.png"); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java index 95eefef5..a2ce0055 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java @@ -7,7 +7,7 @@ import io.github.moulberry.notenoughupdates.cosmetics.CapeManager; import io.github.moulberry.notenoughupdates.gamemodes.SBGamemodes; import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; -import io.github.moulberry.notenoughupdates.questing.SBScoreboardData; +import io.github.moulberry.notenoughupdates.questing.SBInfo; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; @@ -23,7 +23,6 @@ import net.minecraft.event.ClickEvent; import net.minecraft.init.Blocks; import net.minecraft.inventory.ContainerChest; import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -123,22 +122,39 @@ public class NEUEventListener { */ private HashMap<String, Long> newItemAddMap = new HashMap<>(); private long lastLongUpdate = 0; + private long lastVeryLongUpdate = 0; private long lastSkyblockScoreboard = 0; @SubscribeEvent public void onTick(TickEvent.ClientTickEvent event) { if(event.phase != TickEvent.Phase.START) return; boolean longUpdate = false; + boolean veryLongUpdate = false; long currentTime = System.currentTimeMillis(); if(currentTime - lastLongUpdate > 1000) { longUpdate = true; lastLongUpdate = currentTime; } + if(currentTime - lastVeryLongUpdate > 10000) { + veryLongUpdate = true; + lastVeryLongUpdate = currentTime; + } + if(veryLongUpdate) { + DungeonBlocks.reset(); + } if(longUpdate) { + DungeonBlocks.tick(); neu.updateSkyblockScoreboard(); CapeManager.getInstance().tick(); - if(!(Minecraft.getMinecraft().currentScreen instanceof GuiChest)) { + if(Minecraft.getMinecraft().currentScreen instanceof GuiChest) { + GuiChest eventGui = (GuiChest) Minecraft.getMinecraft().currentScreen; + ContainerChest cc = (ContainerChest) eventGui.inventorySlots; + String containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText(); + if(!containerName.trim().startsWith("Accessory Bag")) { + AccessoryBagOverlay.resetCache(); + } + } else { AccessoryBagOverlay.resetCache(); } @@ -170,7 +186,7 @@ public class NEUEventListener { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); } } - SBScoreboardData.getInstance().tick(); + SBInfo.getInstance().tick(); //GuiQuestLine.questLine.tick(); } if(currentTime - lastSkyblockScoreboard < 5*60*1000) { //5 minutes @@ -443,6 +459,14 @@ public class NEUEventListener { EnumChatFormatting.RED+"Invalid recipe ")) { r = ""; } + if(e.message.getFormattedText().contains(EnumChatFormatting.YELLOW+"Visit the Auction House to collect your item!")) { + if(NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.latestBid != null && + System.currentTimeMillis() - NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.latestBidMillis < 5000) { + NotEnoughUpdates.INSTANCE.sendChatMessage("/viewauction " + + NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.niceAucId( + NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.latestBid)); + } + } if(r != null) { if(neu.manager.failViewItem(r)) { e.setCanceled(true); @@ -923,91 +947,95 @@ public class NEUEventListener { @SubscribeEvent(priority = EventPriority.LOW) public void onItemTooltipLow(ItemTooltipEvent event) { + if(!NotEnoughUpdates.INSTANCE.isOnSkyblock()) return; + boolean dungeonProfit = false; int index = 0; List<String> newTooltip = new ArrayList<>(); for(String line : event.toolTip) { - for(String op : neu.manager.config.enchantColours.value) { - List<String> colourOps = GuiEnchantColour.splitter.splitToList(op); - String enchantName = GuiEnchantColour.getColourOpIndex(colourOps, 0); - String comparator = GuiEnchantColour.getColourOpIndex(colourOps, 1); - String comparison = GuiEnchantColour.getColourOpIndex(colourOps, 2); - String colourCode = GuiEnchantColour.getColourOpIndex(colourOps, 3); + if(event.itemStack.isItemEnchanted()) { + for(String op : neu.manager.config.enchantColours.value) { + List<String> colourOps = GuiEnchantColour.splitter.splitToList(op); + String enchantName = GuiEnchantColour.getColourOpIndex(colourOps, 0); + String comparator = GuiEnchantColour.getColourOpIndex(colourOps, 1); + String comparison = GuiEnchantColour.getColourOpIndex(colourOps, 2); + String colourCode = GuiEnchantColour.getColourOpIndex(colourOps, 3); - if(enchantName.length() == 0) continue; - if(comparator.length() == 0) continue; - if(comparison.length() == 0) continue; - if(colourCode.length() == 0) continue; + if(enchantName.length() == 0) continue; + if(comparator.length() == 0) continue; + if(comparison.length() == 0) continue; + if(colourCode.length() == 0) continue; - if(enchantName.contains("(") || enchantName.contains(")")) continue; + if(enchantName.contains("(") || enchantName.contains(")")) continue; - int comparatorI = ">=<".indexOf(comparator.charAt(0)); + int comparatorI = ">=<".indexOf(comparator.charAt(0)); - int levelToFind = -1; - try { - levelToFind = Integer.parseInt(comparison); - } catch(Exception e) { continue; } + int levelToFind = -1; + try { + levelToFind = Integer.parseInt(comparison); + } catch(Exception e) { continue; } - if(comparatorI < 0) continue; - if("0123456789abcdefz".indexOf(colourCode.charAt(0)) < 0) continue; + if(comparatorI < 0) continue; + if("0123456789abcdefz".indexOf(colourCode.charAt(0)) < 0) continue; - //item_lore = item_lore.replaceAll("\\u00A79("+lvl4Max+" IV)", EnumChatFormatting.DARK_PURPLE+"$1"); - //9([a-zA-Z ]+?) ([0-9]+|(I|II|III|IV|V|VI|VII|VIII|IX|X))(,|$) - Pattern pattern; - try { - String prefix = "\u00A79"; - if(enchantName.startsWith("ULT_")) prefix = "\u00A7l\u00A7d"; - pattern = Pattern.compile(prefix+"("+enchantName+") ([0-9]+|(I|II|III|IV|V|VI|VII|VIII|IX|X))(,|$)"); - } catch(Exception e) {continue;} //malformed regex - Matcher matcher = pattern.matcher(line); - int matchCount = 0; - while(matcher.find() && matchCount < 5) { - matchCount++; - int level = -1; - String levelStr = matcher.group(2); - if(levelStr == null) continue; + //item_lore = item_lore.replaceAll("\\u00A79("+lvl4Max+" IV)", EnumChatFormatting.DARK_PURPLE+"$1"); + //9([a-zA-Z ]+?) ([0-9]+|(I|II|III|IV|V|VI|VII|VIII|IX|X))(,|$) + Pattern pattern; try { - level = Integer.parseInt(levelStr); - } catch(Exception e) { - switch(levelStr) { - case "I": - level = 1; break; - case "II": - level = 2; break; - case "III": - level = 3; break; - case "IV": - level = 4; break; - case "V": - level = 5; break; - case "VI": - level = 6; break; - case "VII": - level = 7; break; - case "VIII": - level = 8; break; - case "IX": - level = 9; break; - case "X": - level = 10; break; + String prefix = "\u00A79"; + if(enchantName.startsWith("ULT_")) prefix = "\u00A7l\u00A7d"; + pattern = Pattern.compile(prefix+"("+enchantName+") ([0-9]+|(I|II|III|IV|V|VI|VII|VIII|IX|X))(,|$)"); + } catch(Exception e) {continue;} //malformed regex + Matcher matcher = pattern.matcher(line); + int matchCount = 0; + while(matcher.find() && matchCount < 5) { + matchCount++; + int level = -1; + String levelStr = matcher.group(2); + if(levelStr == null) continue; + try { + level = Integer.parseInt(levelStr); + } catch(Exception e) { + switch(levelStr) { + case "I": + level = 1; break; + case "II": + level = 2; break; + case "III": + level = 3; break; + case "IV": + level = 4; break; + case "V": + level = 5; break; + case "VI": + level = 6; break; + case "VII": + level = 7; break; + case "VIII": + level = 8; break; + case "IX": + level = 9; break; + case "X": + level = 10; break; + } } - } - boolean matches = false; - if(level > 0) { - switch(comparator) { - case ">": - matches = level > levelToFind; break; - case "=": - matches = level == levelToFind; break; - case "<": - matches = level < levelToFind; break; + boolean matches = false; + if(level > 0) { + switch(comparator) { + case ">": + matches = level > levelToFind; break; + case "=": + matches = level == levelToFind; break; + case "<": + matches = level < levelToFind; break; + } } - } - if(matches) { - if(!colourCode.equals("z")) { - line = line.replaceAll("\\u00A79"+matcher.group(1), "\u00A7"+colourCode+matcher.group(1)); - } else { - line = line.replaceAll("\\u00A79"+matcher.group(1), Utils.chromaString(matcher.group(1))); + if(matches) { + if(!colourCode.equals("z")) { + line = line.replaceAll("\\u00A79"+matcher.group(1), "\u00A7"+colourCode+matcher.group(1)); + } else { + line = line.replaceAll("\\u00A79"+matcher.group(1), Utils.chromaString(matcher.group(1))); + } } } } @@ -1157,8 +1185,88 @@ public class NEUEventListener { index++; } + event.toolTip.clear(); event.toolTip.addAll(newTooltip); + + if(neu.manager.config.invAuctionPrice.value || neu.manager.config.invBazaarPrice.value) { + String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(event.itemStack); + + if(internalname != null) { + JsonObject auctionInfo = neu.manager.auctionManager.getItemAuctionInfo(internalname); + JsonObject bazaarInfo = neu.manager.auctionManager.getBazaarInfo(internalname); + + boolean hasAuctionPrice = neu.manager.config.invAuctionPrice.value && auctionInfo != null; + boolean hasBazaarPrice = neu.manager.config.invBazaarPrice.value && bazaarInfo != null; + + int lowestBin = neu.manager.auctionManager.getLowestBin(internalname); + + NumberFormat format = NumberFormat.getInstance(Locale.US); + + APIManager.CraftInfo craftCost = neu.manager.auctionManager.getCraftCost(internalname); + + if(hasAuctionPrice || hasBazaarPrice || craftCost.fromRecipe) event.toolTip.add(""); + if(hasAuctionPrice) { + if(lowestBin > 0) { + event.toolTip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Lowest BIN: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(lowestBin)+" coins"); + } + int auctionPrice = (int)(auctionInfo.get("price").getAsFloat() / auctionInfo.get("count").getAsFloat()); + event.toolTip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"AH Price: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(auctionPrice)+" coins"); + if(neu.manager.config.advancedPriceInfo.value) { + event.toolTip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"AH Sales: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(auctionInfo.get("sales").getAsFloat())+" sales/day"); + } + if(auctionInfo.has("clean_price")) { + event.toolTip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"AH Price (Clean): "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format((int)auctionInfo.get("clean_price").getAsFloat())+" coins"); + if(neu.manager.config.advancedPriceInfo.value) { + event.toolTip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"AH Sales (Clean): "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(auctionInfo.get("clean_sales").getAsFloat())+" sales/day"); + } + } + + } else if(hasBazaarPrice) { + if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { + int bazaarBuyPrice = (int)bazaarInfo.get("avg_buy").getAsFloat()*64; + event.toolTip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Buy (Stack): "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarBuyPrice)+" coins"); + int bazaarSellPrice = (int)bazaarInfo.get("avg_sell").getAsFloat()*64; + event.toolTip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Sell (Stack): "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarSellPrice)+" coins"); + if(neu.manager.config.advancedPriceInfo.value) { + int bazaarInstantBuyPrice = (int)bazaarInfo.get("curr_buy").getAsFloat()*64; + event.toolTip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Insta-Buy (Stack): "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarInstantBuyPrice)+" coins"); + int bazaarInstantSellPrice = (int)bazaarInfo.get("curr_sell").getAsFloat()*64; + event.toolTip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Insta-Sell (Stack): "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarInstantSellPrice)+" coins"); + } + } else { + event.toolTip.add(EnumChatFormatting.DARK_GRAY.toString()+"[SHIFT show stack]"); + int bazaarBuyPrice = (int)bazaarInfo.get("avg_buy").getAsFloat(); + event.toolTip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Buy: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarBuyPrice)+" coins"); + int bazaarSellPrice = (int)bazaarInfo.get("avg_sell").getAsFloat(); + event.toolTip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Sell: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarSellPrice)+" coins"); + if(neu.manager.config.advancedPriceInfo.value) { + int bazaarInstantBuyPrice = (int)bazaarInfo.get("curr_buy").getAsFloat(); + event.toolTip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Insta-Buy: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarInstantBuyPrice)+" coins"); + int bazaarInstantSellPrice = (int)bazaarInfo.get("curr_sell").getAsFloat(); + event.toolTip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Insta-Sell: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarInstantSellPrice)+" coins"); + } + } + } + if((hasAuctionPrice || hasBazaarPrice) && craftCost.fromRecipe) { + event.toolTip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Raw Craft Cost: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format((int)craftCost.craftCost)+" coins"); + } + } + } } /** diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index c0932fcf..c78885c3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -69,6 +69,8 @@ public class NEUManager { private HashMap<String, Set<String>> usagesMap = new HashMap<>(); + public String latestRepoCommit = null; + public File configLocation; public File repoLocation; public File configFile; @@ -92,7 +94,7 @@ public class NEUManager { repoLocation.mkdir(); this.itemRenameFile = new File(configLocation, "itemRename.json"); - try { itemRenameJson = getJsonFromFile(itemRenameFile); } catch(IOException ignored) {} + itemRenameJson = getJsonFromFile(itemRenameFile); if(itemRenameJson == null) { itemRenameJson = new JsonObject(); } @@ -144,13 +146,13 @@ public class NEUManager { /** * Parses a file in to a JsonObject. */ - public JsonObject getJsonFromFile(File file) throws IOException { + public JsonObject getJsonFromFile(File file) { try { InputStream in = new FileInputStream(file); BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)); JsonObject json = gson.fromJson(reader, JsonObject.class); return json; - } catch(Exception e) { e.printStackTrace(); return null; } + } catch(Exception e) { return null; } } public void resetRepo() { @@ -210,18 +212,18 @@ public class NEUManager { JsonObject currentCommitJSON = getJsonFromFile(new File(configLocation, "currentCommit.json")); - String latestCommit = null; + latestRepoCommit = null; try(Reader inReader = new InputStreamReader(new URL(GIT_COMMITS_URL).openStream())) { JsonObject commits = gson.fromJson(inReader, JsonObject.class); - latestCommit = commits.get("sha").getAsString(); + latestRepoCommit = commits.get("sha").getAsString(); } catch (Exception e) { e.printStackTrace(); } - if(latestCommit == null || latestCommit.isEmpty()) return; + if(latestRepoCommit == null || latestRepoCommit.isEmpty()) return; if(new File(configLocation, "repo").exists() && new File(configLocation, "repo/items").exists()) { - if(currentCommitJSON != null && currentCommitJSON.get("sha").getAsString().equals(latestCommit)) { + if(currentCommitJSON != null && currentCommitJSON.get("sha").getAsString().equals(latestRepoCommit)) { dialog.setVisible(false); return; } @@ -330,9 +332,9 @@ public class NEUManager { }*/ } - if(currentCommitJSON == null || !currentCommitJSON.get("sha").getAsString().equals(latestCommit)) { + if(currentCommitJSON == null || !currentCommitJSON.get("sha").getAsString().equals(latestRepoCommit)) { JsonObject newCurrentCommitJSON = new JsonObject(); - newCurrentCommitJSON.addProperty("sha", latestCommit); + newCurrentCommitJSON.addProperty("sha", latestRepoCommit); try { writeJson(newCurrentCommitJSON, new File(configLocation, "currentCommit.json")); } catch (IOException e) { @@ -447,7 +449,7 @@ public class NEUManager { } } } - } catch(IOException e) { + } catch(Exception e) { e.printStackTrace(); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index 49a886b6..450653da 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -10,9 +10,7 @@ import io.github.moulberry.notenoughupdates.mbgui.MBAnchorPoint; import io.github.moulberry.notenoughupdates.mbgui.MBGuiElement; import io.github.moulberry.notenoughupdates.mbgui.MBGuiGroupAligned; import io.github.moulberry.notenoughupdates.mbgui.MBGuiGroupFloating; -import io.github.moulberry.notenoughupdates.util.LerpingFloat; -import io.github.moulberry.notenoughupdates.util.LerpingInteger; -import io.github.moulberry.notenoughupdates.util.Utils; +import io.github.moulberry.notenoughupdates.util.*; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.*; import net.minecraft.client.gui.inventory.GuiContainer; @@ -58,6 +56,8 @@ import static io.github.moulberry.notenoughupdates.GuiTextures.*; public class NEUOverlay extends Gui { + private static final ResourceLocation SUPERGEHEIMNISVERMOGEN = new ResourceLocation("notenoughupdates:supersecretassets/bald.png"); + private NEUManager manager; private String mobRegex = ".*?((_MONSTER)|(_ANIMAL)|(_MINIBOSS)|(_BOSS)|(_SC))$"; @@ -540,6 +540,7 @@ public class NEUOverlay extends Gui { itemPaneOffsetFactor.setValue(1); itemPaneTabOffset.setValue(20); } + if(activeInfoPane != null) activeInfoPane.reset(); } /** @@ -1072,6 +1073,10 @@ public class NEUOverlay extends Gui { * Checks whether an item matches the current sort mode. */ public boolean checkMatchesSort(String internalname, JsonObject item) { + if(!manager.config.showVanillaItems.value && item.has("vanilla") && item.get("vanilla").getAsBoolean()) { + return false; + } + if(getSortMode() == SORT_MODE_ALL) { return !internalname.matches(mobRegex); } else if(getSortMode() == SORT_MODE_MOB) { @@ -1120,7 +1125,6 @@ public class NEUOverlay extends Gui { } for(String itemname : entry.getValue()) { JsonObject item = manager.getItemInformation().get(itemname); - System.out.println("searching "+itemname); if(item != null) searchedItems.add(item); } } @@ -1600,6 +1604,7 @@ public class NEUOverlay extends Gui { } int guiScaleLast = 0; + private boolean showVanillaLast = false; /** * Renders the search bar, quick commands, item selection (right) and item info (left) gui elements. @@ -1613,6 +1618,18 @@ public class NEUOverlay extends Gui { scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); int width = scaledresolution.getScaledWidth(); int height = scaledresolution.getScaledHeight(); + + if(showVanillaLast != manager.config.showVanillaItems.value) { + showVanillaLast = manager.config.showVanillaItems.value; + updateSearch(); + } + + if(textField.getText().toLowerCase().contains("bald")) { + Minecraft.getMinecraft().getTextureManager().bindTexture(SUPERGEHEIMNISVERMOGEN); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect((width-64)/2f, (height-64)/2f-114, 64, 64, GL11.GL_LINEAR); + GlStateManager.bindTexture(0); + } updateGuiGroupSize(); @@ -1631,13 +1648,13 @@ public class NEUOverlay extends Gui { yaw++; yaw %= 360; - int opacity = Math.min(255, Math.max(0, manager.config.bgOpacity.value.intValue())); - bg = new Color((bg.getRGB() & 0x00ffffff) | opacity << 24, true); + bg = new Color(SpecialColour.specialToChromaRGB(manager.config.paneBackgroundColour.value), true); + fg = new Color(SpecialColour.specialToChromaRGB(manager.config.itemBackgroundColour.value)); + Color fgCustomOpacity = new Color(SpecialColour.specialToChromaRGB(manager.config.itemBackgroundColour.value), true); - opacity = Math.min(255, Math.max(0, manager.config.fgOpacity.value.intValue())); - Color fgCustomOpacity = new Color((fg.getRGB() & 0x00ffffff) | opacity << 24, true); - Color fgFavourite = new Color(limCol(fg.getRed()+20), limCol(fg.getGreen()+10), limCol(fg.getBlue()-10), opacity); - Color fgFavourite2 = new Color(limCol(fg.getRed()+100), limCol(fg.getGreen()+50), limCol(fg.getBlue()-50), opacity); + Color fgFavourite2 = new Color(SpecialColour.specialToChromaRGB(manager.config.itemFavouriteColour.value), true); + Color fgFavourite = new Color((int)(fgFavourite2.getRed()*0.8f), (int)(fgFavourite2.getGreen()*0.8f), + (int)(fgFavourite2.getBlue()*0.8f), fgFavourite2.getAlpha()); if(itemPaneOpen) { if(itemPaneTabOffset.getValue() == 0) { @@ -1915,8 +1932,8 @@ public class NEUOverlay extends Gui { JsonObject auctionInfo = manager.auctionManager.getItemAuctionInfo(internalname); JsonObject bazaarInfo = manager.auctionManager.getBazaarInfo(internalname); - boolean hasAuctionPrice = auctionInfo != null; - boolean hasBazaarPrice = bazaarInfo != null; + boolean hasAuctionPrice = !manager.config.invAuctionPrice.value && auctionInfo != null; + boolean hasBazaarPrice = !manager.config.invBazaarPrice.value && bazaarInfo != null; int lowestBin = manager.auctionManager.getLowestBin(internalname); @@ -1924,28 +1941,12 @@ public class NEUOverlay extends Gui { APIManager.CraftInfo craftCost = manager.auctionManager.getCraftCost(json.get("internalname").getAsString()); - if(hasAuctionPrice || hasBazaarPrice || craftCost.fromRecipe || lowestBin > 0) text.add(""); - if(lowestBin > 0) { - text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Lowest BIN: "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(lowestBin)+" coins"); - } - if(hasBazaarPrice) { - int bazaarBuyPrice = (int)bazaarInfo.get("avg_buy").getAsFloat(); - text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Buy: "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarBuyPrice)+" coins"); - int bazaarSellPrice = (int)bazaarInfo.get("avg_sell").getAsFloat(); - text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Sell: "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarSellPrice)+" coins"); - if(manager.config.advancedPriceInfo.value) { - int bazaarInstantBuyPrice = (int)bazaarInfo.get("curr_buy").getAsFloat(); - text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Insta-Buy: "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarInstantBuyPrice)+" coins"); - int bazaarInstantSellPrice = (int)bazaarInfo.get("curr_sell").getAsFloat(); - text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Insta-Sell: "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarInstantSellPrice)+" coins"); - } - } + if(hasAuctionPrice || hasBazaarPrice || craftCost.fromRecipe) text.add(""); if(hasAuctionPrice) { + if(lowestBin > 0) { + text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Lowest BIN: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(lowestBin)+" coins"); + } int auctionPrice = (int)(auctionInfo.get("price").getAsFloat() / auctionInfo.get("count").getAsFloat()); text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"AH Price: "+ EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(auctionPrice)+" coins"); @@ -1962,8 +1963,41 @@ public class NEUOverlay extends Gui { } } + } else if(hasBazaarPrice) { + if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { + int bazaarBuyPrice = (int)bazaarInfo.get("avg_buy").getAsFloat()*64; + text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Buy (Stack): "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarBuyPrice)+" coins"); + int bazaarSellPrice = (int)bazaarInfo.get("avg_sell").getAsFloat()*64; + text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Sell (Stack): "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarSellPrice)+" coins"); + if(manager.config.advancedPriceInfo.value) { + int bazaarInstantBuyPrice = (int)bazaarInfo.get("curr_buy").getAsFloat()*64; + text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Insta-Buy (Stack): "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarInstantBuyPrice)+" coins"); + int bazaarInstantSellPrice = (int)bazaarInfo.get("curr_sell").getAsFloat()*64; + text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Insta-Sell (Stack): "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarInstantSellPrice)+" coins"); + } + } else { + text.add(EnumChatFormatting.DARK_GRAY.toString()+"[SHIFT show stack]"); + int bazaarBuyPrice = (int)bazaarInfo.get("avg_buy").getAsFloat(); + text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Buy: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarBuyPrice)+" coins"); + int bazaarSellPrice = (int)bazaarInfo.get("avg_sell").getAsFloat(); + text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Sell: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarSellPrice)+" coins"); + if(manager.config.advancedPriceInfo.value) { + int bazaarInstantBuyPrice = (int)bazaarInfo.get("curr_buy").getAsFloat(); + text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Insta-Buy: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarInstantBuyPrice)+" coins"); + int bazaarInstantSellPrice = (int)bazaarInfo.get("curr_sell").getAsFloat(); + text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Insta-Sell: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarInstantSellPrice)+" coins"); + } + } } - if(craftCost.fromRecipe) { + if((hasAuctionPrice || hasBazaarPrice) && craftCost.fromRecipe) { text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Raw Craft Cost: "+ EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format((int)craftCost.craftCost)+" coins"); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index 79e57529..575562a0 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -18,38 +18,57 @@ import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; import io.github.moulberry.notenoughupdates.profileviewer.PlayerStats; import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; import io.github.moulberry.notenoughupdates.questing.GuiQuestLine; +import io.github.moulberry.notenoughupdates.questing.SBInfo; import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.block.material.MapColor; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.texture.DynamicTexture; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.client.resources.IReloadableResourceManager; +import net.minecraft.client.resources.IResourceManager; +import net.minecraft.client.resources.IResourceManagerReloadListener; import net.minecraft.client.settings.KeyBinding; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.event.ClickEvent; import net.minecraft.event.HoverEvent; +import net.minecraft.item.ItemMap; +import net.minecraft.item.ItemStack; import net.minecraft.scoreboard.ScoreObjective; import net.minecraft.scoreboard.Scoreboard; import net.minecraft.util.*; +import net.minecraft.world.storage.MapData; import net.minecraftforge.client.ClientCommandHandler; +import net.minecraftforge.common.ForgeVersion; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; +import net.minecraftforge.fml.common.ModContainer; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.text.WordUtils; import org.apache.commons.lang3.text.translate.UnicodeUnescaper; +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.GL11; +import javax.imageio.ImageIO; import javax.net.ssl.*; import javax.swing.*; import java.awt.*; import java.awt.datatransfer.StringSelection; +import java.awt.image.BufferedImage; import java.io.*; +import java.lang.management.ManagementFactory; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.net.*; @@ -65,7 +84,7 @@ import java.util.concurrent.TimeUnit; @Mod(modid = NotEnoughUpdates.MODID, version = NotEnoughUpdates.VERSION, clientSideOnly = true) public class NotEnoughUpdates { public static final String MODID = "notenoughupdates"; - public static final String VERSION = "1.3-REL"; + public static final String VERSION = "1.4-REL"; public static NotEnoughUpdates INSTANCE = null; @@ -207,6 +226,21 @@ public class NotEnoughUpdates { } }); + SimpleCommand reloadRepoCommand = new SimpleCommand("neureloadrepo", new SimpleCommand.ProcessCommandRunnable() { + public void processCommand(ICommandSender sender, String[] args) { + File items = new File(manager.repoLocation, "items"); + if(items.exists()) { + File[] itemFiles = new File(manager.repoLocation, "items").listFiles(); + if(itemFiles != null) { + for(File f : itemFiles) { + String internalname = f.getName().substring(0, f.getName().length()-5); + manager.loadItem(internalname); + } + } + } + } + }); + private static HashMap<String, String> petRarityToColourMap = new HashMap<>(); static { petRarityToColourMap.put("UNKNOWN", EnumChatFormatting.RED.toString()); @@ -426,6 +460,80 @@ public class NotEnoughUpdates { } }); + + SimpleCommand pcStatsCommand = new SimpleCommand("neustats", new SimpleCommand.ProcessCommandRunnable() { + public void processCommand(ICommandSender sender, String[] args) { + Minecraft mc = Minecraft.getMinecraft(); + StringBuilder builder = new StringBuilder(); + + if (args.length > 0 && args[0].toLowerCase().equals("modlist")){ + builder.append("```md\n"); + builder.append("# Mods Loaded").append("\n"); + for (ModContainer modContainer : Loader.instance().getActiveModList()) { + builder.append("[").append(modContainer.getName()).append("]") + .append("[").append(modContainer.getSource().getName()).append("]\n"); + } + builder.append("```"); + } else { + long memorySize = -1; + try { + memorySize = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize(); + } catch(Exception e){} + long maxMemory = Runtime.getRuntime().maxMemory(); + long totalMemory = Runtime.getRuntime().totalMemory(); + long freeMemory = Runtime.getRuntime().freeMemory(); + long currentMemory = totalMemory - freeMemory; + int modCount = Loader.instance().getModList().size(); + int activeModCount = Loader.instance().getActiveModList().size(); + + builder.append("```md\n"); + builder.append("# System Stats").append("\n"); + builder.append("[OS]").append("[").append(System.getProperty("os.name")).append("]").append("\n"); + builder.append("[CPU]").append("[").append(OpenGlHelper.getCpu()).append("]").append("\n"); + builder.append("[Display]").append("[").append(String.format("%dx%d (%s)", Display.getWidth(), Display.getHeight(), GL11.glGetString(GL11.GL_VENDOR))).append("]").append("\n"); + builder.append("[GPU]").append("[").append(GL11.glGetString(GL11.GL_RENDERER)).append("]").append("\n"); + builder.append("[GPU Driver]").append("[").append(GL11.glGetString(GL11.GL_VERSION)).append("]").append("\n"); + if(memorySize > 0) { + builder.append("[Maximum Memory]").append("[").append(memorySize / 1024L / 1024L).append("MB]").append("\n"); + } + builder.append("[Shaders]").append("[").append((""+OpenGlHelper.areShadersSupported()).toUpperCase()).append("]").append("\n"); + builder.append("[Framebuffers]").append("[").append((""+OpenGlHelper.isFramebufferEnabled()).toUpperCase()).append("]").append("\n"); + builder.append("# Java Stats").append("\n"); + builder.append("[Java]").append("[").append(String.format("%s %dbit", System.getProperty("java.version"), mc.isJava64bit() ? 64 : 32)).append("]").append("\n"); + builder.append("[Memory]").append("[").append(String.format("% 2d%% %03d/%03dMB", currentMemory * 100L / maxMemory, currentMemory / 1024L / 1024L, maxMemory / 1024L / 1024L)).append("]").append("\n"); + builder.append("[Memory Allocated]").append("[").append(String.format("% 2d%% %03dMB", totalMemory * 100L / maxMemory, totalMemory / 1024L / 1024L)).append("]").append("\n"); + builder.append("# Game Stats").append("\n"); + builder.append("[Current FPS]").append("[").append(Minecraft.getDebugFPS()).append("]").append("\n"); + builder.append("[Loaded Mods]").append("[").append(activeModCount).append("/").append(modCount).append("]").append("\n"); + builder.append("[Forge]").append("[").append(ForgeVersion.getVersion()).append("]").append("\n"); + builder.append("# Neu Settings").append("\n"); + builder.append("[API Key]").append("[").append(!INSTANCE.manager.config.apiKey.value.isEmpty()).append("]").append("\n"); + builder.append("[On Skyblock]").append("[").append(hasSkyblockScoreboard).append("]").append("\n"); + builder.append("[Mod Version]").append("[").append(Loader.instance().getIndexedModList().get(MODID).getSource().getName()).append("]").append("\n"); + builder.append("# Repo Stats").append("\n"); + builder.append("[Last Commit]").append("[").append(manager.latestRepoCommit).append("]").append("\n"); + builder.append("[Loaded Items]").append("[").append(manager.getItemInformation().size()).append("]").append("\n"); + if (activeModCount <= 15) { + builder.append("# Mods Loaded").append("\n"); + for (ModContainer modContainer : Loader.instance().getActiveModList()) { + builder.append("[").append(modContainer.getName()).append("]") + .append("[").append(modContainer.getSource().getName()).append("]\n"); + } + builder.append("```"); + } else { + builder.append("```"); + } + } + try { + StringSelection clipboard = new StringSelection(builder.toString()); + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(clipboard, clipboard); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GOLD + "[" + EnumChatFormatting.RED + "NotEnoughUpdates" + EnumChatFormatting.GOLD + "]: " + EnumChatFormatting.GREEN + "Dev info copied to clipboard.")); + } catch (Exception ignored) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GOLD + "[" + EnumChatFormatting.RED + "NotEnoughUpdates" + EnumChatFormatting.GOLD + "]: " + EnumChatFormatting.DARK_RED + "Could not copy to clipboard.")); + } + } + }); + public static ProfileViewer profileViewer; SimpleCommand.ProcessCommandRunnable viewProfileRunnable = new SimpleCommand.ProcessCommandRunnable() { @@ -439,8 +547,8 @@ public class NotEnoughUpdates { while((line = reader.readLine()) != null) { if(line.contains("ofFastRender:true")) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "This feature is incompatible with OF Fast Render. Go to Video > Performance to disable it.")); - return; + "Some parts of the profile viewer do not work with OF Fast Render. Go to Video > Performance to disable it.")); + break; } } } catch(Exception e) { @@ -574,6 +682,75 @@ public class NotEnoughUpdates { } }); + public Color[][] colourMap = null; + SimpleCommand neumapCommand = new SimpleCommand("neumap", new SimpleCommand.ProcessCommandRunnable() { + public void processCommand(ICommandSender sender, String[] args) { + if(args.length == 1 && args[0] == "reset") { + colourMap = null; + return; + } + + if(args.length != 2) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED+ + "Dev feature if you don't know how to use then don't use it 4Head.")); + return; + } + + if(args[0].equals("save")) { + ItemStack stack = Minecraft.getMinecraft().thePlayer.getHeldItem(); + if(stack != null && stack.getItem() instanceof ItemMap) { + ItemMap map = (ItemMap) stack.getItem(); + MapData mapData = map.getMapData(stack, Minecraft.getMinecraft().theWorld); + + if (mapData == null) return; + + JsonObject json = new JsonObject(); + for (int i = 0; i < 16384; ++i) { + int x = i % 128; + int y = i / 128; + + int j = mapData.colors[i] & 255; + + Color c; + if (j / 4 == 0) { + c = new Color((i + i / 128 & 1) * 8 + 16 << 24, true); + } else { + c = new Color(MapColor.mapColorArray[j / 4].func_151643_b(j & 3), true); + } + + json.addProperty(x+":"+y, c.getRGB()); + } + + try { + new File(manager.configLocation, "maps").mkdirs(); + manager.writeJson(json, new File(manager.configLocation, "maps/"+args[1]+".json")); + } catch(Exception e) { + e.printStackTrace(); + } + + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN+ + "Saved to file.")); + } + } + + if(args[0].equals("load")) { + JsonObject json = manager.getJsonFromFile(new File(manager.configLocation, "maps/"+args[1]+".json")); + colourMap = new Color[128][128]; + for(int x=0; x<128; x++) { + for(int y=0; y<128; y++) { + colourMap[x][y] = new Color(0, 0, 0, 0); + } + } + for(Map.Entry<String, JsonElement> entry : json.entrySet()) { + int x = Integer.parseInt(entry.getKey().split(":")[0]); + int y = Integer.parseInt(entry.getKey().split(":")[1]); + + colourMap[x][y] = new Color(entry.getValue().getAsInt(), true); + } + } + } + }); + SimpleCommand cosmeticsCommand = new SimpleCommand("neucosmetics", new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { openGui = new GuiCosmetics(); @@ -609,9 +786,16 @@ public class NotEnoughUpdates { MinecraftForge.EVENT_BUS.register(new NEUEventListener(this)); MinecraftForge.EVENT_BUS.register(CapeManager.getInstance()); MinecraftForge.EVENT_BUS.register(new SBGamemodes()); + MinecraftForge.EVENT_BUS.register(SBInfo.getInstance()); MinecraftForge.EVENT_BUS.register(CustomItemEffects.INSTANCE); + MinecraftForge.EVENT_BUS.register(new DungeonMap()); //MinecraftForge.EVENT_BUS.register(new BetterPortals()); + IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager(); + if(resourceManager instanceof IReloadableResourceManager) { + ((IReloadableResourceManager)resourceManager).registerReloadListener(new DungeonBlocks()); + } + File f = new File(event.getModConfigurationDirectory(), "notenoughupdates"); f.mkdirs(); ClientCommandHandler.instance.registerCommand(collectionLogCommand); @@ -619,6 +803,7 @@ public class NotEnoughUpdates { ClientCommandHandler.instance.registerCommand(linksCommand); ClientCommandHandler.instance.registerCommand(gamemodesCommand); ClientCommandHandler.instance.registerCommand(resetRepoCommand); + ClientCommandHandler.instance.registerCommand(reloadRepoCommand); ClientCommandHandler.instance.registerCommand(itemRenameCommand); ClientCommandHandler.instance.registerCommand(viewProfileCommand); ClientCommandHandler.instance.registerCommand(viewProfileShortCommand); @@ -628,6 +813,8 @@ public class NotEnoughUpdates { ClientCommandHandler.instance.registerCommand(overlayPlacementsCommand); ClientCommandHandler.instance.registerCommand(enchantColourCommand); ClientCommandHandler.instance.registerCommand(neuAhCommand); + ClientCommandHandler.instance.registerCommand(pcStatsCommand); + ClientCommandHandler.instance.registerCommand(neumapCommand); manager = new NEUManager(this, f); manager.loadItemInformation(); 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 03796993..b466d226 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java @@ -91,6 +91,7 @@ public class APIManager { public boolean bin; public String category; public String rarity; + public int dungeonTier; public String item_tag_str; public NBTTagCompound item_tag = null; private ItemStack stack; @@ -98,7 +99,7 @@ public class APIManager { public int enchLevel = 0; //0 = clean, 1 = ench, 2 = ench/hpb public Auction(String auctioneerUuid, long end, int starting_bid, int highest_bid_amount, int bid_count, - boolean bin, String category, String rarity, String item_tag_str) { + boolean bin, String category, String rarity, int dungeonTier, String item_tag_str) { this.auctioneerUuid = auctioneerUuid; this.end = end; this.starting_bid = starting_bid; @@ -106,6 +107,7 @@ public class APIManager { this.bid_count = bid_count; this.bin = bin; this.category = category; + this.dungeonTier = dungeonTier; this.rarity = rarity; this.item_tag_str = item_tag_str; } @@ -468,7 +470,6 @@ public class APIManager { NBTTagCompound tag = item_tag.getTagList("i", 10).getCompoundTagAt(0).getCompoundTag("tag"); String internalname = manager.getInternalnameFromNBT(tag); - String[] lore = new String[0]; NBTTagCompound display = tag.getCompoundTag("display"); if(display.hasKey("Lore", 9)) { NBTTagList loreList = new NBTTagList(); @@ -527,10 +528,15 @@ public class APIManager { } } + int dungeonTier = -1; if(checkItemType(item_lore, true, "DUNGEON") >= 0) { - HashMap<Integer, HashSet<String>> extrasMap = extrasToAucIdMap.computeIfAbsent("dungeon", k -> new HashMap<>()); - HashSet<String> aucids = extrasMap.computeIfAbsent(0, k -> new HashSet<>()); - aucids.add(auctionUuid); + dungeonTier = 0; + for(int i=0; i<item_name.length(); i++) { + char c = item_name.charAt(i); + if(c == 0x272A) { + dungeonTier++; + } + } } //Categories @@ -548,7 +554,7 @@ public class APIManager { item_lore.split("\n")[0].endsWith("Mount")) category = "pet"; Auction auction1 = new Auction(auctioneerUuid, end, starting_bid, highest_bid_amount, - bid_count, bin, category, rarity, item_bytes); + bid_count, bin, category, rarity, dungeonTier, item_bytes); if(tag.hasKey("ench")) { auction1.enchLevel = 1; @@ -580,7 +586,7 @@ public class APIManager { if(pagesToDownload == null) { int totalPages = jsonObject.get("totalPages").getAsInt(); pagesToDownload = new LinkedList<>(); - for(int i=0; i<totalPages; i++) { + for(int i=0; i<totalPages+2; i++) { pagesToDownload.add(i); } } 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 f23b87fd..8f17037b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/CustomAH.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/CustomAH.java @@ -80,10 +80,13 @@ public class CustomAH extends Gui { public long lastOpen; public long lastGuiScreenSwitch; - private int splits = 2; + private final int splits = 2; - private int ySplit = 35; - private int ySplitSize = 18; + public String latestBid; + public long latestBidMillis; + + private final int ySplit = 35; + private final int ySplitSize = 18; private float scrollAmount; @@ -129,11 +132,11 @@ public class CustomAH extends Gui { private static final int SORT_MODE_SOON = 2; private static final String[] rarities = { "COMMON", "UNCOMMON", "RARE", "EPIC", - "LEGENDARY", "MYTHIC", "SPECIAL", "VERY SPECIAL" }; + "LEGENDARY", "MYTHIC", "SPECIAL", "VERY SPECIAL", "SUPREME" }; private static final String[] rarityColours = { ""+EnumChatFormatting.WHITE, ""+EnumChatFormatting.GREEN, ""+EnumChatFormatting.BLUE, ""+EnumChatFormatting.DARK_PURPLE, ""+EnumChatFormatting.GOLD, ""+EnumChatFormatting.LIGHT_PURPLE, ""+EnumChatFormatting.RED, - ""+EnumChatFormatting.RED }; + ""+EnumChatFormatting.RED, ""+EnumChatFormatting.DARK_RED }; private static final int BIN_FILTER_ALL = 0; private static final int BIN_FILTER_BIN = 1; @@ -144,12 +147,23 @@ public class CustomAH extends Gui { private static final int ENCH_FILTER_ENCH = 2; private static final int ENCH_FILTER_ENCHHPB = 3; + private static final int DUNGEON_FILTER_ALL = 0; + private static final int DUNGEON_FILTER_DUNGEON = 1; + private static final int DUNGEON_FILTER_1 = 2; + private static final int DUNGEON_FILTER_2 = 3; + private static final int DUNGEON_FILTER_3 = 4; + private static final int DUNGEON_FILTER_4 = 5; + private static final int DUNGEON_FILTER_5 = 6; + + private int dungeonFilter = DUNGEON_FILTER_ALL; private int sortMode = SORT_MODE_HIGH; private int rarityFilter = -1; private boolean filterMyAuctions = false; private int binFilter = BIN_FILTER_ALL; private int enchFilter = ENCH_FILTER_ALL; + private static ItemStack DUNGEON_SORT = Utils.createItemStack(Item.getItemFromBlock(Blocks.deadbush), + EnumChatFormatting.GREEN+"Dungeon Sorting"); private static ItemStack CONTROL_SORT = Utils.createItemStack(Item.getItemFromBlock(Blocks.hopper), EnumChatFormatting.GREEN+"Sort"); private static ItemStack CONTROL_TIER = Utils.createItemStack(Items.ender_eye, @@ -162,7 +176,7 @@ public class CustomAH extends Gui { EnumChatFormatting.GREEN+"Enchant Filter"); private static ItemStack CONTROL_STATS = Utils.createItemStack(Item.getItemFromBlock(Blocks.command_block), EnumChatFormatting.GREEN+"Stats for nerds"); - private ItemStack[] controls = {null,CONTROL_SORT,CONTROL_TIER,null,CONTROL_MYAUC,null,CONTROL_BIN,CONTROL_ENCH,CONTROL_STATS}; + private ItemStack[] controls = {DUNGEON_SORT,CONTROL_SORT,CONTROL_TIER,null,CONTROL_MYAUC,null,CONTROL_BIN,CONTROL_ENCH,CONTROL_STATS}; private NEUManager manager; @@ -179,6 +193,7 @@ public class CustomAH extends Gui { filterMyAuctions = false; //binFilter = BIN_FILTER_ALL; enchFilter = ENCH_FILTER_ALL; + dungeonFilter = DUNGEON_FILTER_ALL; searchField.setText(""); searchField.setFocused(true); @@ -859,7 +874,6 @@ public class CustomAH extends Gui { } } } catch(Exception e) { - break out; } } } @@ -903,7 +917,30 @@ public class CustomAH extends Gui { String selPrefix = EnumChatFormatting.DARK_AQUA + selPrefixNC; String unselPrefix = EnumChatFormatting.GRAY.toString(); switch(index) { - case 0: break; + case 0: + lore.add(""); + String gold = EnumChatFormatting.GOLD.toString(); + String gray = EnumChatFormatting.GRAY.toString(); + char s = 0x272A; + String[] linesDung = {"Show All","Any Dungeon", + gold+s+gray+s+s+s+s, + gold+s+s+gray+s+s+s, + gold+s+s+s+gray+s+s, + gold+s+s+s+s+gray+s, + gold+s+s+s+s+s}; + for(int i=0; i<linesDung.length; i++) { + String line = linesDung[i]; + if(i == dungeonFilter) { + line = selPrefix + line.replace(gray, EnumChatFormatting.DARK_AQUA.toString()); + } else { + line = unselPrefix + line; + } + lore.add(line); + } + lore.add(""); + lore.add(EnumChatFormatting.AQUA + "Right-Click to go backwards!"); + lore.add(EnumChatFormatting.YELLOW + "Click to switch sort!"); + return lore; case 1: lore.add(""); String[] linesSort = {"Highest Bid","Lowest Bid","Ending soon"}; @@ -1031,7 +1068,7 @@ public class CustomAH extends Gui { } } - private String niceAucId(String aucId) { + public String niceAucId(String aucId) { if(aucId.length()!=32) return aucId; StringBuilder niceAucId = new StringBuilder(); @@ -1093,6 +1130,14 @@ public class CustomAH extends Gui { } } + if(dungeonFilter > DUNGEON_FILTER_ALL) { + if(dungeonFilter == DUNGEON_FILTER_DUNGEON && auc.dungeonTier < 0) { + match = false; + } else { + match &= dungeonFilter == auc.dungeonTier+1; + } + } + return match; } @@ -1155,7 +1200,7 @@ public class CustomAH extends Gui { long currentTime = System.currentTimeMillis(); es.submit(() -> { - if(currentTime - lastUpdateSearch < 500) { + if(currentTime - lastUpdateSearch < 100) { shouldUpdateSearch = true; return; } @@ -1405,7 +1450,15 @@ public class CustomAH extends Gui { int index = offset/18; boolean rightClicked = Mouse.getEventButton() == 1; switch(index) { - case 0: break; + case 0: + if(rightClicked) { + dungeonFilter--; + if(dungeonFilter < DUNGEON_FILTER_ALL) dungeonFilter = DUNGEON_FILTER_5; + } else { + dungeonFilter++; + if(dungeonFilter > DUNGEON_FILTER_5) dungeonFilter = DUNGEON_FILTER_ALL; + } + break; case 1: if(rightClicked) { sortMode--; @@ -1505,6 +1558,8 @@ public class CustomAH extends Gui { if(mouseY > guiTop+31 && mouseY < guiTop+31+16) { if(currentAucId != null) { manager.auctionManager.getPlayerBids().add(currentAucId); + latestBid = currentAucId; + latestBidMillis = System.currentTimeMillis(); //reset timer to 2m if below if(manager.auctionManager.getAuctionItems().get(currentAucId).end - System.currentTimeMillis() < 2*60*1000) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/CapeManager.java b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/CapeManager.java index 98907029..fa1db64e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/CapeManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/CapeManager.java @@ -32,8 +32,8 @@ public class CapeManager { private boolean allAvailable = false; private HashSet<String> availableCapes = new HashSet<>(); - private String[] capes = new String[]{"patreon1", "patreon2", "fade", "contrib", "nullzee", "gravy", "space", "mcworld" }; - public Boolean[] specialCapes = new Boolean[]{ true, true, false, true, true, true, false, false }; + private String[] capes = new String[]{"patreon1", "patreon2", "fade", "contrib", "nullzee", "gravy", "space", "mcworld", "lava", "packshq", "mbstaff" }; + public Boolean[] specialCapes = new Boolean[]{ true, true, false, true, true, true, false, false, true, true, true }; public static CapeManager getInstance() { return INSTANCE; @@ -51,6 +51,7 @@ public class CapeManager { NotEnoughUpdates.INSTANCE.manager.hypixelApi.getMyApiAsync("activecapes.json", (jsonObject) -> { if(jsonObject.get("success").getAsBoolean()) { lastCapeSynced = System.currentTimeMillis(); + capeMap.clear(); for(JsonElement active : jsonObject.get("active").getAsJsonArray()) { if(active.isJsonObject()) { JsonObject activeObj = (JsonObject) active; @@ -176,21 +177,24 @@ public class CapeManager { } Set<String> toRemove = new HashSet<>(); - for(String playerUUID : capeMap.keySet()) { - EntityPlayer player = getPlayerForUUID(playerUUID); - if(player != null) { - String capeName = capeMap.get(playerUUID).getRight(); - if(capeName != null && !capeName.equals("null")) { - if(playerUUID.equals(clientUuid) && localCape != null && localCape.getRight() != null && !localCape.getRight().equals("null")) { - continue; + try { + for(String playerUUID : capeMap.keySet()) { + EntityPlayer player = getPlayerForUUID(playerUUID); + if(player != null) { + String capeName = capeMap.get(playerUUID).getRight(); + if(capeName != null && !capeName.equals("null")) { + if(playerUUID.equals(clientUuid) && localCape != null && localCape.getRight() != null && !localCape.getRight().equals("null")) { + continue; + } + capeMap.get(playerUUID).getLeft().setCapeTexture(capeName); + capeMap.get(playerUUID).getLeft().onTick(event, player); + } else { + toRemove.add(playerUUID); } - capeMap.get(playerUUID).getLeft().setCapeTexture(capeName); - capeMap.get(playerUUID).getLeft().onTick(event, player); - } else { - toRemove.add(playerUUID); } } - } + } catch(Exception e) {} + if(localCape != null) { localCape.getLeft().setCapeTexture(localCape.getValue()); localCape.getLeft().onTick(event, Minecraft.getMinecraft().thePlayer); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/GuiCosmetics.java b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/GuiCosmetics.java index 6712f34f..4723d00f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/GuiCosmetics.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/GuiCosmetics.java @@ -1,61 +1,23 @@ package io.github.moulberry.notenoughupdates.cosmetics; -import com.google.common.base.Splitter; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import com.mojang.authlib.GameProfile; -import com.mojang.authlib.minecraft.MinecraftProfileTexture; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.SBAIntegration; -import io.github.moulberry.notenoughupdates.itemeditor.GuiElementTextField; -import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; -import io.github.moulberry.notenoughupdates.profileviewer.Panorama; -import io.github.moulberry.notenoughupdates.profileviewer.PlayerStats; -import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; -import io.github.moulberry.notenoughupdates.questing.SBScoreboardData; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityOtherPlayerMP; -import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.entity.RenderManager; -import net.minecraft.client.resources.DefaultPlayerSkin; -import net.minecraft.client.resources.SkinManager; import net.minecraft.client.shader.Framebuffer; import net.minecraft.client.shader.Shader; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EnumPlayerModelParts; -import net.minecraft.init.Blocks; import net.minecraft.init.Items; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagByteArray; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.Matrix4f; import net.minecraft.util.ResourceLocation; -import org.apache.commons.lang3.text.WordUtils; -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.text.NumberFormat; import java.util.List; import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; public class GuiCosmetics extends GuiScreen { @@ -311,10 +273,14 @@ public class GuiCosmetics extends GuiScreen { lastCapeEquip = System.currentTimeMillis(); if(wantToEquipCape == null) { NotEnoughUpdates.INSTANCE.manager.hypixelApi.getMyApiAsync("cgi-bin/changecape.py?capeType=null&accessToken="+ - Minecraft.getMinecraft().getSession().getToken(), (jsonObject) -> {}, () -> {}); + Minecraft.getMinecraft().getSession().getToken(), (jsonObject) -> { System.out.println(jsonObject); }, () -> { + System.out.println("change cape error"); + }); } else { NotEnoughUpdates.INSTANCE.manager.hypixelApi.getMyApiAsync("cgi-bin/changecape.py?capeType="+wantToEquipCape+"&accessToken="+ - Minecraft.getMinecraft().getSession().getToken(), (jsonObject) -> {}, () -> {}); + Minecraft.getMinecraft().getSession().getToken(), (jsonObject) -> { System.out.println(jsonObject); }, () -> { + System.out.println("change cape error"); + }); } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/NEUCape.java b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/NEUCape.java index 197e5483..13e61a06 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/NEUCape.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/NEUCape.java @@ -79,6 +79,8 @@ public class NEUCape { shaderName = "space_cape"; } else if(capeName.equalsIgnoreCase("mcworld")) { shaderName = "mcworld_cape"; + } else if(capeName.equalsIgnoreCase("lava")) { + shaderName = "lava_cape"; } else { shaderName = "cape"; } @@ -302,6 +304,8 @@ public class NEUCape { shaderManager.loadData(shaderName, "eventRand", eventRandom); } else if(shaderName.equalsIgnoreCase("mcworld_cape")) { shaderManager.loadData(shaderName, "millis", (int) (System.currentTimeMillis() - startTime)); + } else if(shaderName.equalsIgnoreCase("lava_cape")) { + shaderManager.loadData(shaderName, "millis", (int) (System.currentTimeMillis() - startTime)); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/gamemodes/SBGamemodes.java b/src/main/java/io/github/moulberry/notenoughupdates/gamemodes/SBGamemodes.java index 696e226b..81be2204 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/gamemodes/SBGamemodes.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/gamemodes/SBGamemodes.java @@ -3,25 +3,19 @@ package io.github.moulberry.notenoughupdates.gamemodes; import com.google.gson.Gson; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.options.Options; -import io.github.moulberry.notenoughupdates.questing.SBScoreboardData; +import io.github.moulberry.notenoughupdates.questing.SBInfo; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiChest; -import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.inventory.ContainerChest; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; -import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; -import org.lwjgl.input.Keyboard; import javax.crypto.Cipher; -import javax.crypto.KeyGenerator; -import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; import java.io.*; import java.nio.ByteBuffer; @@ -229,7 +223,7 @@ public class SBGamemodes { public void onPlayerInteract(PlayerInteractEvent event) { if(getGamemode() == null || !NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return; - if(!"Your Island".equals(SBScoreboardData.getInstance().location)) return; + if(!"Your Island".equals(SBInfo.getInstance().location)) return; if((getGamemode().gamemodeModifiers & MODIFIER_SMALLISLAND) != 0) { if(event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) { @@ -252,8 +246,8 @@ public class SBGamemodes { public void onTick(TickEvent.ClientTickEvent event) { if(getGamemode() == null || !NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return; - if("Your Island".equals(SBScoreboardData.getInstance().location) && - (EnumChatFormatting.YELLOW+"Break a log").equals(SBScoreboardData.getInstance().objective)) { + if("Your Island".equals(SBInfo.getInstance().location) && + (EnumChatFormatting.YELLOW+"Break a log").equals(SBInfo.getInstance().objective)) { getGamemode().locked = false; } else { getGamemode().locked = true; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/CollectionLogInfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/CollectionLogInfoPane.java index 0302d74a..d0600796 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/CollectionLogInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/CollectionLogInfoPane.java @@ -5,6 +5,7 @@ import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NEUManager; import io.github.moulberry.notenoughupdates.NEUOverlay; import io.github.moulberry.notenoughupdates.NEUResourceManager; +import io.github.moulberry.notenoughupdates.util.SpecialColour; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; @@ -395,9 +396,8 @@ public class CollectionLogInfoPane extends ScrollableInfoPane { } private void renderItemBackgrounds(Color fg, int left, int right, int top, int bottom) { - int opacity = Math.min(255, Math.max(0, manager.config.fgOpacity.value.intValue())); - Color fgGold = new Color(limCol(fg.getRed()+100), limCol(fg.getGreen()+50), limCol(fg.getBlue()-50), opacity); - Color fgCustomOpacity = new Color((fg.getRGB() & 0x00ffffff) | opacity << 24, true); + Color fgCustomOpacity = new Color(SpecialColour.specialToChromaRGB(manager.config.itemBackgroundColour.value), true); + Color fgGold = new Color(SpecialColour.specialToChromaRGB(manager.config.itemFavouriteColour.value), true); String[] items = getItemList(); iterateItemSlots(new ItemSlotConsumer() { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/InfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/InfoPane.java index 60f8ca72..76b500f5 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/InfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/InfoPane.java @@ -17,6 +17,8 @@ public abstract class InfoPane extends Gui { this.manager = manager; } + public void reset() {} + public void tick() {} public abstract void render(int width, int height, Color bg, Color fg, ScaledResolution scaledresolution, int mouseX, diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/SettingsInfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/SettingsInfoPane.java index 00716271..e5fc10b2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/SettingsInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/SettingsInfoPane.java @@ -3,18 +3,26 @@ package io.github.moulberry.notenoughupdates.infopanes; import io.github.moulberry.notenoughupdates.BetterContainers; import io.github.moulberry.notenoughupdates.NEUManager; import io.github.moulberry.notenoughupdates.NEUOverlay; +import io.github.moulberry.notenoughupdates.util.SpecialColour; import io.github.moulberry.notenoughupdates.util.Utils; import io.github.moulberry.notenoughupdates.itemeditor.GuiElementTextField; import io.github.moulberry.notenoughupdates.options.Options; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.texture.DynamicTexture; +import net.minecraft.entity.item.EntityXPOrb; import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.ResourceLocation; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; +import scala.tools.cmd.Spec; import java.awt.*; +import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -34,10 +42,44 @@ public class SettingsInfoPane extends InfoPane { private int clickedSliderX = 0; private float clickedSliderMult = 0; + private static final int colourEditorBG = new Color(80, 80, 80, 220).getRGB(); + private static ResourceLocation colourPickerLocation = new ResourceLocation("notenoughupdates:dynamic/colourpicker"); + private static ResourceLocation colourPickerBarValueLocation = new ResourceLocation("notenoughupdates:dynamic/colourpickervalue"); + private static ResourceLocation colourPickerBarOpacityLocation = new ResourceLocation("notenoughupdates:dynamic/colourpickeropacity"); + + private GuiElementTextField hexField = new GuiElementTextField("", + GuiElementTextField.SCALE_TEXT | GuiElementTextField.FORCE_CAPS | GuiElementTextField.NO_SPACE); + private ColourEditor activeColourEditor = null; + + private class ColourEditor { + public int x; + public int y; + public Options.Option<String> option; + public String special; + + public ColourEditor(int x, int y, Options.Option<String> option, String special) { + this.x = x; + this.y = y; + this.option = option; + this.special = special; + } + } + public SettingsInfoPane(NEUOverlay overlay, NEUManager manager) { super(overlay, manager); } + public void reset() { + textConfigMap.clear(); + activeColourEditor = null; + hexField.otherComponentClick(); + } + + private void showColourEditor(int mouseX, int mouseY, Options.Option<String> option, String special) { + activeColourEditor = new ColourEditor(mouseX, mouseY, option, special); + hexField.otherComponentClick(); + } + public void render(int width, int height, Color bg, Color fg, ScaledResolution scaledresolution, int mouseX, int mouseY) { FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; @@ -116,6 +158,7 @@ public class SettingsInfoPane extends InfoPane { textConfigMap.put(option, new GuiElementTextField(String.valueOf(option.value), GuiElementTextField.NUM_ONLY | GuiElementTextField.NO_SPACE | GuiElementTextField.SCALE_TEXT)); } + GuiElementTextField tf = textConfigMap.get(option); if(tf.getText().trim().endsWith(".0")) { tf.setText(tf.getText().trim().substring(0, tf.getText().trim().length()-2)); @@ -147,18 +190,46 @@ public class SettingsInfoPane extends InfoPane { Utils.drawTexturedRect(x+1*mult+(float)(54*sliderAmount*mult), y + tileHeight - 20*mult, 8*mult, 16*mult); } else { - if(!textConfigMap.containsKey(option)) { - textConfigMap.put(option, new GuiElementTextField(String.valueOf(option.value), 0)); - } - GuiElementTextField tf = textConfigMap.get(option); - if(tf.getFocus()) { - tf.setSize(Math.max(tileWidth-(int)(20*mult), fr.getStringWidth(tf.getText())+10), (int)(16*mult)); - tfTop.set(tf); - tfTopX.set(x+(int)(10*mult)); - tfTopY.set(y+tileHeight-(int)(20*mult)); + if((option.flags & Options.FLAG_COLOUR) != 0) { + Utils.renderStringTrimWidth(option.displayName, fr, true, x+(int)(8*mult), y+(int)(8*mult), + tileWidth-(int)(16*mult), new Color(100,255,150).getRGB(), 3, + 2f/scaledresolution.getScaleFactor()); + + Color c = new Color(SpecialColour.specialToChromaRGB((String)option.value)); + GlStateManager.color( + Math.min(1f, c.getRed()/255f), + Math.min(1f, c.getGreen()/255f), + Math.min(1f, c.getBlue()/255f), 1f); + Minecraft.getMinecraft().getTextureManager().bindTexture(button_white); + Utils.drawTexturedRect(x + tileWidth/2f - (int) (32 * mult), y + tileHeight - (int) (20 * mult), (int) (48 * mult), (int) (16 * mult)); + + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(help); + Utils.drawTexturedRect(x + tileWidth/2f + (int) (19 * mult), y + tileHeight - (int) (19 * mult), (int) (14 * mult), (int) (14 * mult)); + GlStateManager.bindTexture(0); + + if (mouseX > x + tileWidth / 2 + (int) (19 * mult) && mouseX < x + tileWidth / 2 + (int) (19 * mult) + (int) (14 * mult)) { + if (mouseY > y + tileHeight - (int) (19 * mult) && mouseY < y + tileHeight - (int) (19 * mult) + (int) (14 * mult)) { + List<String> textLines = new ArrayList<>(); + textLines.add(option.displayName); + textLines.add(EnumChatFormatting.GRAY + option.desc); + textToDisplay.set(textLines); + } + } } else { - tf.setSize(tileWidth-(int)(20*mult), (int)(16*mult)); - tf.render(x+(int)(10*mult), y+tileHeight-(int)(20*mult)); + if(!textConfigMap.containsKey(option)) { + textConfigMap.put(option, new GuiElementTextField(String.valueOf(option.value), 0)); + } + GuiElementTextField tf = textConfigMap.get(option); + if(tf.getFocus()) { + tf.setSize(Math.max(tileWidth-(int)(20*mult), fr.getStringWidth(tf.getText())+10), (int)(16*mult)); + tfTop.set(tf); + tfTopX.set(x+(int)(10*mult)); + tfTopY.set(y+tileHeight-(int)(20*mult)); + } else { + tf.setSize(tileWidth-(int)(20*mult), (int)(16*mult)); + tf.render(x+(int)(10*mult), y+tileHeight-(int)(20*mult)); + } } } } @@ -166,6 +237,137 @@ public class SettingsInfoPane extends InfoPane { if(tfTop.get() != null) { tfTop.get().render(tfTopX.get(), tfTopY.get()); } + + if(activeColourEditor != null) { + Gui.drawRect(activeColourEditor.x, activeColourEditor.y, activeColourEditor.x+119, activeColourEditor.y+89, colourEditorBG); + + int currentColour = SpecialColour.specialToSimpleRGB(activeColourEditor.special); + Color c = new Color(currentColour, true); + float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); + + BufferedImage bufferedImage = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB); + for(int x=0; x<256; x++) { + for(int y=0; y<256; y++) { + float radius = (float) Math.sqrt(((x-128)*(x-128)+(y-128)*(y-128))/16384f); + float angle = (float) Math.toDegrees(Math.atan((128-x)/(y-128+1E-5))+Math.PI/2); + if(y < 128) angle += 180; + if(radius <= 1) { + int rgb = Color.getHSBColor(angle/360f, (float)Math.pow(radius, 1.5f), hsv[2]).getRGB(); + bufferedImage.setRGB(x, y, rgb); + } + } + } + + BufferedImage bufferedImageValue = new BufferedImage(10, 64, BufferedImage.TYPE_INT_ARGB); + for(int x=0; x<10; x++) { + for(int y=0; y<64; y++) { + if((x == 0 || x == 9) && (y == 0 || y == 63)) continue; + + int rgb = Color.getHSBColor(hsv[0], hsv[1], (64-y)/64f).getRGB(); + bufferedImageValue.setRGB(x, y, rgb); + } + } + + BufferedImage bufferedImageOpacity = new BufferedImage(10, 64, BufferedImage.TYPE_INT_ARGB); + for(int x=0; x<10; x++) { + for(int y=0; y<64; y++) { + if((x == 0 || x == 9) && (y == 0 || y == 63)) continue; + + int rgb = (currentColour & 0x00FFFFFF) | (Math.min(255, (64-y)*4) << 24); + bufferedImageOpacity.setRGB(x, y, rgb); + } + } + + float selradius = (float) Math.pow(hsv[1], 1/1.5f)*32; + int selx = (int)(Math.cos(Math.toRadians(hsv[0]*360))*selradius); + int sely = (int)(Math.sin(Math.toRadians(hsv[0]*360))*selradius); + + Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_bar_alpha); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(activeColourEditor.x+5+64+5+10+5, activeColourEditor.y+5, 10, 64, GL11.GL_NEAREST); + + Minecraft.getMinecraft().getTextureManager().loadTexture(colourPickerBarValueLocation, new DynamicTexture(bufferedImageValue)); + Minecraft.getMinecraft().getTextureManager().bindTexture(colourPickerBarValueLocation); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(activeColourEditor.x+5+64+5, activeColourEditor.y+5, 10, 64, GL11.GL_NEAREST); + + Minecraft.getMinecraft().getTextureManager().loadTexture(colourPickerBarOpacityLocation, new DynamicTexture(bufferedImageOpacity)); + Minecraft.getMinecraft().getTextureManager().bindTexture(colourPickerBarOpacityLocation); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(activeColourEditor.x+5+64+5+10+5, activeColourEditor.y+5, 10, 64, GL11.GL_NEAREST); + + int chromaSpeed = SpecialColour.getSpeed(activeColourEditor.special); + int currentColourChroma = SpecialColour.specialToChromaRGB(activeColourEditor.special); + Color cChroma = new Color(currentColourChroma, true); + float hsvChroma[] = Color.RGBtoHSB(cChroma.getRed(), cChroma.getGreen(), cChroma.getBlue(), null); + + if(chromaSpeed > 0) { + Gui.drawRect(activeColourEditor.x+5+64+5+10+5+10+5+1, activeColourEditor.y+5+1, + activeColourEditor.x+5+64+5+10+5+10+5+10-1, activeColourEditor.y+5+64-1, + Color.HSBtoRGB(hsvChroma[0], 0.8f, 0.8f)); + } else { + Gui.drawRect(activeColourEditor.x+5+64+5+10+5+10+5+1, activeColourEditor.y+5+27+1, + activeColourEditor.x+5+64+5+10+5+10+5+10-1, activeColourEditor.y+5+37-1, + Color.HSBtoRGB((hsvChroma[0]+(System.currentTimeMillis()-SpecialColour.startTime)/1000f)%1, 0.8f, 0.8f)); + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_bar); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(activeColourEditor.x+5+64+5, activeColourEditor.y+5, 10, 64, GL11.GL_NEAREST); + Utils.drawTexturedRect(activeColourEditor.x+5+64+5+10+5, activeColourEditor.y+5, 10, 64, GL11.GL_NEAREST); + + if(chromaSpeed > 0) { + Utils.drawTexturedRect(activeColourEditor.x+5+64+5+10+5+10+5, activeColourEditor.y+5, 10, 64, GL11.GL_NEAREST); + } else { + Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_chroma); + Utils.drawTexturedRect(activeColourEditor.x+5+64+5+10+5+10+5, activeColourEditor.y+5+27, 10, 10, GL11.GL_NEAREST); + } + + Gui.drawRect(activeColourEditor.x+5+64+5, activeColourEditor.y+5+64-(int)(64*hsv[2]), + activeColourEditor.x+5+64+5+10, activeColourEditor.y+5+64-(int)(64*hsv[2])+1, 0xFF000000); + Gui.drawRect(activeColourEditor.x+5+64+5+10+5, activeColourEditor.y+5+64-c.getAlpha()/4, + activeColourEditor.x+5+64+5+10+5+10, activeColourEditor.y+5+64-c.getAlpha()/4-1, 0xFF000000); + if(chromaSpeed > 0) { + Gui.drawRect(activeColourEditor.x+5+64+5+10+5+10+5, + activeColourEditor.y+5+64-(int)(chromaSpeed/255f*64), + activeColourEditor.x+5+64+5+10+5+10+5+10, + activeColourEditor.y+5+64-(int)(chromaSpeed/255f*64)+1, 0xFF000000); + } + + Minecraft.getMinecraft().getTextureManager().loadTexture(colourPickerLocation, new DynamicTexture(bufferedImage)); + Minecraft.getMinecraft().getTextureManager().bindTexture(colourPickerLocation); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(activeColourEditor.x+5, activeColourEditor.y+5, 64, 64, GL11.GL_NEAREST); + + Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_dot); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(activeColourEditor.x+5+32+selx-4, activeColourEditor.y+5+32+sely-4, 8, 8, GL11.GL_NEAREST); + + Utils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GRAY.toString()+Math.round(hsv[2]*100)+"", + Minecraft.getMinecraft().fontRendererObj, + activeColourEditor.x+5+64+5+5-(Math.round(hsv[2]*100)==100?1:0), activeColourEditor.y+5+64+5+5, true, 13, -1); + Utils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GRAY.toString()+Math.round(c.getAlpha()/255f*100)+"", + Minecraft.getMinecraft().fontRendererObj, + activeColourEditor.x+5+64+5+15+5, activeColourEditor.y+5+64+5+5, true, 13, -1); + if(chromaSpeed > 0) { + Utils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GRAY.toString()+(int)SpecialColour.getSecondsForSpeed(chromaSpeed)+"s", + Minecraft.getMinecraft().fontRendererObj, + activeColourEditor.x+5+64+5+30+6, activeColourEditor.y+5+64+5+5, true, 13, -1); + } + + hexField.setSize(48, 10); + if(!hexField.getFocus()) hexField.setText(Integer.toHexString(c.getRGB() & 0xFFFFFF).toUpperCase()); + + StringBuilder sb = new StringBuilder(EnumChatFormatting.GRAY+"#"); + for(int i=0; i<6-hexField.getText().length(); i++) { + sb.append("0"); + } + sb.append(EnumChatFormatting.WHITE); + + hexField.setPrependText(sb.toString()); + hexField.render(activeColourEditor.x+5+8, activeColourEditor.y+5+64+5); + } + if(textToDisplay.get() != null) { Utils.drawHoveringText(textToDisplay.get(), mouseX, mouseY, width, height, 200, fr); } @@ -187,9 +389,84 @@ public class SettingsInfoPane extends InfoPane { for(GuiElementTextField tf : textConfigMap.values()) { tf.otherComponentClick(); } + activeColourEditor = null; + hexField.otherComponentClick(); } public void mouseInput(int width, int height, int mouseX, int mouseY, boolean mouseDown) { + if(activeColourEditor != null && (Mouse.isButtonDown(0) || Mouse.isButtonDown(1))) { + if(mouseX >= activeColourEditor.x && mouseX <= activeColourEditor.x+119) { + if(mouseY >= activeColourEditor.y && mouseY <= activeColourEditor.y+89) { + if(Mouse.getEventButtonState()) { + if(mouseX > activeColourEditor.x+5+8 && mouseX < activeColourEditor.x+5+8+48) { + if(mouseY > activeColourEditor.y+5+64+5 && mouseY < activeColourEditor.y+5+64+5+10) { + hexField.mouseClicked(mouseX, mouseY, Mouse.getEventButton()); + return; + } + } + } + hexField.otherComponentClick(); + + int currentColour = SpecialColour.specialToSimpleRGB(activeColourEditor.special); + Color c = new Color(currentColour, true); + float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); + + int xWheel = mouseX - activeColourEditor.x - 5; + int yWheel = mouseY - activeColourEditor.y - 5; + + if(xWheel > 0 && xWheel < 64) { + if(yWheel > 0 && yWheel < 64) { + float radius = (float) Math.sqrt(((xWheel-32)*(xWheel-32)+(yWheel-32)*(yWheel-32))/1024f); + float angle = (float) Math.toDegrees(Math.atan((32-xWheel)/(yWheel-32+1E-5))+Math.PI/2); + if(yWheel < 32) angle += 180; + + int rgb = Color.getHSBColor(angle/360f, (float)Math.pow(Math.min(1, radius), 1.5f), hsv[2]).getRGB(); + activeColourEditor.special = SpecialColour.special(SpecialColour.getSpeed(activeColourEditor.special), c.getAlpha(), rgb); + activeColourEditor.option.value = (String) activeColourEditor.special; + } + } + + int xValue = mouseX - (activeColourEditor.x+5+64+5); + int y = mouseY - activeColourEditor.y - 5; + + if(y > -5 && y <= 69) { + y = Math.max(0, Math.min(64, y)); + if(xValue > 0 && xValue < 10) { + int rgb = Color.getHSBColor(hsv[0], hsv[1], 1-y/64f).getRGB(); + activeColourEditor.special = SpecialColour.special(SpecialColour.getSpeed(activeColourEditor.special), c.getAlpha(), rgb); + activeColourEditor.option.value = activeColourEditor.special; + } + + int xOpacity = mouseX - (activeColourEditor.x+5+64+5+10+5); + + if(xOpacity > 0 && xOpacity < 10) { + activeColourEditor.special = SpecialColour.special(SpecialColour.getSpeed(activeColourEditor.special), + 255-(int)(y/64f*255), currentColour); + activeColourEditor.option.value = activeColourEditor.special; + } + } + + int chromaSpeed = SpecialColour.getSpeed(activeColourEditor.special); + + int xChroma = mouseX - (activeColourEditor.x+5+64+5+10+5+10+5); + if(xChroma > 0 && xChroma < 10) { + if(chromaSpeed > 0) { + if(y > -5 && y <= 69) { + y = Math.max(0, Math.min(64, y)); + activeColourEditor.special = SpecialColour.special(255-Math.round(y/64f*255), c.getAlpha(), currentColour); + activeColourEditor.option.value = activeColourEditor.special; + } + } else if(mouseY > activeColourEditor.y+5+27 && mouseY < activeColourEditor.y+5+37) { + activeColourEditor.special = SpecialColour.special(200, c.getAlpha(), currentColour); + activeColourEditor.option.value = activeColourEditor.special; + } + } + + return; + } + } + if(Mouse.getEventButtonState()) activeColourEditor = null; + } iterateSettingTile(new SettingsTileConsumer() { @Override public void consume(int x, int y, int tileWidth, int tileHeight, Options.Option<?> option, Options.Button button) { @@ -271,27 +548,40 @@ public class SettingsInfoPane extends InfoPane { if(Mouse.getEventButtonState()) tf.otherComponentClick(); } else { - if(!textConfigMap.containsKey(option)) { - textConfigMap.put(option, new GuiElementTextField(String.valueOf(option.value), 0)); - } - GuiElementTextField tf = textConfigMap.get(option); - int tfX = x+(int)(10*mult); - int tfY = y+tileHeight-(int)(20*mult); - int tfWidth = tf.getWidth(); - int tfHeight = tf.getHeight(); - if(mouseX > tfX && mouseX < tfX+tfWidth) { - if(mouseY > tfY && mouseY < tfY+tfHeight) { - if(Mouse.getEventButtonState()) { - tf.mouseClicked(mouseX, mouseY, Mouse.getEventButton()); - onTextfieldChange(tf, option); - return; - } else if(Mouse.getEventButton() == -1 && mouseDown) { - tf.mouseClickMove(mouseX, mouseY, 0, 0); //last 2 values are unused - return; + if((option.flags & Options.FLAG_COLOUR) != 0) { + if(Mouse.getEventButtonState()) { + if(mouseX > x+tileWidth/2-(int)(32*mult) && mouseX < x+tileWidth/2-(int)(32*mult)+(int)(48*mult)) { + if(mouseY > y+tileHeight-(int)(20*mult) && mouseY < y+tileHeight-(int)(20*mult)+(int)(16*mult)) { + int editorX = (int)Math.min(mouseX, width*overlay.getInfoPaneOffsetFactor()-129); + int editorY = Math.min(mouseY, height-99); + showColourEditor(editorX, editorY, (Options.Option<String>) option, (String)option.value); + return; + } } } + } else { + if(!textConfigMap.containsKey(option)) { + textConfigMap.put(option, new GuiElementTextField(String.valueOf(option.value), 0)); + } + GuiElementTextField tf = textConfigMap.get(option); + int tfX = x+(int)(10*mult); + int tfY = y+tileHeight-(int)(20*mult); + int tfWidth = tf.getWidth(); + int tfHeight = tf.getHeight(); + if(mouseX > tfX && mouseX < tfX+tfWidth) { + if(mouseY > tfY && mouseY < tfY+tfHeight) { + if(Mouse.getEventButtonState()) { + tf.mouseClicked(mouseX, mouseY, Mouse.getEventButton()); + onTextfieldChange(tf, option); + return; + } else if(Mouse.getEventButton() == -1 && mouseDown) { + tf.mouseClickMove(mouseX, mouseY, 0, 0); //last 2 values are unused + return; + } + } + } + if(Mouse.getEventButtonState()) tf.otherComponentClick(); } - if(Mouse.getEventButtonState()) tf.otherComponentClick(); } } }); @@ -345,6 +635,24 @@ public class SettingsInfoPane extends InfoPane { } } }); + if(activeColourEditor != null && hexField.getFocus()) { + String old = hexField.getText(); + + hexField.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey()); + + if(hexField.getText().length() > 6) { + hexField.setText(old); + } else { + try { + String text = hexField.getText().toLowerCase(); + + int rgb = Integer.parseInt(text, 16); + int alpha = (SpecialColour.specialToSimpleRGB(activeColourEditor.special) >> 24) & 0xFF; + activeColourEditor.special = SpecialColour.special(SpecialColour.getSpeed(activeColourEditor.special), alpha, rgb); + activeColourEditor.option.value = activeColourEditor.special; + } catch(Exception e) {}; + } + } return ret.get(); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/GuiElementTextField.java b/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/GuiElementTextField.java index 23f4ad0b..5a5bfb5c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/GuiElementTextField.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/GuiElementTextField.java @@ -32,6 +32,8 @@ public class GuiElementTextField extends GuiElement { private int x; private int y; + private String prependText = ""; + private GuiTextField textField = new GuiTextField(0, Minecraft.getMinecraft().fontRendererObj, 0 , 0, 0, 0); @@ -53,6 +55,10 @@ public class GuiElementTextField extends GuiElement { return textField.getText(); } + public void setPrependText(String text) { + this.prependText = text; + } + public void setText(String text) { if(textField.getText() == null || !textField.getText().equals(text)) { textField.setText(text); @@ -115,16 +121,20 @@ public class GuiElementTextField extends GuiElement { int extraSize = (searchBarYSize-8)/2+8; + String renderText = prependText + textField.getText(); + int lineNum = Math.round(((yComp - (searchBarYSize-8)/2))/extraSize); Pattern patternControlCode = Pattern.compile("(?i)\\u00A7([^\\u00B6])(?!\\u00B6)"); - String text = textField.getText(); - String textNoColour = textField.getText(); - while(true) { - Matcher matcher = patternControlCode.matcher(text); - if(!matcher.find() || matcher.groupCount() < 1) break; - String code = matcher.group(1); - text = matcher.replaceFirst("\u00A7"+code+"\u00B6"+code); + String text = renderText; + String textNoColour = renderText; + if((options & COLOUR) != 0) { + while(true) { + Matcher matcher = patternControlCode.matcher(text); + if(!matcher.find() || matcher.groupCount() < 1) break; + String code = matcher.group(1); + text = matcher.replaceFirst("\u00A7"+code+"\u00B6"+code); + } } while(true) { Matcher matcher = patternControlCode.matcher(textNoColour); @@ -141,20 +151,31 @@ public class GuiElementTextField extends GuiElement { currentLine++; } } + + String textNC = textNoColour.substring(0, cursorIndex); int colorCodes = StringUtils.countMatches(textNC, "\u00B6"); - String line = text.substring(cursorIndex+colorCodes*2).split("\n")[0]; - String trimmed = Minecraft.getMinecraft().fontRendererObj.trimStringToWidth(line, xComp-5); + String line = text.substring(cursorIndex+(((options & COLOUR) != 0)?colorCodes*2:0)).split("\n")[0]; + int padding = Math.min(5, searchBarXSize-strLenNoColor(line))/2; + String trimmed = Minecraft.getMinecraft().fontRendererObj.trimStringToWidth(line, xComp-padding); int linePos = strLenNoColor(trimmed); if(linePos != strLenNoColor(line)) { char after = line.charAt(linePos); int trimmedWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(trimmed); int charWidth = Minecraft.getMinecraft().fontRendererObj.getCharWidth(after); - if(trimmedWidth + charWidth/2 < xComp-5) { + if(trimmedWidth + charWidth/2 < xComp-padding) { linePos++; } } cursorIndex += linePos; + + int pre = Utils.cleanColour(prependText).length(); + if(cursorIndex < pre) { + cursorIndex = 0; + } else { + cursorIndex -= pre; + } + return cursorIndex; } @@ -319,7 +340,6 @@ public class GuiElementTextField extends GuiElement { textField.setCursorPosition(pos+1); } } - } } @@ -336,6 +356,7 @@ public class GuiElementTextField extends GuiElement { private void drawTextbox(int x, int y, int searchBarXSize, int searchBarYSize, int searchBarPadding, GuiTextField textField, boolean focus) { ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); + String renderText = prependText + textField.getText(); GlStateManager.disableLighting(); @@ -345,7 +366,7 @@ public class GuiElementTextField extends GuiElement { int paddingUnscaled = searchBarPadding/scaledresolution.getScaleFactor(); if(paddingUnscaled < 1) paddingUnscaled = 1; - int numLines = StringUtils.countMatches(textField.getText(), "\n")+1; + int numLines = StringUtils.countMatches(renderText, "\n")+1; int extraSize = (searchBarYSize-8)/2+8; int bottomTextBox = y + searchBarYSize + extraSize*(numLines-1); @@ -366,13 +387,15 @@ public class GuiElementTextField extends GuiElement { //bar text Pattern patternControlCode = Pattern.compile("(?i)\\u00A7([^\\u00B6\n])(?!\\u00B6)"); - String text = textField.getText(); - String textNoColor = textField.getText(); - while(true) { - Matcher matcher = patternControlCode.matcher(text); - if(!matcher.find() || matcher.groupCount() < 1) break; - String code = matcher.group(1); - text = matcher.replaceFirst("\u00A7"+code+"\u00B6"+code); + String text = renderText; + String textNoColor = renderText; + if((options & COLOUR) != 0) { + while(true) { + Matcher matcher = patternControlCode.matcher(text); + if(!matcher.find() || matcher.groupCount() < 1) break; + String code = matcher.group(1); + text = matcher.replaceFirst("\u00A7"+code+"\u00B6"+code); + } } while(true) { Matcher matcher = patternControlCode.matcher(textNoColor); @@ -403,9 +426,9 @@ public class GuiElementTextField extends GuiElement { } if(focus && System.currentTimeMillis()%1000>500) { - String textNCBeforeCursor = textNoColor.substring(0, textField.getCursorPosition()); + String textNCBeforeCursor = textNoColor.substring(0, textField.getCursorPosition()+prependText.length()); int colorCodes = StringUtils.countMatches(textNCBeforeCursor, "\u00B6"); - String textBeforeCursor = text.substring(0, textField.getCursorPosition()+colorCodes*2); + String textBeforeCursor = text.substring(0, textField.getCursorPosition()+prependText.length()+(((options & COLOUR) != 0) ? colorCodes*2 : 0)); int numLinesBeforeCursor = StringUtils.countMatches(textBeforeCursor, "\n"); int yOff = numLinesBeforeCursor*extraSize; @@ -425,8 +448,8 @@ public class GuiElementTextField extends GuiElement { String selectedText = textField.getSelectedText(); if(!selectedText.isEmpty()) { - int leftIndex = Math.min(textField.getCursorPosition(), textField.getSelectionEnd()); - int rightIndex = Math.max(textField.getCursorPosition(), textField.getSelectionEnd()); + int leftIndex = Math.min(textField.getCursorPosition()+prependText.length(), textField.getSelectionEnd()+prependText.length()); + int rightIndex = Math.max(textField.getCursorPosition()+prependText.length(), textField.getSelectionEnd()+prependText.length()); float texX = 0; int texY = 0; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinEntityPlayer.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinEntityPlayer.java new file mode 100644 index 00000000..78201a8f --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinEntityPlayer.java @@ -0,0 +1,34 @@ +package io.github.moulberry.notenoughupdates.mixins; + +import io.github.moulberry.notenoughupdates.DungeonBlocks; +import io.github.moulberry.notenoughupdates.cosmetics.CapeManager; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.RenderList; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EnumPlayerModelParts; +import net.minecraft.util.EnumWorldBlockLayer; +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; +import org.lwjgl.opengl.GL14; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin({EntityPlayer.class}) +public abstract class MixinEntityPlayer { + + @Inject(method="isWearing", at=@At("HEAD"), cancellable = true) + public void isWearing(EnumPlayerModelParts part, CallbackInfoReturnable<Boolean> cir) { + if(part == EnumPlayerModelParts.CAPE) { + EntityPlayer $this = (EntityPlayer)(Object)this; + String uuid = $this.getUniqueID().toString().replace("-", ""); + String cape = CapeManager.getInstance().getCape(uuid); + if(cape != null && !cape.equalsIgnoreCase("null")) { + cir.setReturnValue(false); + } + } + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiChest.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiChest.java index f56093b8..bd74b44c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiChest.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiChest.java @@ -3,6 +3,7 @@ package io.github.moulberry.notenoughupdates.mixins; import io.github.moulberry.notenoughupdates.BetterContainers; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.StreamerMode; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiIngame; import net.minecraft.client.gui.inventory.GuiChest; import net.minecraft.client.renderer.texture.DynamicTexture; @@ -29,4 +30,23 @@ public class MixinGuiChest { BetterContainers.bindHook(textureManager, location); } + private static final String TARGET_DRAWSTRING = "Lnet/minecraft/client/gui/FontRenderer;drawString(Ljava/lang/String;III)I"; + @Redirect(method="drawGuiContainerForegroundLayer", at=@At(value="INVOKE", target = TARGET_DRAWSTRING)) + public int drawGuiContainerForegroundLayer_drawString(FontRenderer fontRenderer, String text, int x, int y, int color) { + return fontRenderer.drawString(text, x, y, BetterContainers.isOverriding() ? BetterContainers.getTextColour() : color); + } + + private static final String TARGET_SBADRAWSTRING = "Lcodes/biscuit/skyblockaddons/asm/hooks/GuiChestHook;" + + "drawString(Lnet/minecraft/client/gui/FontRenderer;Ljava/lang/String;III)I"; + @Redirect(method="drawGuiContainerForegroundLayer", at=@At(value="INVOKE", target = TARGET_SBADRAWSTRING, remap = false)) + public int drawGuiContainerForegroundLayer_SBA_drawString(FontRenderer fontRenderer, String text, int x, int y, int color) { + try { + return (int)Class.forName("codes.biscuit.skyblockaddons.asm.hooks.GuiChestHook") + .getDeclaredMethod("drawString", FontRenderer.class, String.class, int.class, int.class, int.class) + .invoke(null, fontRenderer, text, x, y, BetterContainers.isOverriding() ? BetterContainers.getTextColour() : color); + } catch(Exception e) {} + return fontRenderer.drawString(text, x, y, BetterContainers.isOverriding() ? BetterContainers.getTextColour() : color); + } + + } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java index 879d348b..e8b635c1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java @@ -22,7 +22,7 @@ public abstract class MixinGuiContainer { @Inject(method="drawSlot", at=@At("HEAD"), cancellable = true) public void drawSlot(Slot slot, CallbackInfo ci) { - if(slot != null && BetterContainers.isOverriding() && BetterContainers.isBlankStack(slot.getStack())) { + if(slot != null && BetterContainers.isOverriding() && !BetterContainers.shouldRenderStack(slot.getStack())) { ci.cancel(); } } @@ -43,9 +43,11 @@ public abstract class MixinGuiContainer { BetterContainers.clickSlot(slotIn.getSlotIndex()); Utils.playPressSound(); - GuiContainer $this = (GuiContainer)(Object)this; - $this.mc.playerController.windowClick($this.inventorySlots.windowId, slotId, 2, clickType, $this.mc.thePlayer); - ci.cancel(); + /*if(!BetterContainers.isAh()) { + GuiContainer $this = (GuiContainer)(Object)this; + $this.mc.playerController.windowClick($this.inventorySlots.windowId, slotId, 2, clickType, $this.mc.thePlayer); + ci.cancel(); + }*/ } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderBat.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderBat.java new file mode 100644 index 00000000..93182439 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderBat.java @@ -0,0 +1,40 @@ +package io.github.moulberry.notenoughupdates.mixins; + +import io.github.moulberry.notenoughupdates.DungeonBlocks; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.util.SpecialColour; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.entity.RenderBat; +import net.minecraft.client.renderer.texture.AbstractTexture; +import net.minecraft.client.renderer.texture.SimpleTexture; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.client.resources.IResourceManager; +import net.minecraft.entity.passive.EntityBat; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.io.IOException; + +@Mixin({RenderBat.class}) +public abstract class MixinRenderBat { + + @Inject(method="getEntityTexture", at=@At("HEAD"), cancellable = true) + public void getEntityTexture(EntityBat entity, CallbackInfoReturnable<ResourceLocation> cir) { + if(DungeonBlocks.isInDungeons()) { + ResourceLocation rl = new ResourceLocation("notenoughupdates:dynamic/dungeon_bat"); + Minecraft.getMinecraft().getTextureManager().loadTexture(rl, new AbstractTexture() { + public void loadTexture(IResourceManager resourceManager) { + glTextureId = DungeonBlocks.getModifiedTexture(new ResourceLocation("textures/entity/bat.png"), + SpecialColour.specialToSimpleRGB(NotEnoughUpdates.INSTANCE.manager.config.dungBatColour.value)); + } + }); + cir.setReturnValue(rl); + } + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderList.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderList.java new file mode 100644 index 00000000..03300d45 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderList.java @@ -0,0 +1,38 @@ +package io.github.moulberry.notenoughupdates.mixins; + +import io.github.moulberry.notenoughupdates.DungeonBlocks; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.*; +import net.minecraft.client.renderer.texture.DynamicTexture; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.util.EnumWorldBlockLayer; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; +import org.lwjgl.opengl.GL14; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; + +@Mixin({RenderList.class}) +public abstract class MixinRenderList { + + @Inject(method="renderChunkLayer", at=@At("HEAD")) + public void renderChunkLayer(EnumWorldBlockLayer layer, CallbackInfo ci) { + if(DungeonBlocks.textureExists()) { + DungeonBlocks.bindTextureIfExists(); + + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); + } + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinTileEntitySpecialRenderer.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinTileEntitySpecialRenderer.java new file mode 100644 index 00000000..16e4bfbe --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinTileEntitySpecialRenderer.java @@ -0,0 +1,33 @@ +package io.github.moulberry.notenoughupdates.mixins; + +import io.github.moulberry.notenoughupdates.DungeonBlocks; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.util.SpecialColour; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.RenderList; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.util.EnumWorldBlockLayer; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.GL11; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin({TileEntitySpecialRenderer.class}) +public abstract class MixinTileEntitySpecialRenderer { + + @Inject(method="bindTexture", at=@At("HEAD"), cancellable = true) + public void bindTexture(ResourceLocation location, CallbackInfo info) { + if(DungeonBlocks.isInDungeons() && location.getResourcePath().equals("textures/entity/chest/normal.png")) { + info.cancel(); + + GlStateManager.bindTexture(DungeonBlocks.getModifiedTexture(location, + SpecialColour.specialToSimpleRGB(NotEnoughUpdates.INSTANCE.manager.config.dungChestColour.value))); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); + } + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinVboRenderList.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinVboRenderList.java new file mode 100644 index 00000000..03dded06 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinVboRenderList.java @@ -0,0 +1,42 @@ +package io.github.moulberry.notenoughupdates.mixins; + +import io.github.moulberry.notenoughupdates.DungeonBlocks; +import io.github.moulberry.notenoughupdates.ItemRarityHalo; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.ChunkRenderContainer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.VboRenderList; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.client.renderer.texture.DynamicTexture; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumWorldBlockLayer; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; +import org.lwjgl.opengl.GL14; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; + +@Mixin({VboRenderList.class}) +public abstract class MixinVboRenderList { + + @Inject(method="renderChunkLayer", at=@At("HEAD")) + public void renderChunkLayer(EnumWorldBlockLayer layer, CallbackInfo ci) { + if(DungeonBlocks.textureExists()) { + DungeonBlocks.bindTextureIfExists(); + + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); + } + } +} 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 294a8873..c8a596b1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/Options.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/Options.java @@ -5,6 +5,7 @@ import io.github.moulberry.notenoughupdates.GuiEnchantColour; import io.github.moulberry.notenoughupdates.NEUOverlayPlacements; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.mbgui.MBAnchorPoint; +import io.github.moulberry.notenoughupdates.util.SpecialColour; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.util.Util; @@ -28,6 +29,8 @@ public class Options { * variables with defaults values/etc. It works. I'm happy. */ + public static final transient int FLAG_COLOUR = 0b1; + public Option<Boolean> enableItemEditing = new Option( false, "Enable Item Editing", @@ -38,6 +41,11 @@ public class Options { "Only Show On Skyblock", false, "NEU Overlay only appears when you are playing Skyblock."); + public Option<Boolean> showVanillaItems = new Option( + true, + "Show Vanilla Items", + false, + "Shows vanilla items in the itemlist."); public Option<Boolean> hidePotionEffect = new Option( true, "Hide Potion Effects", @@ -143,6 +151,21 @@ public class Options { "Custom Trade", false, "If true, uses the custom trade window for skyblock trades."); + public Option<Boolean> invBazaarPrice = new Option( + false, + "Show Bazaar Price In Inventory", + false, + "If true, shows the bazaar price for the item you hover in your inventory."); + public Option<Boolean> invAuctionPrice = new Option( + false, + "Show Auction Price In Inventory", + false, + "If true, shows the auction price for the item you hover in your inventory."); + public Option<Boolean> dungeonBlocksEverywhere = new Option( + false, + "Show Dungeon Block Overlay Everywhere", + false, + "If true, will show the overlay for cracked bricks, etc. even when not in dungeons."); public Option<Double> paneWidthMult = new Option( 1.0, "Pane Width", @@ -153,16 +176,6 @@ public class Options { "Smooth AOTE Milliseconds", false, "How long teleporting with the AOTE takes. 0 = disable.", 0, 300); - public Option<Double> bgOpacity = new Option( - 30.0, - "Pane Background Opacity", - false, - "Changes the background colour opacity of item and info panes. Value between 0-255.", 0, 255); - public Option<Double> fgOpacity = new Option( - 255.0, - "Item Background Opacity", - false, - "Changes the opacity of item background. Value between 0-255.", 0, 255); public Option<Double> itemHighlightOpacity = new Option( 178.0, "Item Highlight Opacity", @@ -194,6 +207,68 @@ public class Options { false, "Style of the buttons used for the skyblock menu.", 0, 10); + public Option<String> itemBackgroundColour = new Option( + "00:255:100:100:100", + "Item BG Colour", + false, + "Treecapitator Overlay Colour", + FLAG_COLOUR); + public Option<String> itemFavouriteColour = new Option( + "00:255:200:150:50", + "Item BG Favourite Colour", + false, + "Item BG Favourite Colour", + FLAG_COLOUR); + public Option<String> paneBackgroundColour = new Option( + "15:6:0:0:255", + "Pane Background Colour", + false, + "Pane Background Colour", + FLAG_COLOUR); + public Option<String> treecapOverlayColour = new Option( + "00:50:64:224:208", + "Treecapitator Overlay Colour", + false, + "Treecapitator Overlay Colour", + FLAG_COLOUR); + + public Option<String> dungCrackedColour = new Option( + "0:252:7:255:217", + "Dungeon Cracked Brick Colour", + false, + "Dungeon Cracked Brick Colour", + FLAG_COLOUR); + public Option<String> dungDispenserColour = new Option( + "0:255:255:76:0", + "Dungeon Dispenser Colour", + false, + "Dungeon Dispenser Colour", + FLAG_COLOUR); + public Option<String> dungLeverColour = new Option( + "0:252:24:249:255", + "Dungeon Lever Colour", + false, + "Dungeon Lever Colour", + FLAG_COLOUR); + public Option<String> dungTripWireColour = new Option( + "0:255:255:0:0", + "Dungeon Trip Wire Colour", + false, + "Dungeon Trip Wire Colour", + FLAG_COLOUR); + public Option<String> dungChestColour = new Option( + "0:255:0:163:36", + "Dungeon Chest Colour", + false, + "Dungeon Chest Colour", + FLAG_COLOUR); + public Option<String> dungBatColour = new Option( + "0:255:12:255:0", + "Dungeon Bat Colour", + false, + "Dungeon Bat Colour", + FLAG_COLOUR); + /** * OPTIONS THAT DON'T SHOW IN GUI */ @@ -336,6 +411,7 @@ public class Options { //Buttons tryAddOption(enableItemEditing, options); tryAddOption(onlyShowOnSkyblock, options); + tryAddOption(showVanillaItems, options); tryAddOption(showQuickCommands, options); tryAddOption(hidePotionEffect, options); tryAddOption(hideEmptyPanes, options); @@ -356,12 +432,13 @@ public class Options { tryAddOption(useCustomTrade, options); tryAddOption(customTradePrices, options); tryAddOption(customTradePriceStyle, options); + tryAddOption(invBazaarPrice, options); + tryAddOption(invAuctionPrice, options); + tryAddOption(dungeonBlocksEverywhere, options); //Sliders tryAddOption(smoothAoteMillis, options); tryAddOption(bgBlurFactor, options); tryAddOption(ahNotification, options); - tryAddOption(bgOpacity, options); - tryAddOption(fgOpacity, options); tryAddOption(itemHighlightOpacity, options); tryAddOption(panePadding, options); tryAddOption(tooltipBorderOpacity, options); @@ -369,6 +446,18 @@ public class Options { tryAddOption(dynamicMenuButtonStyle, options); //Text tryAddOption(apiKey, options); + //Colour + tryAddOption(paneBackgroundColour, options); + tryAddOption(itemBackgroundColour, options); + tryAddOption(itemFavouriteColour, options); + tryAddOption(treecapOverlayColour, options); + + tryAddOption(dungCrackedColour, options); + tryAddOption(dungDispenserColour, options); + tryAddOption(dungLeverColour, options); + tryAddOption(dungTripWireColour, options); + tryAddOption(dungChestColour, options); + tryAddOption(dungBatColour, options); return options; } @@ -385,19 +474,29 @@ public class Options { public final transient String displayName; public final transient boolean secret; public final transient String desc; + public final transient int flags; public final transient double minValue; public final transient double maxValue; public Option(T defaultValue, String displayName, boolean secret, String desc) { - this(defaultValue, displayName, secret, desc, 0, 100); + this(defaultValue, displayName, secret, desc, 0, 0, 100); + } + + public Option(T defaultValue, String displayName, boolean secret, String desc, int flags) { + this(defaultValue, displayName, secret, desc, flags, 0, 100); } public Option(T defaultValue, String displayName, boolean secret, String desc, double minValue, double maxValue) { + this(defaultValue, displayName, secret, desc, 0, minValue, maxValue); + } + + public Option(T defaultValue, String displayName, boolean secret, String desc, int flags, double minValue, double maxValue) { this.value = defaultValue; this.defaultValue = defaultValue; this.displayName = displayName; this.secret = secret; this.desc = desc; + this.flags = flags; this.minValue = minValue; this.maxValue = maxValue; } 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 837addf3..fc0caa28 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java @@ -11,7 +11,7 @@ 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; +import io.github.moulberry.notenoughupdates.questing.SBInfo; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityOtherPlayerMP; @@ -675,9 +675,9 @@ public class GuiProfileViewer extends GuiScreen { backgroundRotation %= 360; String panoramaIdentifier = "day"; - if(SBScoreboardData.getInstance().currentTimeDate != null) { - if(SBScoreboardData.getInstance().currentTimeDate.getHours() <= 6 || - SBScoreboardData.getInstance().currentTimeDate.getHours() >= 20) { + if(SBInfo.getInstance().currentTimeDate != null) { + if(SBInfo.getInstance().currentTimeDate.getHours() <= 6 || + SBInfo.getInstance().currentTimeDate.getHours() >= 20) { panoramaIdentifier = "night"; } } @@ -1902,9 +1902,9 @@ public class GuiProfileViewer extends GuiScreen { backgroundRotation %= 360; String panoramaIdentifier = "day"; - if(SBScoreboardData.getInstance().currentTimeDate != null) { - if(SBScoreboardData.getInstance().currentTimeDate.getHours() <= 6 || - SBScoreboardData.getInstance().currentTimeDate.getHours() >= 20) { + if(SBInfo.getInstance().currentTimeDate != null) { + if(SBInfo.getInstance().currentTimeDate.getHours() <= 6 || + SBInfo.getInstance().currentTimeDate.getHours() >= 20) { panoramaIdentifier = "night"; } } @@ -1984,6 +1984,30 @@ public class GuiProfileViewer extends GuiScreen { long networth = profile.getNetWorth(profileId); if(networth > 0) { Utils.drawStringCentered(EnumChatFormatting.GREEN+"Net Worth: "+EnumChatFormatting.GOLD+numberFormat.format(networth), fr, guiLeft+63, guiTop+38, true, 0); + try { + double networthInCookies = (networth / NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo("BOOSTER_COOKIE").get("avg_buy").getAsDouble()); + String networthIRLMoney = Long.toString(Math.round(((networthInCookies * 325) / 675) * 4.99)); + + if(mouseX > guiLeft+8 && mouseX < guiLeft+8+fontRendererObj.getStringWidth("Net Worth: " + numberFormat.format(networth))) { + if(mouseY > guiTop+32 && mouseY < guiTop+32+fontRendererObj.FONT_HEIGHT) { + tooltipToDisplay = new ArrayList<>(); + tooltipToDisplay.add(EnumChatFormatting.GREEN+"Net worth in IRL money: "+EnumChatFormatting.DARK_GREEN+"$" +EnumChatFormatting.GOLD+networthIRLMoney); + tooltipToDisplay.add(""); + if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { + tooltipToDisplay.add(EnumChatFormatting.RED+"This is calculated using the current"); + tooltipToDisplay.add(EnumChatFormatting.RED+"price of booster cookies on bazaar and the price"); + tooltipToDisplay.add(EnumChatFormatting.RED+"for cookies using gems, then the price of gems"); + tooltipToDisplay.add(EnumChatFormatting.RED+"is where we get the amount of IRL money you" ); + tooltipToDisplay.add(EnumChatFormatting.RED+"theoretically have on skyblock in net worth."); + } else { + tooltipToDisplay.add(EnumChatFormatting.GRAY+"[SHIFT for Info]"); + } + tooltipToDisplay.add(""); + tooltipToDisplay.add(EnumChatFormatting.RED+"THIS IS IN NO WAY ENDORSING IRL TRADING!"); + + } + } + } catch(Exception e){} } if(status != null) { @@ -2212,6 +2236,11 @@ public class GuiProfileViewer extends GuiScreen { } private void renderGoldBar(float x, float y, float xSize) { + if(!OpenGlHelper.areShadersSupported()) { + renderBar(x, y, xSize, 1); + return; + } + Minecraft.getMinecraft().getTextureManager().bindTexture(icons); ShaderManager shaderManager = ShaderManager.getInstance(); shaderManager.loadShader("make_gold"); @@ -2384,6 +2413,8 @@ public class GuiProfileViewer extends GuiScreen { */ private double lastBgBlurFactor = -1; private void blurBackground() { + if(!OpenGlHelper.isFramebufferEnabled()) return; + int width = Minecraft.getMinecraft().displayWidth; int height = Minecraft.getMinecraft().displayHeight; @@ -2443,6 +2474,8 @@ public class GuiProfileViewer extends GuiScreen { * Essentially, this method will "blur" the background inside the bounds specified by [x->x+blurWidth, y->y+blurHeight] */ public void renderBlurredBackground(int width, int height, int x, int y, int blurWidth, int blurHeight) { + if(!OpenGlHelper.isFramebufferEnabled()) return; + float uMin = x/(float)width; float uMax = (x+blurWidth)/(float)width; float vMin = (height-y)/(float)height; 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 fa585f1e..379935ad 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/Panorama.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/Panorama.java @@ -1,9 +1,11 @@ package io.github.moulberry.notenoughupdates.profileviewer; import io.github.moulberry.notenoughupdates.util.TexLoc; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.texture.DynamicTexture; @@ -24,6 +26,15 @@ public class Panorama { private static int lastHeight = 0; public static void drawPanorama(float angle, int x, int y, int width, int height, float yOffset, float zOffset, ResourceLocation[] panoramas) { + if(!OpenGlHelper.isFramebufferEnabled()) { + Minecraft.getMinecraft().getTextureManager().bindTexture(panoramas[0]); + + float aspect = width/(float)height; + Utils.drawTexturedRect(x, y, width, height, 0.5f-aspect/2, 0.5f+aspect/2, 0, 1); + + return; + } + Minecraft.getMinecraft().getFramebuffer().unbindFramebuffer(); ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/questing/SBScoreboardData.java b/src/main/java/io/github/moulberry/notenoughupdates/questing/SBInfo.java index 9735f917..b647fb1c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/questing/SBScoreboardData.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/questing/SBInfo.java @@ -1,12 +1,16 @@ package io.github.moulberry.notenoughupdates.questing; +import com.google.gson.JsonObject; +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 net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.event.world.WorldEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -16,11 +20,10 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -public class SBScoreboardData { +public class SBInfo { - private static final SBScoreboardData INSTANCE = new SBScoreboardData(); + private static final SBInfo INSTANCE = new SBInfo(); - private static final Pattern locationPattern = Pattern.compile("(\\u00a7)(?!.*\\u00a7).+"); private static final Pattern timePattern = Pattern.compile(".+(am|pm)"); public String location = ""; @@ -28,13 +31,51 @@ public class SBScoreboardData { public String time = ""; public String objective = ""; + public String mode = ""; + public Date currentTimeDate = null; - public static SBScoreboardData getInstance() { + public static SBInfo getInstance() { return INSTANCE; } + private long lastLocRaw = -1; + private JsonObject locraw = null; + + @SubscribeEvent + public void onWorldChange(WorldEvent.Load event) { + lastLocRaw = -1; + locraw = null; + } + + @SubscribeEvent + public void onChatMessage(ClientChatReceivedEvent event) { + if(event.message.getUnformattedText().startsWith("{")) { + try { + JsonObject obj = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(event.message.getUnformattedText(), JsonObject.class); + if(obj.has("server") && obj.has("gametype") && obj.has("mode") && obj.has("map")) { + locraw = obj; + event.setCanceled(true); + } + } catch(Exception e) { + e.printStackTrace(); + } + } + } + + public String getLocation() { + if(locraw == null) { + return null; + } + return locraw.get("mode").getAsString(); + } + public void tick() { + if(locraw == null && (System.currentTimeMillis() - lastLocRaw) > 20000) { + lastLocRaw = System.currentTimeMillis(); + NotEnoughUpdates.INSTANCE.sendChatMessage("/locraw"); + } + try { Scoreboard scoreboard = Minecraft.getMinecraft().thePlayer.getWorldScoreboard(); @@ -53,9 +94,9 @@ public class SBScoreboardData { lines.add(line); } if(lines.size() >= 5) { - date = Utils.cleanColour(lines.get(2)).trim(); + date = Utils.cleanColour(lines.get(1)).trim(); //ยง74:40am - Matcher matcher = timePattern.matcher(lines.get(3)); + Matcher matcher = timePattern.matcher(lines.get(2)); if(matcher.find()) { time = Utils.cleanColour(matcher.group()).trim(); try { @@ -64,10 +105,7 @@ public class SBScoreboardData { currentTimeDate = parseFormat.parse(timeSpace); } catch (ParseException e) {} } - matcher = locationPattern.matcher(lines.get(4)); - if(matcher.find()) { - location = Utils.cleanColour(matcher.group()).trim(); - } + location = Utils.cleanColour(lines.get(3)).replaceAll("[^A-Za-z0-9() ]", "").trim(); } objective = null; @@ -82,7 +120,6 @@ public class SBScoreboardData { } catch(Exception e) { e.printStackTrace(); } - //System.out.println(date + ":" + time + ":" + location); } } 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 319bc1b6..c0aef344 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.SBScoreboardData; +import io.github.moulberry.notenoughupdates.questing.SBInfo; public class RequirementIslandType extends Requirement { @@ -14,6 +14,6 @@ public class RequirementIslandType extends Requirement { @Override public void updateRequirement() { - completed = islandType.equalsIgnoreCase(SBScoreboardData.getInstance().location); + completed = islandType.equalsIgnoreCase(SBInfo.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 d6f89409..2e6b29da 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java @@ -24,7 +24,7 @@ public class HypixelApi { private ExecutorService es = Executors.newFixedThreadPool(3); private int myApiErrors = 0; - private String[] myApiURLs = {"https://moulberry.codes/", "http://51.89.22.3/", "http://moulberry.codes/", "https://51.89.22.3/"}; + private String[] myApiURLs = {"https://moulberry.codes/", "http://51.75.78.252/", "http://moulberry.codes/" }; public void getHypixelApiAsync(String apiKey, String method, HashMap<String, String> args, Consumer<JsonObject> consumer) { getHypixelApiAsync(apiKey, method, args, consumer, () -> {}); @@ -42,7 +42,7 @@ public class HypixelApi { es.submit(() -> { try { consumer.accept(getApiSync(urlS)); - } catch(IOException e) { + } catch(Exception e) { error.run(); } }); @@ -52,7 +52,7 @@ public class HypixelApi { es.submit(() -> { try { consumer.accept(getApiSync(getMyApiURL()+urlS)); - } catch(IOException e) { + } catch(Exception e) { myApiErrors++; error.run(); } @@ -63,7 +63,7 @@ public class HypixelApi { es.submit(() -> { try { consumer.accept(getApiGZIPSync(getMyApiURL()+urlS)); - } catch(IOException e) { + } catch(Exception e) { myApiErrors++; error.run(); } @@ -74,7 +74,7 @@ public class HypixelApi { es.submit(() -> { try { consumer.accept(getApiGZIPSync(urlS)); - } catch(IOException e) { + } catch(Exception e) { error.run(); } }); @@ -83,7 +83,7 @@ public class HypixelApi { public JsonObject getApiSync(String urlS) throws IOException { URL url = new URL(urlS); URLConnection connection = url.openConnection(); - connection.setConnectTimeout(3000); + connection.setConnectTimeout(10000); connection.setReadTimeout(10000); String response = IOUtils.toString(connection.getInputStream(), StandardCharsets.UTF_8); @@ -95,7 +95,7 @@ public class HypixelApi { public JsonObject getApiGZIPSync(String urlS) throws IOException { URL url = new URL(urlS); URLConnection connection = url.openConnection(); - connection.setConnectTimeout(3000); + connection.setConnectTimeout(10000); connection.setReadTimeout(10000); String response = IOUtils.toString(new GZIPInputStream(connection.getInputStream()), StandardCharsets.UTF_8); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/SpecialColour.java b/src/main/java/io/github/moulberry/notenoughupdates/util/SpecialColour.java new file mode 100644 index 00000000..9ec6da3e --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/SpecialColour.java @@ -0,0 +1,81 @@ +package io.github.moulberry.notenoughupdates.util; + +import java.awt.*; + +public class SpecialColour { + + public static String special(int chromaSpeed, int alpha, int rgb) { + return special(chromaSpeed, alpha, (rgb & 0xFF0000) >> 16, (rgb & 0x00FF00) >> 8, (rgb & 0x0000FF)); + } + + private static final int RADIX = 10; + + public static String special(int chromaSpeed, int alpha, int r, int g, int b) { + StringBuilder sb = new StringBuilder(); + sb.append(Integer.toString(chromaSpeed, RADIX)).append(":"); + sb.append(Integer.toString(alpha, RADIX)).append(":"); + sb.append(Integer.toString(r, RADIX)).append(":"); + sb.append(Integer.toString(g, RADIX)).append(":"); + sb.append(Integer.toString(b, RADIX)); + return sb.toString(); + } + + private static int[] decompose(String csv) { + String[] split = csv.split(":"); + + int[] arr = new int[split.length]; + + + for(int i=0; i<split.length; i++) { + arr[i] = Integer.parseInt(split[split.length-1-i], RADIX); + } + return arr; + } + + public static int specialToSimpleRGB(String special) { + int[] d = decompose(special); + int r = d[2]; + int g = d[1]; + int b = d[0]; + int a = d[3]; + int chr = d[4]; + + return (a & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF); + } + + public static int getSpeed(String special) { + return decompose(special)[4]; + } + + public static float getSecondsForSpeed(int speed) { + return (255-speed)/254f*(MAX_CHROMA_SECS-MIN_CHROMA_SECS)+MIN_CHROMA_SECS; + } + + private static final int MIN_CHROMA_SECS = 1; + private static final int MAX_CHROMA_SECS = 60; + + public static long startTime = -1; + public static int specialToChromaRGB(String special) { + if(startTime < 0) startTime = System.currentTimeMillis(); + + int[] d = decompose(special); + int chr = d[4]; + int a = d[3]; + int r = d[2]; + int g = d[1]; + int b = d[0]; + + float[] hsv = Color.RGBtoHSB(r, g, b, null); + + if(chr > 0) { + float seconds = getSecondsForSpeed(chr); + hsv[0] += (System.currentTimeMillis()-startTime)/1000f/seconds; + hsv[0] %= 1; + if(hsv[0] < 0) hsv[0] += 1; + } + + return (a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF); + } + + +} |