From a0402708801b525145d01d0f4da17f0ba9d93455 Mon Sep 17 00:00:00 2001 From: Moulberry Date: Sun, 18 Oct 2020 21:01:11 +1100 Subject: 1.4 --- .../notenoughupdates/AccessoryBagOverlay.java | 299 ++++++++++++++- .../notenoughupdates/BetterContainers.java | 92 ++++- .../notenoughupdates/CustomItemEffects.java | 7 +- .../moulberry/notenoughupdates/DungeonBlocks.java | 315 ++++++++++++++++ .../moulberry/notenoughupdates/DungeonMap.java | 416 +++++++++++++++++++++ .../notenoughupdates/GuiEnchantColour.java | 35 +- .../moulberry/notenoughupdates/GuiTextures.java | 6 + .../notenoughupdates/NEUEventListener.java | 260 +++++++++---- .../moulberry/notenoughupdates/NEUManager.java | 22 +- .../moulberry/notenoughupdates/NEUOverlay.java | 102 +++-- .../notenoughupdates/NotEnoughUpdates.java | 193 +++++++++- .../notenoughupdates/auction/APIManager.java | 20 +- .../notenoughupdates/auction/CustomAH.java | 77 +++- .../notenoughupdates/cosmetics/CapeManager.java | 32 +- .../notenoughupdates/cosmetics/GuiCosmetics.java | 46 +-- .../notenoughupdates/cosmetics/NEUCape.java | 4 + .../notenoughupdates/gamemodes/SBGamemodes.java | 14 +- .../infopanes/CollectionLogInfoPane.java | 6 +- .../notenoughupdates/infopanes/InfoPane.java | 2 + .../infopanes/SettingsInfoPane.java | 366 ++++++++++++++++-- .../itemeditor/GuiElementTextField.java | 69 ++-- .../notenoughupdates/mixins/MixinEntityPlayer.java | 34 ++ .../notenoughupdates/mixins/MixinGuiChest.java | 20 + .../notenoughupdates/mixins/MixinGuiContainer.java | 10 +- .../notenoughupdates/mixins/MixinRenderBat.java | 40 ++ .../notenoughupdates/mixins/MixinRenderList.java | 38 ++ .../mixins/MixinTileEntitySpecialRenderer.java | 33 ++ .../mixins/MixinVboRenderList.java | 42 +++ .../notenoughupdates/options/Options.java | 125 ++++++- .../profileviewer/GuiProfileViewer.java | 47 ++- .../notenoughupdates/profileviewer/Panorama.java | 11 + .../notenoughupdates/questing/SBInfo.java | 125 +++++++ .../questing/SBScoreboardData.java | 88 ----- .../requirements/RequirementIslandType.java | 4 +- .../notenoughupdates/util/HypixelApi.java | 14 +- .../notenoughupdates/util/SpecialColour.java | 81 ++++ 36 files changed, 2699 insertions(+), 396 deletions(-) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/DungeonBlocks.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/DungeonMap.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinEntityPlayer.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderBat.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderList.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinTileEntitySpecialRenderer.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinVboRenderList.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/SBInfo.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/SBScoreboardData.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/SpecialColour.java (limited to 'src/main/java') 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 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 duplicates = new HashSet<>(); + private static Set 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 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 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 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 missingInternal = new ArrayList<>(); + for(Map.Entry 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 talisman_upgrade_element : talisman_upgrades.entrySet()) { + JsonArray upgrades = talisman_upgrade_element.getValue().getAsJsonArray(); + for(int j=0; j 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 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= 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 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> 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 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 entry : spriteMap.entrySet()) { + TextureAtlasSprite tas = entry.getKey(); + for(int x=(int)(w2*tas.getMinU()); x> 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 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 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 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 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 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; + } + } + } +