From cfa0aa0c9a24aa739d3254b24ef4bf0bea7087a6 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 7 Jan 2021 12:57:35 +0800 Subject: PRE4 --- .../notenoughupdates/AccessoryBagOverlay.java | 824 ----------- .../notenoughupdates/AllowEmptyHTMLTag.java | 74 - .../notenoughupdates/BetterContainers.java | 458 ------ .../moulberry/notenoughupdates/BetterPortals.java | 209 --- .../notenoughupdates/CalendarOverlay.java | 1472 -------------------- .../notenoughupdates/CustomItemEffects.java | 850 ----------- .../notenoughupdates/GuiEnchantColour.java | 257 ---- .../moulberry/notenoughupdates/GuiItemRecipe.java | 241 ---- .../moulberry/notenoughupdates/GuiTextures.java | 81 -- .../github/moulberry/notenoughupdates/HelpGUI.java | 189 --- .../notenoughupdates/ItemPriceInformation.java | 205 +++ .../moulberry/notenoughupdates/ItemRarityHalo.java | 251 ---- .../notenoughupdates/NEUEventListener.java | 623 ++++----- .../moulberry/notenoughupdates/NEUManager.java | 34 +- .../moulberry/notenoughupdates/NEUOverlay.java | 253 ++-- .../notenoughupdates/NEUOverlayPlacements.java | 221 --- .../notenoughupdates/NEUResourceManager.java | 38 - .../notenoughupdates/NotEnoughUpdates.java | 143 +- .../notenoughupdates/RequestFocusListener.java | 63 - .../moulberry/notenoughupdates/SBAIntegration.java | 217 --- .../moulberry/notenoughupdates/StreamerMode.java | 40 - .../github/moulberry/notenoughupdates/SunTzu.java | 94 -- .../moulberry/notenoughupdates/TradeWindow.java | 1042 -------------- .../notenoughupdates/auction/APIManager.java | 16 +- .../notenoughupdates/auction/CustomAH.java | 54 +- .../notenoughupdates/core/BackgroundBlur.java | 181 +++ .../notenoughupdates/core/ChromaColour.java | 95 ++ .../notenoughupdates/core/GlScissorStack.java | 87 ++ .../notenoughupdates/core/GuiElement.java | 8 + .../notenoughupdates/core/GuiElementBoolean.java | 118 ++ .../notenoughupdates/core/GuiElementColour.java | 368 +++++ .../notenoughupdates/core/GuiElementTextField.java | 519 +++++++ .../core/GuiScreenElementWrapper.java | 35 + .../notenoughupdates/core/config/Config.java | 4 + .../core/config/annotations/Category.java | 15 + .../config/annotations/ConfigEditorBoolean.java | 12 + .../config/annotations/ConfigEditorColour.java | 13 + .../config/annotations/ConfigEditorDropdown.java | 16 + .../config/annotations/ConfigEditorSlider.java | 18 + .../core/config/annotations/ConfigEditorText.java | 13 + .../core/config/annotations/ConfigOption.java | 17 + .../core/config/gui/GuiOptionEditor.java | 61 + .../core/config/gui/GuiOptionEditorBoolean.java | 38 + .../core/config/gui/GuiOptionEditorColour.java | 80 ++ .../core/config/gui/GuiOptionEditorDropdown.java | 142 ++ .../core/config/gui/GuiOptionEditorSlider.java | 132 ++ .../core/config/gui/GuiOptionEditorText.java | 84 ++ .../core/config/struct/ConfigProcessor.java | 157 +++ .../core/util/GuiElementSlider.java | 124 ++ .../notenoughupdates/core/util/MiscUtils.java | 104 ++ .../notenoughupdates/core/util/Splitters.java | 10 + .../notenoughupdates/core/util/StringUtils.java | 39 + .../notenoughupdates/core/util/lerp/LerpUtils.java | 22 + .../core/util/lerp/LerpingFloat.java | 68 + .../core/util/lerp/LerpingInteger.java | 68 + .../core/util/render/RenderUtils.java | 144 ++ .../core/util/render/TextRenderUtils.java | 215 +++ .../notenoughupdates/cosmetics/CapeManager.java | 78 +- .../notenoughupdates/cosmetics/NEUCape.java | 13 +- .../notenoughupdates/dungeons/DungeonBlocks.java | 29 +- .../notenoughupdates/dungeons/DungeonMap.java | 98 +- .../notenoughupdates/dungeons/DungeonWin.java | 10 +- .../dungeons/GuiDungeonMapEditor.java | 513 +++---- .../notenoughupdates/gamemodes/GuiGamemodes.java | 2 +- .../notenoughupdates/gamemodes/SBGamemodes.java | 2 +- .../infopanes/CollectionLogInfoPane.java | 19 +- .../infopanes/FlipperInfoPane.java | 2 +- .../notenoughupdates/infopanes/HTMLInfoPane.java | 2 +- .../infopanes/ScrollableInfoPane.java | 2 +- .../infopanes/SettingsInfoPane.java | 851 ----------- .../notenoughupdates/itemeditor/NEUItemEditor.java | 2 +- .../notenoughupdates/mbgui/MBGuiGroupFloating.java | 2 +- .../miscfeatures/BetterContainers.java | 473 +++++++ .../miscfeatures/CustomItemEffects.java | 852 +++++++++++ .../miscfeatures/EnchantingSolvers.java | 542 +++++++ .../miscfeatures/ItemRarityHalo.java | 252 ++++ .../miscfeatures/StreamerMode.java | 40 + .../notenoughupdates/miscfeatures/SunTzu.java | 93 ++ .../miscgui/AccessoryBagOverlay.java | 825 +++++++++++ .../notenoughupdates/miscgui/CalendarOverlay.java | 1460 +++++++++++++++++++ .../notenoughupdates/miscgui/GuiEnchantColour.java | 249 ++++ .../notenoughupdates/miscgui/GuiItemRecipe.java | 242 ++++ .../notenoughupdates/miscgui/HelpGUI.java | 189 +++ .../miscgui/NEUOverlayPlacements.java | 219 +++ .../notenoughupdates/miscgui/TradeWindow.java | 1040 ++++++++++++++ .../notenoughupdates/mixins/MixinContainer.java | 19 + .../mixins/MixinEntityRenderer.java | 11 +- .../notenoughupdates/mixins/MixinGuiChest.java | 13 +- .../notenoughupdates/mixins/MixinGuiContainer.java | 52 +- .../notenoughupdates/mixins/MixinGuiIngame.java | 4 +- .../mixins/MixinInventoryEffectRenderer.java | 2 +- .../mixins/MixinNetHandlerPlayClient.java | 19 +- .../notenoughupdates/mixins/MixinRender.java | 2 +- .../notenoughupdates/mixins/MixinRenderFish.java | 6 +- .../notenoughupdates/mixins/MixinRenderGlobal.java | 15 +- .../notenoughupdates/mixins/MixinRenderItem.java | 31 +- .../mixins/MixinTileEntitySpecialRenderer.java | 4 +- .../notenoughupdates/mixins/MixinWorld.java | 25 + .../notenoughupdates/options/NEUConfig.java | 1234 ++++++++++++++++ .../notenoughupdates/options/NEUConfigEditor.java | 390 ++++++ .../notenoughupdates/options/Options.java | 819 ----------- .../profileviewer/GuiProfileViewer.java | 205 ++- .../profileviewer/PlayerStats.java | 132 +- .../profileviewer/ProfileViewer.java | 77 +- .../notenoughupdates/questing/GuiQuestLine.java | 27 - .../notenoughupdates/questing/QuestLine.java | 226 --- .../notenoughupdates/questing/SBInfo.java | 126 -- .../questing/requirements/Requirement.java | 29 - .../questing/requirements/RequirementApi.java | 108 -- .../questing/requirements/RequirementGuiOpen.java | 28 - .../requirements/RequirementIslandType.java | 19 - .../requirements/RequirementItemObtained.java | 29 - .../questing/requirements/RequirementLocation.java | 26 - .../requirements/RequirementLocationRect.java | 34 - .../notenoughupdates/util/AllowEmptyHTMLTag.java | 74 + .../notenoughupdates/util/GuiTextures.java | 103 ++ .../notenoughupdates/util/LerpingInteger.java | 68 - .../notenoughupdates/util/NEUResourceManager.java | 38 + .../util/RequestFocusListener.java | 63 + .../notenoughupdates/util/SBAIntegration.java | 217 +++ .../moulberry/notenoughupdates/util/SBInfo.java | 125 ++ .../moulberry/notenoughupdates/util/Utils.java | 51 +- .../assets/notenoughupdates/capes/furf.png | Bin 0 -> 10380 bytes .../assets/notenoughupdates/capes/lightning.png | Bin 6490 -> 0 bytes .../assets/notenoughupdates/capes/void.png | Bin 0 -> 41607 bytes .../resources/assets/notenoughupdates/core/bar.png | Bin 0 -> 2095 bytes .../notenoughupdates/core/colour_selector_bar.png | Bin 0 -> 245 bytes .../core/colour_selector_bar_alpha.png | Bin 0 -> 240 bytes .../core/colour_selector_chroma.png | Bin 0 -> 211 bytes .../notenoughupdates/core/colour_selector_dot.png | Bin 0 -> 3677 bytes .../core/slider/slider_off_cap.png | Bin 0 -> 595 bytes .../core/slider/slider_off_notch.png | Bin 0 -> 555 bytes .../core/slider/slider_off_segment.png | Bin 0 -> 575 bytes .../notenoughupdates/core/slider/slider_on_cap.png | Bin 0 -> 603 bytes .../core/slider/slider_on_notch.png | Bin 0 -> 555 bytes .../core/slider/slider_on_segment.png | Bin 0 -> 575 bytes .../assets/notenoughupdates/core/toggle_1.png | Bin 0 -> 592 bytes .../assets/notenoughupdates/core/toggle_2.png | Bin 0 -> 590 bytes .../assets/notenoughupdates/core/toggle_3.png | Bin 0 -> 592 bytes .../assets/notenoughupdates/core/toggle_off.png | Bin 0 -> 594 bytes .../assets/notenoughupdates/core/toggle_on.png | Bin 0 -> 593 bytes .../assets/notenoughupdates/shaders/void.frag | 41 + .../assets/notenoughupdates/shaders/void.vert | 16 + .../assets/notenoughupdates/social/discord.png | Bin 0 -> 6690 bytes .../assets/notenoughupdates/social/github.png | Bin 0 -> 11716 bytes .../assets/notenoughupdates/social/patreon.png | Bin 0 -> 3696 bytes .../assets/notenoughupdates/social/twitter.png | Bin 0 -> 5816 bytes .../assets/notenoughupdates/social/youtube.png | Bin 0 -> 348 bytes src/main/resources/mixins.notenoughupdates.json | 4 +- 149 files changed, 13161 insertions(+), 10408 deletions(-) delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/AccessoryBagOverlay.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/AllowEmptyHTMLTag.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/BetterContainers.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/BetterPortals.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/CalendarOverlay.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/CustomItemEffects.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/GuiEnchantColour.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/HelpGUI.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/ItemRarityHalo.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/NEUOverlayPlacements.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/NEUResourceManager.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/RequestFocusListener.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/SBAIntegration.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/StreamerMode.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/SunTzu.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/TradeWindow.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/BackgroundBlur.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/ChromaColour.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/GlScissorStack.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/GuiElement.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementBoolean.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementColour.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementTextField.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/GuiScreenElementWrapper.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/config/Config.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/Category.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigEditorBoolean.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigEditorColour.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigEditorDropdown.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigEditorSlider.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigEditorText.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigOption.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditor.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorBoolean.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorColour.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorDropdown.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorSlider.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorText.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/ConfigProcessor.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/util/GuiElementSlider.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/util/MiscUtils.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/util/Splitters.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/util/lerp/LerpUtils.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/util/lerp/LerpingFloat.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/util/lerp/LerpingInteger.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/util/render/RenderUtils.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/core/util/render/TextRenderUtils.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/infopanes/SettingsInfoPane.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BetterContainers.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomItemEffects.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemRarityHalo.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/StreamerMode.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SunTzu.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/AccessoryBagOverlay.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiEnchantColour.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/HelpGUI.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/NEUOverlayPlacements.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinContainer.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinWorld.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfigEditor.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/options/Options.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/GuiQuestLine.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/QuestLine.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/SBInfo.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/Requirement.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/RequirementApi.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/RequirementGuiOpen.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/RequirementIslandType.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/RequirementItemObtained.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/RequirementLocation.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/questing/requirements/RequirementLocationRect.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/AllowEmptyHTMLTag.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/GuiTextures.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/LerpingInteger.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/NEUResourceManager.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/RequestFocusListener.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/SBAIntegration.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java create mode 100644 src/main/resources/assets/notenoughupdates/capes/furf.png delete mode 100644 src/main/resources/assets/notenoughupdates/capes/lightning.png create mode 100644 src/main/resources/assets/notenoughupdates/capes/void.png create mode 100644 src/main/resources/assets/notenoughupdates/core/bar.png create mode 100644 src/main/resources/assets/notenoughupdates/core/colour_selector_bar.png create mode 100644 src/main/resources/assets/notenoughupdates/core/colour_selector_bar_alpha.png create mode 100644 src/main/resources/assets/notenoughupdates/core/colour_selector_chroma.png create mode 100644 src/main/resources/assets/notenoughupdates/core/colour_selector_dot.png create mode 100644 src/main/resources/assets/notenoughupdates/core/slider/slider_off_cap.png create mode 100644 src/main/resources/assets/notenoughupdates/core/slider/slider_off_notch.png create mode 100644 src/main/resources/assets/notenoughupdates/core/slider/slider_off_segment.png create mode 100644 src/main/resources/assets/notenoughupdates/core/slider/slider_on_cap.png create mode 100644 src/main/resources/assets/notenoughupdates/core/slider/slider_on_notch.png create mode 100644 src/main/resources/assets/notenoughupdates/core/slider/slider_on_segment.png create mode 100644 src/main/resources/assets/notenoughupdates/core/toggle_1.png create mode 100644 src/main/resources/assets/notenoughupdates/core/toggle_2.png create mode 100644 src/main/resources/assets/notenoughupdates/core/toggle_3.png create mode 100644 src/main/resources/assets/notenoughupdates/core/toggle_off.png create mode 100644 src/main/resources/assets/notenoughupdates/core/toggle_on.png create mode 100644 src/main/resources/assets/notenoughupdates/shaders/void.frag create mode 100644 src/main/resources/assets/notenoughupdates/shaders/void.vert create mode 100644 src/main/resources/assets/notenoughupdates/social/discord.png create mode 100644 src/main/resources/assets/notenoughupdates/social/github.png create mode 100644 src/main/resources/assets/notenoughupdates/social/patreon.png create mode 100644 src/main/resources/assets/notenoughupdates/social/twitter.png create mode 100644 src/main/resources/assets/notenoughupdates/social/youtube.png diff --git a/src/main/java/io/github/moulberry/notenoughupdates/AccessoryBagOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/AccessoryBagOverlay.java deleted file mode 100644 index 5ca25082..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/AccessoryBagOverlay.java +++ /dev/null @@ -1,824 +0,0 @@ -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.Constants; -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; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.inventory.ContainerChest; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.util.EnumChatFormatting; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL14; - -import java.awt.*; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.*; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import static io.github.moulberry.notenoughupdates.GuiTextures.*; - -public class AccessoryBagOverlay { - - private static final int TAB_BASIC = 0; - private static final int TAB_TOTAL = 1; - 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", - 10, EnumChatFormatting.GREEN+"- Talis count by rarity"), - Utils.createItemStack(Items.diamond_sword, EnumChatFormatting.DARK_AQUA+"Total Stat Bonuses", - 0), - Utils.createItemStack(Item.getItemFromBlock(Blocks.anvil), EnumChatFormatting.DARK_AQUA+"Total Stat Bonuses (from reforges)", - 0), - Utils.createItemStack(Items.dye, EnumChatFormatting.DARK_AQUA+"Duplicates", - 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; - - public static boolean mouseClick() { - 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")) { - return false; - } - } else { - return false; - } - - if(!Mouse.getEventButtonState()) return false; - try { - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - - int width = scaledResolution.getScaledWidth(); - int height = scaledResolution.getScaledHeight(); - - int mouseX = Mouse.getX() / scaledResolution.getScaleFactor(); - int mouseY = height - Mouse.getY() / scaledResolution.getScaleFactor(); - - int xSize = (int) Utils.getField(GuiContainer.class, Minecraft.getMinecraft().currentScreen, "xSize", "field_146999_f"); - int ySize = (int) Utils.getField(GuiContainer.class, Minecraft.getMinecraft().currentScreen, "ySize", "field_147000_g"); - int guiLeft = (int) Utils.getField(GuiContainer.class, Minecraft.getMinecraft().currentScreen, "guiLeft", "field_147003_i"); - int guiTop = (int) Utils.getField(GuiContainer.class, Minecraft.getMinecraft().currentScreen, "guiTop", "field_147009_r"); - - if(mouseX < guiLeft+xSize+3 || mouseX > guiLeft+xSize+80+28) return false; - if(mouseY < guiTop || mouseY > guiTop+166) return false; - - if(mouseX > guiLeft+xSize+83 && mouseY < guiTop+20*TAB_MISSING+22) { - currentTab = (mouseY - guiTop)/20; - if(currentTab < 0) currentTab = 0; - 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; - } - } - - public static void resetCache() { - accessoryStacks = new HashSet<>(); - pagesVisited = new HashSet<>(); - talismanCountRarity = null; - totalStats = null; - reforgeStats = null; - duplicates = null; - missing = null; - } - - private static Set accessoryStacks = new HashSet<>(); - private static Set pagesVisited = new HashSet<>(); - - public static void renderVisitOverlay(int x, int y) { - Utils.drawStringCenteredScaledMaxWidth("Please visit all", Minecraft.getMinecraft().fontRendererObj, x+40, y+78, true, 70, -1); - Utils.drawStringCenteredScaledMaxWidth("pages of the bag", Minecraft.getMinecraft().fontRendererObj, x+40, y+86, true, 70, -1); - } - - private static TreeMap talismanCountRarity = null; - public static void renderBasicOverlay(int x, int y) { - if(talismanCountRarity == null) { - talismanCountRarity = new TreeMap<>(); - for(ItemStack stack : accessoryStacks) { - int rarity = getRarity(stack); - if(rarity >= 0) { - talismanCountRarity.put(rarity, talismanCountRarity.getOrDefault(rarity, 0)+1); - } - } - } - - Utils.drawStringCenteredScaledMaxWidth("# By Rarity", Minecraft.getMinecraft().fontRendererObj, x+40, y+12, false, 70, - new Color(80, 80, 80).getRGB()); - - int yIndex = 0; - for(Map.Entry entry : talismanCountRarity.descendingMap().entrySet()) { - String rarityName = rarityArrC[entry.getKey()]; - renderAlignedString(rarityName, EnumChatFormatting.WHITE.toString()+entry.getValue(), x+5, y+20+11*yIndex, 70); - yIndex++; - } - } - - - private static PlayerStats.Stats totalStats = null; - public static void renderTotalStatsOverlay(int x, int y) { - if(totalStats == null) { - totalStats = new PlayerStats.Stats(); - for(ItemStack stack : accessoryStacks) { - if(stack != null) totalStats.add(getStatForItem(stack, STAT_PATTERN_MAP, true)); - } - } - - 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 = null; - public static void renderDuplicatesOverlay(int x, int y) { - if(duplicates == null) { - JsonObject misc = Constants.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 = Constants.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() { - 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")) { - try { - int xSize = (int) Utils.getField(GuiContainer.class, eventGui, "xSize", "field_146999_f"); - int ySize = (int) Utils.getField(GuiContainer.class, eventGui, "ySize", "field_147000_g"); - int guiLeft = (int) Utils.getField(GuiContainer.class, eventGui, "guiLeft", "field_147003_i"); - int guiTop = (int) Utils.getField(GuiContainer.class, eventGui, "guiTop", "field_147009_r"); - - if(accessoryStacks.isEmpty()) { - for(ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { - if(stack != null && isAccessory(stack)) { - accessoryStacks.add(stack); - } - } - } - - if(containerName.trim().contains("(")) { - String first = containerName.trim().split("\\(")[1].split("/")[0]; - Integer currentPageNumber = Integer.parseInt(first); - //System.out.println("current:"+currentPageNumber); - if(!pagesVisited.contains(currentPageNumber)) { - boolean hasStack = false; - if(Minecraft.getMinecraft().thePlayer.openContainer instanceof ContainerChest) { - IInventory inv = ((ContainerChest)Minecraft.getMinecraft().thePlayer.openContainer).getLowerChestInventory(); - for(int i=0; i pagesVisited.size()) { - Minecraft.getMinecraft().getTextureManager().bindTexture(accessory_bag_overlay); - Utils.drawTexturedRect(guiLeft+xSize+3, guiTop, 80, 149, 0, 80/256f, 0, 149/256f, GL11.GL_NEAREST); - - renderVisitOverlay(guiLeft+xSize+3, guiTop); - return; - } - } else if(pagesVisited.isEmpty()) { - boolean hasStack = false; - if(Minecraft.getMinecraft().thePlayer.openContainer instanceof ContainerChest) { - IInventory inv = ((ContainerChest)Minecraft.getMinecraft().thePlayer.openContainer).getLowerChestInventory(); - for(int i=0; i= length) { - for(int xOff=-2; xOff<=2; xOff++) { - for(int yOff=-2; yOff<=2; yOff++) { - if(Math.abs(xOff) != Math.abs(yOff)) { - Utils.drawStringCenteredScaledMaxWidth(Utils.cleanColourNotModifiers(first + " " + second), Minecraft.getMinecraft().fontRendererObj, - x+length/2f+xOff/2f, y+4+yOff/2f, false, length, - new Color(0, 0, 0, 200/Math.max(Math.abs(xOff), Math.abs(yOff))).getRGB()); - } - } - } - - GlStateManager.color(1, 1, 1, 1); - Utils.drawStringCenteredScaledMaxWidth(first + " " + second, Minecraft.getMinecraft().fontRendererObj, - x+length/2f, y+4, false, length, 4210752); - } else { - for(int xOff=-2; xOff<=2; xOff++) { - for(int yOff=-2; yOff<=2; yOff++) { - if(Math.abs(xOff) != Math.abs(yOff)) { - fontRendererObj.drawString(Utils.cleanColourNotModifiers(first), - x+xOff/2f, y+yOff/2f, - new Color(0, 0, 0, 200/Math.max(Math.abs(xOff), Math.abs(yOff))).getRGB(), false); - } - } - } - - int secondLen = fontRendererObj.getStringWidth(second); - GlStateManager.color(1, 1, 1, 1); - fontRendererObj.drawString(first, x, y, 4210752, false); - for(int xOff=-2; xOff<=2; xOff++) { - for(int yOff=-2; yOff<=2; yOff++) { - if(Math.abs(xOff) != Math.abs(yOff)) { - fontRendererObj.drawString(Utils.cleanColourNotModifiers(second), - x+length-secondLen+xOff/2f, y+yOff/2f, - new Color(0, 0, 0, 200/Math.max(Math.abs(xOff), Math.abs(yOff))).getRGB(), false); - } - } - } - - GlStateManager.color(1, 1, 1, 1); - fontRendererObj.drawString(second, x+length-secondLen, y, 4210752, false); - } - } - - private static final Pattern HEALTH_PATTERN_BONUS = Pattern.compile("^Health: (?:\\+|-)[0-9]+ HP \\([a-zA-Z]+ ((?:\\+|-)[0-9]+)"); - private static final Pattern DEFENCE_PATTERN_BONUS = Pattern.compile("^Defense: (?:\\+|-)[0-9]+ \\([a-zA-Z]+ ((?:\\+|-)[0-9]+)"); - private static final Pattern STRENGTH_PATTERN_BONUS = Pattern.compile("^Strength: (?:\\+|-)[0-9]+ \\([a-zA-Z]+ ((?:\\+|-)[0-9]+)"); - private static final Pattern SPEED_PATTERN_BONUS = Pattern.compile("^Speed: (?:\\+|-)[0-9]+ \\([a-zA-Z]+ ((?:\\+|-)[0-9]+)"); - private static final Pattern CC_PATTERN_BONUS = Pattern.compile("^Crit Chance: (?:\\+|-)[0-9]+% \\([a-zA-Z]+ ((?:\\+|-)[0-9]+)"); - private static final Pattern CD_PATTERN_BONUS = Pattern.compile("^Crit Damage: (?:\\+|-)[0-9]+% \\([a-zA-Z]+ ((?:\\+|-)[0-9]+)"); - private static final Pattern ATKSPEED_PATTERN_BONUS = Pattern.compile("^Bonus Attack Speed: (?:\\+|-)[0-9]+% \\([a-zA-Z]+ ((?:\\+|-)[0-9]+)"); - private static final Pattern INTELLIGENCE_PATTERN_BONUS = Pattern.compile("^Intelligence: (?:\\+|-)[0-9]+ \\([a-zA-Z]+ ((?:\\+|-)[0-9]+)"); - private static final Pattern SCC_PATTERN_BONUS = Pattern.compile("^Sea Creature Chance: (?:\\+|-)[0-9]+ \\([a-zA-Z]+ ((?:\\+|-)[0-9]+)"); - private static final HashMap STAT_PATTERN_MAP_BONUS = new HashMap<>(); - static { - STAT_PATTERN_MAP_BONUS.put("health", HEALTH_PATTERN_BONUS); - STAT_PATTERN_MAP_BONUS.put("defence", DEFENCE_PATTERN_BONUS); - STAT_PATTERN_MAP_BONUS.put("strength", STRENGTH_PATTERN_BONUS); - STAT_PATTERN_MAP_BONUS.put("speed", SPEED_PATTERN_BONUS); - STAT_PATTERN_MAP_BONUS.put("crit_chance", CC_PATTERN_BONUS); - STAT_PATTERN_MAP_BONUS.put("crit_damage", CD_PATTERN_BONUS); - STAT_PATTERN_MAP_BONUS.put("bonus_attack_speed", ATKSPEED_PATTERN_BONUS); - STAT_PATTERN_MAP_BONUS.put("intelligence", INTELLIGENCE_PATTERN_BONUS); - STAT_PATTERN_MAP_BONUS.put("sea_creature_chance", SCC_PATTERN_BONUS); - } - - private static final Pattern HEALTH_PATTERN = Pattern.compile("^Health: ((?:\\+|-)[0-9]+)"); - private static final Pattern DEFENCE_PATTERN = Pattern.compile("^Defense: ((?:\\+|-)[0-9]+)"); - private static final Pattern STRENGTH_PATTERN = Pattern.compile("^Strength: ((?:\\+|-)[0-9]+)"); - private static final Pattern SPEED_PATTERN = Pattern.compile("^Speed: ((?:\\+|-)[0-9]+)"); - private static final Pattern CC_PATTERN = Pattern.compile("^Crit Chance: ((?:\\+|-)[0-9]+)"); - private static final Pattern CD_PATTERN = Pattern.compile("^Crit Damage: ((?:\\+|-)[0-9]+)"); - private static final Pattern ATKSPEED_PATTERN = Pattern.compile("^Bonus Attack Speed: ((?:\\+|-)[0-9]+)"); - private static final Pattern INTELLIGENCE_PATTERN = Pattern.compile("^Intelligence: ((?:\\+|-)[0-9]+)"); - private static final Pattern SCC_PATTERN = Pattern.compile("^Sea Creature Chance: ((?:\\+|-)[0-9]+)"); - private static final HashMap STAT_PATTERN_MAP = new HashMap<>(); - static { - STAT_PATTERN_MAP.put("health", HEALTH_PATTERN); - STAT_PATTERN_MAP.put("defence", DEFENCE_PATTERN); - STAT_PATTERN_MAP.put("strength", STRENGTH_PATTERN); - STAT_PATTERN_MAP.put("speed", SPEED_PATTERN); - STAT_PATTERN_MAP.put("crit_chance", CC_PATTERN); - STAT_PATTERN_MAP.put("crit_damage", CD_PATTERN); - STAT_PATTERN_MAP.put("bonus_attack_speed", ATKSPEED_PATTERN); - STAT_PATTERN_MAP.put("intelligence", INTELLIGENCE_PATTERN); - STAT_PATTERN_MAP.put("sea_creature_chance", SCC_PATTERN); - } - private static PlayerStats.Stats getStatForItem(ItemStack stack, HashMap patternMap, boolean addExtras) { - String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); - NBTTagCompound tag = stack.getTagCompound(); - PlayerStats.Stats stats = new PlayerStats.Stats(); - - if(internalname == null) { - return stats; - } - - if(tag != null) { - NBTTagCompound display = tag.getCompoundTag("display"); - if (display.hasKey("Lore", 9)) { - NBTTagList list = display.getTagList("Lore", 8); - for (int i = 0; i < list.tagCount(); i++) { - String line = list.getStringTagAt(i); - for(Map.Entry entry : patternMap.entrySet()) { - Matcher matcher = entry.getValue().matcher(Utils.cleanColour(line)); - if(matcher.find()) { - int bonus = Integer.parseInt(matcher.group(1)); - stats.addStat(entry.getKey(), bonus); - } - } - } - } - } - - if(!addExtras) return stats; - - if(internalname.equals("DAY_CRYSTAL") || internalname.equals("NIGHT_CRYSTAL")) { - stats.addStat(PlayerStats.STRENGTH, 2.5f); - stats.addStat(PlayerStats.DEFENCE, 2.5f); - } - - if(internalname.equals("NEW_YEAR_CAKE_BAG") && tag != null && tag.hasKey("ExtraAttributes", 10)) { - NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); - - byte[] bytes = null; - for (String key : ea.getKeySet()) { - if (key.endsWith("backpack_data") || key.equals("new_year_cake_bag_data")) { - bytes = ea.getByteArray(key); - try { - NBTTagCompound contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(bytes)); - NBTTagList items = contents_nbt.getTagList("i", 10); - HashSet cakes = new HashSet<>(); - for(int j=0; j 0) { - NBTTagCompound nbt = items.getCompoundTagAt(j).getCompoundTag("tag"); - if(nbt != null && nbt.hasKey("ExtraAttributes", 10)) { - NBTTagCompound ea2 = nbt.getCompoundTag("ExtraAttributes"); - if (ea2.hasKey("new_years_cake")) { - cakes.add(ea2.getInteger("new_years_cake")); - } - } - } - } - stats.addStat(PlayerStats.HEALTH, cakes.size()); - } catch(IOException e) { - e.printStackTrace(); - return stats; - } - break; - } - } - } - return stats; - } - - private static String[] rarityArr = new String[] { - "COMMON", "UNCOMMON", "RARE", "EPIC", "LEGENDARY", "MYTHIC", "SPECIAL", "VERY SPECIAL", - }; - private static String[] rarityArrC = new String[] { - EnumChatFormatting.WHITE+EnumChatFormatting.BOLD.toString()+"COMMON", - EnumChatFormatting.GREEN+EnumChatFormatting.BOLD.toString()+"UNCOMMON", - EnumChatFormatting.BLUE+EnumChatFormatting.BOLD.toString()+"RARE", - EnumChatFormatting.DARK_PURPLE+EnumChatFormatting.BOLD.toString()+"EPIC", - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD.toString()+"LEGENDARY", - EnumChatFormatting.LIGHT_PURPLE+EnumChatFormatting.BOLD.toString()+"MYTHIC", - EnumChatFormatting.RED+EnumChatFormatting.BOLD.toString()+"SPECIAL", - EnumChatFormatting.RED+EnumChatFormatting.BOLD.toString()+"VERY SPECIAL", - EnumChatFormatting.DARK_RED+EnumChatFormatting.BOLD.toString()+"SUPREME", - }; - public static int checkItemType(ItemStack stack, boolean contains, String... typeMatches) { - NBTTagCompound tag = stack.getTagCompound(); - if(tag != null) { - NBTTagCompound display = tag.getCompoundTag("display"); - if (display.hasKey("Lore", 9)) { - NBTTagList list = display.getTagList("Lore", 8); - for (int i = list.tagCount()-1; i >= 0; i--) { - String line = list.getStringTagAt(i); - for(String rarity : rarityArr) { - for(int j=0; j=0; i--) { - String line = lore.get(i).getAsString(); - - for(String rarity : rarityArr) { - for(int j=0; j= 0; - } - - public static int getRarity(ItemStack stack) { - NBTTagCompound tag = stack.getTagCompound(); - if(tag != null) { - NBTTagCompound display = tag.getCompoundTag("display"); - if (display.hasKey("Lore", 9)) { - NBTTagList list = display.getTagList("Lore", 8); - for (int i = list.tagCount(); i >= 0; i--) { - String line = list.getStringTagAt(i); - for(int j=0; j children = node.getChildren(); - - if (NEW_LINES) { - switch (name) { - case "div": - case "p": - case "li": - case "td": - buf.append('\n'); - break; - case "table": - case "ul": - case "ol": - case "th": - case "tr": - buf.append('\n'); - newLinesAfterTag = true; - newLinesAfterChildren = true; - break; - case "pre": - buf.append('\n'); - newLinesAfterTag = false; - newLinesAfterChildren = true; - break; - case "blockquote": - newLinesAfterChildren = true; - break; - } - } - buf.append('<'); - buf.append(name); - - Map tagAtttributes = node.getAttributes(); - - appendAttributes(buf, tagAtttributes); - - if (children.size() == 0) { - buf.append(" />"); - } else { - buf.append('>'); - if (newLinesAfterTag) { - buf.append('\n'); - } - converter.nodesToText(children, buf, model); - if (newLinesAfterChildren) { - buf.append('\n'); - } - buf.append("'); - } - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/BetterContainers.java b/src/main/java/io/github/moulberry/notenoughupdates/BetterContainers.java deleted file mode 100644 index 02ff2164..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/BetterContainers.java +++ /dev/null @@ -1,458 +0,0 @@ -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; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.gui.inventory.GuiChest; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.texture.DynamicTexture; -import net.minecraft.client.renderer.texture.TextureManager; -import net.minecraft.init.Blocks; -import net.minecraft.inventory.Container; -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 org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL14; - -import javax.imageio.ImageIO; -import java.awt.*; -import java.awt.image.BufferedImage; -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -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; - private static long clickedSlotMillis = 0; - public static long lastRenderMillis = 0; - - public static HashMap itemCache = new HashMap<>(); - public static boolean lastUsingCached = false; - public static boolean usingCached = false; - - public static void clickSlot(int slot) { - clickedSlotMillis = System.currentTimeMillis(); - clickedSlot = slot; - } - - public static int getClickedSlot() { - if(System.currentTimeMillis() - clickedSlotMillis < 500) { - return clickedSlot; - } - return -1; - } - - public static void bindHook(TextureManager textureManager, ResourceLocation location) { - if(isChestOpen()) { - Container container = ((GuiChest)Minecraft.getMinecraft().currentScreen).inventorySlots; - if(container instanceof ContainerChest) { - usingCached = true; - IInventory lower = ((ContainerChest)container).getLowerChestInventory(); - int size = lower.getSizeInventory(); - for(int index=0; index 0 && buttons[xi][yi-1]; - boolean right = xi < buttons.length-1 && buttons[xi+1][yi]; - boolean down = yi < buttons[xi].length-1 && buttons[xi][yi+1]; - boolean left = xi > 0 && buttons[xi-1][yi]; - - boolean upleft = yi > 0 && xi > 0 && buttons[xi-1][yi-1]; - boolean upright = yi > 0 && xi < buttons.length-1 && buttons[xi+1][yi-1]; - boolean downright = xi < buttons.length-1 && yi < buttons[xi+1].length-1 && buttons[xi+1][yi+1]; - boolean downleft = xi > 0 && yi < buttons[xi-1].length-1 && buttons[xi-1][yi+1]; - - int ctmIndex = getCTMIndex(up, right, down, left, upleft, upright, downright, downleft); - 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]; - boolean down = yi < slots[xi].length-1 && slots[xi][yi+1]; - boolean left = xi > 0 && slots[xi-1][yi]; - - boolean upleft = yi > 0 && xi > 0 && slots[xi-1][yi-1]; - boolean upright = yi > 0 && xi < slots.length-1 && slots[xi+1][yi-1]; - boolean downright = xi < slots.length-1 && yi < slots[xi+1].length-1 && slots[xi+1][yi+1]; - boolean downleft = xi > 0 && yi < slots[xi-1].length-1 && slots[xi-1][yi+1]; - - int ctmIndex = getCTMIndex(up, right, down, left, upleft, upright, downright, downleft); - int[] rgbs = bufferedImageSlot.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); - } - } - } - texture = new DynamicTexture(bufferedImageNew); - } catch(Exception e) { - e.printStackTrace(); - } - } - } - - public static void reset() { - texture = null; - loaded = false; - clickedSlot = -1; - clickedSlotMillis = 0; - textColour = 4210752; - } - - private static boolean isChestOpen() { - return Minecraft.getMinecraft().currentScreen instanceof GuiChest && - NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() && - (NotEnoughUpdates.INSTANCE.manager.config.dynamicMenuBackgroundStyle.value >= 1 && - NotEnoughUpdates.INSTANCE.manager.config.dynamicMenuButtonStyle.value >= 1); - } - - private static boolean hasItem() { - if(!isChestOpen()) return false; - Container container = ((GuiChest)Minecraft.getMinecraft().currentScreen).inventorySlots; - if(container instanceof ContainerChest) { - IInventory lower = ((ContainerChest)container).getLowerChestInventory(); - int size = lower.getSizeInventory(); - for(int index=0; index loadedPortals = new HashSet<>(); - private HashMap portalNameMap = new HashMap<>(); - - @SubscribeEvent - public void onWorldChange(WorldEvent.Load event) { - portalNameMap.clear(); - loadedPortals.clear(); - } - - /** The current GL viewport */ - private static final IntBuffer VIEWPORT = GLAllocation.createDirectIntBuffer(16); - /** The current GL modelview matrix */ - private static final FloatBuffer MODELVIEW = GLAllocation.createDirectFloatBuffer(16); - /** The current GL projection matrix */ - private static final FloatBuffer PROJECTION = GLAllocation.createDirectFloatBuffer(16); - private static final FloatBuffer WINCOORDS = GLAllocation.createDirectFloatBuffer(3); - - private float getFOVModifier(float partialTicks) { - Entity entity = Minecraft.getMinecraft().getRenderViewEntity(); - - float f = Minecraft.getMinecraft().gameSettings.fovSetting; - //f = f * (this.fovModifierHandPrev + (this.fovModifierHand - this.fovModifierHandPrev) * partialTicks); - - if (entity instanceof EntityLivingBase && ((EntityLivingBase)entity).getHealth() <= 0.0F) { - float f1 = (float)((EntityLivingBase)entity).deathTime + partialTicks; - f /= (1.0F - 500.0F / (f1 + 500.0F)) * 2.0F + 1.0F; - } - - Block block = ActiveRenderInfo.getBlockAtEntityViewpoint(Minecraft.getMinecraft().theWorld, entity, partialTicks); - - if (block.getMaterial() == Material.water) { - f = f * 60.0F / 70.0F; - } - - return net.minecraftforge.client.ForgeHooksClient.getFOVModifier(Minecraft.getMinecraft().entityRenderer, entity, block, partialTicks, f); - } - - TexLoc tl = new TexLoc(0, 1, Keyboard.KEY_M); - - @SubscribeEvent - public void renderWorld(RenderGameOverlayEvent event) { - - GlStateManager.getFloat(2982, MODELVIEW); - GlStateManager.getFloat(2983, PROJECTION); - GL11.glGetInteger(GL11.GL_VIEWPORT, VIEWPORT); - - EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; - GlStateManager.disableCull(); - - tl.handleKeyboardInput(); - - WINCOORDS.flip().limit(3); - - /*float objx = -(float)(0-player.posX); - float objy = (float)(100-player.posY-player.eyeHeight); - float objz = (float)(0-player.posZ);*/ - - float dX = -(float)(0-player.posX); - float dY = (float)(100-player.posY-player.eyeHeight); - float dZ = (float)(0-player.posZ); - - //GLU.gluProject(objx, objy, objz, MODELVIEW, PROJECTION, VIEWPORT, WINCOORDS); - - double x = dX*Math.cos(Math.toRadians(player.rotationYawHead))-dZ*Math.sin(Math.toRadians(player.rotationYawHead)); - double z = dX*Math.sin(Math.toRadians(player.rotationYawHead))+dZ*Math.cos(Math.toRadians(player.rotationYawHead)); - - float fov = getFOVModifier(event.partialTicks); - x = x / z * Math.toRadians(fov); - dY = (float)(dY / z * Math.toRadians(fov)); - - //System.out.println(z); - - //GLU.gluProject((float)x, dY, (float)z, MODELVIEW, PROJECTION, VIEWPORT, WINCOORDS); - //x = x / z * 2; - //dY = (float)(dY / z * 2); - - GL11.glEnable(GL11.GL_SCISSOR_TEST); - - GL11.glScissor((int)(x*Minecraft.getMinecraft().displayWidth*tl.x/tl.y)+Minecraft.getMinecraft().displayWidth/2, - (int)(dY+Minecraft.getMinecraft().displayHeight/2), 2, 2); - - drawRect(0, 0, 2000, 2000, -1); - - GL11.glDisable(GL11.GL_SCISSOR_TEST); - - /*for(BlockPos pos : portalNameMap.keySet()) { - WINCOORDS.flip().limit(3); - - /*float objx = -(float)((pos.getX()-player.posX)*Math.cos(Math.toRadians(player.rotationYawHead))*Math.cos(Math.toRadians(player.rotationPitch))); - float objy = (float)((pos.getY()-player.posY)*Math.sin(Math.toRadians(player.rotationPitch))); - float objz = (float)((pos.getZ()-player.posZ)*Math.sin(Math.toRadians(player.rotationYawHead))); - - float objx = -(float)(pos.getX()-player.posX); - float objy = (float)(pos.getY()-player.posY-player.eyeHeight); - float objz = (float)(pos.getZ()-player.posZ); - - GLU.gluProject(objx, objy, objz, MODELVIEW, PROJECTION, VIEWPORT, WINCOORDS); - //GLU.glu - - GL11.glEnable(GL11.GL_SCISSOR_TEST); - - //System.out.println(WINCOORDS.get(1)); - - GL11.glScissor((int)WINCOORDS.get(0)*2, - Minecraft.getMinecraft().displayHeight-(int)WINCOORDS.get(1), (int)50, (int)50); - - //0-1 - //-1 - 1 - //0-1920 - - drawRect(0, 0, 2000, 2000, -1); - - GL11.glDisable(GL11.GL_SCISSOR_TEST); - }*/ - - GlStateManager.enableCull(); - } - - @SubscribeEvent - public void tick(TickEvent.ClientTickEvent event) { - if(event.phase != TickEvent.Phase.END) { - return; - } - if(Minecraft.getMinecraft().theWorld != null) { - List travelToPositions = new ArrayList<>(); - for(Entity entity : Minecraft.getMinecraft().theWorld.loadedEntityList) { - if(entity instanceof EntityArmorStand) { - EntityArmorStand armorStand = (EntityArmorStand) entity; - if(armorStand.isInvisible() && armorStand.hasCustomName()) { - String customName = armorStand.getCustomNameTag(); - if(customName.equals(EnumChatFormatting.AQUA+"Travel to:")) { - travelToPositions.add(new Vector3f((float)armorStand.posX, (float)armorStand.posY, (float)armorStand.posZ)); - } - } - } - } - travelToPositions.removeAll(loadedPortals); - for(Entity entity : Minecraft.getMinecraft().theWorld.loadedEntityList) { - if(entity instanceof EntityArmorStand) { - EntityArmorStand armorStand = (EntityArmorStand) entity; - if(armorStand.isInvisible() && armorStand.hasCustomName()) { - String customName = armorStand.getCustomNameTag(); - for(Vector3f position : travelToPositions) { - if(position.x == (float)armorStand.posX && position.y-0.375 == (float)armorStand.posY && position.z == (float)armorStand.posZ) { - float smallestDist = 999; - BlockPos closestPortal = null; - for(int xOff=-3; xOff<=3; xOff++) { - for(int zOff=-3; zOff<=3; zOff++) { - if(xOff != 0 && zOff != 0) continue; - BlockPos pos = new BlockPos(armorStand.posX+xOff, armorStand.posY+2, armorStand.posZ+zOff); - if(Minecraft.getMinecraft().theWorld.getBlockState(pos).getBlock() == Blocks.portal) { - float dist = (float)(armorStand.posX-(pos.getX()+0.5) + armorStand.posZ-(pos.getZ()+0.5)); - if(closestPortal == null || dist < smallestDist) { - smallestDist = dist; - closestPortal = pos; - } - } - } - } - if(closestPortal != null) { - portalNameMap.put(closestPortal, customName); - } - } - } - } - } - } - loadedPortals.addAll(travelToPositions); - } - } - - public void tryRegisterPortal() { - - } - -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/CalendarOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/CalendarOverlay.java deleted file mode 100644 index ccfe4a65..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/CalendarOverlay.java +++ /dev/null @@ -1,1472 +0,0 @@ -package io.github.moulberry.notenoughupdates; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.audio.PositionedSoundRecord; -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; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.client.shader.Framebuffer; -import net.minecraft.client.shader.Shader; -import net.minecraft.init.Items; -import net.minecraft.inventory.ContainerChest; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.Matrix4f; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.ClientCommandHandler; -import net.minecraftforge.client.event.GuiScreenEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.client.event.sound.SoundEvent; -import net.minecraftforge.fml.common.eventhandler.EventPriority; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent; -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL14; - -import static io.github.moulberry.notenoughupdates.GuiTextures.*; - -import java.io.File; -import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class CalendarOverlay { - - private static final ResourceLocation BACKGROUND = new ResourceLocation("notenoughupdates:calendar/background.png"); - private static final ResourceLocation DISPLAYBAR = new ResourceLocation("notenoughupdates:calendar/displaybar.png"); - private static final ResourceLocation TOAST = new ResourceLocation("notenoughupdates:calendar/toast.png"); - - private static JsonObject farmingEventTypes = null; - - private static boolean enabled = false; - - public static void setEnabled(boolean enabled) { - CalendarOverlay.enabled = enabled; - } - - public static boolean isEnabled() { - return enabled; - } - - private int guiLeft = -1; - private int guiTop = -1; - private int xSize = 168; - private int ySize = 170; - - private class SBEvent { - String id; - String display; - ItemStack stack; - List desc; - long lastsFor; - - public SBEvent(String id, String display, ItemStack stack, List desc) { - this(id, display, stack, desc, -1); - } - - public SBEvent(String id, String display, ItemStack stack, List desc, long lastsFor) { - this.id = id; - this.display = display; - this.stack = stack; - this.desc = desc; - this.lastsFor = lastsFor; - } - } - - private int jingleIndex = -1; - - private TreeMap> eventMap = new TreeMap<>(); - private List jfFavouriteSelect = null; - private int jfFavouriteSelectIndex = 0; - private int jfFavouriteSelectX = 0; - private int jfFavouriteSelectY = 0; - - private boolean drawTimerForeground = false; - - private static long spookyStart = 0; - - private static long SECOND = 1000; - private static long MINUTE = SECOND*60; - private static long HOUR = MINUTE*60; - private static long DAY = HOUR*24; - - private static long DA_OFFSET = 1000*60*55; - private static long JF_OFFSET = 1000*60*15; - - private static ItemStack DA_STACK; - private static ItemStack JF_STACK; - static { - NBTTagCompound tag = new NBTTagCompound(); - tag.setString("event_id", "dark_auction"); - //tag.setTag("ench", new NBTTagList()); - - DA_STACK = new ItemStack(Items.netherbrick); - DA_STACK.setTagCompound(tag); - - tag.setString("event_id", "jacob_farming"); - JF_STACK = new ItemStack(Items.wheat); - JF_STACK.setTagCompound(tag); - } - - public long getTimeOffset(String time) { - long offset = 0; - - StringBuilder numS = new StringBuilder(); - for(int timeIndex=0; timeIndex= '0' && c <= '9') { - numS.append(c); - } else { - try { - int num = Integer.parseInt(numS.toString()); - switch (c) { - case 'd': - offset += num * DAY; continue; - case 'h': - offset += num * HOUR; continue; - case 'm': - offset += num * MINUTE; continue; - case 's': - offset += num * SECOND; continue; - } - } catch(Exception ignored) {} - numS = new StringBuilder(); - } - } - - return offset; - } - - private static Pattern CALENDAR_PATTERN = Pattern.compile("([A-Za-z ]+), Year ([0-9]+)"); - private static long SKYBLOCK_START = 1559829300000L; //Day 0, Year 0 - - @SubscribeEvent - public void tick(TickEvent.ClientTickEvent event) { - if(event.phase != TickEvent.Phase.START) return; - - if(jingleIndex == 0) { - if (NotEnoughUpdates.INSTANCE.manager.config.eventNotificationSounds.value) { - Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create( - new ResourceLocation("notenoughupdates:calendar_notif_jingle") - )); - Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create( - new ResourceLocation("notenoughupdates:calendar_notif_in") - )); - } - jingleIndex = -15*20; - } else if(jingleIndex >= 1) { - if (NotEnoughUpdates.INSTANCE.manager.config.eventNotificationSounds.value) { - Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create( - new ResourceLocation("notenoughupdates:calendar_notif_in") - )); - } - jingleIndex = -15*20; - } else if(jingleIndex < -1) { - jingleIndex++; - } - if(jingleIndex == -20*6-10) { - if(NotEnoughUpdates.INSTANCE.manager.config.eventNotificationSounds.value) { - Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create( - new ResourceLocation("notenoughupdates:calendar_notif_out") - )); - } - } - - if(farmingEventTypes == null) { - farmingEventTypes = NotEnoughUpdates.INSTANCE.manager.getJsonFromFile(new File(NotEnoughUpdates.INSTANCE.manager.configLocation, - "farmingEventTypes.json")); - if(farmingEventTypes == null) { - farmingEventTypes = new JsonObject(); - } - } - - if(!(Minecraft.getMinecraft().currentScreen instanceof GuiChest)) { - jfFavouriteSelect = null; - if(eventMap.isEmpty() || eventMap.size() <= 20) { - long currentTime = System.currentTimeMillis(); - long floorHour = (currentTime/HOUR)*HOUR; - for(int i=0; i<15; i++) { - long daEvent = floorHour+i*HOUR+DA_OFFSET; - long jfEvent = floorHour+i*HOUR+JF_OFFSET; - - if(daEvent > currentTime) { - eventMap.computeIfAbsent(daEvent, k->new HashSet<>()).add(new SBEvent("dark_auction", - EnumChatFormatting.DARK_PURPLE+"Dark Auction", DA_STACK, null, MINUTE*5)); - } - if(jfEvent > currentTime) { - SBEvent jf = new SBEvent("jacob_farming", - EnumChatFormatting.YELLOW+"Jacob's Farming Contest", JF_STACK, null, MINUTE*20); - if(farmingEventTypes != null && farmingEventTypes.has(""+jfEvent) && - farmingEventTypes.get(""+jfEvent).isJsonArray()) { - JsonArray arr = farmingEventTypes.get(""+jfEvent).getAsJsonArray(); - jf.desc = new ArrayList<>(); - for(JsonElement e : arr) { - jf.desc.add(EnumChatFormatting.YELLOW+"\u25CB "+e.getAsString()); - jf.id += ":" + e.getAsString(); - } - } - eventMap.computeIfAbsent(jfEvent, k->new HashSet<>()).add(jf); - } - } - } - return; - } - - GuiChest eventGui = (GuiChest) Minecraft.getMinecraft().currentScreen; - ContainerChest cc = (ContainerChest) eventGui.inventorySlots; - String containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText(); - - Matcher matcher = CALENDAR_PATTERN.matcher(Utils.cleanColour(containerName)); - if(farmingEventTypes != null && matcher.matches()) { - try { - int year = Integer.parseInt(matcher.group(2)); - int skyblockDays = year * 12 * 31; - - String month = matcher.group(1); - boolean spring = month.endsWith("Spring"); - boolean summer = month.endsWith("Summer"); - boolean autumn = month.endsWith("Autumn"); - boolean winter = month.endsWith("Winter"); - if(spring || summer || autumn || winter) { - if(spring) { - skyblockDays += 1*31; - } else if(summer) { - skyblockDays += 4*31; - } else if(autumn) { - skyblockDays += 7*31; - } else { - skyblockDays += 10*31; - } - if(month.startsWith("Early")) { - skyblockDays -= 31; - } else if(month.startsWith("Late")) { - skyblockDays += 31; - } - - long start = SKYBLOCK_START + skyblockDays*20*MINUTE; - - boolean changed = false; - for(int i=0; i<31; i++) { - ItemStack item = cc.getLowerChestInventory().getStackInSlot(1+(i%7)+(i/7)*9); - - JsonArray array = new JsonArray(); - if(item.getTagCompound() != null) { - NBTTagCompound tag = item.getTagCompound(); - - if(tag.hasKey("display", 10)) { - NBTTagCompound display = tag.getCompoundTag("display"); - if (display.hasKey("Lore", 9)) { - NBTTagList list = display.getTagList("Lore", 8); - for(int j=0; j currentTime) { - eventMap.computeIfAbsent(daEvent, k->new HashSet<>()).add(new SBEvent("dark_auction", - EnumChatFormatting.DARK_PURPLE+"Dark Auction", DA_STACK, null, MINUTE*5)); - } - if(jfEvent > currentTime) { - SBEvent jf = new SBEvent("jacob_farming", - EnumChatFormatting.YELLOW+"Jacob's Farming Contest", JF_STACK, null, MINUTE*20); - if(farmingEventTypes != null && farmingEventTypes.has(""+jfEvent) && - farmingEventTypes.get(""+jfEvent).isJsonArray()) { - JsonArray arr = farmingEventTypes.get(""+jfEvent).getAsJsonArray(); - jf.desc = new ArrayList<>(); - for(JsonElement e : arr) { - jf.desc.add(EnumChatFormatting.YELLOW+"\u25CB "+e.getAsString()); - jf.id += ":" + e.getAsString(); - } - } - eventMap.computeIfAbsent(jfEvent, k->new HashSet<>()).add(jf); - } - } - } - return; - } - - if(!containerName.trim().equals("Calendar and Events")) { - setEnabled(false); - return; - } - - eventMap.clear(); - - long currentTime = System.currentTimeMillis(); - long floorHour = (currentTime/HOUR)*HOUR; - for(int i=0; i<15; i++) { - long daEvent = floorHour+i*HOUR+DA_OFFSET; - long jfEvent = floorHour+i*HOUR+JF_OFFSET; - - if(daEvent > currentTime) { - eventMap.computeIfAbsent(daEvent, k->new HashSet<>()).add(new SBEvent("dark_auction", - EnumChatFormatting.DARK_PURPLE+"Dark Auction", DA_STACK, null, MINUTE*5)); - } - if(jfEvent > currentTime) { - SBEvent jf = new SBEvent("jacob_farming", - EnumChatFormatting.YELLOW+"Jacob's Farming Contest", JF_STACK, null, MINUTE*20); - if(farmingEventTypes != null && farmingEventTypes.has(""+jfEvent) && - farmingEventTypes.get(""+jfEvent).isJsonArray()) { - JsonArray arr = farmingEventTypes.get(""+jfEvent).getAsJsonArray(); - jf.desc = new ArrayList<>(); - for(JsonElement e : arr) { - jf.desc.add(EnumChatFormatting.YELLOW+"\u25CB "+e.getAsString()); - jf.id += ":" + e.getAsString(); - } - } - eventMap.computeIfAbsent(jfEvent, k->new HashSet<>()).add(jf); - } - } - - String lastsForText = EnumChatFormatting.GRAY+"Event lasts for "+EnumChatFormatting.YELLOW; - String startsInText = EnumChatFormatting.GRAY+"Starts in: "+EnumChatFormatting.YELLOW; - for(int i=0; i<21; i++) { - int itemIndex = 10+i+(i/7)*2; - ItemStack item = cc.getLowerChestInventory().getStackInSlot(itemIndex); - - if(item != null && item.getTagCompound() != null) { - NBTTagCompound tag = item.getTagCompound(); - - if(tag.hasKey("display", 10)) { - NBTTagCompound display = tag.getCompoundTag("display"); - if (display.hasKey("Lore", 9)) { - NBTTagList list = display.getTagList("Lore", 8); - - String first = list.getStringTagAt(0); - if(first.startsWith(startsInText)) { - String time = Utils.cleanColour(first.substring(startsInText.length())); - long eventTime = currentTime + getTimeOffset(time); - - long lastsFor = -1; - - List desc = new ArrayList<>(); - boolean foundBreak = false; - for(int index=1; indexnew HashSet<>()).add(new SBEvent( - getIdForDisplayName(item.getDisplayName()), item.getDisplayName(), - item, desc, lastsFor)); - } - } - } - } - } - } - - private static String getIdForDisplayName(String displayName) { - return Utils.cleanColour(displayName) - .toLowerCase() - .replaceAll("[0-9]+th", "") - .replaceAll("[0-9]+nd", "") - .replaceAll("[0-9]+rd", "") - .replaceAll("[0-9]+st", "") - .replaceAll("[^a-z ]", "") - .trim() - .replace(" ", "_"); - } - - - @SubscribeEvent - public void onGuiScreenMouse(GuiScreenEvent.MouseInputEvent.Pre event) { - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - int width = scaledResolution.getScaledWidth(); - int height = scaledResolution.getScaledHeight(); - int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; - int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; - - if(!enabled) { - if(Mouse.getEventButtonState() && NotEnoughUpdates.INSTANCE.manager.config.showEventTimerInInventory.value && - Minecraft.getMinecraft().currentScreen instanceof GuiContainer) { - xSize = 168; - ySize = 20; - - guiLeft = (width - xSize)/2; - guiTop = 5; - - if(mouseX >= guiLeft && mouseX <= guiLeft+xSize) { - if(mouseY >= guiTop && mouseY <= guiTop+ySize) { - ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, "/neucalendar"); - } - } - } - - return; - } - - if(!(Minecraft.getMinecraft().currentScreen instanceof GuiChest)) { - return; - } - - GuiChest eventGui = (GuiChest) Minecraft.getMinecraft().currentScreen; - ContainerChest cc = (ContainerChest) eventGui.inventorySlots; - String containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText(); - if(!containerName.trim().equals("Calendar and Events")) { - setEnabled(false); - return; - } - - event.setCanceled(true); - - xSize = 168; - ySize = 170; - guiLeft = (width - xSize) / 2; - guiTop = (height - ySize) / 2; - - if(Mouse.getEventButtonState()) { - if(jfFavouriteSelect != null) { - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - int arrowLen = fr.getStringWidth("> "); - int selectSizeX = 0; - int selectStringIndex = 0; - for (String s : jfFavouriteSelect) { - int sWidth = fr.getStringWidth(s); - if (selectStringIndex + 1 == jfFavouriteSelectIndex) sWidth += arrowLen; - if (sWidth > selectSizeX) { - selectSizeX = sWidth; - } - selectStringIndex++; - } - selectSizeX += +10; - - if(mouseX > jfFavouriteSelectX && mouseX < jfFavouriteSelectX + selectSizeX && - mouseY > jfFavouriteSelectY && mouseY < jfFavouriteSelectY + 18 + jfFavouriteSelect.size() * 10) { - jfFavouriteSelectIndex = Math.max(0, (mouseY - jfFavouriteSelectY - 5)/10); - - List eventFavourites = NotEnoughUpdates.INSTANCE.manager.config.eventFavourites.value; - String id = null; - if(jfFavouriteSelectIndex == 0) { - id = "jacob_farming"; - } else if(jfFavouriteSelectIndex-1 < jfFavouriteSelect.size()) { - id = "jacob_farming:"+jfFavouriteSelect.get(jfFavouriteSelectIndex-1); - } - if(id != null) { - if (eventFavourites.contains(id)) { - eventFavourites.remove(id); - } else { - eventFavourites.add(id); - } - try { - NotEnoughUpdates.INSTANCE.manager.saveConfig(); - } catch (Exception ignored) { - } - } - } else { - jfFavouriteSelect = null; - } - } - if(mouseY >= guiTop+26 && mouseY <= guiTop+26+141) { - if(mouseX >= guiLeft+151 && mouseX <= guiLeft+151+14) { - if(mouseY <= guiTop+26+70) { - Minecraft.getMinecraft().playerController.windowClick(cc.windowId, - 50, 2, 3, Minecraft.getMinecraft().thePlayer); - } else { - Minecraft.getMinecraft().playerController.windowClick(cc.windowId, - 45, 2, 3, Minecraft.getMinecraft().thePlayer); - } - } - } - } - } - - @SubscribeEvent - public void onGuiScreenKeyboard(GuiScreenEvent.KeyboardInputEvent.Pre event) { - if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) { - if(jfFavouriteSelect != null) { - jfFavouriteSelect = null; - event.setCanceled(true); - } - } else { - if (!enabled) { - return; - } - - if (!(Minecraft.getMinecraft().currentScreen instanceof GuiChest)) { - return; - } - - GuiChest eventGui = (GuiChest) Minecraft.getMinecraft().currentScreen; - ContainerChest cc = (ContainerChest) eventGui.inventorySlots; - String containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText(); - if (!containerName.trim().equals("Calendar and Events")) { - setEnabled(false); - return; - } - - event.setCanceled(true); - xSize = 168; - ySize = 170; - - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - int width = scaledResolution.getScaledWidth(); - int height = scaledResolution.getScaledHeight(); - int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; - int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; - guiLeft = (width - xSize) / 2; - guiTop = (height - ySize) / 2; - - int keyPressed = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey(); - if(Keyboard.getEventKeyState()) { - if(jfFavouriteSelect != null) { - if(keyPressed == Keyboard.KEY_DOWN) { - jfFavouriteSelectIndex++; - jfFavouriteSelectIndex %= jfFavouriteSelect.size()+1; - } else if(keyPressed == Keyboard.KEY_UP) { - jfFavouriteSelectIndex--; - if(jfFavouriteSelectIndex < 0) jfFavouriteSelectIndex = jfFavouriteSelect.size(); - } else if(keyPressed == Keyboard.KEY_RIGHT || keyPressed == Keyboard.KEY_RETURN) { - List eventFavourites = NotEnoughUpdates.INSTANCE.manager.config.eventFavourites.value; - String id = null; - if(jfFavouriteSelectIndex == 0) { - id = "jacob_farming"; - } else if(jfFavouriteSelectIndex-1 < jfFavouriteSelect.size()) { - id = "jacob_farming:"+jfFavouriteSelect.get(jfFavouriteSelectIndex-1); - } - if(id != null) { - if (eventFavourites.contains(id)) { - eventFavourites.remove(id); - } else { - eventFavourites.add(id); - } - try { - NotEnoughUpdates.INSTANCE.manager.saveConfig(); - } catch (Exception ignored) { - } - } - } else if(keyPressed == Keyboard.KEY_LEFT || - keyPressed == NotEnoughUpdates.INSTANCE.manager.keybindFavourite.getKeyCode()) { - jfFavouriteSelect = null; - } - } else if(keyPressed == NotEnoughUpdates.INSTANCE.manager.keybindFavourite.getKeyCode()) { - String id = null; - - //Daily Events - int index = 0; - out: - for (Map.Entry> sbEvents : eventMap.entrySet()) { - for (SBEvent sbEvent : sbEvents.getValue()) { - int x = guiLeft + 29 + 17 * (index % 3); - int y = guiTop + 44 + 17 * (index / 3); - - if (mouseX >= x && mouseX <= x + 16) { - if (mouseY >= y && mouseY <= y + 16) { - id = sbEvent.id; - } - } - - if (++index >= 21) break out; - } - } - - //Special Events - for (int i = 0; i < 21; i++) { - int itemIndex = 10 + i + (i / 7) * 2; - ItemStack item = cc.getLowerChestInventory().getStackInSlot(itemIndex); - if (item == null) continue; - - int x = guiLeft + 89 + 17 * (i % 3); - int y = guiTop + 44 + 17 * (i / 3); - - if (mouseX >= x && mouseX <= x + 16) { - if (mouseY >= y && mouseY <= y + 16) { - id = getIdForDisplayName(item.getDisplayName()); - } - } - } - - if (id != null) { - String[] split = id.split(":"); - if(split.length > 1 && split[0].equals("jacob_farming")) { - jfFavouriteSelect = new ArrayList<>(); - for(int i=1; i eventFavourites = NotEnoughUpdates.INSTANCE.manager.config.eventFavourites.value; - if (eventFavourites.contains(id)) { - eventFavourites.remove(id); - } else { - eventFavourites.add(id); - } - try { - NotEnoughUpdates.INSTANCE.manager.saveConfig(); - } catch (Exception ignored) { - } - } - } - } - } - } - } - - @SubscribeEvent(priority = EventPriority.LOW) - public void onGuiDraw(RenderGameOverlayEvent.Post event) { - if(NotEnoughUpdates.INSTANCE.manager.config.eventNotifications.value && - event.type == RenderGameOverlayEvent.ElementType.ALL) { - GlStateManager.pushMatrix(); - GlStateManager.translate(0, 0, 10); - if(!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer) && NotEnoughUpdates.INSTANCE.isOnSkyblock()) { - long currentTime = System.currentTimeMillis(); - - long timeUntilNext = 0; - SBEvent nextEvent = null; - long timeUntilFirst = 0; - SBEvent firstEvent = null; - - List eventFavourites = NotEnoughUpdates.INSTANCE.manager.config.eventFavourites.value; - - //Daily Events - out: - for(Map.Entry> sbEvents : eventMap.entrySet()) { - for(SBEvent sbEvent : sbEvents.getValue()) { - long timeUntilMillis = sbEvents.getKey() - currentTime; - - if(timeUntilMillis < -10*SECOND) { - continue; - } - - if(firstEvent == null) { - firstEvent = sbEvent; - timeUntilFirst = timeUntilMillis; - } - - String[] split = sbEvent.id.split(":"); - boolean containsId = false; - for(int i=1; i -8500) { - event = new SBEvent("spooky_festival_7am", "Spooky Festival 7am", new ItemStack(Items.bone), null); - timeUntil = delta; - } - } - - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - int width = scaledResolution.getScaledWidth(); - int height = scaledResolution.getScaledHeight(); - - int ySize = 32; - int xSize = 160; - int guiLeft = (width - xSize)/2; - int guiTop = 5; - - boolean preNotification = false; - long preNotificationTime = SECOND*NotEnoughUpdates.INSTANCE.manager.config.eventNotificationBeforeSeconds.value.intValue(); - - if(preNotificationTime > 500 && timeUntil > 500) { - timeUntil = timeUntil - preNotificationTime; - preNotification = true; - } - - if(timeUntil < 500 && timeUntil > -8500) { - if(jingleIndex == -1) { - if(preNotification) { - jingleIndex = 1; - } else { - jingleIndex = 0; - } - } - - float offset; - float factor = 0; - if(timeUntil > 0) { - factor = (timeUntil/500f); - } else if(timeUntil < -8000) { - factor = -((timeUntil+8000)/500f); - } - factor = (float)(1.06f/(1+Math.exp(-7*(factor-0.5f)))-0.03f); - offset = -(ySize+5)*factor; - float y = guiTop+offset; - - GlStateManager.color(1, 1, 1, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(TOAST); - Utils.drawTexturedRect(guiLeft, y, xSize, ySize, GL11.GL_NEAREST); - - GlStateManager.translate(0, y, 0); - Utils.drawItemStack(event.stack, guiLeft+6, 8); - GlStateManager.translate(0, -y, 0); - - if(preNotification) { - String starting = EnumChatFormatting.YELLOW+"Event Starting in "+prettyTime(preNotificationTime, true)+"!"; - int startingWidth = fr.getStringWidth(starting); - fr.drawString(starting, Math.max(guiLeft+23, width/2f-startingWidth/2f), y+7, -1, false); - } else { - Utils.drawStringCentered(EnumChatFormatting.YELLOW+"Event Starting Now!", fr, width/2, y+11, false, -1); - } - - int displayWidth = fr.getStringWidth(event.display); - fr.drawString(event.display, Math.max(guiLeft+23, width/2f-displayWidth/2f), y+17, -1, false); - - - return true; - } - return false; - } - - @SubscribeEvent - public void onGuiScreenDrawTimer(GuiScreenEvent.BackgroundDrawnEvent event) { - blurBackground(); - if(!drawTimerForeground) { - drawTimer(); - } - GlStateManager.color(1, 1, 1, 1); - GlStateManager.enableBlend(); - } - - @SubscribeEvent - public void onGuiScreenDrawTimer(GuiScreenEvent.DrawScreenEvent.Post event) { - if(drawTimerForeground) { - drawTimer(); - } - } - - public void drawTimer() { - GlStateManager.pushMatrix(); - GlStateManager.translate(0, 0, 10); - if(Minecraft.getMinecraft().currentScreen instanceof GuiContainer && NotEnoughUpdates.INSTANCE.isOnSkyblock()) { - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - int width = scaledResolution.getScaledWidth(); - int height = scaledResolution.getScaledHeight(); - int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; - int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; - long currentTime = System.currentTimeMillis(); - - xSize = 168; - ySize = 20; - - long timeUntilNext = 0; - SBEvent nextEvent = null; - long timeUntilFirst = 0; - SBEvent firstEvent = null; - List nextFavourites = new ArrayList<>(); - List nextFavouritesTime = new ArrayList<>(); - long timeUntilMajor = 0; - SBEvent nextMajorEvent = null; - - List eventFavourites = NotEnoughUpdates.INSTANCE.manager.config.eventFavourites.value; - - guiLeft = (width - xSize)/2; - guiTop = 5; - - //Daily Events - out: - for(Map.Entry> sbEvents : eventMap.entrySet()) { - for(SBEvent sbEvent : sbEvents.getValue()) { - long timeUntilMillis = sbEvents.getKey() - currentTime; - - if(timeUntilMillis < -10*SECOND) { - continue; - } - - if(sbEvent.id.equals("spooky_festival")) { - if(currentTime - spookyStart > HOUR || (sbEvents.getKey() > currentTime && sbEvents.getKey() < spookyStart)) { - spookyStart = sbEvents.getKey(); - } - } - - if(nextMajorEvent == null && !sbEvent.id.split(":")[0].equals("jacob_farming") && - !sbEvent.id.equals("dark_auction")) { - nextMajorEvent = sbEvent; - timeUntilMajor = timeUntilMillis; - } - - if(firstEvent == null) { - firstEvent = sbEvent; - timeUntilFirst = timeUntilMillis; - } - - String[] split = sbEvent.id.split(":"); - boolean containsId = false; - for(int i=1; i= 3 && nextMajorEvent != null) { - break out; - } - } - } - - if(nextEvent == null) { - nextEvent = firstEvent; - timeUntilNext = timeUntilFirst; - } - - if(nextEvent != null) { - GlStateManager.translate(0, 0, 50); - boolean toastRendered = renderToast(nextEvent, timeUntilNext); - GlStateManager.translate(0, 0, -50); - if(!toastRendered && !enabled && NotEnoughUpdates.INSTANCE.manager.config.showEventTimerInInventory.value) { - List tooltipToDisplay = null; - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - - GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - GlStateManager.disableFog(); - GlStateManager.disableLighting(); - GlStateManager.disableColorMaterial(); - - renderBlurredBackground(width, height, guiLeft+3, guiTop+3, xSize-6, ySize-6); - - Minecraft.getMinecraft().getTextureManager().bindTexture(DISPLAYBAR); - Utils.drawTexturedRect(guiLeft, guiTop, xSize, 20, GL11.GL_NEAREST); - - String nextS = EnumChatFormatting.YELLOW+"Next: "; - int nextSLen = fr.getStringWidth(nextS); - fr.drawString(nextS, guiLeft+8, guiTop+6, -1, false); - - String until = " "+EnumChatFormatting.YELLOW+prettyTime(timeUntilNext, false); - int untilLen = fr.getStringWidth(until); - - fr.drawString(until, guiLeft+xSize-8-untilLen, guiTop+6, -1, false); - - int eventTitleLen = xSize-16-untilLen-nextSLen; - int displayWidth = fr.getStringWidth(nextEvent.display); - int spaceLen = fr.getCharWidth(' '); - if(displayWidth > eventTitleLen) { - GL11.glEnable(GL11.GL_SCISSOR_TEST); - GL11.glScissor((guiLeft+8+nextSLen)*scaledResolution.getScaleFactor(), - 0, - eventTitleLen*scaledResolution.getScaleFactor(), - Minecraft.getMinecraft().displayHeight); - fr.drawString(nextEvent.display + " " + nextEvent.display, - guiLeft+8+nextSLen-(float)(currentTime/50.0 % (displayWidth+spaceLen)), guiTop+6, -1, false); - GL11.glDisable(GL11.GL_SCISSOR_TEST); - } else { - if(guiLeft+xSize-8-untilLen > (width+displayWidth)/2) { - Utils.drawStringCentered(nextEvent.display, fr,width/2f, guiTop+10, false, -1); - } else { - fr.drawString(nextEvent.display, guiLeft+8+nextSLen, guiTop+6, -1, false); - } - } - - if(mouseX > guiLeft && mouseX < guiLeft+168) { - if(mouseY > guiTop && mouseY < guiTop+20) { - tooltipToDisplay = new ArrayList<>(); - for(int i=0; i= 0) { - tooltipToDisplay.add( EnumChatFormatting.GRAY+"Lasts for: "+EnumChatFormatting.YELLOW+ - prettyTime(sbEvent.lastsFor, true)); - } - if(sbEvent.id.split(":")[0].equals("jacob_farming") && sbEvent.desc != null) { - tooltipToDisplay.addAll(sbEvent.desc); - } - if(nextMajorEvent != null || i < nextFavourites.size()-1) { - tooltipToDisplay.add(""); - } - } - if(nextMajorEvent != null) { - tooltipToDisplay.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Next Major:"); - tooltipToDisplay.add(nextMajorEvent.display); - tooltipToDisplay.add(EnumChatFormatting.GRAY+"Starts in: "+EnumChatFormatting.YELLOW+prettyTime(timeUntilMajor, false)); - if(nextMajorEvent.lastsFor >= 0) { - tooltipToDisplay.add( EnumChatFormatting.GRAY+"Lasts for: "+EnumChatFormatting.YELLOW+ - prettyTime(nextMajorEvent.lastsFor, true)); - } - } - - - } - } - - drawTimerForeground = false; - if(tooltipToDisplay != null) { - drawTimerForeground = true; - GlStateManager.translate(0, 0, 100); - Utils.drawHoveringText(tooltipToDisplay, mouseX, Math.max(17, mouseY), width, height, -1, fr); - GlStateManager.translate(0, 0, -100); - } - } - } - } - GlStateManager.translate(0, 0, -10); - GlStateManager.popMatrix(); - } - - @SubscribeEvent - public void onGuiDraw(GuiScreenEvent.DrawScreenEvent.Pre event) { - if(!(Minecraft.getMinecraft().currentScreen instanceof GuiChest)) { - return; - } - - if(!enabled) { - return; - } - - GuiChest eventGui = (GuiChest) Minecraft.getMinecraft().currentScreen; - ContainerChest cc = (ContainerChest) eventGui.inventorySlots; - String containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText(); - if(!containerName.trim().equals("Calendar and Events")) { - setEnabled(false); - return; - } - - event.setCanceled(true); - - List tooltipToDisplay = null; - int mouseX = event.mouseX; - int mouseY = event.mouseY; - long currentTime = System.currentTimeMillis(); - - xSize = 168; - ySize = 170; - - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - int width = scaledResolution.getScaledWidth(); - int height = scaledResolution.getScaledHeight(); - guiLeft = (width - xSize)/2; - guiTop = (height - ySize)/2; - - Utils.drawGradientRect(0, 0, width, height, -1072689136, -804253680); - - renderBlurredBackground(width, height, guiLeft+3, guiTop+3, 162, 14); - renderBlurredBackground(width, height, guiLeft+3, guiTop+26, 14, 141); - renderBlurredBackground(width, height, guiLeft+151, guiTop+26, 14, 141); - renderBlurredBackground(width, height, guiLeft+26, guiTop+26, 116, 141); - - Minecraft.getMinecraft().getTextureManager().bindTexture(BACKGROUND); - Utils.drawTexturedRect(guiLeft, guiTop, xSize, ySize, GL11.GL_NEAREST); - - GlStateManager.translate(0, 0, 10); - - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - - fr.drawString("Daily", guiLeft+29, guiTop+30, 0xffffaa00); - int specialLen = fr.getStringWidth("Special"); - fr.drawString("Special", guiLeft+139-specialLen, guiTop+30, 0xffffaa00); - - ItemStack mayorStack = cc.getLowerChestInventory().getStackInSlot(46); - if(mayorStack != null) { - String mayor = mayorStack.getDisplayName(); - float verticalHeight = Utils.getVerticalHeight(mayor); - Utils.drawStringVertical(mayor, fr, guiLeft+8, guiTop+96-verticalHeight/2, - false, -1); - } - - String calendar = EnumChatFormatting.GREEN+"Calendar"; - float calendarHeight = Utils.getVerticalHeight(calendar); - Utils.drawStringVertical(calendar, fr, guiLeft+xSize-12, guiTop+60-calendarHeight/2, - false, -1); - - String rewards = EnumChatFormatting.GOLD+"Rewards"; - float rewardsHeight = Utils.getVerticalHeight(rewards); - Utils.drawStringVertical(rewards, fr, guiLeft+xSize-12, guiTop+132-rewardsHeight/2, - false, -1); - - if(mouseY >= guiTop+26 && mouseY <= guiTop+26+141) { - if(mouseX >= guiLeft+3 && mouseX <= guiLeft+3+14) { - if(mayorStack != null) tooltipToDisplay = mayorStack.getTooltip(Minecraft.getMinecraft().thePlayer, false); - } else if(mouseX >= guiLeft+151 && mouseX <= guiLeft+151+14) { - if(mouseY <= guiTop+26+70) { - ItemStack calendarStack = cc.getLowerChestInventory().getStackInSlot(50); - if(calendarStack != null) tooltipToDisplay = calendarStack.getTooltip(Minecraft.getMinecraft().thePlayer, false); - } else { - ItemStack rewardsStack = cc.getLowerChestInventory().getStackInSlot(45); - if(rewardsStack != null) tooltipToDisplay = rewardsStack.getTooltip(Minecraft.getMinecraft().thePlayer, false); - } - } - } - - long timeUntilNext = 0; - SBEvent nextEvent = null; - long timeUntilFirst = 0; - SBEvent firstEvent = null; - List eventFavourites = NotEnoughUpdates.INSTANCE.manager.config.eventFavourites.value; - - //Daily Events - int index = 0; - out: - for(Map.Entry> sbEvents : eventMap.entrySet()) { - for(SBEvent sbEvent : sbEvents.getValue()) { - long timeUntilMillis = sbEvents.getKey() - currentTime; - - int x = guiLeft+29+17*(index%3); - int y = guiTop+44+17*(index/3); - - if(sbEvent.id.equals("spooky_festival")) { - if(currentTime - spookyStart > HOUR || (sbEvents.getKey() > currentTime && sbEvents.getKey() < spookyStart)) { - spookyStart = sbEvents.getKey(); - } - } - - if(index >= 21) { - if(nextEvent != null) break; - if(eventFavourites.isEmpty()) { - nextEvent = sbEvent; - timeUntilNext = timeUntilMillis; - } else if(eventFavourites.contains(sbEvent.id)) { - nextEvent = sbEvent; - timeUntilNext = timeUntilMillis; - } - continue; - } - - if(firstEvent == null) { - firstEvent = sbEvent; - timeUntilFirst = timeUntilMillis; - } - - String[] split = sbEvent.id.split(":"); - boolean containsId = false; - for(int i=1; i= x && mouseX <= x+16) { - if(mouseY >= y && mouseY <= y+16) { - tooltipToDisplay = Utils.createList(sbEvent.display, - EnumChatFormatting.GRAY+"Starts in: "+EnumChatFormatting.YELLOW+prettyTime(timeUntilMillis, false)); - if(sbEvent.lastsFor >= 0) { - tooltipToDisplay.add( EnumChatFormatting.GRAY+"Lasts for: "+EnumChatFormatting.YELLOW+ - prettyTime(sbEvent.lastsFor, true)); - } - if(sbEvent.desc != null) { - tooltipToDisplay.add(""); - tooltipToDisplay.addAll(sbEvent.desc); - } - } - } - - index++; - } - } - - //Special Events - for(int i=0; i<21; i++) { - int itemIndex = 10+i+(i/7)*2; - ItemStack item = cc.getLowerChestInventory().getStackInSlot(itemIndex); - if(item == null) continue; - - String eventId = getIdForDisplayName(item.getDisplayName()); - - NBTTagCompound tag = item.getTagCompound(); - tag.setString("event_id", eventId); - item.setTagCompound(tag); - - int x = guiLeft+89+17*(i%3); - int y = guiTop+44+17*(i/3); - - if(eventFavourites.contains(eventId)) { - GlStateManager.depthMask(false); - GlStateManager.translate(0, 0, -2); - Gui.drawRect(x, y, x+16, y+16, 0xcfffbf49); - GlStateManager.translate(0, 0, 2); - GlStateManager.depthMask(true); - } - - Utils.drawItemStackWithText(item, x, y, ""+(i+1)); - - if(mouseX >= x && mouseX <= x+16) { - if(mouseY >= y && mouseY <= y+16) { - tooltipToDisplay = item.getTooltip(Minecraft.getMinecraft().thePlayer, false); - } - } - } - - if(nextEvent == null) { - nextEvent = firstEvent; - timeUntilNext = timeUntilFirst; - } - - if(nextEvent != null) { - String nextS = EnumChatFormatting.YELLOW+"Next: "; - int nextSLen = fr.getStringWidth(nextS); - fr.drawString(nextS, guiLeft+8, guiTop+6, -1, false); - - String until = " "+EnumChatFormatting.YELLOW+prettyTime(timeUntilNext, false); - int untilLen = fr.getStringWidth(until); - - fr.drawString(until, guiLeft+xSize-8-untilLen, guiTop+6, -1, false); - - int eventTitleLen = xSize-16-untilLen-nextSLen; - int displayWidth = fr.getStringWidth(nextEvent.display); - int spaceLen = fr.getCharWidth(' '); - if(displayWidth > eventTitleLen) { - GL11.glEnable(GL11.GL_SCISSOR_TEST); - GL11.glScissor((guiLeft+8+nextSLen)*scaledResolution.getScaleFactor(), - 0, - eventTitleLen*scaledResolution.getScaleFactor(), - Minecraft.getMinecraft().displayHeight); - fr.drawString(nextEvent.display + " " + nextEvent.display, - guiLeft+8+nextSLen-(float)(currentTime/50.0 % (displayWidth+spaceLen)), guiTop+6, -1, false); - GL11.glDisable(GL11.GL_SCISSOR_TEST); - } else { - fr.drawString(nextEvent.display, guiLeft+8+nextSLen, guiTop+6, -1, false); - } - - if(mouseX > guiLeft && mouseX < guiLeft+168) { - if(mouseY > guiTop && mouseY < guiTop+20) { - tooltipToDisplay = Utils.createList(nextEvent.display, - EnumChatFormatting.GRAY+"Starts in: "+EnumChatFormatting.YELLOW+prettyTime(timeUntilNext, false)); - if(nextEvent.lastsFor >= 0) { - tooltipToDisplay.add( EnumChatFormatting.GRAY+"Lasts for: "+EnumChatFormatting.YELLOW+ - prettyTime(nextEvent.lastsFor, true)); - } - if(nextEvent.desc != null) { - tooltipToDisplay.add(""); - tooltipToDisplay.addAll(nextEvent.desc); - } - } - } - } - - GlStateManager.color(1, 1, 1, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(help); - Utils.drawTexturedRect(guiLeft+xSize-18, guiTop+ySize+2, 16, 16, GL11.GL_LINEAR); - - if(mouseX >= guiLeft+xSize-18 && mouseX < guiLeft+xSize-2) { - if(mouseY >= guiTop+ySize+2 && mouseY <= guiTop+ySize+18) { - tooltipToDisplay = new ArrayList<>(); - tooltipToDisplay.add(EnumChatFormatting.AQUA+"NEU Calendar Help"); - tooltipToDisplay.add(EnumChatFormatting.YELLOW+"This calendar displays various skyblock events"); - tooltipToDisplay.add(EnumChatFormatting.YELLOW+"'Daily' events are events that happen frequently"); - tooltipToDisplay.add(EnumChatFormatting.YELLOW+"'Special' events are events that happen infrequently"); - tooltipToDisplay.add(EnumChatFormatting.YELLOW+""); - tooltipToDisplay.add(EnumChatFormatting.YELLOW+"The eventbar at the top will also show in your inventory"); - tooltipToDisplay.add(EnumChatFormatting.YELLOW+""); - tooltipToDisplay.add(EnumChatFormatting.YELLOW+"Press 'F' on an event to mark it as a favourite"); - tooltipToDisplay.add(EnumChatFormatting.YELLOW+"Favourited events will show over normal events"); - tooltipToDisplay.add(EnumChatFormatting.YELLOW+"Favourited events will also give a notification when it"); - tooltipToDisplay.add(EnumChatFormatting.YELLOW+"is about to start and when it does start"); - tooltipToDisplay.add(EnumChatFormatting.YELLOW+""); - tooltipToDisplay.add(EnumChatFormatting.DARK_GRAY+"In order to show crop types for Jacob's Farming"); - tooltipToDisplay.add(EnumChatFormatting.DARK_GRAY+"contest, visit the full skyblock calendar and go all"); - tooltipToDisplay.add(EnumChatFormatting.DARK_GRAY+"the way to the end of the skyblock year"); - Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, fr); - tooltipToDisplay = null; - } - } - - if(jfFavouriteSelect != null) { - int arrowLen = fr.getStringWidth("> "); - int selectSizeX = 0; - int selectStringIndex=0; - for(String s : jfFavouriteSelect) { - int sWidth = fr.getStringWidth(s); - if(selectStringIndex+1 == jfFavouriteSelectIndex) sWidth += arrowLen; - if(sWidth > selectSizeX) { - selectSizeX = sWidth; - } - selectStringIndex++; - } - selectSizeX += +10; - - GlStateManager.translate(0, 0, 19); - - Gui.drawRect(jfFavouriteSelectX+2, jfFavouriteSelectY+2, jfFavouriteSelectX+selectSizeX+2, - jfFavouriteSelectY+18+jfFavouriteSelect.size()*10+2, 0xa0000000); - - GlStateManager.depthFunc(GL11.GL_LESS); - GlStateManager.translate(0, 0, 1); - Gui.drawRect(jfFavouriteSelectX+1, jfFavouriteSelectY+1, jfFavouriteSelectX+selectSizeX-1, - jfFavouriteSelectY+18+jfFavouriteSelect.size()*10-1, 0xffc0c0c0); - Gui.drawRect(jfFavouriteSelectX, jfFavouriteSelectY, jfFavouriteSelectX+selectSizeX-1, - jfFavouriteSelectY+18+jfFavouriteSelect.size()*10-1, 0xfff0f0f0); - Gui.drawRect(jfFavouriteSelectX, jfFavouriteSelectY, jfFavouriteSelectX+selectSizeX, - jfFavouriteSelectY+18+jfFavouriteSelect.size()*10, 0xff909090); - GlStateManager.depthFunc(GL11.GL_LEQUAL); - - String all = (NotEnoughUpdates.INSTANCE.manager.config.eventFavourites.value.contains("jacob_farming")? - EnumChatFormatting.DARK_GREEN:EnumChatFormatting.DARK_GRAY)+"All"; - if(jfFavouriteSelectIndex == 0) { - fr.drawString(EnumChatFormatting.BLACK+"> "+all, jfFavouriteSelectX+5, jfFavouriteSelectY+5, 0xff000000); - } else { - fr.drawString(all, jfFavouriteSelectX+5, jfFavouriteSelectY+5, 0xff000000); - } - - fr.drawString(EnumChatFormatting.BLACK+"> ", jfFavouriteSelectX+6, - jfFavouriteSelectY+10*jfFavouriteSelectIndex+5, 0xff000000); - - selectStringIndex=0; - for(String s : jfFavouriteSelect) { - EnumChatFormatting colour = NotEnoughUpdates.INSTANCE.manager.config.eventFavourites.value.contains("jacob_farming:"+s) - ? EnumChatFormatting.DARK_GREEN : EnumChatFormatting.DARK_GRAY; - s = (selectStringIndex+1 == jfFavouriteSelectIndex ? EnumChatFormatting.BLACK+"> " : "") + colour + s; - fr.drawString(s, jfFavouriteSelectX+5, jfFavouriteSelectY+10*selectStringIndex+15, 0xff000000); - selectStringIndex++; - } - GlStateManager.translate(0, 0, -20); - } else if(tooltipToDisplay != null) { - Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, fr); - } - - GlStateManager.translate(0, 0, -10); - - } - - private String prettyTime(long millis, boolean trimmed) { - long seconds = millis / 1000 % 60; - long minutes = (millis / 1000 / 60) % 60; - long hours = (millis / 1000 / 60 / 60) % 24; - long days = (millis / 1000 / 60 / 60 / 24); - - String endsIn = ""; - if(millis < 0) { - endsIn += "Now!"; - } else if(minutes == 0 && hours == 0 && days == 0) { - endsIn += seconds + "s"; - } else if(hours==0 && days==0) { - if(trimmed && seconds == 0) { - endsIn += minutes + "m"; - } else { - endsIn += minutes + "m" + seconds + "s"; - } - } else if(days==0) { - if(hours <= 6) { - if(trimmed && seconds == 0) { - if(minutes == 0) { - endsIn += hours + "h"; - } else { - endsIn += hours + "h" + minutes + "m"; - } - } else { - endsIn += hours + "h" + minutes + "m" + seconds + "s"; - } - } else { - endsIn += hours + "h"; - } - } else { - endsIn += days + "d" + hours + "h"; - } - - return endsIn; - } - - Shader blurShaderHorz = null; - Framebuffer blurOutputHorz = null; - Shader blurShaderVert = null; - Framebuffer blurOutputVert = null; - - /** - * Creates a projection matrix that projects from our coordinate space [0->width; 0->height] to OpenGL coordinate - * space [-1 -> 1; 1 -> -1] (Note: flipped y-axis). - * - * This is so that we can render to and from the framebuffer in a way that is familiar to us, instead of needing to - * apply scales and translations manually. - */ - private Matrix4f createProjectionMatrix(int width, int height) { - Matrix4f projMatrix = new Matrix4f(); - projMatrix.setIdentity(); - projMatrix.m00 = 2.0F / (float)width; - projMatrix.m11 = 2.0F / (float)(-height); - projMatrix.m22 = -0.0020001999F; - projMatrix.m33 = 1.0F; - projMatrix.m03 = -1.0F; - projMatrix.m13 = 1.0F; - projMatrix.m23 = -1.0001999F; - return projMatrix; - } - - private double lastBgBlurFactor = -1; - private void blurBackground() { - if(!OpenGlHelper.isFramebufferEnabled()) return; - - int width = Minecraft.getMinecraft().displayWidth; - int height = Minecraft.getMinecraft().displayHeight; - - if(blurOutputHorz == null) { - blurOutputHorz = new Framebuffer(width, height, false); - blurOutputHorz.setFramebufferFilter(GL11.GL_NEAREST); - } - if(blurOutputVert == null) { - blurOutputVert = new Framebuffer(width, height, false); - blurOutputVert.setFramebufferFilter(GL11.GL_NEAREST); - } - if(blurOutputHorz.framebufferWidth != width || blurOutputHorz.framebufferHeight != height) { - blurOutputHorz.createBindFramebuffer(width, height); - blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); - Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); - } - if(blurOutputVert.framebufferWidth != width || blurOutputVert.framebufferHeight != height) { - blurOutputVert.createBindFramebuffer(width, height); - blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height)); - Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); - } - - if(blurShaderHorz == null) { - try { - blurShaderHorz = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", - Minecraft.getMinecraft().getFramebuffer(), blurOutputHorz); - blurShaderHorz.getShaderManager().getShaderUniform("BlurDir").set(1, 0); - blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); - } catch(Exception e) { } - } - if(blurShaderVert == null) { - try { - blurShaderVert = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", - blurOutputHorz, blurOutputVert); - blurShaderVert.getShaderManager().getShaderUniform("BlurDir").set(0, 1); - blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height)); - } catch(Exception e) { } - } - if(blurShaderHorz != null && blurShaderVert != null) { - if(15 != lastBgBlurFactor) { - blurShaderHorz.getShaderManager().getShaderUniform("Radius").set((float)15); - blurShaderVert.getShaderManager().getShaderUniform("Radius").set((float)15); - lastBgBlurFactor = 15; - } - GL11.glPushMatrix(); - blurShaderHorz.loadShader(0); - blurShaderVert.loadShader(0); - GlStateManager.enableDepth(); - GL11.glPopMatrix(); - - Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); - } - } - - /** - * Renders a subsection of the blurred framebuffer on to the corresponding section of the screen. - * Essentially, this method will "blur" the background inside the bounds specified by [x->x+blurWidth, y->y+blurHeight] - */ - public void renderBlurredBackground(int width, int height, int x, int y, int blurWidth, int blurHeight) { - if(!OpenGlHelper.isFramebufferEnabled()) return; - - float uMin = x/(float)width; - float uMax = (x+blurWidth)/(float)width; - float vMin = (height-y)/(float)height; - float vMax = (height-y-blurHeight)/(float)height; - - GlStateManager.depthMask(false); - blurOutputVert.bindFramebufferTexture(); - GlStateManager.color(1f, 1f, 1f, 1f); - Utils.drawTexturedRect(x, y, blurWidth, blurHeight, uMin, uMax, vMin, vMax); - blurOutputVert.unbindFramebufferTexture(); - GlStateManager.depthMask(true); - } - -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/CustomItemEffects.java b/src/main/java/io/github/moulberry/notenoughupdates/CustomItemEffects.java deleted file mode 100644 index 796d630c..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/CustomItemEffects.java +++ /dev/null @@ -1,850 +0,0 @@ -package io.github.moulberry.notenoughupdates; - -import io.github.moulberry.notenoughupdates.util.SpecialColour; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.block.state.BlockState; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.renderer.*; -import net.minecraft.client.renderer.block.model.BakedQuad; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.client.renderer.texture.TextureUtil; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.client.resources.model.IBakedModel; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTTagByteArray; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.util.*; -import net.minecraftforge.client.event.DrawBlockHighlightEvent; -import net.minecraftforge.client.event.EntityViewRenderEvent; -import net.minecraftforge.client.event.RenderBlockOverlayEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.event.entity.player.PlayerInteractEvent; -import net.minecraftforge.fml.common.Loader; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent; -import org.lwjgl.opengl.GL11; -import org.lwjgl.util.vector.Vector3f; -import scala.tools.cmd.Spec; - -import java.awt.*; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.*; -import java.util.List; - -public class CustomItemEffects { - - public static final CustomItemEffects INSTANCE = new CustomItemEffects(); - - private static final int MAX_BUILDERS_BLOCKS = 164; - - public long aoteUseMillis = 0; - public int aoteTeleportationMillis = 0; - public Vector3f aoteTeleportationCurr = null; - - public long lastMillis = 0; - - public Vector3f getCurrentPosition() { - if(aoteTeleportationMillis <= 0) return null; - return aoteTeleportationCurr; - } - - @SubscribeEvent - public void onTick(TickEvent.RenderTickEvent event) { - if(Minecraft.getMinecraft().thePlayer == null) return; - - long currentTime = System.currentTimeMillis(); - int delta = (int)(currentTime - lastMillis); - lastMillis = currentTime; - - if(delta <= 0) return; - - if(aoteTeleportationMillis > NotEnoughUpdates.INSTANCE.manager.config.smoothAoteMillis.value.intValue()*2) { - aoteTeleportationMillis = NotEnoughUpdates.INSTANCE.manager.config.smoothAoteMillis.value.intValue()*2; - } - if(aoteTeleportationMillis < 0) aoteTeleportationMillis = 0; - - if(currentTime - aoteUseMillis > 1000 && aoteTeleportationMillis <= 0) { - aoteTeleportationCurr = null; - } - - if(aoteTeleportationCurr != null) { - if(aoteTeleportationMillis > 0) { - int deltaMin = Math.min(delta, aoteTeleportationMillis); - - float factor = deltaMin/(float)aoteTeleportationMillis; - - float dX = aoteTeleportationCurr.x - (float)Minecraft.getMinecraft().thePlayer.posX; - float dY = aoteTeleportationCurr.y - (float)Minecraft.getMinecraft().thePlayer.posY; - float dZ = aoteTeleportationCurr.z - (float)Minecraft.getMinecraft().thePlayer.posZ; - - aoteTeleportationCurr.x -= dX*factor; - aoteTeleportationCurr.y -= dY*factor; - aoteTeleportationCurr.z -= dZ*factor; - - if(Minecraft.getMinecraft().theWorld.getBlockState(new BlockPos(aoteTeleportationCurr.x, - aoteTeleportationCurr.y, aoteTeleportationCurr.z)).getBlock().getMaterial() != Material.air) { - aoteTeleportationCurr.y = (float)Math.ceil(aoteTeleportationCurr.y); - } - - aoteTeleportationMillis -= deltaMin; - } else { - aoteTeleportationCurr.x = (float) Minecraft.getMinecraft().thePlayer.posX; - aoteTeleportationCurr.y = (float) Minecraft.getMinecraft().thePlayer.posY; - aoteTeleportationCurr.z = (float) Minecraft.getMinecraft().thePlayer.posZ; - } - } else { - aoteUseMillis = 0; - aoteTeleportationMillis = 0; - } - } - - @SubscribeEvent - public void onPlayerInteract(PlayerInteractEvent event) { - if(NotEnoughUpdates.INSTANCE.manager.config.smoothAoteMillis.value <= 0 - || Minecraft.getMinecraft().gameSettings.thirdPersonView != 0) return; - - if(event.action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR || event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) { - ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem(); - if(held != null) { - String internal = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(held); - if(internal != null && (internal.equals("ASPECT_OF_THE_END") || internal.equals("HYPERION"))) { - aoteUseMillis = System.currentTimeMillis(); - if(aoteTeleportationCurr == null) { - aoteTeleportationCurr = new Vector3f(); - aoteTeleportationCurr.x = (float) Minecraft.getMinecraft().thePlayer.posX; - aoteTeleportationCurr.y = (float) Minecraft.getMinecraft().thePlayer.posY; - aoteTeleportationCurr.z = (float) Minecraft.getMinecraft().thePlayer.posZ; - } - } - } - } - } - - @SubscribeEvent - public void onOverlayDrawn(RenderGameOverlayEvent event) { - if(!NotEnoughUpdates.INSTANCE.manager.config.disableWandOverlay.value && - Minecraft.getMinecraft().objectMouseOver != null && - Minecraft.getMinecraft().objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && - ((event.type == null && Loader.isModLoaded("labymod")) || - event.type == RenderGameOverlayEvent.ElementType.CROSSHAIRS)) { - - IBlockState hover = Minecraft.getMinecraft().theWorld.getBlockState( - Minecraft.getMinecraft().objectMouseOver.getBlockPos().offset( - Minecraft.getMinecraft().objectMouseOver.sideHit, 1)); - if(hover.getBlock() == Blocks.air) { - ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem(); - String heldInternal = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(held); - - if(heldInternal != null && heldInternal.equals("BUILDERS_WAND")) { - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - - HashSet candidatesOld = new HashSet<>(); - TreeMap> candidatesOldSorted = new TreeMap<>(); - - IBlockState match = Minecraft.getMinecraft().theWorld.getBlockState(Minecraft.getMinecraft().objectMouseOver.getBlockPos()); - Item matchItem = Item.getItemFromBlock(match.getBlock()); - if(matchItem != null) { - ItemStack matchStack = new ItemStack(matchItem, 1, - match.getBlock().getDamageValue(Minecraft.getMinecraft().theWorld, Minecraft.getMinecraft().objectMouseOver.getBlockPos())); - - getBuildersWandCandidates(Minecraft.getMinecraft().thePlayer, Minecraft.getMinecraft().objectMouseOver, event.partialTicks, - candidatesOld, candidatesOldSorted, 999-MAX_BUILDERS_BLOCKS); - - boolean usingDirtWand = false; - int itemCount; - if(match.getBlock() == Blocks.dirt && matchStack.getItemDamage() == 0 && hasDirtWand()) { - itemCount = candidatesOld.size(); - usingDirtWand = true; - } else { - itemCount = countItemsInInventoryAndStorage(matchStack); - } - - if(candidatesOld.size() > MAX_BUILDERS_BLOCKS) { - Utils.drawStringCentered(EnumChatFormatting.RED.toString()+candidatesOld.size()+"/"+MAX_BUILDERS_BLOCKS, - Minecraft.getMinecraft().fontRendererObj, - scaledResolution.getScaledWidth()/2f, scaledResolution.getScaledHeight()/2f+10, true, 0); - } else { - String pre = EnumChatFormatting.GREEN.toString(); - if(itemCount < candidatesOld.size()) { - pre = EnumChatFormatting.RED.toString(); - } - Utils.drawStringCentered(pre+Math.min(candidatesOld.size(), itemCount)+"/"+ - Math.min(candidatesOld.size(), MAX_BUILDERS_BLOCKS), - Minecraft.getMinecraft().fontRendererObj, - scaledResolution.getScaledWidth()/2f, scaledResolution.getScaledHeight()/2f+10, true, 0); - } - - String itemCountS = EnumChatFormatting.DARK_GRAY+"x"+EnumChatFormatting.RESET+itemCount; - int itemCountLen = Minecraft.getMinecraft().fontRendererObj.getStringWidth(itemCountS); - - if(NotEnoughUpdates.INSTANCE.manager.config.wandBlockCount.value) { - if(usingDirtWand) { - Utils.drawItemStack(new ItemStack(Items.gold_nugget), scaledResolution.getScaledWidth()/2 - (itemCountLen+16)/2, - scaledResolution.getScaledHeight()/2+10+4); - Minecraft.getMinecraft().fontRendererObj.drawString(itemCountS, - scaledResolution.getScaledWidth()/2f - (itemCountLen+16)/2f+11, scaledResolution.getScaledHeight()/2f+10+8, - -1, - true); - } else { - Utils.drawItemStack(matchStack, scaledResolution.getScaledWidth()/2 - (itemCountLen+16)/2, - scaledResolution.getScaledHeight()/2+10+4); - Minecraft.getMinecraft().fontRendererObj.drawString(itemCountS, - scaledResolution.getScaledWidth()/2f - (itemCountLen+16)/2f+16, scaledResolution.getScaledHeight()/2f+10+8, - -1, - true); - } - - } - - GlStateManager.color(1, 1, 1, 1); - } - - } - } - } - } - - public int countItemsInInventoryAndStorage(ItemStack match) { - int count = 0; - - for(ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { - if(match.isItemEqual(stack)) { - count += stack.stackSize; - } - } - - ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem(); - String heldInternal = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(held); - - if(heldInternal != null && heldInternal.equals("BUILDERS_WAND")) { - if(held.hasTagCompound() && held.getTagCompound().hasKey("ExtraAttributes", 10) && - held.getTagCompound().getCompoundTag("ExtraAttributes").hasKey("builder's_wand_data", 7)) { - byte[] bytes = held.getTagCompound().getCompoundTag("ExtraAttributes").getByteArray("builder's_wand_data"); - try { - NBTTagCompound contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(bytes)); - NBTTagList items = contents_nbt.getTagList("i", 10); - for(int j=0; j 0) { - if(buildersItem.getInteger("id") == Item.getIdFromItem(match.getItem()) && - buildersItem.getInteger("Damage") == match.getItemDamage()) { - count += items.getCompoundTagAt(j).getByte("Count"); - } - } - } - } catch(Exception e) { - return count; - } - } - } - - return count; - } - - public boolean hasDirtWand() { - for(ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { - String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); - if(internalname != null && internalname.equals("INFINIDIRT_WAND")) { - return true; - } - } - - ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem(); - String heldInternal = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(held); - - if(heldInternal != null && heldInternal.equals("BUILDERS_WAND")) { - if(held.hasTagCompound() && held.getTagCompound().hasKey("ExtraAttributes", 10) && - held.getTagCompound().getCompoundTag("ExtraAttributes").hasKey("builder's_wand_data", 7)) { - byte[] bytes = held.getTagCompound().getCompoundTag("ExtraAttributes").getByteArray("builder's_wand_data"); - try { - NBTTagCompound contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(bytes)); - NBTTagList items = contents_nbt.getTagList("i", 10); - for(int j=0; j 0) { - String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalnameFromNBT(buildersItem.getCompoundTag("tag")); - if(internalname != null && internalname.equals("INFINIDIRT_WAND")) { - return true; - } - } - } - } catch(Exception e) { - } - } - } - - return false; - } - - @SubscribeEvent - public void renderBlockOverlay(DrawBlockHighlightEvent event) { - if(aoteTeleportationCurr != null && aoteTeleportationMillis > 0) { - event.setCanceled(true); - } - ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem(); - String heldInternal = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(held); - if(heldInternal != null) { - EntityPlayer player = event.player; - double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double)event.partialTicks; - double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double)event.partialTicks; - double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double)event.partialTicks; - - if(!NotEnoughUpdates.INSTANCE.manager.config.disableTreecapOverlay.value && - (heldInternal.equals("JUNGLE_AXE") || heldInternal.equals("TREECAPITATOR_AXE"))) { - int maxWood = 10; - if(heldInternal.equals("TREECAPITATOR_AXE")) maxWood = 35; - - if (event.target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { - GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - GlStateManager.color(0.0F, 0.0F, 0.0F, 0.4F); - GlStateManager.disableTexture2D(); - GlStateManager.depthMask(false); - - if(Minecraft.getMinecraft().theWorld.getBlockState(event.target.getBlockPos()).getBlock() == Blocks.log || - Minecraft.getMinecraft().theWorld.getBlockState(event.target.getBlockPos()).getBlock() == Blocks.log2) { - - int woods = 0; - - HashSet candidatesOld = new HashSet<>(); - LinkedList candidates = new LinkedList<>(); - LinkedList candidatesNew = new LinkedList<>(); - - candidatesNew.add(event.target.getBlockPos()); - - while(woods < maxWood) { - if(candidatesNew.isEmpty()) { - break; - } - - candidates.addAll(candidatesNew); - candidatesNew.clear(); - - woods += candidates.size(); - boolean random = woods > maxWood; - - while(!candidates.isEmpty()) { - BlockPos candidate = candidates.pop(); - Block block = Minecraft.getMinecraft().theWorld.getBlockState(candidate).getBlock(); - - candidatesOld.add(candidate); - - for(int x = -1; x <= 1; x++) { - for(int y = -1; y <= 1; y++) { - for(int z = -1; z <= 1; z++) { - if(x != 0 || y != 0 || z != 0) { - BlockPos posNew = candidate.add(x, y, z); - if(!candidatesOld.contains(posNew) && !candidates.contains(posNew) && !candidatesNew.contains(posNew)) { - Block blockNew = Minecraft.getMinecraft().theWorld.getBlockState(posNew).getBlock(); - if(blockNew == Blocks.log || blockNew == Blocks.log2) { - candidatesNew.add(posNew); - } - } - } - } - } - } - - block.setBlockBoundsBasedOnState(Minecraft.getMinecraft().theWorld, candidate); - - drawFilledBoundingBox(block.getSelectedBoundingBox(Minecraft.getMinecraft().theWorld, candidate) - .expand(0.001D, 0.001D, 0.001D).offset(-d0, -d1, -d2), - random ? 0.5f : 1f, NotEnoughUpdates.INSTANCE.manager.config.treecapOverlayColour.value); - } - } - } - - GlStateManager.depthMask(true); - GlStateManager.enableTexture2D(); - GlStateManager.disableBlend(); - } - } else if(!NotEnoughUpdates.INSTANCE.manager.config.disableWandOverlay.value) { - if(heldInternal.equals("BUILDERS_WAND")) { - int maxBlocks = 164; - if (event.target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { - IBlockState hover = Minecraft.getMinecraft().theWorld.getBlockState(event.target.getBlockPos().offset(event.target.sideHit, 1)); - if(hover.getBlock() == Blocks.air) { - IBlockState match = Minecraft.getMinecraft().theWorld.getBlockState(event.target.getBlockPos()); - Item matchItem = Item.getItemFromBlock(match.getBlock()); - if(matchItem != null) { - GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - GlStateManager.disableTexture2D(); - GlStateManager.depthMask(false); - - HashSet candidatesOld = new HashSet<>(); - TreeMap> candidatesOldSorted = new TreeMap<>(); - - getBuildersWandCandidates(player, event.target, event.partialTicks, candidatesOld, candidatesOldSorted, 10); - - ItemStack matchStack = new ItemStack(matchItem, 1, match.getBlock().getMetaFromState(match)); - int itemCount; - if(match.getBlock() == Blocks.dirt && matchStack.getItemDamage() == 0 && hasDirtWand()) { - itemCount = candidatesOld.size(); - } else { - itemCount = countItemsInInventoryAndStorage(matchStack); - } - - String special = (candidatesOld.size() <= itemCount) ? NotEnoughUpdates.INSTANCE.manager.config.wandOverlayColour.value : - "0:255:255:0:0"; - - if(candidatesOld.size() <= maxBlocks) { - for(Set candidatesSorted : candidatesOldSorted.values()) { - for(BlockPos candidate : candidatesSorted) { - match.getBlock().setBlockBoundsBasedOnState(Minecraft.getMinecraft().theWorld, candidate); - AxisAlignedBB bb = match.getBlock().getSelectedBoundingBox(Minecraft.getMinecraft().theWorld, candidate) - .offset(event.target.sideHit.getFrontOffsetX(), event.target.sideHit.getFrontOffsetY(), - event.target.sideHit.getFrontOffsetZ()); - - drawBlock((int)bb.minX, (int)bb.minY, (int)bb.minZ+1, match, event.partialTicks, 0.75f); - } - } - - for(BlockPos candidate : candidatesOld) { - match.getBlock().setBlockBoundsBasedOnState(Minecraft.getMinecraft().theWorld, candidate); - AxisAlignedBB bb = match.getBlock().getSelectedBoundingBox(Minecraft.getMinecraft().theWorld, candidate) - .expand(0.001D, 0.001D, 0.001D).offset(-d0, -d1, -d2) - .offset(event.target.sideHit.getFrontOffsetX(), event.target.sideHit.getFrontOffsetY(), - event.target.sideHit.getFrontOffsetZ()); - - drawOutlineBoundingBox(bb, 1f, special); - } - } - - GlStateManager.depthMask(true); - GlStateManager.enableTexture2D(); - GlStateManager.disableBlend(); - } - } - } - } else if(heldInternal.equals("INFINIDIRT_WAND") && event.target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { - BlockPos hover = event.target.getBlockPos().offset(event.target.sideHit, 1); - IBlockState hoverState = Minecraft.getMinecraft().theWorld.getBlockState(event.target.getBlockPos().offset(event.target.sideHit, 1)); - if(hoverState.getBlock() == Blocks.air) { - GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - GlStateManager.disableTexture2D(); - GlStateManager.depthMask(false); - - String special = NotEnoughUpdates.INSTANCE.manager.config.wandOverlayColour.value; - - AxisAlignedBB bb = Blocks.dirt.getSelectedBoundingBox(Minecraft.getMinecraft().theWorld, hover); - drawBlock((int)bb.minX, (int)bb.minY, (int)bb.minZ+1, Blocks.dirt.getDefaultState(), - event.partialTicks, 0.75f); - - AxisAlignedBB bbExpanded = Blocks.dirt.getSelectedBoundingBox(Minecraft.getMinecraft().theWorld, hover) - .expand(0.001D, 0.001D, 0.001D).offset(-d0, -d1, -d2); - drawOutlineBoundingBox(bbExpanded, 1f, special); - - GlStateManager.depthMask(true); - GlStateManager.enableTexture2D(); - GlStateManager.disableBlend(); - } - } else if((heldInternal.equals("WATER_BUCKET") || heldInternal.equals("MAGICAL_WATER_BUCKET")) && - event.target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { - BlockPos hover = event.target.getBlockPos().offset(event.target.sideHit, 1); - - HashSet verticalSources = new HashSet<>(); - TreeMap> watersSorted = new TreeMap<>(); - - for(int xOff=-1; xOff<=1; xOff++) { - for(int yOff=0; yOff<=1; yOff++) { - for(int zOff=-1; zOff<=1; zOff++) { - if((xOff == 0 && yOff == 0) || - (xOff == 0 && zOff == 0) || - (zOff == 0 && yOff == 0)) { - - BlockPos checkPos = hover.add(-xOff, -yOff, -zOff); - IBlockState check = Minecraft.getMinecraft().theWorld.getBlockState(checkPos); - if(check.getBlock() == Blocks.prismarine && check.getBlock().getMetaFromState(check) == 2) { - for(int i=0; i<300; i++) { - BlockPos renderPos = hover.add(xOff*i, yOff*i, zOff*i); - - if(Math.abs(renderPos.getX()) > 128) { - break; - } - if(Math.abs(renderPos.getY()) > 255) { - break; - } - if(Math.abs(renderPos.getZ()) > 128) { - break; - } - - IBlockState renderState = Minecraft.getMinecraft().theWorld.getBlockState(renderPos); - - if(renderState.getBlock() != Blocks.air && renderState.getBlock() != Blocks.water && - renderState.getBlock() != Blocks.flowing_water) { - break; - } - - if(yOff != 0) { - verticalSources.add(renderPos); - } else { - IBlockState belowState = Minecraft.getMinecraft().theWorld.getBlockState(renderPos.add(0, -1, 0)); - if(belowState.getBlock() == Blocks.air) { - break; - } - } - - for(EnumFacing facing : EnumFacing.values()) { - float xDist = (float)(renderPos.getX()+0.5f+0.5f*facing.getFrontOffsetX()-d0); - float yDist = (float)(renderPos.getY()+0.5f+0.5f*facing.getFrontOffsetY()-d1-player.getEyeHeight()); - float zDist = (float)(renderPos.getZ()+0.5f+0.5f*facing.getFrontOffsetZ()-d2); - - float distSq = xDist*xDist + yDist*yDist + zDist*zDist; - - watersSorted.computeIfAbsent(distSq, k->new HashMap<>()).put(renderPos, facing); - } - - } - } - } - } - } - } - - GlStateManager.enableDepth(); - GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - GlStateManager.disableTexture2D(); - GlStateManager.depthMask(true); - - for(HashMap blockPoses : watersSorted.values()) { - for(Map.Entry entry : blockPoses.entrySet()) { - boolean vertical = verticalSources.contains(entry.getKey()); - AxisAlignedBB bbExpanded = Blocks.water.getSelectedBoundingBox(Minecraft.getMinecraft().theWorld, entry.getKey()) - .expand(-0.001D, -0.001D-(vertical?0:0.0625D), -0.001D) - .offset(-d0, -d1-(vertical?0:0.0625), -d2); - drawFilledBoundingBoxSide(bbExpanded, entry.getValue(), 1f, "0:100:20:50:160"); - } - } - - GlStateManager.depthMask(true); - GlStateManager.enableTexture2D(); - GlStateManager.disableBlend(); - } else if((heldInternal.equals("HOE_OF_GREAT_TILLING") || heldInternal.equals("HOE_OF_GREATER_TILLING")) && - event.target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { - BlockPos target = event.target.getBlockPos(); - IBlockState targetState = Minecraft.getMinecraft().theWorld.getBlockState(target); - - int radius = heldInternal.equals("HOE_OF_GREAT_TILLING") ? 1 : 2; - - if(targetState.getBlock() == Blocks.dirt || targetState.getBlock() == Blocks.grass) { - GlStateManager.enableDepth(); - GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - GlStateManager.disableTexture2D(); - GlStateManager.depthMask(true); - - for(int xOff=-radius; xOff<=radius; xOff++) { - for(int zOff=-radius; zOff<=radius; zOff++) { - BlockPos renderPos = target.add(xOff, 0, zOff); - IBlockState renderState = Minecraft.getMinecraft().theWorld.getBlockState(renderPos); - if(renderState.getBlock() == Blocks.dirt || renderState.getBlock() == Blocks.grass) { - AxisAlignedBB bbExpanded = Blocks.dirt.getSelectedBoundingBox(Minecraft.getMinecraft().theWorld, renderPos) - .expand(0.001D, 0.001D, 0.001D) - .offset(-d0, -d1, -d2); - drawFilledBoundingBox(bbExpanded, 1f, "0:100:178:34:34"); - } - } - } - - GlStateManager.depthMask(true); - GlStateManager.enableTexture2D(); - GlStateManager.disableBlend(); - } - } - } - } - } - - public void getBuildersWandCandidates(EntityPlayer player, MovingObjectPosition target, float partialTicks, - HashSet candidatesOld, TreeMap> candidatesOldSorted, int extraMax) { - IBlockState match = Minecraft.getMinecraft().theWorld.getBlockState(target.getBlockPos()); - - candidatesOld.clear(); - candidatesOldSorted.clear(); - LinkedList candidates = new LinkedList<>(); - LinkedList candidatesNew = new LinkedList<>(); - - candidatesNew.add(target.getBlockPos()); - - double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double)partialTicks; - double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double)partialTicks; - double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double)partialTicks; - - while(candidatesOld.size() <= MAX_BUILDERS_BLOCKS+extraMax) { - if(candidatesNew.isEmpty()) { - break; - } - - candidates.addAll(candidatesNew); - candidatesNew.clear(); - - while(!candidates.isEmpty()) { - if(candidatesOld.size() > MAX_BUILDERS_BLOCKS+extraMax) break; - - BlockPos candidate = candidates.pop(); - - float distSq = (float)((candidate.getX()+0.5f-d0)*(candidate.getX()+0.5f-d0) + - (candidate.getY()+0.5f-d1-player.getEyeHeight())*(candidate.getY()+0.5f-d1-player.getEyeHeight()) + - (candidate.getZ()+0.5f-d2)*(candidate.getZ()+0.5f-d2)); - candidatesOldSorted.computeIfAbsent(distSq, k->new HashSet<>()).add(candidate); - - candidatesOld.add(candidate); - - for(int x = -1; x <= 1; x++) { - for(int y = -1; y <= 1; y++) { - for(int z = -1; z <= 1; z++) { - if(x*x+y*y+z*z == 1) { - if(((x == 0) && (target.sideHit.getAxis() == EnumFacing.Axis.X)) || - ((y == 0) && (target.sideHit.getAxis() == EnumFacing.Axis.Y)) || - ((z == 0) && (target.sideHit.getAxis() == EnumFacing.Axis.Z))) { - if(Minecraft.getMinecraft().theWorld.getBlockState(candidate.add( - x+target.sideHit.getFrontOffsetX(), - y+target.sideHit.getFrontOffsetY(), - z+target.sideHit.getFrontOffsetZ())).getBlock() == Blocks.air) { - BlockPos posNew = candidate.add(x, y, z); - if(!candidatesOld.contains(posNew) && !candidates.contains(posNew) && !candidatesNew.contains(posNew)) { - IBlockState blockNew = Minecraft.getMinecraft().theWorld.getBlockState(posNew); - if(blockNew == match) { - candidatesNew.add(posNew); - } - } - } - } - } - } - } - } - } - } - } - - public static void drawBlock(int x, int y, int z, IBlockState state, float partialTicks, float brightness) { - EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; - double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double)partialTicks; - double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double)partialTicks; - double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double)partialTicks; - - BlockRendererDispatcher blockrendererdispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher(); - - GlStateManager.enableTexture2D(); - GlStateManager.disableLighting(); - GlStateManager.enableBlend(); - GlStateManager.blendFunc(770, 771); - - GlStateManager.enableDepth(); - GlStateManager.depthMask(true); - GlStateManager.enableCull(); - GlStateManager.cullFace(GL11.GL_BACK); - - GlStateManager.pushMatrix(); - GlStateManager.translate(x-d0, y-d1, z-d2); - - int i = state.getBlock().getRenderType(); - if(i == 3) { - IBakedModel ibakedmodel = blockrendererdispatcher.getModelFromBlockState(state, Minecraft.getMinecraft().theWorld, null); - - Block block = state.getBlock(); - block.setBlockBoundsForItemRender(); - GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F); - int colour = block.getRenderColor(block.getStateForEntityRender(state)); - - if (EntityRenderer.anaglyphEnable) { - colour = TextureUtil.anaglyphColor(i); - } - - colour = (colour & 0x00FFFFFF) | (100 << 24); //Set alpha to 100 - - for (EnumFacing enumfacing : EnumFacing.values()) { - renderModelBrightnessColorQuads(colour, ibakedmodel.getFaceQuads(enumfacing)); - } - - renderModelBrightnessColorQuads(colour, ibakedmodel.getGeneralQuads()); - } - - GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - GlStateManager.translate(-x+d0, -y+d1, -z+d2); - GlStateManager.popMatrix(); - } - - private static void renderModelBrightnessColorQuads(int c, List listQuads) { - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldrenderer = tessellator.getWorldRenderer(); - - for (BakedQuad bakedquad : listQuads) { - worldrenderer.begin(7, DefaultVertexFormats.ITEM); - worldrenderer.addVertexData(bakedquad.getVertexData()); - - worldrenderer.putColor4(c); - - Vec3i vec3i = bakedquad.getFace().getDirectionVec(); - worldrenderer.putNormal((float)vec3i.getX(), (float)vec3i.getY(), (float)vec3i.getZ()); - tessellator.draw(); - } - } - - public static void drawFilledBoundingBox(AxisAlignedBB p_181561_0_, float alpha, String special) { - Color c = new Color(SpecialColour.specialToChromaRGB(special), true); - GlStateManager.color(c.getRed()/255f, c.getGreen()/255f, c.getBlue()/255f, c.getAlpha()/255f*alpha); - - GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - GlStateManager.disableTexture2D(); - - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldrenderer = tessellator.getWorldRenderer(); - - //vertical - worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); - tessellator.draw(); - worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); - tessellator.draw(); - //x - - worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); - tessellator.draw(); - worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); - tessellator.draw(); - - //z - worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); - tessellator.draw(); - worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); - tessellator.draw(); - - } - - public static void drawFilledBoundingBoxSide(AxisAlignedBB p_181561_0_, EnumFacing facing, float alpha, String special) { - Color c = new Color(SpecialColour.specialToChromaRGB(special), true); - GlStateManager.color(c.getRed()/255f, c.getGreen()/255f, c.getBlue()/255f, c.getAlpha()/255f*alpha); - - GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - GlStateManager.disableTexture2D(); - - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldrenderer = tessellator.getWorldRenderer(); - worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); - switch(facing) { - case UP: - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); - break; - case DOWN: - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); - break; - case EAST: - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); - break; - case WEST: - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); - break; - case SOUTH: - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); - break; - case NORTH: - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); - break; - } - tessellator.draw(); - } - - public static void drawOutlineBoundingBox(AxisAlignedBB p_181561_0_, float alpha, String special) { - Color c = new Color(SpecialColour.specialToChromaRGB(special), true); - GlStateManager.color(c.getRed()/255f, c.getGreen()/255f, c.getBlue()/255f, c.getAlpha()/255f*alpha); - - GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - GlStateManager.disableTexture2D(); - GlStateManager.depthMask(false); - - GL11.glLineWidth(3); - - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldrenderer = tessellator.getWorldRenderer(); - worldrenderer.begin(3, DefaultVertexFormats.POSITION); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); - tessellator.draw(); - worldrenderer.begin(3, DefaultVertexFormats.POSITION); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); - tessellator.draw(); - worldrenderer.begin(1, DefaultVertexFormats.POSITION); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); - worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); - worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); - tessellator.draw(); - - GL11.glLineWidth(1); - } - -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/GuiEnchantColour.java b/src/main/java/io/github/moulberry/notenoughupdates/GuiEnchantColour.java deleted file mode 100644 index c450c6f4..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/GuiEnchantColour.java +++ /dev/null @@ -1,257 +0,0 @@ -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; -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; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -public class GuiEnchantColour extends GuiScreen { - - public static final ResourceLocation custom_ench_colour = new ResourceLocation("notenoughupdates:custom_ench_colour.png"); - - private int guiLeft; - private int guiTop; - private final int xSize = 176; - private int ySize = 0; - - private List getEnchantColours() { - return NotEnoughUpdates.INSTANCE.manager.config.enchantColours.value; - } - - public static final Splitter splitter = Splitter.on(":").limit(4); - - private HashMap comparators = new HashMap<>(); - private List guiElementTextFields = new ArrayList<>(); - - private LerpingInteger scroll = new LerpingInteger(0, 100); - - @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { - drawDefaultBackground(); - - List enchantColours = getEnchantColours(); - - ySize = 53+25*enchantColours.size(); - guiLeft = (width-xSize)/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(); - - Minecraft.getMinecraft().getTextureManager().bindTexture(custom_ench_colour); - Utils.drawTexturedRect(guiLeft, guiTop, xSize, 21, 0, 1, 0, 21/78f, GL11.GL_NEAREST); - Utils.drawTexturedRect(guiLeft, guiTop+ySize-32, xSize, 32, 0, 1, 46/78f, 1, GL11.GL_NEAREST); - - fontRendererObj.drawString("Ench Name", guiLeft+10, guiTop+7, 4210752); - fontRendererObj.drawString("CMP", guiLeft+71, guiTop+7, 4210752); - fontRendererObj.drawString("LVL", guiLeft+96, guiTop+7, 4210752); - fontRendererObj.drawString("COL", guiLeft+121, guiTop+7, 4210752); - fontRendererObj.drawString("DEL", guiLeft+146, guiTop+7, 4210752); - - Utils.drawStringCentered("Add Ench Colour", fontRendererObj, guiLeft+xSize/2, guiTop+ySize-20, false, 4210752); - - int yIndex = 0; - for(String str : enchantColours) { - Minecraft.getMinecraft().getTextureManager().bindTexture(custom_ench_colour); - GlStateManager.color(1, 1, 1, 1); - Utils.drawTexturedRect(guiLeft, guiTop+21+yIndex*25, xSize, 25, 0, 1, 21/78f, 46/78f, GL11.GL_NEAREST); - - List colourOps = splitter.splitToList(str); - String enchantName = getColourOpIndex(colourOps, 0); - String comparator = getColourOpIndex(colourOps, 1); - String comparison = getColourOpIndex(colourOps, 2); - String colourCode = getColourOpIndex(colourOps, 3); - - if(colourCode.length() > 1) colourCode = String.valueOf(colourCode.toLowerCase().charAt(0)); - if(comparator.length() > 1) comparator = String.valueOf(comparator.toLowerCase().charAt(0)); - - Utils.drawStringCentered(comparator, fontRendererObj, guiLeft+81, guiTop+33+25*yIndex, false, 4210752); - - if(guiElementTextFields.size() <= yIndex) { - guiElementTextFields.add(new GuiElementTextField[3]); - } - if(guiElementTextFields.get(yIndex)[0] == null) { - guiElementTextFields.get(yIndex)[0] = new GuiElementTextField(enchantName, GuiElementTextField.SCALE_TEXT); - guiElementTextFields.get(yIndex)[0].setSize(56, 20); - } - if(guiElementTextFields.get(yIndex)[1] == null) { - guiElementTextFields.get(yIndex)[1] = new GuiElementTextField(comparison, - GuiElementTextField.SCALE_TEXT|GuiElementTextField.NUM_ONLY|GuiElementTextField.NO_SPACE); - guiElementTextFields.get(yIndex)[1].setSize(20, 20); - } - if(guiElementTextFields.get(yIndex)[2] == null) { - guiElementTextFields.get(yIndex)[2] = new GuiElementTextField(colourCode, GuiElementTextField.SCALE_TEXT); - guiElementTextFields.get(yIndex)[2].setSize(20, 20); - } - guiElementTextFields.get(yIndex)[0].setText(enchantName); - guiElementTextFields.get(yIndex)[1].setText(comparison); - comparators.put(yIndex, comparator); - guiElementTextFields.get(yIndex)[2].setText(colourCode); - - guiElementTextFields.get(yIndex)[0].render(guiLeft+10, guiTop+23+25*yIndex); - guiElementTextFields.get(yIndex)[1].render(guiLeft+96, guiTop+23+25*yIndex); - guiElementTextFields.get(yIndex)[2].render(guiLeft+121, guiTop+23+25*yIndex); - - yIndex++; - } - } - - @Override - protected void keyTyped(char typedChar, int keyCode) throws IOException { - super.keyTyped(typedChar, keyCode); - for(int yIndex=0; yIndex NotEnoughUpdates.INSTANCE.manager.config.enchantColours.value.size()) { - addOffset = NotEnoughUpdates.INSTANCE.manager.config.enchantColours.value.size()-yIndex; - } - System.out.println(addOffset); - NotEnoughUpdates.INSTANCE.manager.config.enchantColours.value.add(yIndex+addOffset, - getEnchantOpString(guiElementTextFields.get(yIndex), comparators.get(yIndex))); - NotEnoughUpdates.INSTANCE.manager.saveConfig(); - if(addOffset != 0) { - GuiElementTextField[] guiElementTextFieldArray = guiElementTextFields.remove(yIndex); - guiElementTextFields.add(yIndex+addOffset, guiElementTextFieldArray); - } - return; - } - } - } - } - - public String getEnchantOpString(GuiElementTextField[] tfs, String comparator) { - StringBuilder enchantOp = new StringBuilder(); - enchantOp.append(tfs[0].getText()); - enchantOp.append(":"); - enchantOp.append(comparator); - enchantOp.append(":"); - enchantOp.append(tfs[1].getText()); - enchantOp.append(":"); - enchantOp.append(tfs[2].getText()); - return enchantOp.toString(); - } - - @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 x && mouseX < x+guiElementTextFields.get(yIndex)[i].getWidth()) { - if(mouseY > guiTop+23+25*yIndex && mouseY < guiTop+23+25*yIndex+20) { - guiElementTextFields.get(yIndex)[i].mouseClicked(mouseX, mouseY, mouseButton); - if(mouseButton == 1) { - NotEnoughUpdates.INSTANCE.manager.config.enchantColours.value.remove(yIndex); - NotEnoughUpdates.INSTANCE.manager.config.enchantColours.value.add(yIndex, - getEnchantOpString(guiElementTextFields.get(yIndex), comparators.get(yIndex))); - NotEnoughUpdates.INSTANCE.manager.saveConfig(); - } - continue; - } - } - guiElementTextFields.get(yIndex)[i].otherComponentClick(); - } - comparators.computeIfAbsent(yIndex, k->">"); - if(mouseY > guiTop+23+25*yIndex && mouseY < guiTop+23+25*yIndex+20) { - if(mouseX > guiLeft+71 && mouseX < guiLeft+71+20) { - switch (comparators.get(yIndex)) { - case ">": - comparators.put(yIndex, "="); break; - case "=": - comparators.put(yIndex, "<"); break; - default: - comparators.put(yIndex, ">"); break; - } - NotEnoughUpdates.INSTANCE.manager.config.enchantColours.value.remove(yIndex); - NotEnoughUpdates.INSTANCE.manager.config.enchantColours.value.add(yIndex, - getEnchantOpString(guiElementTextFields.get(yIndex), comparators.get(yIndex))); - NotEnoughUpdates.INSTANCE.manager.saveConfig(); - } else if(mouseX > guiLeft+146 && mouseX < guiLeft+146+20) { - NotEnoughUpdates.INSTANCE.manager.config.enchantColours.value.remove(yIndex); - guiElementTextFields.remove(yIndex); - comparators.remove(yIndex); - NotEnoughUpdates.INSTANCE.manager.saveConfig(); - } - } - } - if(mouseX >= guiLeft+42 && mouseX <= guiLeft+42+88) { - if(mouseY >= guiTop+ySize-30 && mouseY <= guiTop+ySize-10) { - NotEnoughUpdates.INSTANCE.manager.config.enchantColours.value.add("[a-zA-Z\\- ]+:>:5:9"); - NotEnoughUpdates.INSTANCE.manager.saveConfig(); - } - } - } - - public static String getColourOpIndex(List colourOps, int index) { - if(colourOps.size() > index) { - return colourOps.get(index); - } else { - switch(index) { - case 0: - return "[a-zA-Z\\- ]+"; - case 1: - return ">"; - case 2: - return "5"; - case 3: - return "9"; - } - } - return null; - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java deleted file mode 100644 index c4040f60..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/GuiItemRecipe.java +++ /dev/null @@ -1,241 +0,0 @@ -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; -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.resources.I18n; -import net.minecraft.inventory.ContainerWorkbench; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; -import net.minecraft.inventory.SlotCrafting; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; -import org.lwjgl.util.vector.Vector2f; -import org.lwjgl.util.vector.Vector3f; - -import java.awt.*; -import java.io.IOException; -import java.util.List; - -public class GuiItemRecipe extends GuiScreen { - - private static final ResourceLocation resourcePacksTexture = new ResourceLocation("textures/gui/resource_packs.png"); - private static final ResourceLocation craftingTableGuiTextures = new ResourceLocation("textures/gui/container/crafting_table.png"); - - private List craftMatrices; - private List results; - private int currentIndex = 0; - - private String title; - private NEUManager manager; - - public int guiLeft = 0; - public int guiTop = 0; - public int xSize = 176; - public int ySize = 166; - - public GuiItemRecipe(String title, List craftMatrices, List results, NEUManager manager) { - this.craftMatrices = craftMatrices; - this.results = results; - this.manager = manager; - this.title = title; - } - - private String getCraftText() { - if(results.get(currentIndex).has("crafttext")) { - return results.get(currentIndex).get("crafttext").getAsString(); - } else { - return ""; - } - } - - @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { - drawDefaultBackground(); - - if(currentIndex < 0) { - currentIndex = 0; - } else if(currentIndex >= craftMatrices.size()) { - currentIndex = craftMatrices.size()-1; - } - - FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRendererObj; - - this.guiLeft = (width - this.xSize) / 2; - this.guiTop = (height - this.ySize) / 2; - - GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - Minecraft.getMinecraft().getTextureManager().bindTexture(craftingTableGuiTextures); - this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, this.xSize, this.ySize); - - List tooltipToRender = null; - for(int index=0; index <= 45; index++) { - Vector2f pos = getPositionForIndex(index); - Utils.drawItemStack(getStackForIndex(index), (int)pos.x, (int)pos.y); - - if(mouseX > pos.x && mouseX < pos.x+16) { - if(mouseY > pos.y && mouseY < pos.y+16) { - ItemStack stack = getStackForIndex(index); - if(stack != null) { - tooltipToRender = stack.getTooltip(Minecraft.getMinecraft().thePlayer, false); - } - } - } - } - - if(craftMatrices.size() > 1) { - int guiX = mouseX - guiLeft; - int guiY = mouseY - guiTop; - - int buttonWidth = 7; - int buttonHeight = 11; - - boolean leftSelected = false; - boolean rightSelected = false; - - if(guiY > + 63 && guiY < + 63 + buttonHeight) { - if(guiX > + 110 && guiX < 110 + buttonWidth) { - leftSelected = true; - } else if(guiX > 147 && guiX < 147 + buttonWidth) { - rightSelected = true; - } - } - - Minecraft.getMinecraft().getTextureManager().bindTexture(resourcePacksTexture); - //Left arrow - Utils.drawTexturedRect(guiLeft+110, guiTop+63, 7, 11, 34/256f, 48/256f, - 5/256f + (leftSelected ? 32/256f : 0), 27/256f + (leftSelected ? 32/256f : 0)); - //Right arrow - Utils.drawTexturedRect(guiLeft+147, guiTop+63, 7, 11, 10/256f, 24/256f, - 5/256f + (rightSelected ? 32/256f : 0), 27/256f + (rightSelected ? 32/256f : 0)); - GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); - - String str = (currentIndex+1)+"/"+craftMatrices.size(); - Utils.drawStringCenteredScaledMaxWidth(str, fontRendererObj, guiLeft+132, guiTop+69, - false, 24, Color.BLACK.getRGB()); - } - - Utils.drawStringCenteredScaledMaxWidth(getCraftText(), fontRendererObj, guiLeft+132, guiTop+25, - false, 75, 4210752); - - Utils.drawStringScaledMaxWidth(title, fontRendererObj, guiLeft+28, guiTop+6, title.contains("\u00a7"), xSize-38, 4210752); - - if(tooltipToRender != null) { - Utils.drawHoveringText(tooltipToRender, mouseX, mouseY, width, height, -1, fontRendererObj); - } - } - - public ItemStack getStackForIndex(int index) { - if(index == 0) { - return manager.jsonToStack(results.get(currentIndex)); - } else if(index >= 1 && index <= 9) { - return craftMatrices.get(currentIndex)[index-1]; - } else { - return Minecraft.getMinecraft().thePlayer.inventory.getStackInSlot(index-10); - } - } - - public Vector2f getPositionForIndex(int index) { - //0 = result - //1-9 = craft matrix - //10-18 = hotbar - //19-45 = player inv - - if(index == 0) { - return new Vector2f(guiLeft+124, guiTop+35); - } else if(index >= 1 && index <= 9) { - index -= 1; - int x = index % 3; - int y = index / 3; - return new Vector2f(guiLeft+30 + x*18, guiTop+17 + y * 18); - } else if(index >= 10 && index <= 18) { - index -= 10; - return new Vector2f(guiLeft+8 + index*18, guiTop+142); - } else if(index >= 19 && index <= 45) { - index -= 19; - int x = index % 9; - int y = index / 9; - return new Vector2f(guiLeft+8 + x*18, guiTop+84 + y*18); - } - return null; - } - - @Override - public void handleKeyboardInput() throws IOException { - super.handleKeyboardInput(); - - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - int width = scaledResolution.getScaledWidth(); - int height = scaledResolution.getScaledHeight(); - int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; - int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; - - int keyPressed = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter()+256 : Keyboard.getEventKey(); - - for(int index=0; index <= 45; index++) { - Vector2f pos = getPositionForIndex(index); - if(mouseX > pos.x && mouseX < pos.x+16) { - if(mouseY > pos.y && mouseY < pos.y+16) { - ItemStack stack = getStackForIndex(index); - if(stack != null) { - if(keyPressed == manager.keybindViewRecipe.getKeyCode()) { - manager.displayGuiItemRecipe(manager.getInternalNameForItem(stack), ""); - } else if(keyPressed == manager.keybindViewUsages.getKeyCode()) { - manager.displayGuiItemUsages(manager.getInternalNameForItem(stack)); - } - } - return; - } - } - } - } - - @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { - super.mouseClicked(mouseX, mouseY, mouseButton); - - int guiX = mouseX - guiLeft; - int guiY = mouseY - guiTop; - - int buttonWidth = 7; - int buttonHeight = 11; - - if(guiY > + 63 && guiY < + 63 + buttonHeight) { - if(guiX > + 110 && guiX < 110 + buttonWidth) { - currentIndex--; - Utils.playPressSound(); - return; - } else if(guiX > 147 && guiX < 147 + buttonWidth) { - currentIndex++; - Utils.playPressSound(); - return; - } - } - - for(int index=0; index <= 45; index++) { - Vector2f pos = getPositionForIndex(index); - if(mouseX > pos.x && mouseX < pos.x+16) { - if(mouseY > pos.y && mouseY < pos.y+16) { - ItemStack stack = getStackForIndex(index); - if(stack != null) { - if(mouseButton == 0) { - manager.displayGuiItemRecipe(manager.getInternalNameForItem(stack), ""); - } else if(mouseButton == 1) { - manager.displayGuiItemUsages(manager.getInternalNameForItem(stack)); - } - } - return; - } - } - } - } - -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java b/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java deleted file mode 100644 index 141ffefb..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/GuiTextures.java +++ /dev/null @@ -1,81 +0,0 @@ -package io.github.moulberry.notenoughupdates; - -import net.minecraft.util.ResourceLocation; - -public class GuiTextures { - - private GuiTextures() {} //Not instantiable. Use import static to access class members. - - public static final ResourceLocation itemPaneTabArrow = new ResourceLocation("notenoughupdates:item_pane_tab_arrow.png"); - //public static final ResourceLocation prev = new ResourceLocation("notenoughupdates:prev.png"); - //public static final ResourceLocation next = new ResourceLocation("notenoughupdates:next.png"); - public static final ResourceLocation rightarrow_overlay = new ResourceLocation("notenoughupdates:rightarrow_overlay.png"); - public static final ResourceLocation rightarrow = new ResourceLocation("notenoughupdates:rightarrow.png"); - public static final ResourceLocation close = new ResourceLocation("notenoughupdates:close.png"); - public static final ResourceLocation settings = new ResourceLocation("notenoughupdates:settings.png"); - - public static final ResourceLocation off = new ResourceLocation("notenoughupdates:off.png"); - public static final ResourceLocation on = new ResourceLocation("notenoughupdates:on.png"); - public static final ResourceLocation help = new ResourceLocation("notenoughupdates:help.png"); - public static final ResourceLocation slider_off = new ResourceLocation("notenoughupdates:slider_off.png"); - public static final ResourceLocation slider_on = new ResourceLocation("notenoughupdates:slider_on.png"); - public static final ResourceLocation slider_off_large = new ResourceLocation("notenoughupdates:slider_off_large.png"); - public static final ResourceLocation slider_on_large = new ResourceLocation("notenoughupdates:slider_on_large.png"); - public static final ResourceLocation slider_button = new ResourceLocation("notenoughupdates:slider_button.png"); - - public static final ResourceLocation item_mask = new ResourceLocation("notenoughupdates:item_mask.png"); - 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 setting_border = new ResourceLocation("notenoughupdates:setting_border.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"); - - public static final ResourceLocation gamemodes = new ResourceLocation("notenoughupdates:gamemodes.png"); - public static final ResourceLocation radial_square_off = new ResourceLocation("notenoughupdates:radial_square_off.png"); - public static final ResourceLocation radial_square_on = new ResourceLocation("notenoughupdates:radial_square_on.png"); - public static final ResourceLocation radial_circle_off = new ResourceLocation("notenoughupdates:radial_circle_off.png"); - public static final ResourceLocation radial_circle_on = new ResourceLocation("notenoughupdates:radial_circle_on.png"); - - public static final ResourceLocation dungeon_chest_worth = new ResourceLocation("notenoughupdates:dungeon_chest_worth.png"); - - public static final ResourceLocation auction_view = new ResourceLocation("notenoughupdates:auction_view.png"); - public static final ResourceLocation auction_accept = new ResourceLocation("notenoughupdates:auction_accept.png"); - public static final ResourceLocation auction_price = new ResourceLocation("notenoughupdates:auction_price.png"); - public static final ResourceLocation auction_view_buttons = new ResourceLocation("notenoughupdates:auction_view_buttons.png"); - - public static final ResourceLocation logo = new ResourceLocation("notenoughupdates:logo.png"); - public static final ResourceLocation logo_fg = new ResourceLocation("notenoughupdates:logo_fg.png"); - public static final ResourceLocation logo_bg = new ResourceLocation("notenoughupdates:logo_bg.png"); - - public static final ResourceLocation sort_all = new ResourceLocation("notenoughupdates:sort_all.png"); - public static final ResourceLocation sort_mob = new ResourceLocation("notenoughupdates:sort_mob.png"); - public static final ResourceLocation sort_pet = new ResourceLocation("notenoughupdates:sort_pet.png"); - public static final ResourceLocation sort_tool = new ResourceLocation("notenoughupdates:sort_weapon.png"); - public static final ResourceLocation sort_armor = new ResourceLocation("notenoughupdates:sort_armor.png"); - public static final ResourceLocation sort_accessory = new ResourceLocation("notenoughupdates:sort_accessory.png"); - public static final ResourceLocation sort_all_active = new ResourceLocation("notenoughupdates:sort_all_active.png"); - public static final ResourceLocation sort_mob_active = new ResourceLocation("notenoughupdates:sort_mob_active.png"); - public static final ResourceLocation sort_pet_active = new ResourceLocation("notenoughupdates:sort_pet_active.png"); - public static final ResourceLocation sort_tool_active = new ResourceLocation("notenoughupdates:sort_weapon_active.png"); - public static final ResourceLocation sort_armor_active = new ResourceLocation("notenoughupdates:sort_armor_active.png"); - public static final ResourceLocation sort_accessory_active = new ResourceLocation("notenoughupdates:sort_accessory_active.png"); - - public static final ResourceLocation order_alphabetical = new ResourceLocation("notenoughupdates:order_alphabetical.png"); - public static final ResourceLocation order_rarity = new ResourceLocation("notenoughupdates:order_rarity.png"); - public static final ResourceLocation order_value = new ResourceLocation("notenoughupdates:order_value.png"); - public static final ResourceLocation order_alphabetical_active = new ResourceLocation("notenoughupdates:order_alphabetical_active.png"); - public static final ResourceLocation order_rarity_active = new ResourceLocation("notenoughupdates:order_rarity_active.png"); - public static final ResourceLocation order_value_active = new ResourceLocation("notenoughupdates:order_value_active.png"); - public static final ResourceLocation ascending_overlay = new ResourceLocation("notenoughupdates:ascending_overlay.png"); - public static final ResourceLocation descending_overlay = new ResourceLocation("notenoughupdates:descending_overlay.png"); - -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/HelpGUI.java b/src/main/java/io/github/moulberry/notenoughupdates/HelpGUI.java deleted file mode 100644 index 1049dc55..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/HelpGUI.java +++ /dev/null @@ -1,189 +0,0 @@ -package io.github.moulberry.notenoughupdates; - -import io.github.moulberry.notenoughupdates.util.TexLoc; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.input.Keyboard; -import org.lwjgl.util.vector.Vector2f; - -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class HelpGUI extends GuiScreen { - - private int guiLeft = 0; - private int guiTop = 0; - private int sizeX = 0; - private int sizeY = 0; - - private int page = 0; - private ResourceLocation screenshotBorder = new ResourceLocation("notenoughupdates:ss_border.jpg"); - private ResourceLocation[] screenshots = null; - - int scaleFactor = 0; - - @Override - public void setWorldAndResolution(Minecraft mc, int width, int height) { - super.setWorldAndResolution(mc, width, height); - - screenshots = new ResourceLocation[18]; - for(int i=0; i<=17; i++) { - screenshots[i] = new ResourceLocation("notenoughupdates:ss_small/ss"+(i+1)+"-0.jpg"); - } - } - - @Override - protected void keyTyped(char typedChar, int keyCode) throws IOException { - Keyboard.enableRepeatEvents(true); - super.keyTyped(typedChar, keyCode); - if(keyCode == Keyboard.KEY_LEFT) { - page--; - } else if(keyCode == Keyboard.KEY_RIGHT) { - page++; - } - } - - @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { - super.drawScreen(mouseX, mouseY, partialTicks); - - drawDefaultBackground(); - - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - scaleFactor = scaledResolution.getScaleFactor(); - - sizeX = width/2+40/scaleFactor; - sizeY = height/2+40/scaleFactor; - guiLeft = width/4-20/scaleFactor; - guiTop = height/4-20/scaleFactor; - - Minecraft.getMinecraft().getTextureManager().bindTexture(screenshotBorder); - Utils.drawTexturedRect(guiLeft, guiTop, sizeX, sizeY); - - page = Math.max(0, Math.min(17, page)); - - Minecraft.getMinecraft().getTextureManager().bindTexture(screenshots[page]); - Utils.drawTexturedRect(guiLeft+20f/scaleFactor, guiTop+20f/scaleFactor, sizeX-40f/scaleFactor, sizeY-40f/scaleFactor); - - Utils.drawStringCentered(EnumChatFormatting.GOLD+"NEU Tutorial - Page "+(page+1)+"/18 - Use arrow keys", Minecraft.getMinecraft().fontRendererObj, - width/2, guiTop+8, true, 0); - if(scaleFactor != 2) Utils.drawStringCentered(EnumChatFormatting.GOLD+"Use GUI Scale normal for better reading experience", Minecraft.getMinecraft().fontRendererObj, - width/2, guiTop+18, true, 0); - - for(Map.Entry> entry : texts[page].entrySet()) { - Vector2f location = entry.getKey(); - List text = entry.getValue(); - - float x = guiLeft+20f/scaleFactor+(sizeX-40f/scaleFactor)*location.x; - float y = guiTop+20f/scaleFactor+(sizeY-40f/scaleFactor)*location.y; - - Utils.drawHoveringText(text, (int)x, (int)y+12, 100000, 100000, 200, Minecraft.getMinecraft().fontRendererObj); - } - } - - - private static HashMap>[] texts = new HashMap[18]; - static { - for(int i=0; i<18; i++) { - texts[i] = new HashMap<>(); - } - texts[0].put(new Vector2f(0.73f, 0.60f), Utils.createList( - EnumChatFormatting.GOLD+"Itemlist", - EnumChatFormatting.GRAY+"Here you will find a list of (most) skyblock items", - EnumChatFormatting.GRAY+"The itemlist can be accessed by opening your inventory or most menus while on skyblock")); - texts[1].put(new Vector2f(0.73f, 0.16f), Utils.createList( - EnumChatFormatting.GOLD+"Itemlist", - EnumChatFormatting.GRAY+"These are the page controls for the itemlist", - EnumChatFormatting.GRAY+"Clicking these controls will bring you to other pages of the itemlist")); - texts[2].put(new Vector2f(0.73f, 1.05f), Utils.createList( - EnumChatFormatting.GOLD+"Itemlist", - EnumChatFormatting.GRAY+"These are the sorting controls for the itemlist", - EnumChatFormatting.GRAY+"The buttons on the left control the ordering of the items", - EnumChatFormatting.GRAY+"The buttons on the right can be used to filter a certain type of item")); - texts[3].put(new Vector2f(0.39f, 1.04f), Utils.createList( - EnumChatFormatting.GOLD+"Itemlist", - EnumChatFormatting.GRAY+"This is the search bar for the itemlist", - EnumChatFormatting.GRAY+"Double-click the bar to enable inventory search mode", - EnumChatFormatting.GRAY+"The button on the left opens up the mod settings", - EnumChatFormatting.GRAY+"The button on the right displays this tutorial")); - texts[4].put(new Vector2f(0.39f, 0.99f), Utils.createList( - EnumChatFormatting.GOLD+"QuickCommands", - EnumChatFormatting.GRAY+"These are the QuickCommands", - EnumChatFormatting.GRAY+"They let you warp around or access certain menus more easily")); - texts[5].put(new Vector2f(0.7f, 0.71f), Utils.createList( - EnumChatFormatting.GOLD+"Itemlist", - EnumChatFormatting.GRAY+"Hover over an item in the list to display it's lore", - EnumChatFormatting.GRAY+"Left clicking some items will display the recipe for that item", - EnumChatFormatting.GRAY+"Right clicking some items will display a wiki page for that item", - EnumChatFormatting.GRAY+"'F' will favourite an item, putting it to the top of the itemlist")); - texts[6].put(new Vector2f(0.17f, 0.21f), Utils.createList( - EnumChatFormatting.GOLD+"Collection Log", - EnumChatFormatting.GRAY+"This is the collection log. It can be accessed using the /neucl command, or via the QuickCommand", - EnumChatFormatting.GRAY+"The collection log keeps track of all items that enter your inventory while you are playing skyblock", - EnumChatFormatting.GRAY+"If you are a completionist, this feature is for you")); - texts[7].put(new Vector2f(0.05f, 0.13f), Utils.createList( - EnumChatFormatting.GOLD+"Collection Log", - EnumChatFormatting.GRAY+"Clicking on 'Filter' will change the items that", - EnumChatFormatting.GRAY+"appear in the list")); - texts[8].put(new Vector2f(0.35f, 0.74f), Utils.createList( - EnumChatFormatting.GOLD+"NeuAH", - EnumChatFormatting.GRAY+"This is the NEU Auction House (NeuAH)", - EnumChatFormatting.GRAY+"This AH can be accessed from anywhere using the /neuah command, or via the QuickCommand", - EnumChatFormatting.GRAY+"The items here refresh automatically, so there is no need to close the GUI to see the latest auctions", - EnumChatFormatting.GRAY+"Sometimes, you might have to wait until the list is populated with items from the API")); - texts[9].put(new Vector2f(0.41f, 0.40f), Utils.createList( - EnumChatFormatting.GOLD+"NeuAH", - EnumChatFormatting.GRAY+"These tabs control the items that appear in NeuAH", - EnumChatFormatting.GRAY+"You can find the main categories on the top of the GUI and subcategories appear on the side of the GUI once a main category is selected")); - texts[10].put(new Vector2f(0.57f, 0.38f), Utils.createList( - EnumChatFormatting.GOLD+"NeuAH", - EnumChatFormatting.GRAY+"Search for items using the search bar at the top", - EnumChatFormatting.GRAY+"Boolean operators such as &, | or ! work here.")); - texts[10].put(new Vector2f(0.40f, 0.72f), Utils.createList( - EnumChatFormatting.GOLD+"NeuAH", - EnumChatFormatting.GRAY+"This toolbar contains many useful features", - EnumChatFormatting.GRAY+"which control the sorting and ordering of", - EnumChatFormatting.GRAY+"the auction house, similar to the normal AH")); - texts[11].put(new Vector2f(0.55f, 0.72f), Utils.createList( - EnumChatFormatting.GOLD+"NeuAH", - EnumChatFormatting.GRAY+"Clicking on an item will bring up the auction view", - EnumChatFormatting.GRAY+"Here you can viewer the buyer/seller and place bids or make purchases", - EnumChatFormatting.GRAY+"Trying to purchase an item will result in a confirmation GUI similar to the normal AH")); - texts[12].put(new Vector2f(0.28f, 0.82f), Utils.createList( - EnumChatFormatting.GOLD+"Profile Viewer", - EnumChatFormatting.GRAY+"Access the profile viewer using /neuprofile (ign) or /pv (ign)", - EnumChatFormatting.GRAY+"This is the main page of the profile viewer", - EnumChatFormatting.GRAY+"This page contains basic information like stats and skill levels")); - texts[12].put(new Vector2f(0.72f, 0.55f), Utils.createList( - EnumChatFormatting.GOLD+"Profile Viewer", - EnumChatFormatting.GRAY+"Click the button on the left to switch profiles and use the bar on the right to switch players")); - texts[13].put(new Vector2f(0.28f, 0.82f), Utils.createList( - EnumChatFormatting.GOLD+"Profile Viewer", - EnumChatFormatting.GRAY+"This is the extra info page of the profile viewer", - EnumChatFormatting.GRAY+"This page contains all the small bits of information about a player that don't fit anywhere else")); - texts[14].put(new Vector2f(0.28f, 0.82f), Utils.createList( - EnumChatFormatting.GOLD+"Profile Viewer", - EnumChatFormatting.GRAY+"This is the inventories page of the profile viewer", - EnumChatFormatting.GRAY+"Click on the inventory icons in the top-left or use your keyboard to switch the inventory type", - EnumChatFormatting.GRAY+"The bar on the bottom-left searches the current inventory for matching items")); - texts[15].put(new Vector2f(0.28f, 0.82f), Utils.createList( - EnumChatFormatting.GOLD+"Profile Viewer", - EnumChatFormatting.GRAY+"This is the collections page of the profile viewer", - EnumChatFormatting.GRAY+"Click on the icons on the left or use the keyboard shortcut to switch collection type")); - texts[16].put(new Vector2f(0.28f, 0.82f), Utils.createList( - EnumChatFormatting.GOLD+"Profile Viewer", - EnumChatFormatting.GRAY+"This is the pets page of the profile viewer", - EnumChatFormatting.GRAY+"Click to select the pet on the left", - EnumChatFormatting.GRAY+"The selected pet's stats will display on the right")); - texts[17].put(new Vector2f(0.27f, 0.40f), Utils.createList( - EnumChatFormatting.GOLD+"Overlay", - EnumChatFormatting.GRAY+"Rearrange certain GUI elements of the main overlay using /neuoverlay", - EnumChatFormatting.GRAY+"If you accidentally move them off screen, use the button in the top left to reset the GUI")); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java b/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java new file mode 100644 index 00000000..8d71992e --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java @@ -0,0 +1,205 @@ +package io.github.moulberry.notenoughupdates; + +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.auction.APIManager; +import net.minecraft.util.EnumChatFormatting; +import org.lwjgl.input.Keyboard; + +import java.text.NumberFormat; +import java.util.List; +import java.util.Locale; + +public class ItemPriceInformation { + + public static boolean addToTooltip(List tooltip, String internalname) { + JsonObject auctionInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalname); + JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalname); + float lowestBinAvg = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAvgBin(internalname); + + int lowestBin = NotEnoughUpdates.INSTANCE.manager.auctionManager.getLowestBin(internalname); + APIManager.CraftInfo craftCost = NotEnoughUpdates.INSTANCE.manager.auctionManager.getCraftCost(internalname); + + boolean auctionItem = lowestBin > 0 || lowestBinAvg > 0 || auctionInfo != null; + boolean bazaarItem = bazaarInfo != null; + + NumberFormat format = NumberFormat.getInstance(Locale.US); + + if(auctionItem) { + int[] lines = { + NotEnoughUpdates.INSTANCE.config.priceInfoAuc.line1, + NotEnoughUpdates.INSTANCE.config.priceInfoAuc.line2, + NotEnoughUpdates.INSTANCE.config.priceInfoAuc.line3, + NotEnoughUpdates.INSTANCE.config.priceInfoAuc.line4, + NotEnoughUpdates.INSTANCE.config.priceInfoAuc.line5, + NotEnoughUpdates.INSTANCE.config.priceInfoAuc.line6 + }; + + boolean added = false; + + for(int lineId : lines) { + switch (lineId) { + case 0: + continue; + case 1: + if(lowestBin > 0) { + if(!added) { + tooltip.add(""); + added = true; + } + tooltip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Lowest BIN: " + + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(lowestBin)+" coins"); + } + break; + case 2: + if(auctionInfo != null) { + if(!added) { + tooltip.add(""); + added = true; + } + + if(auctionInfo.has("clean_price")) { + tooltip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"AH Price (Clean): "+ EnumChatFormatting.GOLD+ + EnumChatFormatting.BOLD+ + format.format((int)auctionInfo.get("clean_price").getAsFloat())+" coins"); + } else { + int auctionPrice = (int)(auctionInfo.get("price").getAsFloat() / auctionInfo.get("count").getAsFloat()); + tooltip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"AH Price: "+ EnumChatFormatting.GOLD+ + EnumChatFormatting.BOLD+format.format(auctionPrice)+" coins"); + } + + } + break; + case 3: + if(auctionInfo != null) { + if(!added) { + tooltip.add(""); + added = true; + } + if(auctionInfo.has("clean_price")) { + tooltip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"AH Sales (Clean): "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+ + format.format(auctionInfo.get("clean_sales").getAsFloat())+" sales/day"); + } else { + tooltip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"AH Sales: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+ + format.format(auctionInfo.get("sales").getAsFloat())+" sales/day"); + } + } + break; + case 4: + if(craftCost.fromRecipe) { + if(!added) { + tooltip.add(""); + added = true; + } + tooltip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Raw Craft Cost: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format((int)craftCost.craftCost)+" coins"); + } + break; + case 5: + if(lowestBinAvg > 0) { + if(!added) { + tooltip.add(""); + added = true; + } + tooltip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"AVG Lowest BIN: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(lowestBinAvg)+" coins"); + } + break; + } + } + + return added; + } else if(bazaarItem) { + int[] lines = { + NotEnoughUpdates.INSTANCE.config.priceInfoBaz.line1, + NotEnoughUpdates.INSTANCE.config.priceInfoBaz.line2, + NotEnoughUpdates.INSTANCE.config.priceInfoBaz.line3, + NotEnoughUpdates.INSTANCE.config.priceInfoBaz.line4, + NotEnoughUpdates.INSTANCE.config.priceInfoBaz.line5, + NotEnoughUpdates.INSTANCE.config.priceInfoBaz.line6 + }; + + boolean added = false; + + boolean shiftPressed = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT); + + int stackMultiplier = 1; + int shiftStackMultiplier = 64; + if(shiftPressed) { + stackMultiplier = shiftStackMultiplier; + } + + //values = {"", "Buy", "Sell", "Buy (Insta)", "Sell (Insta)", "Raw Craft Cost"} + for(int lineId : lines) { + switch (lineId) { + case 0: + continue; + case 1: + if(bazaarInfo.has("avg_buy")) { + if(!added) { + tooltip.add(""); + if(!shiftPressed) tooltip.add(EnumChatFormatting.DARK_GRAY.toString()+"[SHIFT show x"+shiftStackMultiplier+"]"); + added = true; + } + int bazaarBuyPrice = (int)bazaarInfo.get("avg_buy").getAsFloat()*stackMultiplier; + tooltip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Buy: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarBuyPrice)+" coins"); + } + break; + case 2: + if(bazaarInfo.has("avg_sell")) { + if(!added) { + tooltip.add(""); + if(!shiftPressed) tooltip.add(EnumChatFormatting.DARK_GRAY.toString()+"[SHIFT show x"+shiftStackMultiplier+"]"); + added = true; + } + int bazaarSellPrice = (int)bazaarInfo.get("avg_sell").getAsFloat()*stackMultiplier; + tooltip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Sell: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarSellPrice)+" coins"); + } + break; + case 3: + if(bazaarInfo.has("curr_buy")) { + if(!added) { + tooltip.add(""); + if(!shiftPressed) tooltip.add(EnumChatFormatting.DARK_GRAY.toString()+"[SHIFT show x"+shiftStackMultiplier+"]"); + added = true; + } + int bazaarInstantBuyPrice = (int)bazaarInfo.get("curr_buy").getAsFloat()*stackMultiplier; + tooltip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Insta-Buy: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarInstantBuyPrice)+" coins"); + } + break; + case 4: + if(bazaarInfo.has("curr_sell")) { + if(!added) { + tooltip.add(""); + if(!shiftPressed) tooltip.add(EnumChatFormatting.DARK_GRAY.toString()+"[SHIFT show x"+shiftStackMultiplier+"]"); + added = true; + } + int bazaarInstantSellPrice = (int)bazaarInfo.get("curr_sell").getAsFloat()*stackMultiplier; + tooltip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Insta-Sell: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarInstantSellPrice)+" coins"); + } + break; + case 5: + if(craftCost.fromRecipe) { + if(!added) { + tooltip.add(""); + added = true; + } + tooltip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Raw Craft Cost: "+ + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format((int)craftCost.craftCost)+" coins"); + } + break; + } + } + + return added; + } + + return false; + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/ItemRarityHalo.java b/src/main/java/io/github/moulberry/notenoughupdates/ItemRarityHalo.java deleted file mode 100644 index 2c70ec1e..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/ItemRarityHalo.java +++ /dev/null @@ -1,251 +0,0 @@ -package io.github.moulberry.notenoughupdates; - -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.renderer.*; -import net.minecraft.client.renderer.entity.RenderItem; -import net.minecraft.client.renderer.texture.TextureUtil; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.client.shader.Framebuffer; -import net.minecraft.client.shader.Shader; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Matrix4f; -import org.lwjgl.BufferUtils; -import org.lwjgl.input.Keyboard; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL14; -import org.lwjgl.opengl.GL30; -import org.lwjgl.opengl.GL45; - -import java.awt.*; -import java.nio.ByteBuffer; -import java.nio.IntBuffer; -import java.util.HashMap; - -public class ItemRarityHalo { - - public static Framebuffer itemFramebuffer1 = null; - public static Framebuffer itemFramebuffer2 = null; - public static HashMap itemHaloTexMap = new HashMap<>(); - public static Matrix4f projectionMatrix = null; - - public static Shader colourShader = null; - public static Shader blurShaderHorz = null; - public static Shader blurShaderVert = null; - - private static int oldScaledResolution = 0; - - public static void onItemRender(ItemStack stack, int x, int y) { - if(x == 0 && y == 0) return; - - if(!OpenGlHelper.isFramebufferEnabled() || !OpenGlHelper.areShadersSupported()) return; - NotEnoughUpdates neu = NotEnoughUpdates.INSTANCE; - if(!neu.isOnSkyblock()) return; - if(neu.manager.config.itemHighlightOpacity.value <= 1) return; - if(neu.manager.getInternalNameForItem(stack) == null) return; - - ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); - int size = 16*scaledresolution.getScaleFactor(); - - if(projectionMatrix == null) { - projectionMatrix = Utils.createProjectionMatrix(size, size); - } - - itemFramebuffer1 = checkFramebufferSizes(itemFramebuffer1, size, size); - itemFramebuffer2 = checkFramebufferSizes(itemFramebuffer2, size, size); - - try { - if(colourShader == null) { - colourShader = new Shader(new NEUResourceManager(Minecraft.getMinecraft().getResourceManager()), - "setrgbtoalpha", itemFramebuffer1, itemFramebuffer2); - upload(colourShader, size, size); - } - - if(blurShaderHorz == null) { - blurShaderHorz = new Shader(new NEUResourceManager(Minecraft.getMinecraft().getResourceManager()), - "blur", itemFramebuffer2, itemFramebuffer1); - blurShaderHorz.getShaderManager().getShaderUniform("BlurDir").set(1, 0); - blurShaderHorz.getShaderManager().getShaderUniform("Radius").set(5f); - blurShaderHorz.getShaderManager().getShaderUniform("AlphaMult").set(2f); - upload(blurShaderHorz, size, size); - } - - if(blurShaderVert == null) { - blurShaderVert = new Shader(new NEUResourceManager(Minecraft.getMinecraft().getResourceManager()), - "blur", itemFramebuffer1, itemFramebuffer2); - blurShaderVert.getShaderManager().getShaderUniform("BlurDir").set(0, 1); - blurShaderVert.getShaderManager().getShaderUniform("Radius").set(5f); - blurShaderVert.getShaderManager().getShaderUniform("AlphaMult").set(2f); - upload(blurShaderVert, size, size); - } - } catch(Exception e) { return; } - - if(oldScaledResolution != scaledresolution.getScaleFactor()) { - resetItemHaloCache(); - oldScaledResolution = scaledresolution.getScaleFactor(); - } - - int currentBuffer = GL11.glGetInteger(GL30.GL_FRAMEBUFFER_BINDING); - IntBuffer currentViewport = BufferUtils.createIntBuffer(16); - GL11.glGetInteger(GL11.GL_VIEWPORT, currentViewport); - try { - if(!itemHaloTexMap.containsKey(stack)) { - int texture1 = TextureUtil.glGenTextures(); - int texture2 = TextureUtil.glGenTextures(); - - GlStateManager.bindTexture(texture1); - GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, size, size, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, ((ByteBuffer)null)); - itemFramebuffer1.bindFramebuffer(false); - OpenGlHelper.glFramebufferTexture2D(OpenGlHelper.GL_FRAMEBUFFER, OpenGlHelper.GL_COLOR_ATTACHMENT0, 3553, texture1, 0); - - GlStateManager.bindTexture(texture2); - GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, size, size, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, ((ByteBuffer)null)); - itemFramebuffer2.bindFramebuffer(false); - OpenGlHelper.glFramebufferTexture2D(OpenGlHelper.GL_FRAMEBUFFER, OpenGlHelper.GL_COLOR_ATTACHMENT0, 3553, texture2, 0); - - itemFramebuffer1.framebufferClear(); - itemFramebuffer2.framebufferClear(); - - GlStateManager.pushMatrix(); { - GlStateManager.matrixMode(5889); - GlStateManager.loadIdentity(); - GlStateManager.ortho(0.0D, size, size, 0.0D, 1000.0D, 3000.0D); - GlStateManager.matrixMode(5888); - GlStateManager.loadIdentity(); - GlStateManager.translate(0.0F, 0.0F, -2000.0F); - - GL11.glScalef(scaledresolution.getScaleFactor(), scaledresolution.getScaleFactor(), 1); - - itemFramebuffer1.bindFramebuffer(true); - - RenderItem itemRender = Minecraft.getMinecraft().getRenderItem(); - RenderHelper.enableGUIStandardItemLighting(); - float zLevel = itemRender.zLevel; - itemRender.zLevel = -145; //Negates the z-offset of the below method. - itemRender.renderItemAndEffectIntoGUI(stack, 0, 0); - itemRender.zLevel = zLevel; - RenderHelper.disableStandardItemLighting(); - } GlStateManager.popMatrix(); - - GlStateManager.pushMatrix(); { - GL45.glTextureBarrier(); GL11.glFlush(); GL11.glFinish(); - executeShader(colourShader); - //GL45.glTextureBarrier(); GL11.glFlush(); GL11.glFinish(); - //executeShader(blurShaderHorz); - //GL45.glTextureBarrier(); GL11.glFlush(); GL11.glFinish(); - //executeShader(blurShaderVert); - //GL45.glTextureBarrier(); GL11.glFlush(); GL11.glFinish(); - } GlStateManager.popMatrix(); - - GlStateManager.matrixMode(5889); - GlStateManager.loadIdentity(); - GlStateManager.ortho(0.0D, scaledresolution.getScaledWidth_double(), scaledresolution.getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D); - GlStateManager.matrixMode(5888); - - OpenGlHelper.glBindFramebuffer(OpenGlHelper.GL_FRAMEBUFFER, currentBuffer); - GlStateManager.viewport(currentViewport.get(), currentViewport.get(), currentViewport.get(), currentViewport.get()); - - //TextureUtil.deleteTexture(texture1); - itemHaloTexMap.put(stack, texture2); - } - - OpenGlHelper.glBindFramebuffer(OpenGlHelper.GL_FRAMEBUFFER, currentBuffer); - GlStateManager.viewport(currentViewport.get(), currentViewport.get(), currentViewport.get(), currentViewport.get()); - - GlStateManager.bindTexture(itemHaloTexMap.get(stack)); - Color color = Utils.getPrimaryColour(stack.getDisplayName()); - GlStateManager.color(color.getRed()/255f, color.getGreen()/255f, color.getBlue()/255f, - NotEnoughUpdates.INSTANCE.manager.config.itemHighlightOpacity.value.floatValue()/255f); - Utils.drawTexturedRect(x, y, 16, 16, - 0, 1, 1, 0, GL11.GL_NEAREST); - GlStateManager.bindTexture(0); - } catch(Exception e) { - e.printStackTrace(); - OpenGlHelper.glBindFramebuffer(OpenGlHelper.GL_FRAMEBUFFER, currentBuffer); - GlStateManager.viewport(currentViewport.get(), currentViewport.get(), currentViewport.get(), currentViewport.get()); - } - } - - 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, true); - } else { - framebuffer.createBindFramebuffer(width, height); - } - framebuffer.setFramebufferFilter(GL11.GL_NEAREST); - } - return framebuffer; - } - - public static void resetItemHaloCache() { - ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); - int size = 16*scaledresolution.getScaleFactor(); - - for(int tex : itemHaloTexMap.values()) { - TextureUtil.deleteTexture(tex); - } - itemHaloTexMap.clear(); - - if(NotEnoughUpdates.INSTANCE.isOnSkyblock()) { - projectionMatrix = Utils.createProjectionMatrix(size, size); - upload(colourShader, size, size); - upload(blurShaderHorz, size, size); - upload(blurShaderVert, size, size); - } - } - - private static void upload(Shader shader, int width, int height) { - if(shader == null) return; - shader.getShaderManager().getShaderUniformOrDefault("ProjMat").set(projectionMatrix); - shader.getShaderManager().getShaderUniformOrDefault("InSize").set(width, height); - shader.getShaderManager().getShaderUniformOrDefault("OutSize").set(width, height); - shader.getShaderManager().getShaderUniformOrDefault("ScreenSize").set((float)width, (float)height); - } - - private static void executeShader(Shader shader) { - GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - GlStateManager.disableBlend(); - GlStateManager.disableDepth(); - GlStateManager.disableAlpha(); - GlStateManager.disableFog(); - GlStateManager.disableLighting(); - GlStateManager.disableColorMaterial(); - GlStateManager.enableTexture2D(); - GlStateManager.bindTexture(0); - - float f = (float)shader.framebufferOut.framebufferTextureWidth; - float f1 = (float)shader.framebufferOut.framebufferTextureHeight; - GlStateManager.viewport(0, 0, (int)f, (int)f1); - - shader.getShaderManager().useShader(); - shader.getShaderManager().addSamplerTexture("DiffuseSampler", shader.framebufferIn); - - shader.framebufferOut.framebufferClear(); - shader.framebufferOut.bindFramebuffer(false); - - GlStateManager.depthMask(false); - - GlStateManager.enableAlpha(); - GlStateManager.enableBlend(); - GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldrenderer = tessellator.getWorldRenderer(); - worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR); - worldrenderer.pos(0.0D, (double)f1, 500.0D).color(255, 255, 255, 255).endVertex(); - worldrenderer.pos((double)f, (double)f1, 500.0D).color(255, 255, 255, 255).endVertex(); - worldrenderer.pos((double)f, 0.0D, 500.0D).color(255, 255, 255, 255).endVertex(); - worldrenderer.pos(0.0D, 0.0D, 500.0D).color(255, 255, 255, 255).endVertex(); - tessellator.draw(); - - GlStateManager.depthMask(true); - - shader.getShaderManager().endShader(); - - shader.framebufferOut.unbindFramebuffer(); - shader.framebufferIn.unbindFramebufferTexture(); - } - -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java index 47ea832f..7b08ddf4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java @@ -9,9 +9,12 @@ import io.github.moulberry.notenoughupdates.cosmetics.CapeManager; import io.github.moulberry.notenoughupdates.dungeons.DungeonBlocks; import io.github.moulberry.notenoughupdates.dungeons.DungeonWin; import io.github.moulberry.notenoughupdates.gamemodes.SBGamemodes; +import io.github.moulberry.notenoughupdates.miscfeatures.BetterContainers; +import io.github.moulberry.notenoughupdates.miscfeatures.StreamerMode; +import io.github.moulberry.notenoughupdates.miscgui.*; import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; -import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; -import io.github.moulberry.notenoughupdates.questing.SBInfo; +import io.github.moulberry.notenoughupdates.util.RequestFocusListener; +import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; @@ -21,7 +24,6 @@ import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.gui.inventory.GuiChest; import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.gui.inventory.GuiCrafting; import net.minecraft.client.gui.inventory.GuiEditSign; import net.minecraft.client.network.NetworkPlayerInfo; import net.minecraft.client.renderer.GlStateManager; @@ -39,7 +41,7 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.client.event.*; import net.minecraftforge.event.entity.player.EntityInteractEvent; import net.minecraftforge.event.entity.player.ItemTooltipEvent; -import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -64,7 +66,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.regex.Matcher; import java.util.regex.Pattern; -import static io.github.moulberry.notenoughupdates.GuiTextures.dungeon_chest_worth; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.dungeon_chest_worth; public class NEUEventListener { @@ -124,6 +126,11 @@ public class NEUEventListener { } } + @SubscribeEvent + public void onWorldLoad(WorldEvent.Unload event) { + NotEnoughUpdates.INSTANCE.saveConfig(); + } + private long notificationDisplayMillis = 0; private List notificationLines = null; @@ -146,14 +153,14 @@ public class NEUEventListener { longUpdate = true; lastLongUpdate = currentTime; } - if(!NotEnoughUpdates.INSTANCE.manager.config.slowDungeonBlocks.value) { + if(!neu.config.dungeonBlock.slowDungeonBlocks) { DungeonBlocks.tick(); } DungeonWin.tick(); if(longUpdate) { NotEnoughUpdates.INSTANCE.overlay.redrawItems(); - if(NotEnoughUpdates.INSTANCE.manager.config.slowDungeonBlocks.value) { + if(neu.config.dungeonBlock.slowDungeonBlocks) { DungeonBlocks.tick(); } @@ -181,11 +188,11 @@ public class NEUEventListener { SBGamemodes.loadFromFile(); - if(neu.manager.config.showUpdateMsg.value) { + if(neu.config.notifications.showUpdateMsg) { displayUpdateMessageIfOutOfDate(); } - if(NotEnoughUpdates.INSTANCE.manager.config.doRamNotif.value) { + if(neu.config.hidden.doRamNotif) { long maxMemoryMB = Runtime.getRuntime().maxMemory()/1024L/1024L; if(maxMemoryMB > 4100) { notificationDisplayMillis = System.currentTimeMillis(); @@ -199,9 +206,8 @@ public class NEUEventListener { } } - if(!neu.manager.config.loadedModBefore.value) { - neu.manager.config.loadedModBefore.value = true; - try { neu.manager.saveConfig(); } catch(IOException e) {} + if(!neu.config.hidden.loadedModBefore) { + neu.config.hidden.loadedModBefore = true; Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( @@ -283,7 +289,7 @@ public class NEUEventListener { if(stack != null && stack.hasTagCompound()) { String internalname = neu.manager.getInternalNameForItem(stack); if(internalname != null) { - ArrayList log = neu.manager.config.collectionLog.value.computeIfAbsent( + /*ArrayList log = neu.manager.config.collectionLog.value.computeIfAbsent( neu.manager.getCurrentProfile(), k -> new ArrayList<>()); if(!log.contains(internalname)) { newItem.add(internalname); @@ -295,7 +301,7 @@ public class NEUEventListener { } else { newItemAddMap.put(internalname, System.currentTimeMillis()); } - } + }*/ } } } @@ -396,16 +402,8 @@ public class NEUEventListener { if(Minecraft.getMinecraft().currentScreen == null && event.gui instanceof GuiContainer) { neu.overlay.reset(); - neu.manager.loadConfig(); } - //CLOSE - if(Minecraft.getMinecraft().currentScreen instanceof GuiContainer - && event.gui == null) { - try { - neu.manager.saveConfig(); - } catch(IOException e) {} - } - if(event.gui != null && neu.manager.config.dev.value) { + if(event.gui != null && neu.config.hidden.dev) { if(event.gui instanceof GuiChest) { GuiChest eventGui = (GuiChest) event.gui; ContainerChest cc = (ContainerChest) eventGui.inventorySlots; @@ -540,8 +538,9 @@ public class NEUEventListener { } else if(unformatted.startsWith("Your profile was changed to: ")) {//Your profile was changed to: neu.manager.setCurrentProfile(unformatted.substring("Your profile was changed to: ".length()).split(" ")[0].trim()); } else if(unformatted.startsWith("Your new API key is ")) { - neu.manager.config.apiKey.value = unformatted.substring("Your new API key is ".length()); - try { neu.manager.saveConfig(); } catch(IOException ioe) {} + neu.config.apiKey.apiKey = unformatted.substring("Your new API key is ".length()); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW+ + "[NEU] API Key automatically configured")); } if(e.message.getFormattedText().equals(EnumChatFormatting.RESET.toString()+ EnumChatFormatting.RED+"You haven't unlocked this recipe!"+EnumChatFormatting.RESET)) { @@ -566,7 +565,7 @@ public class NEUEventListener { } //System.out.println(e.message); if(unformatted.startsWith("Sending to server") && - neu.isOnSkyblock() && neu.manager.config.streamerMode.value && e.message instanceof ChatComponentText) { + neu.isOnSkyblock() && neu.config.misc.streamerMode && e.message instanceof ChatComponentText) { String m = e.message.getFormattedText(); String m2 = StreamerMode.filterChat(e.message.getFormattedText()); if(!m.equals(m2)) { @@ -633,13 +632,6 @@ public class NEUEventListener { GL11.glTranslatef(0, 0, 10); } } - - if(shouldRenderOverlay(event.gui) && neu.isOnSkyblock()) { - renderDungeonChestOverlay(event.gui); - if(neu.manager.config.accessoryBagOverlay.value) { - AccessoryBagOverlay.renderOverlay(); - } - } } @SubscribeEvent @@ -706,10 +698,17 @@ public class NEUEventListener { GlStateManager.popMatrix(); } } + + if(shouldRenderOverlay(event.gui) && neu.isOnSkyblock()) { + renderDungeonChestOverlay(event.gui); + if(neu.config.accessoryBag.enableOverlay) { + AccessoryBagOverlay.renderOverlay(); + } + } } private void renderDungeonChestOverlay(GuiScreen gui) { - if(gui instanceof GuiChest && !neu.manager.config.dungeonProfitLore.value) { + if(gui instanceof GuiChest && neu.config.dungeonProfit.profitDisplayLoc != 2) { try { int xSize = (int) Utils.getField(GuiContainer.class, gui, "xSize", "field_146999_f"); int ySize = (int) Utils.getField(GuiContainer.class, gui, "ySize", "field_147000_g"); @@ -722,30 +721,24 @@ public class NEUEventListener { ItemStack rewardChest = lower.getStackInSlot(31); if (rewardChest != null && rewardChest.getDisplayName().endsWith(EnumChatFormatting.GREEN+"Open Reward Chest")) { - Minecraft.getMinecraft().getTextureManager().bindTexture(dungeon_chest_worth); - GL11.glColor4f(1, 1, 1, 1); - GlStateManager.disableLighting(); - Utils.drawTexturedRect(guiLeft+xSize+4, guiTop, 180, 101, 0, 180/256f, 0, 101/256f, GL11.GL_NEAREST); - int chestCost = 0; - String line6 = Utils.cleanColour(neu.manager.getLoreFromNBT(rewardChest.getTagCompound())[6]); - StringBuilder cost = new StringBuilder(); - for(int i=0; i= 0) { - cost.append(c); + try { + String line6 = Utils.cleanColour(neu.manager.getLoreFromNBT(rewardChest.getTagCompound())[6]); + StringBuilder cost = new StringBuilder(); + for(int i=0; i= 0) { + cost.append(c); + } } - } - if(cost.length() > 0) { - chestCost = Integer.parseInt(cost.toString()); - } + if(cost.length() > 0) { + chestCost = Integer.parseInt(cost.toString()); + } + } catch(Exception ignored) {} - String missingItemBIN = null; - String missingItemABIN = null; - String missingItemAUC = null; - int totalValueBIN = 0; - int totalValueABIN = 0; - int totalValueAUC = 0; + String missingItem = null; + int totalValue = 0; + HashMap itemValues = new HashMap<>(); for(int i=0; i<5; i++) { ItemStack item = lower.getStackInSlot(11+i); String internal = neu.manager.getInternalNameForItem(item); @@ -757,119 +750,128 @@ public class NEUEventListener { bazaarPrice = bazaarInfo.get("avg_sell").getAsFloat(); } - float worthBIN; - float worthABIN; - float worthAUC = -1; - + float worth = -1; if(bazaarPrice > 0) { - worthBIN = bazaarPrice; - worthABIN = bazaarPrice; - worthAUC = bazaarPrice; + worth = bazaarPrice; } else { - worthABIN = neu.manager.auctionManager.getItemAvgBin(internal); - worthBIN = neu.manager.auctionManager.getLowestBin(internal); - - JsonObject aucInfo = neu.manager.auctionManager.getItemAuctionInfo(internal); - if(aucInfo != null) { - worthAUC = aucInfo.get("price").getAsFloat(); + switch(neu.config.dungeonProfit.profitType) { + case 1: + worth = neu.manager.auctionManager.getItemAvgBin(internal); + break; + case 2: + JsonObject auctionInfo = neu.manager.auctionManager.getItemAuctionInfo(internal); + if(auctionInfo != null) { + if(auctionInfo.has("clean_price")) { + worth = (int)auctionInfo.get("clean_price").getAsFloat(); + } else { + worth = (int)(auctionInfo.get("price").getAsFloat() / auctionInfo.get("count").getAsFloat()); + } + } + break; + default: + worth = neu.manager.auctionManager.getLowestBin(internal); } - } - - if(worthBIN > 0 && totalValueBIN >= 0) { - totalValueBIN += worthBIN; - } else { - if(totalValueBIN != -1) { - missingItemBIN = internal; + if(worth <= 0) { + worth = neu.manager.auctionManager.getLowestBin(internal); + if(worth <= 0) { + worth = neu.manager.auctionManager.getItemAvgBin(internal); + if(worth <= 0) { + JsonObject auctionInfo = neu.manager.auctionManager.getItemAuctionInfo(internal); + if(auctionInfo != null) { + if(auctionInfo.has("clean_price")) { + worth = (int)auctionInfo.get("clean_price").getAsFloat(); + } else { + worth = (int)(auctionInfo.get("price").getAsFloat() / auctionInfo.get("count").getAsFloat()); + } + } + } + } } - totalValueBIN = -1; } - if(worthABIN > 0 && totalValueABIN >= 0) { - totalValueABIN += worthABIN; - } else { - if(totalValueABIN != -1) { - missingItemABIN = internal; + if(worth > 0 && totalValue >= 0) { + totalValue += worth; + String display = item.getDisplayName(); + + if(display.contains("Enchanted Book")) { + NBTTagCompound tag = item.getTagCompound(); + if(tag != null && tag.hasKey("ExtraAttributes", 10)) { + NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); + NBTTagCompound enchants = ea.getCompoundTag("enchantments"); + + int highestLevel = -1; + for(String enchname : enchants.getKeySet()) { + int level = enchants.getInteger(enchname); + if(level > highestLevel) { + display = EnumChatFormatting.BLUE+WordUtils.capitalizeFully( + enchname.replace("_", " ") + .replace("Ultimate", "") + .trim()) + " " + level; + } + } + } } - totalValueABIN = -1; - } - if(worthAUC > 0 && totalValueAUC >= 0) { - totalValueAUC += worthAUC; + itemValues.put(display, worth); } else { - if(totalValueAUC != -1) { - missingItemAUC = internal; + if(totalValue != -1) { + missingItem = internal; } - totalValueAUC = -1; + totalValue = -1; } } } NumberFormat format = NumberFormat.getInstance(Locale.US); - String valueStringBIN; - String valueStringABIN; - String valueStringAUC; - if(totalValueBIN >= 0) { - valueStringBIN = EnumChatFormatting.YELLOW+"Value (BIN): " + EnumChatFormatting.GOLD - + EnumChatFormatting.BOLD + format.format(totalValueBIN) + " coins"; - } else { - valueStringBIN = EnumChatFormatting.YELLOW+"Can't find BIN: " + missingItemBIN; - } - if(totalValueABIN >= 0) { - valueStringABIN = EnumChatFormatting.YELLOW+"Value (AVG BIN): " + EnumChatFormatting.GOLD - + EnumChatFormatting.BOLD + format.format(totalValueABIN) + " coins"; + String valueStringBIN1; + String valueStringBIN2; + if(totalValue >= 0) { + valueStringBIN1 = EnumChatFormatting.YELLOW+"Value (BIN): "; + valueStringBIN2 = EnumChatFormatting.GOLD + format.format(totalValue) + " coins"; } else { - valueStringABIN = EnumChatFormatting.YELLOW+"Can't find AVG BIN: " + missingItemABIN; - } - if(totalValueAUC >= 0) { - valueStringAUC = EnumChatFormatting.YELLOW+"Value (AUC): " + EnumChatFormatting.GOLD - + EnumChatFormatting.BOLD + format.format(totalValueAUC) + " coins"; - } else { - valueStringAUC = EnumChatFormatting.YELLOW+"Can't find AUC: " + missingItemAUC; + valueStringBIN1 = EnumChatFormatting.YELLOW+"Can't find BIN: "; + valueStringBIN2 = missingItem; } - String profitPrefix = EnumChatFormatting.YELLOW+"Profit/Loss: " + EnumChatFormatting.DARK_GREEN - + EnumChatFormatting.BOLD + "+"; - String lossPrefix = EnumChatFormatting.YELLOW+"Profit/Loss: " + EnumChatFormatting.RED - + EnumChatFormatting.BOLD + "-"; + int profitLossBIN = totalValue - chestCost; + + String profitPrefix = EnumChatFormatting.DARK_GREEN.toString(); + String lossPrefix = EnumChatFormatting.RED.toString(); + String prefix = profitLossBIN >= 0 ? profitPrefix : lossPrefix; - int profitLossBIN = totalValueBIN - chestCost; String plStringBIN; if(profitLossBIN >= 0) { - plStringBIN = profitPrefix + format.format(profitLossBIN) + " coins"; - } else { - plStringBIN = lossPrefix + format.format(-profitLossBIN) + " coins"; - } - - int profitLossABIN = totalValueABIN - chestCost; - String plStringABIN; - if(profitLossABIN >= 0) { - plStringABIN = profitPrefix + format.format(profitLossABIN) + " coins"; + plStringBIN = prefix + "+" + format.format(profitLossBIN) + " coins"; } else { - plStringABIN = lossPrefix + format.format(-profitLossABIN) + " coins"; + plStringBIN = prefix + "-" + format.format(-profitLossBIN) + " coins"; } - int profitLossAUC = totalValueAUC - chestCost; - String plStringAUC; - if(profitLossAUC >= 0) { - plStringAUC = profitPrefix + format.format(profitLossAUC) + " coins"; - } else { - plStringAUC = lossPrefix + format.format(-profitLossAUC) + " coins"; + if(neu.config.dungeonProfit.profitDisplayLoc == 1 && !valueStringBIN2.equals(missingItem)) { + int w = Minecraft.getMinecraft().fontRendererObj.getStringWidth(plStringBIN); + GlStateManager.disableLighting(); + Minecraft.getMinecraft().fontRendererObj.drawString(plStringBIN, guiLeft+xSize-5-w, guiTop+5, + 0xffffffff, true); + return; } - drawStringShadow(valueStringBIN, guiLeft+xSize+4+90, - guiTop+14, 170); - if(totalValueBIN >= 0) drawStringShadow(plStringBIN, guiLeft+xSize+4+90, - guiTop+26, 170); + Minecraft.getMinecraft().getTextureManager().bindTexture(dungeon_chest_worth); + GL11.glColor4f(1, 1, 1, 1); + GlStateManager.disableLighting(); + Utils.drawTexturedRect(guiLeft+xSize+4, guiTop, 180, 101, 0, 180/256f, 0, 101/256f, GL11.GL_NEAREST); - drawStringShadow(valueStringABIN, guiLeft+xSize+4+90, - guiTop+44, 170); - if(totalValueABIN >= 0) drawStringShadow(plStringABIN, guiLeft+xSize+4+90, - guiTop+56, 170); + Utils.renderAlignedString(valueStringBIN1, valueStringBIN2, + guiLeft+xSize+4+10, guiTop+14, 160); + if(totalValue >= 0) { + Utils.renderAlignedString(EnumChatFormatting.YELLOW+"Profit/Loss: ", plStringBIN, + guiLeft+xSize+4+10, guiTop+24, 160); + } - drawStringShadow(valueStringAUC, guiLeft+xSize+4+90, - guiTop+74, 170); - if(totalValueAUC >= 0) drawStringShadow(plStringAUC, guiLeft+xSize+4+90, - guiTop+86, 170); + int index=0; + for(Map.Entry entry : itemValues.entrySet()) { + Utils.renderAlignedString(entry.getKey(), prefix+ + format.format(entry.getValue().intValue()), + guiLeft+xSize+4+10, guiTop+29+(++index)*10, 160); + } } } catch(Exception e) { e.printStackTrace(); @@ -918,7 +920,7 @@ public class NEUEventListener { return; } if(shouldRenderOverlay(event.gui) && neu.isOnSkyblock()) { - if(!neu.manager.config.accessoryBagOverlay.value || !AccessoryBagOverlay.mouseClick()) { + if(!neu.config.accessoryBag.enableOverlay || !AccessoryBagOverlay.mouseClick()) { if(!(hoverInv && focusInv)) { if(neu.overlay.mouseInput()) { event.setCanceled(true); @@ -964,7 +966,7 @@ public class NEUEventListener { event.setCanceled(true); } } - if(neu.manager.config.dev.value && neu.manager.config.enableItemEditing.value && Minecraft.getMinecraft().theWorld != null && + if(neu.config.hidden.dev && neu.config.hidden.enableItemEditing && Minecraft.getMinecraft().theWorld != null && Keyboard.getEventKey() == Keyboard.KEY_O && Keyboard.getEventKeyState()) { GuiScreen gui = Minecraft.getMinecraft().currentScreen; if(gui instanceof GuiChest) { @@ -1052,7 +1054,7 @@ public class NEUEventListener { JsonObject enchantsConst = Constants.ENCHANTS; JsonArray allItemEnchs = null; Set ignoreFromPool = new HashSet<>(); - if(enchantsConst != null && hasEnchantments && NotEnoughUpdates.INSTANCE.manager.config.missingEnchantList.value) { + if(enchantsConst != null && hasEnchantments && neu.config.tooltipTweaks.missingEnchantList) { try { JsonArray enchantPools = enchantsConst.get("enchant_pools").getAsJsonArray(); for(JsonElement element : enchantPools) { @@ -1104,7 +1106,7 @@ public class NEUEventListener { line = line.replace("\u00A7cR\u00A76a\u00A7ei\u00A7an\u00A7bb\u00A79o\u00A7dw\u00A79 Rune", Utils.chromaString("Rainbow Rune", index, false)+EnumChatFormatting.BLUE); } else if(hasEnchantments) { - if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) && NotEnoughUpdates.INSTANCE.manager.config.missingEnchantList.value) { + if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) && neu.config.tooltipTweaks.missingEnchantList) { boolean lineHasEnch = false; for(String s : enchantIds) { String enchantName = WordUtils.capitalizeFully(s.replace("_", " ")); @@ -1147,7 +1149,7 @@ public class NEUEventListener { } } } - for(String op : neu.manager.config.enchantColours.value) { + for(String op : neu.config.hidden.enchantColours) { List colourOps = GuiEnchantColour.splitter.splitToList(op); String enchantName = GuiEnchantColour.getColourOpIndex(colourOps, 0); String comparator = GuiEnchantColour.getColourOpIndex(colourOps, 1); @@ -1264,63 +1266,21 @@ public class NEUEventListener { newTooltip.add(line); - if(neu.manager.config.auctionPriceInfo.value) { + if(neu.config.tooltipTweaks.showPriceInfoAucItem) { if(line.contains(EnumChatFormatting.GRAY+"Buy it now: ") || line.contains(EnumChatFormatting.GRAY+"Bidder: ") || line.contains(EnumChatFormatting.GRAY+"Starting bid: ")) { - if(internalname != null) { - newTooltip.add(""); - if(!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) && !Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) { - newTooltip.add(EnumChatFormatting.GRAY+"[SHIFT for Price Info]"); - } else { - JsonObject auctionInfo = neu.manager.auctionManager.getItemAuctionInfo(internalname); - float lowestBinAvg = neu.manager.auctionManager.getItemAvgBin(internalname); - - int lowestBin = neu.manager.auctionManager.getLowestBin(internalname); - APIManager.CraftInfo craftCost = neu.manager.auctionManager.getCraftCost(internalname); - - boolean hasAuctionPrice = auctionInfo != null; - boolean hasLowestBinPrice = lowestBin > 0 && neu.manager.config.advancedPriceInfo.value; - boolean hasLowestBinAvgPrice = lowestBinAvg > 0; - - NumberFormat format = NumberFormat.getInstance(Locale.US); - if(hasLowestBinPrice) { - newTooltip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Lowest BIN: "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(lowestBin)+" coins"); - } - if(hasLowestBinAvgPrice) { - newTooltip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"AVG Lowest BIN: "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(lowestBinAvg)+" coins"); - } - if(hasAuctionPrice) { - int auctionPrice = (int)(auctionInfo.get("price").getAsFloat() / auctionInfo.get("count").getAsFloat()); - newTooltip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"AH Price: "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(auctionPrice)+" coins"); - if(neu.manager.config.advancedPriceInfo.value) { - newTooltip.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")) { - newTooltip.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) { - newTooltip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"AH Sales (Clean): "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(auctionInfo.get("clean_sales").getAsFloat())+" sales/day"); - } - } - - } - if(hasAuctionPrice && craftCost.fromRecipe) { - newTooltip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Raw Craft Cost: "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format((int)craftCost.craftCost)+" coins"); - } - } + if(!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) && !Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) { + newTooltip.add(""); + newTooltip.add(EnumChatFormatting.GRAY+"[SHIFT for Price Info]"); + } else { + ItemPriceInformation.addToTooltip(newTooltip, internalname); } } } - if(neu.manager.config.dungeonProfitLore.value && Minecraft.getMinecraft().currentScreen instanceof GuiChest) { + if(neu.config.dungeonProfit.profitDisplayLoc == 2 && Minecraft.getMinecraft().currentScreen instanceof GuiChest) { if(line.contains(EnumChatFormatting.GREEN+"Open Reward Chest")) { dungeonProfit = true; } else if(index == 7 && dungeonProfit) { @@ -1329,141 +1289,141 @@ public class NEUEventListener { IInventory lower = cc.getLowerChestInventory(); int chestCost = 0; - String line6 = Utils.cleanColour(line); - StringBuilder cost = new StringBuilder(); - for(int i=0; i= 0) { - cost.append(c); + try { + String line6 = Utils.cleanColour(line); + StringBuilder cost = new StringBuilder(); + for(int i=0; i= 0) { + cost.append(c); + } } - } - if(cost.length() > 0) { - chestCost = Integer.parseInt(cost.toString()); - } + if(cost.length() > 0) { + chestCost = Integer.parseInt(cost.toString()); + } + } catch(Exception ignored) {} - String missingItemBIN = null; - String missingItemABIN = null; - String missingItemAUC = null; - int totalValueBIN = 0; - int totalValueABIN = 0; - int totalValueAUC = 0; + String missingItem = null; + int totalValue = 0; + HashMap itemValues = new HashMap<>(); for(int i=0; i<5; i++) { ItemStack item = lower.getStackInSlot(11+i); String internal = neu.manager.getInternalNameForItem(item); if(internal != null) { + internal = internal.replace("\u00CD", "I").replace("\u0130", "I"); float bazaarPrice = -1; JsonObject bazaarInfo = neu.manager.auctionManager.getBazaarInfo(internal); if(bazaarInfo != null && bazaarInfo.has("avg_sell")) { bazaarPrice = bazaarInfo.get("avg_sell").getAsFloat(); } - float worthBIN; - float worthABIN; - float worthAUC = -1; - + float worth = -1; if(bazaarPrice > 0) { - worthBIN = bazaarPrice; - worthABIN = bazaarPrice; - worthAUC = bazaarPrice; + worth = bazaarPrice; } else { - worthABIN = neu.manager.auctionManager.getItemAvgBin(internal); - worthBIN = neu.manager.auctionManager.getLowestBin(internal); - - JsonObject aucInfo = neu.manager.auctionManager.getItemAuctionInfo(internal); - if(aucInfo != null) { - worthAUC = aucInfo.get("price").getAsFloat(); + switch(neu.config.dungeonProfit.profitType) { + case 1: + worth = neu.manager.auctionManager.getItemAvgBin(internal); + break; + case 2: + JsonObject auctionInfo = neu.manager.auctionManager.getItemAuctionInfo(internal); + if(auctionInfo != null) { + if(auctionInfo.has("clean_price")) { + worth = (int)auctionInfo.get("clean_price").getAsFloat(); + } else { + worth = (int)(auctionInfo.get("price").getAsFloat() / auctionInfo.get("count").getAsFloat()); + } + } + break; + default: + worth = neu.manager.auctionManager.getLowestBin(internal); } - } - - if(worthBIN > 0 && totalValueBIN >= 0) { - totalValueBIN += worthBIN; - } else { - if(totalValueBIN != -1) { - missingItemBIN = internal; + if(worth <= 0) { + worth = neu.manager.auctionManager.getLowestBin(internal); + if(worth <= 0) { + worth = neu.manager.auctionManager.getItemAvgBin(internal); + if(worth <= 0) { + JsonObject auctionInfo = neu.manager.auctionManager.getItemAuctionInfo(internal); + if(auctionInfo != null) { + if(auctionInfo.has("clean_price")) { + worth = (int)auctionInfo.get("clean_price").getAsFloat(); + } else { + worth = (int)(auctionInfo.get("price").getAsFloat() / auctionInfo.get("count").getAsFloat()); + } + } + } + } } - totalValueBIN = -1; } - if(worthABIN > 0 && totalValueABIN >= 0) { - totalValueABIN += worthABIN; - } else { - if(totalValueABIN != -1) { - missingItemABIN = internal; + if(worth > 0 && totalValue >= 0) { + totalValue += worth; + + String display = item.getDisplayName(); + + if(display.contains("Enchanted Book")) { + NBTTagCompound tag = item.getTagCompound(); + if(tag != null && tag.hasKey("ExtraAttributes", 10)) { + NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); + NBTTagCompound enchants = ea.getCompoundTag("enchantments"); + + int highestLevel = -1; + for(String enchname : enchants.getKeySet()) { + int level = enchants.getInteger(enchname); + if(level > highestLevel) { + display = EnumChatFormatting.BLUE+WordUtils.capitalizeFully( + enchname.replace("_", " ") + .replace("Ultimate", "") + .trim()) + " " + level; + } + } + } } - totalValueABIN = -1; - } - if(worthAUC > 0 && totalValueAUC >= 0) { - totalValueAUC += worthAUC; + itemValues.put(display, worth); } else { - if(totalValueAUC != -1) { - missingItemAUC = internal; + if(totalValue != -1) { + missingItem = internal; } - totalValueAUC = -1; + totalValue = -1; } } } NumberFormat format = NumberFormat.getInstance(Locale.US); - String valueStringBIN; - String valueStringABIN; - String valueStringAUC; - if(totalValueBIN >= 0) { - valueStringBIN = EnumChatFormatting.YELLOW+"Value (BIN): " + EnumChatFormatting.GOLD - + EnumChatFormatting.BOLD + format.format(totalValueBIN) + " coins"; + String valueStringBIN1; + String valueStringBIN2; + if(totalValue >= 0) { + valueStringBIN1 = EnumChatFormatting.YELLOW+"Value (BIN): "; + valueStringBIN2 = EnumChatFormatting.GOLD + format.format(totalValue) + " coins"; } else { - valueStringBIN = EnumChatFormatting.YELLOW+"Can't find BIN: " + missingItemBIN; - } - if(totalValueABIN >= 0) { - valueStringABIN = EnumChatFormatting.YELLOW+"Value (AVG BIN): " + EnumChatFormatting.GOLD - + EnumChatFormatting.BOLD + format.format(totalValueABIN) + " coins"; - } else { - valueStringABIN = EnumChatFormatting.YELLOW+"Can't find AVG BIN: " + missingItemABIN; - } - if(totalValueAUC >= 0) { - valueStringAUC = EnumChatFormatting.YELLOW+"Value (AUC): " + EnumChatFormatting.GOLD - + EnumChatFormatting.BOLD + format.format(totalValueAUC) + " coins"; - } else { - valueStringAUC = EnumChatFormatting.YELLOW+"Can't find AUC: " + missingItemAUC; + valueStringBIN1 = EnumChatFormatting.YELLOW+"Can't find BIN: "; + valueStringBIN2 = missingItem; } - String profitPrefix = EnumChatFormatting.YELLOW+"Profit/Loss: " + EnumChatFormatting.DARK_GREEN - + EnumChatFormatting.BOLD + "+"; - String lossPrefix = EnumChatFormatting.YELLOW+"Profit/Loss: " + EnumChatFormatting.RED - + EnumChatFormatting.BOLD + "-"; + int profitLossBIN = totalValue - chestCost; + String profitPrefix = EnumChatFormatting.DARK_GREEN.toString(); + String lossPrefix = EnumChatFormatting.RED.toString(); + String prefix = profitLossBIN >= 0 ? profitPrefix : lossPrefix; - int profitLossBIN = totalValueBIN - chestCost; String plStringBIN; if(profitLossBIN >= 0) { - plStringBIN = profitPrefix + format.format(profitLossBIN) + " coins"; + plStringBIN = prefix + "+" + format.format(profitLossBIN) + " coins"; } else { - plStringBIN = lossPrefix + format.format(-profitLossBIN) + " coins"; + plStringBIN = prefix + "-"+ format.format(-profitLossBIN) + " coins"; } - int profitLossABIN = totalValueABIN - chestCost; - String plStringABIN; - if(profitLossABIN >= 0) { - plStringABIN = profitPrefix + format.format(profitLossABIN) + " coins"; - } else { - plStringABIN = lossPrefix + format.format(-profitLossABIN) + " coins"; - } + String neu = EnumChatFormatting.YELLOW + "[NEU] "; - int profitLossAUC = totalValueAUC - chestCost; - String plStringAUC; - if(profitLossAUC >= 0) { - plStringAUC = profitPrefix + format.format(profitLossAUC) + " coins"; - } else { - plStringAUC = lossPrefix + format.format(-profitLossAUC) + " coins"; + newTooltip.add(neu + valueStringBIN1 + " " + valueStringBIN2); + if(totalValue >= 0) { + newTooltip.add(neu + EnumChatFormatting.YELLOW+"Profit/Loss: " + plStringBIN); } - String neu = EnumChatFormatting.YELLOW + "[NEU] "; - - newTooltip.add(neu + valueStringBIN); - if(totalValueBIN >= 0) newTooltip.add(neu + plStringBIN); - newTooltip.add(neu + valueStringABIN); - if(totalValueABIN >= 0) newTooltip.add(neu + plStringABIN); - newTooltip.add(neu + valueStringAUC); - if(totalValueAUC >= 0) newTooltip.add(neu + plStringAUC); + for(Map.Entry entry : itemValues.entrySet()) { + newTooltip.add(neu + entry.getKey() + prefix+"+"+ + format.format(entry.getValue().intValue())); + } } } @@ -1473,83 +1433,8 @@ public class NEUEventListener { event.toolTip.clear(); event.toolTip.addAll(newTooltip); - if(neu.manager.config.invAuctionPrice.value || neu.manager.config.invBazaarPrice.value) { - if(internalname != null) { - JsonObject auctionInfo = neu.manager.auctionManager.getItemAuctionInfo(internalname); - JsonObject bazaarInfo = neu.manager.auctionManager.getBazaarInfo(internalname); - float lowestBinAvg = neu.manager.auctionManager.getItemAvgBin(internalname); - - int lowestBin = neu.manager.auctionManager.getLowestBin(internalname); - APIManager.CraftInfo craftCost = neu.manager.auctionManager.getCraftCost(internalname); - - boolean hasAuctionPrice = neu.manager.config.invAuctionPrice.value && auctionInfo != null; - boolean hasBazaarPrice = neu.manager.config.invBazaarPrice.value && bazaarInfo != null; - boolean hasLowestBinPrice = neu.manager.config.invAuctionPrice.value && lowestBin > 0 && neu.manager.config.advancedPriceInfo.value; - boolean hasLowestBinAvgPrice = neu.manager.config.invAuctionPrice.value && lowestBinAvg > 0; - - NumberFormat format = NumberFormat.getInstance(Locale.US); - - if(hasAuctionPrice || hasBazaarPrice || hasLowestBinAvgPrice || hasLowestBinPrice) event.toolTip.add(""); - if(hasLowestBinPrice) { - event.toolTip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Lowest BIN: "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(lowestBin)+" coins"); - } - if(hasLowestBinAvgPrice) { - event.toolTip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"AVG Lowest BIN: "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(lowestBinAvg)+" coins"); - } - if(hasAuctionPrice) { - 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) { - int stackMultiplier = 1; - int shiftStackMultiplier = event.itemStack.stackSize > 1 ? event.itemStack.stackSize : 64; - if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { - stackMultiplier = shiftStackMultiplier; - } else { - event.toolTip.add(EnumChatFormatting.DARK_GRAY.toString()+"[SHIFT show x"+shiftStackMultiplier+"]"); - } - if(bazaarInfo.has("avg_buy")) { - int bazaarBuyPrice = (int)bazaarInfo.get("avg_buy").getAsFloat()*stackMultiplier; - event.toolTip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Buy: "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarBuyPrice)+" coins"); - } - if(bazaarInfo.has("avg_sell")) { - int bazaarSellPrice = (int)bazaarInfo.get("avg_sell").getAsFloat()*stackMultiplier; - event.toolTip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Sell: "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarSellPrice)+" coins"); - } - if(neu.manager.config.advancedPriceInfo.value) { - if(bazaarInfo.has("curr_buy")) { - int bazaarInstantBuyPrice = (int)bazaarInfo.get("curr_buy").getAsFloat()*stackMultiplier; - event.toolTip.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Insta-Buy: "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarInstantBuyPrice)+" coins"); - } - if(bazaarInfo.has("curr_sell")) { - int bazaarInstantSellPrice = (int)bazaarInfo.get("curr_sell").getAsFloat()*stackMultiplier; - 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"); - } - } + if(neu.config.tooltipTweaks.showPriceInfoInvItem) { + ItemPriceInformation.addToTooltip(event.toolTip, internalname); } } @@ -1560,7 +1445,7 @@ public class NEUEventListener { @SubscribeEvent public void onItemTooltip(ItemTooltipEvent event) { if(!neu.isOnSkyblock()) return; - if(neu.manager.config.hideEmptyPanes.value && + if(neu.config.improvedSBMenu.hideEmptyPanes && event.itemStack.getItem().equals(Item.getItemFromBlock(Blocks.stained_glass_pane))) { String first = Utils.cleanColour(event.toolTip.get(0)); first = first.replaceAll("\\(.*\\)", "").trim(); @@ -1617,7 +1502,7 @@ public class NEUEventListener { } } }*/ - if(!Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || !neu.manager.config.dev.value) return; + if(!Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)/* || /*!neu.config.hidden.dev*/) return; if(event.toolTip.size()>0&&event.toolTip.get(event.toolTip.size()-1).startsWith(EnumChatFormatting.DARK_GRAY + "NBT: ")) { event.toolTip.remove(event.toolTip.size()-1); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index d2467176..668ac1fe 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -3,8 +3,7 @@ package io.github.moulberry.notenoughupdates; import com.google.common.collect.Lists; import com.google.gson.*; import io.github.moulberry.notenoughupdates.auction.APIManager; -import io.github.moulberry.notenoughupdates.cosmetics.CapeManager; -import io.github.moulberry.notenoughupdates.options.Options; +import io.github.moulberry.notenoughupdates.miscgui.GuiItemRecipe; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.HypixelApi; import io.github.moulberry.notenoughupdates.util.Utils; @@ -25,12 +24,9 @@ import java.io.*; import java.net.URL; import java.net.URLConnection; import java.nio.charset.StandardCharsets; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.zip.GZIPInputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -77,19 +73,13 @@ public class NEUManager { public File configFile; public File itemRenameFile; public JsonObject itemRenameJson; - public Options config; public NEUManager(NotEnoughUpdates neu, File configLocation) { this.neu = neu; this.configLocation = configLocation; this.auctionManager = new APIManager(this); - GsonBuilder gsonBuilder = new GsonBuilder().setPrettyPrinting(); - gsonBuilder.registerTypeAdapter(Options.Option.class, Options.createSerializer()); - gsonBuilder.registerTypeAdapter(Options.Option.class, Options.createDeserializer()); - gson = gsonBuilder.create(); - - this.loadConfig(); + gson = new GsonBuilder().setPrettyPrinting().create(); this.repoLocation = new File(configLocation, "repo"); repoLocation.mkdir(); @@ -130,20 +120,6 @@ public class NEUManager { try { writeJson(itemRenameJson, itemRenameFile); } catch(IOException ignored) {} } - public void saveConfig() throws IOException { - config.saveToFile(gson, configFile); - } - - public void loadConfig() { - this.configFile = new File(configLocation, "config.json"); - try { - configFile.createNewFile(); - config = Options.loadFromFile(gson, configFile); - } catch(Exception e) { - config = new Options(); - } - } - /** * Parses a file in to a JsonObject. */ @@ -201,11 +177,11 @@ public class NEUManager { Thread thread = new Thread(() -> { JDialog dialog = null; try { - if(config.autoupdate.value) { + if(NotEnoughUpdates.INSTANCE.config.hidden.autoupdate) { JOptionPane pane = new JOptionPane("Getting items to download from remote repository."); dialog = pane.createDialog("NotEnoughUpdates Remote Sync"); dialog.setModal(false); - if(config.dev.value) dialog.setVisible(true); + if(NotEnoughUpdates.INSTANCE.config.hidden.dev) dialog.setVisible(true); if (Display.isActive()) dialog.toFront(); @@ -239,7 +215,7 @@ public class NEUManager { pane.setMessage("Downloading NEU Master Archive. (DL# >20)"); dialog.pack(); - if(config.dev.value) dialog.setVisible(true); + if(NotEnoughUpdates.INSTANCE.config.hidden.dev) dialog.setVisible(true); if (Display.isActive()) dialog.toFront(); File itemsZip = new File(repoLocation, "neu-items-master.zip"); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index 94302007..69cda23a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -4,13 +4,17 @@ import com.google.common.collect.Lists; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import io.github.moulberry.notenoughupdates.auction.APIManager; +import io.github.moulberry.notenoughupdates.core.GuiScreenElementWrapper; +import io.github.moulberry.notenoughupdates.core.util.lerp.LerpingInteger; import io.github.moulberry.notenoughupdates.infopanes.*; import io.github.moulberry.notenoughupdates.itemeditor.NEUItemEditor; 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.miscfeatures.SunTzu; +import io.github.moulberry.notenoughupdates.miscgui.HelpGUI; +import io.github.moulberry.notenoughupdates.options.NEUConfigEditor; import io.github.moulberry.notenoughupdates.util.*; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.*; @@ -47,16 +51,12 @@ import org.lwjgl.util.vector.Vector2f; import java.awt.*; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.text.NumberFormat; import java.util.List; import java.util.*; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; -import static io.github.moulberry.notenoughupdates.GuiTextures.*; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.*; public class NEUOverlay extends Gui { @@ -82,8 +82,6 @@ public class NEUOverlay extends Gui { }; //Various constants used for GUI structure - private int searchBarXSize = 200; - private final int searchBarYSize = 40; private final int searchBarYOffset = 10; private final int searchBarPadding = 2; @@ -265,12 +263,7 @@ public class NEUOverlay extends Gui { @Override public void mouseClick(float x, float y, int mouseX, int mouseY) { if(Mouse.getEventButtonState()) { - if(activeInfoPane instanceof SettingsInfoPane) { - displayInformationPane(null); - } else { - displayInformationPane(new SettingsInfoPane(overlay, manager)); - } - Utils.playPressSound(); + Minecraft.getMinecraft().displayGuiScreen(new GuiScreenElementWrapper(new NEUConfigEditor(NotEnoughUpdates.INSTANCE.config))); } } @@ -364,10 +357,10 @@ public class NEUOverlay extends Gui { @Override public void mouseClick(float x, float y, int mouseX, int mouseY) { - if(!manager.config.showQuickCommands.value) return; + if(!NotEnoughUpdates.INSTANCE.config.toolbar.quickCommands) return; - if((manager.config.quickcommandMousePress.value && Mouse.getEventButtonState()) || - (!manager.config.quickcommandMousePress.value && !Mouse.getEventButtonState() && Mouse.getEventButton() != -1)) { + if((NotEnoughUpdates.INSTANCE.config.toolbar.quickCommandsClickType != 0 && Mouse.getEventButtonState()) || + (NotEnoughUpdates.INSTANCE.config.toolbar.quickCommandsClickType == 0 && !Mouse.getEventButtonState() && Mouse.getEventButton() != -1)) { if(quickCommandStr.contains(":")) { String command = quickCommandStr.split(":")[0].trim(); if(command.startsWith("/")) { @@ -386,7 +379,7 @@ public class NEUOverlay extends Gui { @Override public void render(float x, float y) { - if(!manager.config.showQuickCommands.value) return; + if(!NotEnoughUpdates.INSTANCE.config.toolbar.quickCommands) return; int paddingUnscaled = getPaddingUnscaled(); int bigItemSize = getSearchBarYSize(); @@ -461,7 +454,7 @@ public class NEUOverlay extends Gui { private MBGuiGroupAligned createQuickCommandGroup() { List children = new ArrayList<>(); - for(String quickCommand : manager.config.quickCommands.value) { + for(String quickCommand : NotEnoughUpdates.INSTANCE.config.hidden.quickCommands) { children.add(createQuickCommand(quickCommand)); } return new MBGuiGroupAligned(children, false) { @@ -477,14 +470,28 @@ public class NEUOverlay extends Gui { public int getPadding() { return getPaddingUnscaled()*4; } + + @Override + public void mouseClick(float x, float y, int mouseX, int mouseY) { + if(NotEnoughUpdates.INSTANCE.config.toolbar.searchBar) { + super.mouseClick(x, y, mouseX, mouseY); + } + } + + @Override + public void render(float x, float y) { + if(NotEnoughUpdates.INSTANCE.config.toolbar.searchBar) { + super.render(x, y); + } + } }; } private MBGuiGroupFloating createGuiGroup() { LinkedHashMap map = new LinkedHashMap<>(); - MBAnchorPoint searchBarAnchor = MBAnchorPoint.createFromString(manager.config.overlaySearchBar.value); - MBAnchorPoint quickCommandAnchor = MBAnchorPoint.createFromString(manager.config.overlayQuickCommand.value); + MBAnchorPoint searchBarAnchor = MBAnchorPoint.createFromString(NotEnoughUpdates.INSTANCE.config.hidden.overlaySearchBar); + MBAnchorPoint quickCommandAnchor = MBAnchorPoint.createFromString(NotEnoughUpdates.INSTANCE.config.hidden.overlayQuickCommand); searchBarAnchor = searchBarAnchor != null ? searchBarAnchor : new MBAnchorPoint(MBAnchorPoint.AnchorPoint.BOTMID, new Vector2f(0, -searchBarYOffset)); @@ -499,8 +506,8 @@ public class NEUOverlay extends Gui { } public void resetAnchors(boolean onlyIfNull) { - MBAnchorPoint searchBarAnchor = MBAnchorPoint.createFromString(manager.config.overlaySearchBar.value); - MBAnchorPoint quickCommandAnchor = MBAnchorPoint.createFromString(manager.config.overlayQuickCommand.value); + MBAnchorPoint searchBarAnchor = MBAnchorPoint.createFromString(NotEnoughUpdates.INSTANCE.config.hidden.overlaySearchBar); + MBAnchorPoint quickCommandAnchor = MBAnchorPoint.createFromString(NotEnoughUpdates.INSTANCE.config.hidden.overlayQuickCommand); if(onlyIfNull) { searchBarAnchor = searchBarAnchor != null ? null : @@ -541,12 +548,13 @@ public class NEUOverlay extends Gui { */ public void reset() { searchBarHasFocus = false; - if(!(searchMode || (manager.config.keepopen.value && itemPaneOpen))) { + if(!(searchMode || (NotEnoughUpdates.INSTANCE.config.itemlist.keepopen && itemPaneOpen))) { itemPaneOpen = false; itemPaneOffsetFactor.setValue(1); itemPaneTabOffset.setValue(20); } if(activeInfoPane != null) activeInfoPane.reset(); + guiGroup.recalculate(); } /** @@ -600,7 +608,7 @@ public class NEUOverlay extends Gui { return false; } - Utils.pushGuiScale(manager.config.paneGuiScale.value.intValue()); + Utils.pushGuiScale(NotEnoughUpdates.INSTANCE.config.itemlist.paneGuiScale); int width = Utils.peekGuiScale().getScaledWidth(); int height = Utils.peekGuiScale().getScaledHeight(); @@ -721,11 +729,12 @@ public class NEUOverlay extends Gui { int orderIconX = leftSide+i*scaledItemPaddedSize; if(mouseX >= orderIconX && mouseX <= orderIconX+scaledITEM_SIZE) { if(Mouse.getEventButton() == 0) { - manager.config.compareMode.value = new Double(i); + NotEnoughUpdates.INSTANCE.config.hidden.compareMode = i; updateSearch(); Utils.playPressSound(); } else if(Mouse.getEventButton() == 1) { - manager.config.compareAscending.value.set(i, !manager.config.compareAscending.value.get(i)); + NotEnoughUpdates.INSTANCE.config.hidden.compareAscending.set(i, + !NotEnoughUpdates.INSTANCE.config.hidden.compareAscending.get(i)); updateSearch(); Utils.playPressSound(); } @@ -735,7 +744,7 @@ public class NEUOverlay extends Gui { for(int i=0; i= sortIconX && mouseX <= sortIconX+scaledITEM_SIZE) { - manager.config.sortMode.value = new Double(i); + NotEnoughUpdates.INSTANCE.config.hidden.sortMode = i; updateSearch(); Utils.playPressSound(); } @@ -747,35 +756,12 @@ public class NEUOverlay extends Gui { } //Clicking on "close info pane" button - if(activeInfoPane instanceof SettingsInfoPane) { - Utils.pushGuiScale(2); - - int widthN = Utils.peekGuiScale().getScaledWidth(); - int heightN = Utils.peekGuiScale().getScaledHeight(); - int mouseXN = Mouse.getX() * widthN / Minecraft.getMinecraft().displayWidth; - int mouseYN = heightN - Mouse.getY() * heightN / Minecraft.getMinecraft().displayHeight - 1; - - if(mouseXN > widthN*getInfoPaneOffsetFactor()-getBoxPadding()-8 && mouseXN < widthN*getInfoPaneOffsetFactor()-getBoxPadding()+8) { - if(mouseYN > getBoxPadding()-8 && mouseYN < getBoxPadding()+8) { - if(Mouse.getEventButtonState() && Mouse.getEventButton() < 2) { //Left or right click up - displayInformationPane(null); - - Utils.pushGuiScale(-1); - Utils.pushGuiScale(-1); - return true; - } - } - } - - Utils.pushGuiScale(-1); - } else { - if(mouseX > width*getInfoPaneOffsetFactor()-getBoxPadding()-8 && mouseX < width*getInfoPaneOffsetFactor()-getBoxPadding()+8) { - if(mouseY > getBoxPadding()-8 && mouseY < getBoxPadding()+8) { - if(Mouse.getEventButtonState() && Mouse.getEventButton() < 2) { //Left or right click up - displayInformationPane(null); - Utils.pushGuiScale(-1); - return true; - } + if(mouseX > width*getInfoPaneOffsetFactor()-getBoxPadding()-8 && mouseX < width*getInfoPaneOffsetFactor()-getBoxPadding()+8) { + if(mouseY > getBoxPadding()-8 && mouseY < getBoxPadding()+8) { + if(Mouse.getEventButtonState() && Mouse.getEventButton() < 2) { //Left or right click up + displayInformationPane(null); + Utils.pushGuiScale(-1); + return true; } } } @@ -805,8 +791,9 @@ public class NEUOverlay extends Gui { * Returns searchBarXSize, scaled by 0.8 if gui scale == AUTO. */ public int getSearchBarXSize() { + int searchBarXSize = NotEnoughUpdates.INSTANCE.config.toolbar.searchBarWidth; if(Utils.peekGuiScale().getScaleFactor()==4) return (int)(searchBarXSize*0.8); - return (int)(searchBarXSize); + return searchBarXSize; } /** @@ -871,12 +858,14 @@ public class NEUOverlay extends Gui { return false; } - if(Keyboard.isKeyDown(Keyboard.KEY_Y) && manager.config.dev.value) { + if(Keyboard.isKeyDown(Keyboard.KEY_Y) && NotEnoughUpdates.INSTANCE.config.hidden.dev) { displayInformationPane(new DevInfoPane(this, manager)); - //displayInformationPane(new QOLInfoPane(this, manager)); } if(Keyboard.getEventKeyState()) { + if(!NotEnoughUpdates.INSTANCE.config.toolbar.searchBar) { + searchBarHasFocus = false; + } if(searchBarHasFocus) { if(keyPressed == 1) { searchBarHasFocus = false; @@ -915,7 +904,7 @@ public class NEUOverlay extends Gui { itemstack.set(hover); } } else if(!hoverInv) { - Utils.pushGuiScale(manager.config.paneGuiScale.value.intValue()); + Utils.pushGuiScale(NotEnoughUpdates.INSTANCE.config.itemlist.paneGuiScale); int width = Utils.peekGuiScale().getScaledWidth(); int height = Utils.peekGuiScale().getScaledHeight(); @@ -950,7 +939,7 @@ public class NEUOverlay extends Gui { } if(internalname.get() != null) { if(itemstack.get() != null) { - if(manager.config.enableItemEditing.value && Keyboard.getEventCharacter() == 'k') { + if(NotEnoughUpdates.INSTANCE.config.hidden.enableItemEditing && Keyboard.getEventCharacter() == 'k') { Minecraft.getMinecraft().displayGuiScreen(new NEUItemEditor(manager, internalname.get(), manager.getJsonForItem(itemstack.get()))); return true; @@ -972,7 +961,7 @@ public class NEUOverlay extends Gui { Minecraft.getMinecraft().thePlayer.inventory.addItemStackToInventory( manager.jsonToStack(item)); } - } else if(manager.config.enableItemEditing.value && Keyboard.getEventCharacter() == 'k') { + } else if(NotEnoughUpdates.INSTANCE.config.hidden.enableItemEditing && Keyboard.getEventCharacter() == 'k') { Minecraft.getMinecraft().displayGuiScreen(new NEUItemEditor(manager, internalname.get(), item)); return true; @@ -1034,16 +1023,16 @@ public class NEUOverlay extends Gui { * Convenience functions that get various compare/sort modes from the config. */ private int getCompareMode() { - return manager.config.compareMode.value.intValue(); + return NotEnoughUpdates.INSTANCE.config.hidden.compareMode; } private int getSortMode() { - return manager.config.sortMode.value.intValue(); + return NotEnoughUpdates.INSTANCE.config.hidden.sortMode; } private List getCompareAscending() { - return manager.config.compareAscending.value; + return NotEnoughUpdates.INSTANCE.config.hidden.compareAscending; } private List getFavourites() { - return manager.config.favourites.value; + return NotEnoughUpdates.INSTANCE.config.hidden.favourites; } /** @@ -1133,7 +1122,7 @@ 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()) { + if(!NotEnoughUpdates.INSTANCE.config.itemlist.showVanillaItems && item.has("vanilla") && item.get("vanilla").getAsBoolean()) { return false; } @@ -1271,7 +1260,7 @@ public class NEUOverlay extends Gui { } public int getBoxPadding() { - double panePadding = Math.max(0, Math.min(20, manager.config.panePadding.value)); + double panePadding = Math.max(0, Math.min(20, NotEnoughUpdates.INSTANCE.config.itemlist.panePadding)); return (int)(panePadding*2/Utils.peekGuiScale().getScaleFactor()+5); } @@ -1315,7 +1304,7 @@ public class NEUOverlay extends Gui { float scaleFMult = 1; if(Utils.peekGuiScale().getScaleFactor()==4) scaleFMult *= 0.9f; if(manager.auctionManager.customAH.isRenderOverAuctionView()) scaleFMult *= 0.8f; - return (float)Math.max(0.5, Math.min(1.5, manager.config.paneWidthMult.value.floatValue()))*scaleFMult; + return (float)Math.max(0.5, Math.min(1.5, NotEnoughUpdates.INSTANCE.config.itemlist.paneWidthMult))*scaleFMult; } /** @@ -1351,6 +1340,7 @@ public class NEUOverlay extends Gui { } public int getSearchBarYSize() { + int searchBarYSize = NotEnoughUpdates.INSTANCE.config.toolbar.searchBarHeight; return Math.max(searchBarYSize/Utils.peekGuiScale().getScaleFactor(), ITEM_SIZE); } @@ -1596,7 +1586,7 @@ public class NEUOverlay extends Gui { int width = Minecraft.getMinecraft().displayWidth; int height = Minecraft.getMinecraft().displayHeight; - if(manager.config.bgBlurFactor.value <= 0 || !OpenGlHelper.isFramebufferEnabled()) return; + if(NotEnoughUpdates.INSTANCE.config.itemlist.bgBlurFactor <= 0 || !OpenGlHelper.isFramebufferEnabled()) return; if(blurOutputHorz == null) { blurOutputHorz = new Framebuffer(width, height, false); @@ -1634,8 +1624,11 @@ public class NEUOverlay extends Gui { } catch(Exception e) { } } if(blurShaderHorz != null && blurShaderVert != null) { - if(manager.config.bgBlurFactor.value != lastBgBlurFactor) { - lastBgBlurFactor = Math.max(0, Math.min(50, manager.config.bgBlurFactor.value)); + if(NotEnoughUpdates.INSTANCE.config.itemlist.bgBlurFactor != lastBgBlurFactor) { + if(blurShaderHorz.getShaderManager().getShaderUniform("Radius") == null) { + return; + } + lastBgBlurFactor = Math.max(0, Math.min(50, NotEnoughUpdates.INSTANCE.config.itemlist.bgBlurFactor)); blurShaderHorz.getShaderManager().getShaderUniform("Radius").set((float)lastBgBlurFactor); blurShaderVert.getShaderManager().getShaderUniform("Radius").set((float)lastBgBlurFactor); } @@ -1654,7 +1647,7 @@ public class NEUOverlay extends Gui { * 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(manager.config.bgBlurFactor.value <= 0 || !OpenGlHelper.isFramebufferEnabled()) return; + if(NotEnoughUpdates.INSTANCE.config.itemlist.bgBlurFactor <= 0 || !OpenGlHelper.isFramebufferEnabled()) return; float uMin = x/(float)width; float uMax = (x+blurWidth)/(float)width; @@ -1670,7 +1663,7 @@ public class NEUOverlay extends Gui { } public void updateGuiGroupSize() { - Utils.pushGuiScale(manager.config.paneGuiScale.value.intValue()); + Utils.pushGuiScale(NotEnoughUpdates.INSTANCE.config.itemlist.paneGuiScale); int width = Utils.peekGuiScale().getScaledWidth(); int height = Utils.peekGuiScale().getScaledHeight(); @@ -1702,15 +1695,15 @@ public class NEUOverlay extends Gui { FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; Utils.resetGuiScale(); - Utils.pushGuiScale(manager.config.paneGuiScale.value.intValue()); + Utils.pushGuiScale(NotEnoughUpdates.INSTANCE.config.itemlist.paneGuiScale); int width = Utils.peekGuiScale().getScaledWidth(); int height = Utils.peekGuiScale().getScaledHeight(); int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; - if(showVanillaLast != manager.config.showVanillaItems.value) { - showVanillaLast = manager.config.showVanillaItems.value; + if(showVanillaLast != NotEnoughUpdates.INSTANCE.config.itemlist.showVanillaItems) { + showVanillaLast = NotEnoughUpdates.INSTANCE.config.itemlist.showVanillaItems; updateSearch(); } @@ -1740,11 +1733,11 @@ public class NEUOverlay extends Gui { yaw++; yaw %= 360; - 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); + bg = new Color(SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.itemlist.backgroundColour), true); + fg = new Color(SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.itemlist.foregroundColour)); + Color fgCustomOpacity = new Color(SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.itemlist.foregroundColour), true); - Color fgFavourite2 = new Color(SpecialColour.specialToChromaRGB(manager.config.itemFavouriteColour.value), true); + Color fgFavourite2 = new Color(SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.itemlist.favouriteColour), true); Color fgFavourite = new Color((int)(fgFavourite2.getRed()*0.8f), (int)(fgFavourite2.getGreen()*0.8f), (int)(fgFavourite2.getBlue()*0.8f), fgFavourite2.getAlpha()); @@ -1791,7 +1784,7 @@ public class NEUOverlay extends Gui { int rightSide = leftSide+paneWidth-getBoxPadding()-getItemBoxXPadding(); //Tab - if(!manager.config.disableItemTabOpen.value) { + if(NotEnoughUpdates.INSTANCE.config.itemlist.tabOpen) { Minecraft.getMinecraft().getTextureManager().bindTexture(itemPaneTabArrow); GlStateManager.color(1f, 1f, 1f, 0.3f); Utils.drawTexturedRect(width-itemPaneTabOffset.getValue()*64/20f, height/2f - 32, 64, 64); @@ -1945,7 +1938,7 @@ public class NEUOverlay extends Gui { checkFramebufferSizes(width, height); - if(redrawItems || !manager.config.cacheRenderedItempane.value) { + if(redrawItems || !NotEnoughUpdates.INSTANCE.config.hidden.cacheRenderedItempane) { renderItemsToImage(width, height, fgFavourite2, fgFavourite, fgCustomOpacity, true, true); redrawItems = false; } @@ -2014,17 +2007,7 @@ public class NEUOverlay extends Gui { GlStateManager.color(1f, 1f, 1f, 1f); Minecraft.getMinecraft().getTextureManager().bindTexture(close); - if(activeInfoPane instanceof SettingsInfoPane) { - Utils.pushGuiScale(2); - - int widthN = Utils.peekGuiScale().getScaledWidth(); - int rightSideN = (int)(widthN*getInfoPaneOffsetFactor()); - Utils.drawTexturedRect(rightSideN-getBoxPadding()-8, getBoxPadding()-8, 16, 16); - - Utils.pushGuiScale(-1); - } else { - Utils.drawTexturedRect(rightSide-getBoxPadding()-8, getBoxPadding()-8, 16, 16); - } + Utils.drawTexturedRect(rightSide-getBoxPadding()-8, getBoxPadding()-8, 16, 16); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); } @@ -2034,80 +2017,8 @@ public class NEUOverlay extends Gui { List text = manager.jsonToStack(json).getTooltip(Minecraft.getMinecraft().thePlayer, false); String internalname = json.get("internalname").getAsString(); - JsonObject auctionInfo = manager.auctionManager.getItemAuctionInfo(internalname); - JsonObject bazaarInfo = manager.auctionManager.getBazaarInfo(internalname); - float lowestBinAvg = manager.auctionManager.getItemAvgBin(internalname); - - int lowestBin = manager.auctionManager.getLowestBin(internalname); - APIManager.CraftInfo craftCost = manager.auctionManager.getCraftCost(internalname); - - boolean hasAuctionPrice = !manager.config.invAuctionPrice.value && auctionInfo != null; - boolean hasBazaarPrice = !manager.config.invBazaarPrice.value && bazaarInfo != null; - boolean hasLowestBinPrice = !manager.config.invAuctionPrice.value && lowestBin > 0 && manager.config.advancedPriceInfo.value; - boolean hasLowestBinAvgPrice = !manager.config.invAuctionPrice.value && lowestBinAvg > 0; - - NumberFormat format = NumberFormat.getInstance(Locale.US); - - if(hasAuctionPrice || hasBazaarPrice || hasLowestBinAvgPrice || hasLowestBinPrice) text.add(""); - if(hasLowestBinPrice) { - text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Lowest BIN: "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(lowestBin)+" coins"); - } - if(hasLowestBinAvgPrice) { - text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"AVG Lowest BIN: "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(lowestBinAvg)+" coins"); - } - if(hasAuctionPrice) { - 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"); - if(manager.config.advancedPriceInfo.value) { - text.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")) { - text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"AH Price (Clean): "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format((int)auctionInfo.get("clean_price").getAsFloat())+" coins"); - if(manager.config.advancedPriceInfo.value) { - text.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) { - int stackMultiplier = 1; - int shiftStackMultiplier = 64; - if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { - stackMultiplier = shiftStackMultiplier; - } else { - text.add(EnumChatFormatting.DARK_GRAY.toString()+"[SHIFT show x"+shiftStackMultiplier+"]"); - } - if(bazaarInfo.has("avg_buy")) { - int bazaarBuyPrice = (int)bazaarInfo.get("avg_buy").getAsFloat()*stackMultiplier; - text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Buy: "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarBuyPrice)+" coins"); - } - if(bazaarInfo.has("avg_sell")) { - int bazaarSellPrice = (int)bazaarInfo.get("avg_sell").getAsFloat()*stackMultiplier; - text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Sell: "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarSellPrice)+" coins"); - } - if(manager.config.advancedPriceInfo.value) { - if(bazaarInfo.has("curr_buy")) { - int bazaarInstantBuyPrice = (int)bazaarInfo.get("curr_buy").getAsFloat()*stackMultiplier; - text.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Bazaar Insta-Buy: "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format(bazaarInstantBuyPrice)+" coins"); - } - if(bazaarInfo.has("curr_sell")) { - int bazaarInstantSellPrice = (int)bazaarInfo.get("curr_sell").getAsFloat()*stackMultiplier; - 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(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Raw Craft Cost: "+ - EnumChatFormatting.GOLD+EnumChatFormatting.BOLD+format.format((int)craftCost.craftCost)+" coins"); + if(!NotEnoughUpdates.INSTANCE.config.tooltipTweaks.showPriceInfoInvItem) { + ItemPriceInformation.addToTooltip(text, internalname); } boolean hasClick = false; @@ -2345,7 +2256,7 @@ public class NEUOverlay extends Gui { Minecraft.getMinecraft().getTextureManager().bindTexture(item_mask); if (getFavourites().contains(json.get("internalname").getAsString())) { - if(manager.config.itemStyle.value) { + if(NotEnoughUpdates.INSTANCE.config.itemlist.itemStyle == 0) { GlStateManager.color(fgFavourite2.getRed() / 255f, fgFavourite2.getGreen() / 255f, fgFavourite2.getBlue() / 255f, fgFavourite2.getAlpha() / 255f); Utils.drawTexturedRect(x - 1, y - 1, ITEM_SIZE + 2, ITEM_SIZE + 2, GL11.GL_NEAREST); @@ -2358,7 +2269,7 @@ public class NEUOverlay extends Gui { drawRect(x, y, x+ITEM_SIZE, y+ITEM_SIZE, fgFavourite.getRGB()); } } else { - if(manager.config.itemStyle.value) { + if(NotEnoughUpdates.INSTANCE.config.itemlist.itemStyle == 0) { GlStateManager.color(fgCustomOpacity.getRed() / 255f, fgCustomOpacity.getGreen() / 255f, fgCustomOpacity.getBlue() / 255f, fgCustomOpacity.getAlpha() / 255f); Utils.drawTexturedRect(x - 1, y - 1, ITEM_SIZE + 2, ITEM_SIZE + 2, GL11.GL_NEAREST); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlayPlacements.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlayPlacements.java deleted file mode 100644 index 633c1c4b..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlayPlacements.java +++ /dev/null @@ -1,221 +0,0 @@ -package io.github.moulberry.notenoughupdates; - -import io.github.moulberry.notenoughupdates.mbgui.*; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.util.EnumChatFormatting; -import org.lwjgl.input.Keyboard; -import org.lwjgl.util.vector.Vector2f; - -import java.awt.*; -import java.io.IOException; - -public class NEUOverlayPlacements extends GuiScreen { - - private int clickedX; - private int clickedY; - private int clickedAnchorX; - private int clickedAnchorY; - private MBGuiElement clickedElement; - private GuiButton guiButton = new GuiButton(0, 5, 5, "Reset to Default"); - - private boolean dropdownMenuShown = false; - - @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { - super.drawScreen(mouseX, mouseY, partialTicks); - drawDefaultBackground(); - - /*GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - Minecraft.getMinecraft().getTextureManager().bindTexture(icons); - GlStateManager.enableBlend(); - - GlStateManager.tryBlendFuncSeparate(775, 769, 1, 0); - GlStateManager.enableAlpha(); - this.drawTexturedModalRect(width / 2 - 7, height / 2 - 7, 0, 0, 16, 16);*/ - - if(mouseX < 300 && mouseY < 300 && clickedElement != null) { - guiButton.yPosition = height - 5 - guiButton.height; - } else { - guiButton.yPosition = 5; - } - - EnumChatFormatting GOLD = EnumChatFormatting.GOLD; - - guiButton.drawButton(Minecraft.getMinecraft(), mouseX, mouseY); - - NotEnoughUpdates.INSTANCE.overlay.updateGuiGroupSize(); - - drawRect((width-176)/2, (height-166)/2, - (width+176)/2, (height+166)/2, new Color(100, 100, 100, 200).getRGB()); - Utils.drawStringCentered(GOLD+"Inventory", Minecraft.getMinecraft().fontRendererObj, width/2f, height/2f, false, 0); - - MBGuiGroupFloating mainGroup = NotEnoughUpdates.INSTANCE.overlay.guiGroup; - mainGroup.render(0, 0); - GlStateManager.translate(0, 0, 500); - for(MBGuiElement element : mainGroup.getChildren()) { - MBAnchorPoint anchorPoint = mainGroup.getChildrenMap().get(element); - Vector2f position = mainGroup.getChildrenPosition().get(element); - - drawRect((int)position.x, (int)position.y, - (int)position.x+element.getWidth(), (int)position.y+element.getHeight(), new Color(100, 100, 100, 200).getRGB()); - - switch(anchorPoint.anchorPoint) { - case TOPLEFT: - case TOPRIGHT: - case BOTLEFT: - case BOTRIGHT: - drawRect((int)(position.x+element.getWidth()*anchorPoint.anchorPoint.x*0.9f), - (int)(position.y+element.getHeight()*anchorPoint.anchorPoint.y*0.9f), - (int)(position.x+element.getWidth()*anchorPoint.anchorPoint.x*0.9f+element.getWidth()*0.1f), - (int)(position.y+element.getHeight()*anchorPoint.anchorPoint.y*0.9f+element.getHeight()*0.1f), - new Color(200, 200, 200, 100).getRGB()); - break; - case TOPMID: - drawRect((int)position.x, (int)position.y, - (int)position.x+element.getWidth(), (int)(position.y+element.getHeight()*0.1f), - new Color(200, 200, 200, 100).getRGB()); - break; - case MIDLEFT: - drawRect((int)position.x, (int)position.y, - (int)(position.x+element.getWidth()*0.1f), (int)position.y+element.getHeight(), - new Color(200, 200, 200, 100).getRGB()); - break; - case MIDRIGHT: - drawRect((int)(position.x+element.getWidth()*0.9f), (int)position.y, - (int)position.x+element.getWidth(), (int)position.y+element.getHeight(), - new Color(200, 200, 200, 100).getRGB()); - break; - case BOTMID: - drawRect((int)position.x, (int)(position.y+element.getHeight()*0.9f), - (int)position.x+element.getWidth(), (int)position.y+element.getHeight(), - new Color(200, 200, 200, 100).getRGB()); - break; - case MIDMID: - drawRect((int)(position.x+element.getWidth()*0.45f), (int)(position.y+element.getHeight()*0.45f), - (int)(position.x+element.getWidth()*0.55f), (int)(position.y+element.getHeight()*0.55f), - new Color(200, 200, 200, 100).getRGB()); - break; - - } - - if(anchorPoint.inventoryRelative) { - Utils.drawStringCentered(GOLD+"Inv-Relative", Minecraft.getMinecraft().fontRendererObj, - position.x+element.getWidth()*0.5f, position.y+element.getHeight()*0.5f, false, 0); - } - } - GlStateManager.translate(0, 0, -500); - } - - @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { - super.mouseClicked(mouseX, mouseY, mouseButton); - - if(mouseButton != 0 && mouseButton != 1) return; - - MBGuiGroupFloating mainGroup = NotEnoughUpdates.INSTANCE.overlay.guiGroup; - int index=0; - for(MBGuiElement element : mainGroup.getChildren()) { - MBAnchorPoint anchorPoint = mainGroup.getChildrenMap().get(element); - Vector2f position = mainGroup.getChildrenPosition().get(element); - - if(mouseX > position.x && mouseX < position.x + element.getWidth()) { - if(mouseY > position.y && mouseY < position.y + element.getHeight()) { - if(mouseButton == 0) { - clickedElement = element; - clickedX = mouseX; - clickedY = mouseY; - clickedAnchorX = (int)anchorPoint.offset.x; - clickedAnchorY = (int)anchorPoint.offset.y; - } else { - if(Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) { - anchorPoint.inventoryRelative = !anchorPoint.inventoryRelative; - } else { - MBAnchorPoint.AnchorPoint[] vals = MBAnchorPoint.AnchorPoint.values(); - anchorPoint.anchorPoint = vals[(anchorPoint.anchorPoint.ordinal()+1)%vals.length]; - - mainGroup.recalculate(); - - anchorPoint.offset.x += position.x - mainGroup.getChildrenPosition().get(element).x; - anchorPoint.offset.y += position.y - mainGroup.getChildrenPosition().get(element).y; - - mainGroup.recalculate(); - - if(index == 0) { - NotEnoughUpdates.INSTANCE.manager.config.overlaySearchBar.value = anchorPoint.toString(); - } else if(index == 1) { - NotEnoughUpdates.INSTANCE.manager.config.overlayQuickCommand.value = anchorPoint.toString(); - } - try { NotEnoughUpdates.INSTANCE.manager.saveConfig(); } catch(IOException ignored) {} - } - } - return; - } - } - index++; - } - - if(guiButton.mousePressed(Minecraft.getMinecraft(), mouseX, mouseY)) { - NotEnoughUpdates.INSTANCE.manager.config.overlayQuickCommand.value = ""; - NotEnoughUpdates.INSTANCE.manager.config.overlaySearchBar.value = ""; - try { NotEnoughUpdates.INSTANCE.manager.saveConfig(); } catch(IOException ignored) {} - NotEnoughUpdates.INSTANCE.overlay.resetAnchors(false); - - mainGroup.recalculate(); - } - clickedElement = null; - } - - @Override - protected void mouseReleased(int mouseX, int mouseY, int state) { - clickedElement = null; - } - - @Override - protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { - super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); - if(clickedElement != null) { - MBGuiGroupFloating mainGroup = NotEnoughUpdates.INSTANCE.overlay.guiGroup; - MBAnchorPoint anchorPoint = mainGroup.getChildrenMap().get(clickedElement); - - if(Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) { - int dX = mouseX - clickedX; - int dY = mouseY - clickedY; - if(Math.abs(dX) > Math.abs(dY)) { - anchorPoint.offset.x = mouseX - clickedX + clickedAnchorX; - anchorPoint.offset.y = clickedAnchorY; - } else { - anchorPoint.offset.x = clickedAnchorX; - anchorPoint.offset.y = mouseY - clickedY + clickedAnchorY; - } - } else { - anchorPoint.offset.x = mouseX - clickedX + clickedAnchorX; - anchorPoint.offset.y = mouseY - clickedY + clickedAnchorY; - } - - int index = 0; - for(MBGuiElement element : mainGroup.getChildren()) { - if(element == clickedElement) { - if(index == 0) { - NotEnoughUpdates.INSTANCE.manager.config.overlaySearchBar.value = anchorPoint.toString(); - } else if(index == 1) { - NotEnoughUpdates.INSTANCE.manager.config.overlayQuickCommand.value = anchorPoint.toString(); - } - try { NotEnoughUpdates.INSTANCE.manager.saveConfig(); } catch(IOException ignored) {} - break; - } - index++; - } - try { MBDeserializer.serializeAndSave(mainGroup, "overlay"); } catch(Exception e) {} - mainGroup.recalculate(); - } - } - - @Override - public boolean doesGuiPauseGame() { - return false; - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUResourceManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUResourceManager.java deleted file mode 100644 index 41737eda..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUResourceManager.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.github.moulberry.notenoughupdates; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.resources.IResource; -import net.minecraft.client.resources.IResourceManager; -import net.minecraft.util.ResourceLocation; - -import java.io.IOException; -import java.util.List; -import java.util.Set; - -public class NEUResourceManager implements IResourceManager { - - private IResourceManager parentResourceManager; - - public NEUResourceManager(IResourceManager parentResourceManager) { - this.parentResourceManager = parentResourceManager; - } - - @Override - public Set getResourceDomains() { - return parentResourceManager.getResourceDomains(); - } - - @Override - public IResource getResource(ResourceLocation location) throws IOException { - return parentResourceManager.getResource(forceNeuRL(location)); - } - - @Override - public List getAllResources(ResourceLocation location) throws IOException { - return parentResourceManager.getAllResources(forceNeuRL(location)); - } - - private ResourceLocation forceNeuRL(ResourceLocation location) { - return new ResourceLocation("notenoughupdates", location.getResourcePath()); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index a7f37935..897db723 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -1,14 +1,14 @@ package io.github.moulberry.notenoughupdates; import com.google.common.collect.Sets; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.mojang.authlib.Agent; -import com.mojang.authlib.exceptions.AuthenticationException; -import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService; -import com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication; import io.github.moulberry.notenoughupdates.auction.CustomAHGui; import io.github.moulberry.notenoughupdates.commands.SimpleCommand; +import io.github.moulberry.notenoughupdates.core.BackgroundBlur; +import io.github.moulberry.notenoughupdates.core.GuiScreenElementWrapper; import io.github.moulberry.notenoughupdates.cosmetics.CapeManager; import io.github.moulberry.notenoughupdates.cosmetics.GuiCosmetics; import io.github.moulberry.notenoughupdates.dungeons.DungeonMap; @@ -17,12 +17,19 @@ import io.github.moulberry.notenoughupdates.dungeons.GuiDungeonMapEditor; import io.github.moulberry.notenoughupdates.gamemodes.GuiGamemodes; import io.github.moulberry.notenoughupdates.gamemodes.SBGamemodes; import io.github.moulberry.notenoughupdates.infopanes.CollectionLogInfoPane; -import io.github.moulberry.notenoughupdates.infopanes.SettingsInfoPane; +import io.github.moulberry.notenoughupdates.miscfeatures.CustomItemEffects; +import io.github.moulberry.notenoughupdates.miscfeatures.EnchantingSolvers; +import io.github.moulberry.notenoughupdates.miscfeatures.SunTzu; +import io.github.moulberry.notenoughupdates.miscgui.CalendarOverlay; +import io.github.moulberry.notenoughupdates.miscgui.GuiEnchantColour; +import io.github.moulberry.notenoughupdates.miscgui.HelpGUI; +import io.github.moulberry.notenoughupdates.miscgui.NEUOverlayPlacements; +import io.github.moulberry.notenoughupdates.options.NEUConfig; +import io.github.moulberry.notenoughupdates.options.NEUConfigEditor; 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.SBInfo; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.block.material.MapColor; @@ -59,14 +66,10 @@ import org.apache.commons.lang3.text.translate.UnicodeUnescaper; import org.lwjgl.opengl.Display; import org.lwjgl.opengl.GL11; -import javax.swing.*; import java.awt.*; import java.awt.datatransfer.StringSelection; import java.io.*; import java.lang.management.ManagementFactory; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.net.*; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.List; @@ -86,6 +89,9 @@ public class NotEnoughUpdates { public NEUManager manager; public NEUOverlay overlay; + public NEUConfig config; + + private File configFile; private static final long CHAT_MSG_COOLDOWN = 200; private long lastChatMessage = 0; @@ -201,13 +207,6 @@ public class NotEnoughUpdates { } }); - - SimpleCommand questingCommand = new SimpleCommand("neuquest", new SimpleCommand.ProcessCommandRunnable() { - public void processCommand(ICommandSender sender, String[] args) { - openGui = new GuiQuestLine(); - } - }); - SimpleCommand gamemodesCommand = new SimpleCommand("neugamemodes", new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { boolean upgradeOverride = args.length == 1 && args[0].equals("upgradeOverride"); @@ -519,7 +518,7 @@ public class NotEnoughUpdates { 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("[API Key]").append("[").append(!config.apiKey.apiKey.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"); @@ -566,7 +565,7 @@ public class NotEnoughUpdates { } catch(Exception e) { } } - if (manager.config.apiKey.value == null || manager.config.apiKey.value.trim().isEmpty()) { + if (config.apiKey.apiKey == null || config.apiKey.apiKey.trim().isEmpty()) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Can't view profile, apikey is not set. Run /api new and put the result in settings.")); } else if (args.length == 0) { @@ -717,7 +716,7 @@ public class NotEnoughUpdates { } catch(Exception ignored) { } } - if(!manager.config.dev.value) { + if(!config.hidden.dev) { openGui = new GuiDungeonMapEditor(); return; } @@ -802,28 +801,19 @@ public class NotEnoughUpdates { SimpleCommand settingsCommand = new SimpleCommand("neu", new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { - overlay.displayInformationPane(new SettingsInfoPane(overlay, manager)); - if(!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) { - openGui = new GuiInventory(Minecraft.getMinecraft().thePlayer); - } + openGui = new GuiScreenElementWrapper(new NEUConfigEditor(config)); } }); SimpleCommand settingsCommand2 = new SimpleCommand("neusettings", new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { - overlay.displayInformationPane(new SettingsInfoPane(overlay, manager)); - if(!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) { - openGui = new GuiInventory(Minecraft.getMinecraft().thePlayer); - } + openGui = new GuiScreenElementWrapper(new NEUConfigEditor(config)); } }); SimpleCommand settingsCommand3 = new SimpleCommand("neuconfig", new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { - overlay.displayInformationPane(new SettingsInfoPane(overlay, manager)); - if(!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) { - openGui = new GuiInventory(Minecraft.getMinecraft().thePlayer); - } + openGui = new GuiScreenElementWrapper(new NEUConfigEditor(config)); } }); @@ -841,7 +831,7 @@ public class NotEnoughUpdates { if(!hasSkyblockScoreboard()) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED+ "You must be on Skyblock to use this feature.")); - } else if(manager.config.apiKey.value == null || manager.config.apiKey.value.trim().isEmpty()) { + } else if(config.apiKey.apiKey == null || config.apiKey.apiKey.trim().isEmpty()) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED+ "Can't open NeuAH, apikey is not set. Run /api new and put the result in settings.")); } else { @@ -855,6 +845,8 @@ public class NotEnoughUpdates { } }); + private Gson gson = new GsonBuilder().setPrettyPrinting().excludeFieldsWithoutExposeAnnotation().create(); + /** * Instantiates NEUIo, NEUManager and NEUOverlay instances. Registers keybinds and adds a shutdown hook to clear tmp folder. * @param event @@ -863,20 +855,33 @@ public class NotEnoughUpdates { public void preinit(FMLPreInitializationEvent event) { INSTANCE = this; + File f = new File(event.getModConfigurationDirectory(), "notenoughupdates"); + f.mkdirs(); + + configFile = new File(f, "configNew.json"); + + if(configFile.exists()) { + try(BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8))) { + config = gson.fromJson(reader, NEUConfig.class); + } catch(Exception e) { } + } + + if(config == null) { + config = new NEUConfig(); + saveConfig(); + } + MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(new NEUEventListener(this)); MinecraftForge.EVENT_BUS.register(CapeManager.getInstance()); MinecraftForge.EVENT_BUS.register(new SBGamemodes()); + MinecraftForge.EVENT_BUS.register(new EnchantingSolvers()); MinecraftForge.EVENT_BUS.register(new CalendarOverlay()); MinecraftForge.EVENT_BUS.register(SBInfo.getInstance()); MinecraftForge.EVENT_BUS.register(CustomItemEffects.INSTANCE); MinecraftForge.EVENT_BUS.register(new DungeonMap()); MinecraftForge.EVENT_BUS.register(new SunTzu()); - //MinecraftForge.EVENT_BUS.register(new BetterPortals()); - - File f = new File(event.getModConfigurationDirectory(), "notenoughupdates"); - f.mkdirs(); ClientCommandHandler.instance.registerCommand(collectionLogCommand); ClientCommandHandler.instance.registerCommand(cosmeticsCommand); ClientCommandHandler.instance.registerCommand(linksCommand); @@ -900,6 +905,8 @@ public class NotEnoughUpdates { ClientCommandHandler.instance.registerCommand(dungeonWinTest); ClientCommandHandler.instance.registerCommand(calendarCommand); + BackgroundBlur.registerListener(); + manager = new NEUManager(this, f); manager.loadItemInformation(); overlay = new NEUOverlay(manager); @@ -910,54 +917,26 @@ public class NotEnoughUpdates { } Runtime.getRuntime().addShutdownHook(new Thread(() -> { - try { - File tmp = new File(f, "tmp"); - if(tmp.exists()) { - for(File tmpFile : tmp.listFiles()) { - tmpFile.delete(); - } - tmp.delete(); + File tmp = new File(f, "tmp"); + if(tmp.exists()) { + for(File tmpFile : tmp.listFiles()) { + tmpFile.delete(); } + tmp.delete(); + } - manager.saveConfig(); - } catch(IOException e) {} + saveConfig(); })); + } - //TODO: login code. Ignore this, used for testing. - if(manager.config.dev.value) { - try { - Field field = Minecraft.class.getDeclaredField("session"); - YggdrasilUserAuthentication auth = (YggdrasilUserAuthentication) - new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString()) - .createUserAuthentication(Agent.MINECRAFT); - auth.setUsername("james.jenour@protonmail.com"); - auth.setPassword("Miranda728%"); - - JPasswordField pf = new JPasswordField(); - JOptionPane.showConfirmDialog(null, - pf, - "Enter password:", - JOptionPane.DEFAULT_OPTION, - JOptionPane.PLAIN_MESSAGE); - auth.setPassword(new String(pf.getPassword())); - System.out.print("Attempting login..."); - - auth.logIn(); - - Session session = new Session(auth.getSelectedProfile().getName(), - auth.getSelectedProfile().getId().toString().replace("-", ""), - auth.getAuthenticatedToken(), - auth.getUserType().getName()); - - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); - - field.setAccessible(true); - field.set(Minecraft.getMinecraft(), session); - } catch (NoSuchFieldException | AuthenticationException | IllegalAccessException e) { + public void saveConfig() { + try { + configFile.createNewFile(); + + try(BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(configFile), StandardCharsets.UTF_8))) { + writer.write(gson.toJson(config)); } - } + } catch(IOException ignored) {} } /** @@ -1037,7 +1016,7 @@ public class NotEnoughUpdates { } public boolean isOnSkyblock() { - if(!manager.config.onlyShowOnSkyblock.value) return true; + if(!config.misc.onlyShowOnSkyblock) return true; return hasSkyblockScoreboard(); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/RequestFocusListener.java b/src/main/java/io/github/moulberry/notenoughupdates/RequestFocusListener.java deleted file mode 100644 index ecc27c9a..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/RequestFocusListener.java +++ /dev/null @@ -1,63 +0,0 @@ -package io.github.moulberry.notenoughupdates; - -import javax.swing.*; -import javax.swing.event.*; - -/** - * Convenience class to request focus on a component. - * - * When the component is added to a realized Window then component will - * request focus immediately, since the ancestorAdded event is fired - * immediately. - * - * When the component is added to a non realized Window, then the focus - * request will be made once the window is realized, since the - * ancestorAdded event will not be fired until then. - * - * Using the default constructor will cause the listener to be removed - * from the component once the AncestorEvent is generated. A second constructor - * allows you to specify a boolean value of false to prevent the - * AncestorListener from being removed when the event is generated. This will - * allow you to reuse the listener each time the event is generated. - */ -public class RequestFocusListener implements AncestorListener -{ - private boolean removeListener; - - /* - * Convenience constructor. The listener is only used once and then it is - * removed from the component. - */ - public RequestFocusListener() - { - this(true); - } - - /* - * Constructor that controls whether this listen can be used once or - * multiple times. - * - * @param removeListener when true this listener is only invoked once - * otherwise it can be invoked multiple times. - */ - public RequestFocusListener(boolean removeListener) - { - this.removeListener = removeListener; - } - - @Override - public void ancestorAdded(AncestorEvent e) - { - JComponent component = e.getComponent(); - component.requestFocusInWindow(); - - if (removeListener) - component.removeAncestorListener( this ); - } - - @Override - public void ancestorMoved(AncestorEvent e) {} - - @Override - public void ancestorRemoved(AncestorEvent e) {} -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/SBAIntegration.java b/src/main/java/io/github/moulberry/notenoughupdates/SBAIntegration.java deleted file mode 100644 index 4df9c847..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/SBAIntegration.java +++ /dev/null @@ -1,217 +0,0 @@ -package io.github.moulberry.notenoughupdates; - -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.settings.KeyBinding; -import net.minecraft.item.ItemStack; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.List; - -public class SBAIntegration { - - private static boolean hasSBA = true; - private static Class skyblockAddonsClass = null; - private static Method skyblockAddons_getInstance = null; - private static Method skyblockAddons_getUtils = null; - private static Class backpackManagerClass = null; - private static Method backpackManager_getFromItem = null; - private static Class backpackClass = null; - private static Method backpackClass_setX= null; - private static Method backpackClass_setY = null; - private static Class utilsClass = null; - private static Method utils_setBackpackToPreview = null; - public static boolean setActiveBackpack(ItemStack stack, int mouseX, int mouseY) { - if(!hasSBA) return false; - try { - if(skyblockAddonsClass == null) { - skyblockAddonsClass = Class.forName("codes.biscuit.skyblockaddons.SkyblockAddons"); - } - if(skyblockAddons_getInstance == null) { - skyblockAddons_getInstance = skyblockAddonsClass.getDeclaredMethod("getInstance"); - } - if(skyblockAddons_getUtils == null) { - skyblockAddons_getUtils = skyblockAddonsClass.getDeclaredMethod("getUtils"); - } - if(backpackManagerClass == null) { - backpackManagerClass = Class.forName("codes.biscuit.skyblockaddons.features.backpacks.BackpackManager"); - } - if(backpackManager_getFromItem == null) { - backpackManager_getFromItem = backpackManagerClass.getDeclaredMethod("getFromItem", ItemStack.class); - } - if(backpackClass == null) { - try { backpackClass = Class.forName("codes.biscuit.skyblockaddons.features.backpacks.Backpack"); } catch(Exception ignored){} - } - if(backpackClass == null) { - backpackClass = Class.forName("codes.biscuit.skyblockaddons.features.backpacks.ContainerPreview"); - } - if(backpackClass_setX == null) { - backpackClass_setX = backpackClass.getDeclaredMethod("setX", int.class); - } - if(backpackClass_setY == null) { - backpackClass_setY = backpackClass.getDeclaredMethod("setY", int.class); - } - if(utilsClass == null) { - utilsClass = Class.forName("codes.biscuit.skyblockaddons.utils.Utils"); - } - if(utils_setBackpackToPreview == null) { - try { utils_setBackpackToPreview = utilsClass.getDeclaredMethod("setBackpackToPreview", backpackClass); } catch(Exception ignored){} - } - if(utils_setBackpackToPreview == null) { - utils_setBackpackToPreview = utilsClass.getDeclaredMethod("setContainerPreviewToRender", backpackClass);; - } - } catch(Exception e) { - e.printStackTrace(); - hasSBA = false; - return false; - } - try { - Object skyblockAddons = skyblockAddons_getInstance.invoke(null); - Object utils = skyblockAddons_getUtils.invoke(skyblockAddons); - if(stack == null) { - utils_setBackpackToPreview.invoke(utils, (Object) null); - } else { - Object backpack = backpackManager_getFromItem.invoke(null, stack); - backpackClass_setX.invoke(backpack, mouseX); - backpackClass_setY.invoke(backpack, mouseY); - utils_setBackpackToPreview.invoke(utils, backpack); - } - } catch(Exception e) { - e.printStackTrace(); - return false; - } - return true; - } - - private static Field guiContainerHook_freezeBackpack = null; - public static boolean isFreezeBackpack() { - if(!hasSBA) return false; - try { - if(guiContainerHookClass == null) { - guiContainerHookClass = Class.forName("codes.biscuit.skyblockaddons.asm.hooks.GuiContainerHook"); - } - if(guiContainerHook_freezeBackpack == null) { - guiContainerHook_freezeBackpack = guiContainerHookClass.getDeclaredField("freezeBackpack"); - guiContainerHook_freezeBackpack.setAccessible(true); - } - } catch(Exception e) { - e.printStackTrace(); - hasSBA = false; - return false; - } - try { - return (boolean) guiContainerHook_freezeBackpack.get(null); - } catch(Exception e) { - e.printStackTrace(); - return false; - } - } - - public static boolean setFreezeBackpack(boolean freezeBackpack) { - if(!hasSBA) return false; - try { - if(guiContainerHookClass == null) { - guiContainerHookClass = Class.forName("codes.biscuit.skyblockaddons.asm.hooks.GuiContainerHook"); - } - if(guiContainerHook_freezeBackpack == null) { - guiContainerHook_freezeBackpack = guiContainerHookClass.getDeclaredField("freezeBackpack"); - guiContainerHook_freezeBackpack.setAccessible(true); - } - } catch(Exception e) { - e.printStackTrace(); - hasSBA = false; - return false; - } - try { - guiContainerHook_freezeBackpack.set(null, freezeBackpack); - return true; - } catch(Exception e) { - e.printStackTrace(); - return false; - } - } - - private static Method guiContainerHook_keyTyped = null; - private static Method skyblockAddons_getFreezeBackpackKey = null; - public static boolean keyTyped(int keyCode) { - if(!hasSBA) return false; - try { - if(skyblockAddonsClass == null) { - skyblockAddonsClass = Class.forName("codes.biscuit.skyblockaddons.SkyblockAddons"); - } - if(skyblockAddons_getInstance == null) { - skyblockAddons_getInstance = skyblockAddonsClass.getDeclaredMethod("getInstance"); - } - if(skyblockAddons_getFreezeBackpackKey == null) { - skyblockAddons_getFreezeBackpackKey = skyblockAddonsClass.getDeclaredMethod("getFreezeBackpackKey"); - } - if(guiContainerHookClass == null) { - guiContainerHookClass = Class.forName("codes.biscuit.skyblockaddons.asm.hooks.GuiContainerHook"); - } - if(guiContainerHook_keyTyped == null) { - guiContainerHook_keyTyped = guiContainerHookClass.getDeclaredMethod("keyTyped", int.class); - } - } catch(Exception e) { - e.printStackTrace(); - hasSBA = false; - return false; - } - try { - Object skyblockAddons = skyblockAddons_getInstance.invoke(null); - if(!isFreezeBackpack() && ((KeyBinding)skyblockAddons_getFreezeBackpackKey.invoke(skyblockAddons)).getKeyCode() == keyCode) { - setFreezeBackpack(true); - } else { - guiContainerHook_keyTyped.invoke(null, keyCode); - } - } catch(Exception e) { - e.printStackTrace(); - return false; - } - return true; - } - - private static Class guiContainerHookClass = null; - private static Method guiContainerHook_drawBackpacks = null; - public static boolean renderActiveBackpack(int mouseX, int mouseY, FontRenderer fontRendererObj) { - if(!hasSBA) return false; - try { - if(guiContainerHookClass == null) { - guiContainerHookClass = Class.forName("codes.biscuit.skyblockaddons.asm.hooks.GuiContainerHook"); - } - if(guiContainerHook_drawBackpacks == null) { - guiContainerHook_drawBackpacks = guiContainerHookClass.getDeclaredMethod("drawBackpacks", - GuiContainer.class, int.class, int.class, FontRenderer.class); - } - } catch(Exception e) { - e.printStackTrace(); - hasSBA = false; - return false; - } - try { - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - int width = scaledResolution.getScaledWidth(); - int height = scaledResolution.getScaledHeight(); - - if(Minecraft.getMinecraft().currentScreen instanceof GuiContainer) { - guiContainerHook_drawBackpacks.invoke(null, Minecraft.getMinecraft().currentScreen, mouseX, mouseY, fontRendererObj); - } else { - GuiContainer container = new GuiContainer(null) { - protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { - } - }; - container.setWorldAndResolution(Minecraft.getMinecraft(), width, height); - - guiContainerHook_drawBackpacks.invoke(null, container, mouseX, mouseY, fontRendererObj); - } - } catch(Exception e) { - e.printStackTrace(); - return false; - } - return true; - } - -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/StreamerMode.java b/src/main/java/io/github/moulberry/notenoughupdates/StreamerMode.java deleted file mode 100644 index 051313d1..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/StreamerMode.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.github.moulberry.notenoughupdates; - -import io.github.moulberry.notenoughupdates.util.Utils; - -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class StreamerMode { - - private static final Pattern lobbyPattern = Pattern.compile("(mini|mega|m|M)([0-9]{1,3}[A-Z])"); - - public static String filterLobbyNames(String line) { - Matcher matcher = lobbyPattern.matcher(line); - if(matcher.find() && matcher.groupCount() == 2) { - String lobbyType = matcher.group(1); - String lobbyId = matcher.group(2); - long lobbyNum = Long.parseLong(lobbyId.substring(0, lobbyId.length()-1)); - - long obfLobbyNum = (lobbyNum*9182739 + 11) % 500; - char obfLobbyLetter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt((int)(obfLobbyNum%26)); - - line = line.replaceAll("(mini|mega|m|M)([0-9]{1,3}[A-Z])", lobbyType+obfLobbyNum+obfLobbyLetter); - } - return line; - } - - public static String filterScoreboard(String line) { - line = filterLobbyNames(Utils.cleanDuplicateColourCodes(line)); - return line; - } - - public static String filterChat(String line) { - line = filterLobbyNames(line); - return line; - } - -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/SunTzu.java b/src/main/java/io/github/moulberry/notenoughupdates/SunTzu.java deleted file mode 100644 index 6de8245e..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/SunTzu.java +++ /dev/null @@ -1,94 +0,0 @@ -package io.github.moulberry.notenoughupdates; - -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.MovingObjectPosition; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.event.world.WorldEvent; -import net.minecraftforge.fml.common.Loader; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; - -import java.util.Random; - -public class SunTzu { - - private static boolean enabled = false; - private static int quoteNum = 0; - - private static Random rand = new Random(); - - private static String[] quotes = new String[] { - "Appear weak when you are strong, and strong when you are weak.", - "The supreme art of war is to subdue the enemy without fighting.", - "If you know the enemy and know yourself, you need not fear the result of a hundred battles.", - "Let your plans be dark and impenetrable as night, and when you move, fall like a thunderbolt.", - "All warfare is based on deception.", - "In the midst of chaos, there is also opportunity.", - "The greatest victory is that which requires no battle.", - "To know your Enemy, you must become your Enemy.", - "There is no instance of a nation benefitting from prolonged warfare.", - "Even the finest sword plunged into salt water will eventually rust.", - "Opportunities multiply as they are seized.", - "When the enemy is relaxed, make them toil. When full, starve them. When settled, make them move.", - "He who wishes to fight must first count the cost", - "If you wait by the river long enough, the bodies of your enemies will float by.", - "Be extremely subtle even to the point of formlessness. Be extremely mysterious even to the point of soundlessness. Thereby you can be the director of the opponent's fate.", - "Build your opponent a golden bridge to retreat across.", - "The wise warrior avoids the battle.", - "Great results, can be achieved with small forces.", - "Attack is the secret of defense; defense is the planning of an attack.", - "Subscribe to Moulberry on YouTube." - }; - - public static void setEnabled(boolean enabled) { - SunTzu.enabled = enabled; - } - - public static void randomizeQuote() { - for(int i=0; i<3; i++) { - int newQuote = rand.nextInt(quotes.length); - - if(newQuote != quoteNum) { - quoteNum = newQuote; - return; - } - } - } - - private static String getQuote() { - return quotes[quoteNum]; - } - - @SubscribeEvent - public void onOverlayDrawn(RenderGameOverlayEvent event) { - if(enabled && ((event.type == null && Loader.isModLoaded("labymod")) || - event.type == RenderGameOverlayEvent.ElementType.ALL)) { - if(Minecraft.getMinecraft().gameSettings.showDebugInfo || - (Minecraft.getMinecraft().gameSettings.keyBindPlayerList.isKeyDown() && - (!Minecraft.getMinecraft().isIntegratedServerRunning() || - Minecraft.getMinecraft().thePlayer.sendQueue.getPlayerInfoMap().size() > 1))) { - return; - } - - ScaledResolution sr = Utils.pushGuiScale(2); - - int height = Utils.renderStringTrimWidth(EnumChatFormatting.YELLOW+getQuote(), Minecraft.getMinecraft().fontRendererObj, - true, sr.getScaledWidth()/2-100, 5, 200, -1, -1); - String sunTzu = "- Sun Tzu, The Art of War"; - int sunTzuLength = Minecraft.getMinecraft().fontRendererObj.getStringWidth(sunTzu); - Minecraft.getMinecraft().fontRendererObj.drawString(EnumChatFormatting.GOLD+sunTzu, - sr.getScaledWidth()/2f+100-sunTzuLength, 15+height, 0, true); - - Utils.pushGuiScale(-1); - } - } - - @SubscribeEvent - public void switchWorld(WorldEvent.Load event) { - randomizeQuote(); - } - - -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/TradeWindow.java b/src/main/java/io/github/moulberry/notenoughupdates/TradeWindow.java deleted file mode 100644 index 6bdf2c5d..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/TradeWindow.java +++ /dev/null @@ -1,1042 +0,0 @@ -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; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.gui.inventory.GuiChest; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.gui.inventory.GuiEditSign; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.inventory.ContainerChest; -import net.minecraft.inventory.Slot; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.tileentity.TileEntitySign; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.ChatComponentTranslation; -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.awt.*; -import java.io.ByteArrayInputStream; -import java.text.NumberFormat; -import java.util.*; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class TradeWindow { - - private static ResourceLocation location = new ResourceLocation("notenoughupdates", "custom_trade.png"); - - private static final int xSize = 176; - private static final int ySize = 204; - private static int guiLeft; - private static int guiTop; - - private static long lastTradeMillis = -1; - - private static final long CHANGE_EXCLAM_MILLIS = 5000; - - private static Integer[] ourTradeIndexes = new Integer[16]; - private static Integer[] theirTradeIndexes = new Integer[16]; - private static String[] theirTradeOld = new String[16]; - private static Long[] theirTradeChangesMillis = new Long[16]; - - private static ItemStack lastBackpack; - private static int lastBackpackX; - private static int lastBackpackY; - - public static boolean tradeWindowActive() { - if(!NotEnoughUpdates.INSTANCE.isOnSkyblock()) return false; - if(!NotEnoughUpdates.INSTANCE.manager.config.useCustomTrade.value) return false; - - GuiScreen guiScreen = Minecraft.getMinecraft().currentScreen; - if(guiScreen instanceof GuiChest) { - GuiChest eventGui = (GuiChest) guiScreen; - ContainerChest cc = (ContainerChest) eventGui.inventorySlots; - String containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText(); - if(containerName.trim().startsWith("You ")) { - return true; - } - } - - lastTradeMillis = -1; - ourTradeIndexes = new Integer[16]; - theirTradeIndexes = new Integer[16]; - theirTradeOld = new String[16]; - theirTradeChangesMillis = new Long[16]; - - return false; - } - - private static TexLoc tl = new TexLoc(0, 0, Keyboard.KEY_M); - - private static void drawStringShadow(String str, float x, float y, int len) { - for(int xOff=-2; xOff<=2; xOff++) { - for(int yOff=-2; yOff<=2; yOff++) { - if(Math.abs(xOff) != Math.abs(yOff)) { - Utils.drawStringCenteredScaledMaxWidth(Utils.cleanColourNotModifiers(str), - Minecraft.getMinecraft().fontRendererObj, - x+xOff/2f, y+yOff/2f, false, len, - new Color(20, 20, 20, 100/Math.max(Math.abs(xOff), Math.abs(yOff))).getRGB()); - } - } - } - - Utils.drawStringCenteredScaledMaxWidth(str, - Minecraft.getMinecraft().fontRendererObj, - x, y, false, len, - new Color(64, 64, 64, 255).getRGB()); - } - - private static int processTopItems(ItemStack stack, Map> topItems, - Map topItemsStack, Map topItemsCount) { - String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); - if(internalname == null) { - if(stack.getDisplayName().endsWith(" coins")) { - String clean = Utils.cleanColour(stack.getDisplayName()); - - int mult = 1; - StringBuilder sb = new StringBuilder(); - for(int index = 0; index < clean.length(); index++) { - char c = clean.charAt(index); - if("0123456789.".indexOf(c) >= 0) { - sb.append(c); - } else { - switch(c) { - case 'K': - case 'k': - mult = 1000; break; - case 'M': - case 'm': - mult = 1000000; break; - case 'B': - case 'b': - mult = 1000000000; break; - default: - break; - } - break; - } - } - try { - int coins = (int)(Float.parseFloat(sb.toString())*mult); - - topItemsStack.putIfAbsent("TRADE_COINS", stack); - - int existingPrice = coins; - Set toRemove = new HashSet<>(); - for(Map.Entry> entry : topItems.entrySet()) { - if(entry.getValue().contains("TRADE_COINS")) { - entry.getValue().remove("TRADE_COINS"); - existingPrice += entry.getKey(); - } - if(entry.getValue().isEmpty()) toRemove.add(entry.getKey()); - } - topItems.keySet().removeAll(toRemove); - - Set items = topItems.computeIfAbsent(existingPrice, k->new HashSet<>()); - items.add("TRADE_COINS"); - - return coins; - - } catch(Exception ignored) {} - } - } else { - JsonObject info = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalname); - int pricePer = -1; - if(info != null && !NotEnoughUpdates.INSTANCE.manager.auctionManager.isVanillaItem(internalname) && - info.has("price") && info.has("count")) { - int auctionPricePer = (int)(info.get("price").getAsFloat() / info.get("count").getAsFloat()); - - pricePer = auctionPricePer; - } else { - JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalname); - if(bazaarInfo != null && bazaarInfo.has("avg_buy")) { - pricePer = (int)bazaarInfo.get("avg_buy").getAsFloat(); - } - } - if(pricePer > 0) { - topItemsStack.putIfAbsent(internalname, stack); - - int price = pricePer * stack.stackSize; - int priceInclBackpack = price; - - NBTTagCompound tag = stack.getTagCompound(); - if(tag != null && tag.hasKey("ExtraAttributes", 10)) { - NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); - - byte[] bytes = null; - for (String key : ea.getKeySet()) { - if (key.endsWith("backpack_data") || key.equals("new_year_cake_bag_data")) { - bytes = ea.getByteArray(key); - break; - } - } - if(bytes != null) { - try { - NBTTagCompound contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(bytes)); - NBTTagList items = contents_nbt.getTagList("i", 10); - for(int k=0; k 0) { - NBTTagCompound nbt = items.getCompoundTagAt(k).getCompoundTag("tag"); - - int id2 = items.getCompoundTagAt(k).getShort("id"); - int count2 = items.getCompoundTagAt(k).getByte("Count"); - int damage2 = items.getCompoundTagAt(k).getShort("Damage"); - - if(id2 == 141) id2 = 391; //for some reason hypixel thinks carrots have id 141 - - Item mcItem = Item.getItemById(id2); - if(mcItem == null) continue; - - ItemStack stack2 = new ItemStack(mcItem, count2, damage2); - stack2.setTagCompound(nbt); - - priceInclBackpack += processTopItems(stack2, topItems, topItemsStack, topItemsCount); - } - } - } catch(Exception e) { } - } - } - - int existingPrice = price; - Set toRemove = new HashSet<>(); - for(Map.Entry> entry : topItems.entrySet()) { - if(entry.getValue().contains(internalname)) { - entry.getValue().remove(internalname); - existingPrice += entry.getKey(); - } - if(entry.getValue().isEmpty()) toRemove.add(entry.getKey()); - } - topItems.keySet().removeAll(toRemove); - - Set items = topItems.computeIfAbsent(existingPrice, k->new HashSet<>()); - items.add(internalname); - - int count = topItemsCount.computeIfAbsent(internalname, l->0); - topItemsCount.put(internalname, count+stack.stackSize); - - return priceInclBackpack; - } - } - return 0; - } - - private static int getBackpackValue(ItemStack stack) { - int price = 0; - - NBTTagCompound tag = stack.getTagCompound(); - if(tag != null && tag.hasKey("ExtraAttributes", 10)) { - NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); - - byte[] bytes = null; - for (String key : ea.getKeySet()) { - if (key.endsWith("backpack_data") || key.equals("new_year_cake_bag_data")) { - bytes = ea.getByteArray(key); - break; - } - } - if(bytes != null) { - try { - NBTTagCompound contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(bytes)); - NBTTagList items = contents_nbt.getTagList("i", 10); - for(int k=0; k 0) { - NBTTagCompound nbt = items.getCompoundTagAt(k).getCompoundTag("tag"); - String internalname2 = NotEnoughUpdates.INSTANCE.manager.getInternalnameFromNBT(nbt); - if(internalname2 != null) { - JsonObject info2 = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalname2); - - int pricePer2 = -1; - if(info2 != null && info2.has("price") && info2.has("count")) { - int auctionPricePer2 = (int)(info2.get("price").getAsFloat() / info2.get("count").getAsFloat()); - - pricePer2 = auctionPricePer2; - } else { - JsonObject bazaarInfo2 = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalname2); - if(bazaarInfo2 != null && bazaarInfo2.has("avg_buy")) { - pricePer2 = (int)bazaarInfo2.get("avg_buy").getAsFloat(); - } - } - if(pricePer2 > 0) { - int count2 = items.getCompoundTagAt(k).getByte("Count"); - price += pricePer2 * count2; - } - } - } - } - } catch(Exception e) { } - } - } - return price; - } - - public static void render(int mouseX, int mouseY) { - if(!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return; - - GuiContainer chest = ((GuiContainer)Minecraft.getMinecraft().currentScreen); - ContainerChest cc = (ContainerChest) chest.inventorySlots; - String containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText(); - - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - - guiLeft = (scaledResolution.getScaledWidth()-xSize)/2; - guiTop = (scaledResolution.getScaledHeight()-ySize)/2; - - List tooltipToDisplay = null; - ItemStack stackToRender = null; - int tooltipLen = -1; - tl.handleKeyboardInput(); - - //Set index mappings - //Our slots - TreeMap> ourTradeMap = new TreeMap<>(); - for(int i=0; i<16; i++) { - ourTradeIndexes[i] = -1; - - int x = i % 4; - int y = i / 4; - int containerIndex = y*9+x; - - ItemStack stack = chest.inventorySlots.getInventory().get(containerIndex); - if(stack == null) continue; - - String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); - if(internalname == null) { - if(stack.getDisplayName().endsWith(" coins")) { - String clean = Utils.cleanColour(stack.getDisplayName()); - - int mult = 1; - StringBuilder sb = new StringBuilder(); - for(int index = 0; index < clean.length(); index++) { - char c = clean.charAt(index); - if("0123456789.".indexOf(c) >= 0) { - sb.append(c); - } else { - switch(c) { - case 'K': - case 'k': - mult = 1000; break; - case 'M': - case 'm': - mult = 1000000; break; - case 'B': - case 'b': - mult = 1000000000; break; - default: - break; - } - break; - } - } - try { - int coins = (int)(Float.parseFloat(sb.toString())*mult); - - List list = ourTradeMap.computeIfAbsent(coins, k -> new ArrayList<>()); - list.add(containerIndex); - - } catch(Exception ignored) { - List list = ourTradeMap.computeIfAbsent(-1, k -> new ArrayList<>()); - list.add(containerIndex); - } - } else { - List list = ourTradeMap.computeIfAbsent(-1, k -> new ArrayList<>()); - list.add(containerIndex); - } - } else { - JsonObject info = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalname); - int price = -1; - if(info != null && info.has("price") && info.has("count")) { - int auctionPricePer = (int)(info.get("price").getAsFloat() / info.get("count").getAsFloat()); - - price = auctionPricePer * stack.stackSize; - } else { - JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalname); - if(bazaarInfo != null && bazaarInfo.has("avg_buy")) { - price = (int)bazaarInfo.get("avg_buy").getAsFloat() * stack.stackSize; - } - } - - price += getBackpackValue(stack); - - List list = ourTradeMap.computeIfAbsent(price, k -> new ArrayList<>()); - list.add(containerIndex); - } - } - long currentTime = System.currentTimeMillis(); - List theirTradeCurrent = new ArrayList<>(); - TreeMap> theirTradeMap = new TreeMap<>(); - HashMap displayCountMap = new HashMap<>(); - for(int i=0; i<16; i++) { - theirTradeIndexes[i] = -1; - if(theirTradeChangesMillis[i] == null || currentTime - theirTradeChangesMillis[i] > CHANGE_EXCLAM_MILLIS) { - theirTradeChangesMillis[i] = -1L; - } - - int x = i % 4; - int y = i / 4; - int containerIndex = y*9+x+5; - - ItemStack stack = chest.inventorySlots.getInventory().get(containerIndex); - if(stack == null) continue; - - NBTTagCompound tag = stack.getTagCompound(); - String uuid = null; - if(tag != null && tag.hasKey("ExtraAttributes", 10)) { - NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); - - if (ea.hasKey("uuid", 8)) { - uuid = ea.getString("uuid"); - } else { - int displayCount = displayCountMap.computeIfAbsent(stack.getDisplayName(), k->0); - uuid = stack.getDisplayName() + ":" + displayCount; - displayCountMap.put(stack.getDisplayName(), displayCount+1); - } - } else { - int displayCount = displayCountMap.computeIfAbsent(stack.getDisplayName(), k->0); - uuid = stack.getDisplayName() + ":" + displayCount; - displayCountMap.put(stack.getDisplayName(), displayCount+1); - } - if(uuid != null) theirTradeCurrent.add(uuid); - - String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); - if(internalname == null) { - if(stack.getDisplayName().endsWith(" coins")) { - String clean = Utils.cleanColour(stack.getDisplayName()); - - int mult = 1; - StringBuilder sb = new StringBuilder(); - for(int index = 0; index < clean.length(); index++) { - char c = clean.charAt(index); - if("0123456789.".indexOf(c) >= 0) { - sb.append(c); - } else { - switch(c) { - case 'K': - case 'k': - mult = 1000; break; - case 'M': - case 'm': - mult = 1000000; break; - case 'B': - case 'b': - mult = 1000000000; break; - default: - break; - } - break; - } - } - try { - int coins = (int)(Float.parseFloat(sb.toString())*mult); - - List list = theirTradeMap.computeIfAbsent(coins, k -> new ArrayList<>()); - list.add(containerIndex); - - } catch(Exception ignored) { - List list = theirTradeMap.computeIfAbsent(-1, k -> new ArrayList<>()); - list.add(containerIndex); - } - } else { - List list = theirTradeMap.computeIfAbsent(-1, k -> new ArrayList<>()); - list.add(containerIndex); - } - } else { - JsonObject info = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalname); - int price = -1; - if(info != null && info.has("price") && info.has("count")) { - int auctionPricePer = (int)(info.get("price").getAsFloat() / info.get("count").getAsFloat()); - - price = auctionPricePer * stack.stackSize; - } else { - JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalname); - if(bazaarInfo != null && bazaarInfo.has("avg_buy")) { - price = (int)bazaarInfo.get("avg_buy").getAsFloat() * stack.stackSize; - } - } - - price += getBackpackValue(stack); - - List list = theirTradeMap.computeIfAbsent(price, k -> new ArrayList<>()); - list.add(containerIndex); - } - } - int ourTradeIndex = 0; - for(Map.Entry> entry : ourTradeMap.descendingMap().entrySet()) { - for(Integer index : entry.getValue()) { - ourTradeIndexes[ourTradeIndex++] = index; - } - } - - //Their slots - int maxMissing = 16-theirTradeCurrent.size(); - int j=0; - for(int i=0; i<16; i++) { - while(j <= 15 && (j-i= 0) j++; - j = Math.min(15, j); - - String oldUUID = theirTradeOld[i]; - if(oldUUID != null && !theirTradeCurrent.contains(oldUUID)) { - theirTradeChangesMillis[j] = System.currentTimeMillis(); - } - j++; - } - - for(int i=0; i<16; i++) { - theirTradeOld[i] = null; - } - int theirTradeIndex = 0; - displayCountMap.clear(); - j=0; - for(Map.Entry> entry : theirTradeMap.descendingMap().entrySet()) { - for(Integer index : entry.getValue()) { - while(j <= 15 && (j-theirTradeIndex= 0) j++; - j = Math.min(15, j); - - theirTradeIndexes[j] = index; - - ItemStack stack = chest.inventorySlots.getInventory().get(index); - if(stack == null) continue; - - NBTTagCompound tag = stack.getTagCompound(); - String uuid = null; - if(tag != null && tag.hasKey("ExtraAttributes", 10)) { - NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); - - if (ea.hasKey("uuid", 8)) { - uuid = ea.getString("uuid"); - } else { - int displayCount = displayCountMap.computeIfAbsent(stack.getDisplayName(), k->0); - uuid = stack.getDisplayName() + ":" + displayCount; - displayCountMap.put(stack.getDisplayName(), displayCount+1); - } - } else { - int displayCount = displayCountMap.computeIfAbsent(stack.getDisplayName(), k->0); - uuid = stack.getDisplayName() + ":" + displayCount; - displayCountMap.put(stack.getDisplayName(), displayCount+1); - } - //System.out.println(uuid); - theirTradeOld[theirTradeIndex] = uuid; - - j++; - theirTradeIndex++; - } - } - - GlStateManager.color(1, 1, 1, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(location); - Utils.drawTexturedRect(guiLeft, guiTop, xSize, ySize, 0, 176/256f, 0, 204/256f, GL11.GL_NEAREST); - - Utils.drawStringF(new ChatComponentTranslation("container.inventory").getUnformattedText(), - Minecraft.getMinecraft().fontRendererObj, guiLeft+8, guiTop+111, false, 4210752); - Utils.drawStringF("You", Minecraft.getMinecraft().fontRendererObj, guiLeft+8, - guiTop+5, false, 4210752); - String[] split = containerName.split(" "); - if(split.length >= 1) { - Utils.drawStringF(split[split.length-1], Minecraft.getMinecraft().fontRendererObj, - guiLeft+167-Minecraft.getMinecraft().fontRendererObj.getStringWidth(split[split.length-1]), - guiTop+5, false, 4210752); - } - - int index=0; - for(ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { - int x = 8+18*(index % 9); - int y = 104+18*(index / 9); - if(index < 9) y = 180; - - Utils.drawItemStack(stack, guiLeft+x, guiTop+y); - - if(mouseX > guiLeft+x-1 && mouseX < guiLeft+x+18) { - if(mouseY > guiTop+y-1 && mouseY < guiTop+y+18) { - if(stack != null) stackToRender = stack; - - GlStateManager.disableLighting(); - GlStateManager.disableDepth(); - GlStateManager.colorMask(true, true, true, false); - Utils.drawGradientRect(guiLeft+x, guiTop+y, - guiLeft+x + 16, guiTop+y + 16, -2130706433, -2130706433); - GlStateManager.colorMask(true, true, true, true); - GlStateManager.enableLighting(); - GlStateManager.enableDepth(); - } - } - - index++; - } - - for(int i=0; i<16; i++) { - int x = i % 4; - int y = i / 4; - - int containerIndex = ourTradeIndexes[i]; - - ItemStack stack = null; - if(containerIndex >= 0) { - stack = chest.inventorySlots.getInventory().get(containerIndex); - Utils.drawItemStack(stack, guiLeft+10+x*18, guiTop+15+y*18); - } - - if(mouseX > guiLeft+10+x*18-1 && mouseX < guiLeft+10+x*18+18) { - if(mouseY > guiTop+15+y*18-1 && mouseY < guiTop+15+y*18+18) { - if(stack != null) stackToRender = stack; - - GlStateManager.disableLighting(); - GlStateManager.disableDepth(); - GlStateManager.colorMask(true, true, true, false); - Utils.drawGradientRect(guiLeft+10+x*18, guiTop+15+y*18, - guiLeft+10+x*18 + 16, guiTop+15+y*18 + 16, -2130706433, -2130706433); - GlStateManager.colorMask(true, true, true, true); - GlStateManager.enableLighting(); - GlStateManager.enableDepth(); - } - } - } - - ItemStack bidStack = chest.inventorySlots.getInventory().get(36); - if(bidStack != null) { - Utils.drawItemStack(bidStack, guiLeft+10, guiTop+90); - if(mouseX > guiLeft+10-1 && mouseX < guiLeft+10+18) { - if(mouseY > guiTop+90-1 && mouseY < guiTop+90+18) { - tooltipToDisplay = bidStack.getTooltip(Minecraft.getMinecraft().thePlayer, - Minecraft.getMinecraft().gameSettings.advancedItemTooltips); - } - } - } - - ItemStack confirmStack = chest.inventorySlots.getInventory().get(39); - if(confirmStack != null) { - String confirmDisplay = confirmStack.getDisplayName(); - if(!confirmDisplay.equals(EnumChatFormatting.GREEN+"Trading!")) { - if(mouseX > guiLeft+81-51 && mouseX < guiLeft+81) { - if (mouseY > guiTop+91 && mouseY < guiTop+91+14) { - tooltipToDisplay = confirmStack.getTooltip(Minecraft.getMinecraft().thePlayer, - Minecraft.getMinecraft().gameSettings.advancedItemTooltips); - } - } - - Minecraft.getMinecraft().getTextureManager().bindTexture(location); - Utils.drawTexturedRect(guiLeft+81-51, guiTop+91, 51, 14, - 0, 51/256f, ySize/256f, (ySize+14)/256f, GL11.GL_NEAREST); - - Pattern pattern = Pattern.compile(EnumChatFormatting.GRAY+"\\("+EnumChatFormatting.YELLOW+"([0-9]+)"+EnumChatFormatting.GRAY+"\\)"); - Matcher matcher = pattern.matcher(confirmDisplay); - - if(!confirmDisplay.equals(EnumChatFormatting.YELLOW+"Warning!") && - !confirmDisplay.equals(EnumChatFormatting.YELLOW+"Deal!")) { - lastTradeMillis = -1; - } - - if(matcher.find()) { - String numS = matcher.group(1); - int num = Integer.parseInt(numS); - - Utils.drawStringCentered(EnumChatFormatting.DARK_RED + "Check " + EnumChatFormatting.BOLD + (char) (9311 + num), Minecraft.getMinecraft().fontRendererObj, guiLeft + 56, guiTop + 99, - false, 4210752); - } else if(confirmDisplay.equals(EnumChatFormatting.AQUA+"Gift!")) { - Utils.drawStringCentered(EnumChatFormatting.GREEN+"Accept", Minecraft.getMinecraft().fontRendererObj, guiLeft+56, guiTop+99, - true, 4210752); - } else if(confirmDisplay.equals(EnumChatFormatting.GREEN+"Deal accepted!")) { - Utils.drawStringCentered(EnumChatFormatting.GREEN+"Accepted", Minecraft.getMinecraft().fontRendererObj, - guiLeft+56, guiTop+99, true, 4210752); - } else if(lastTradeMillis > 0) { - long delta = System.currentTimeMillis() - lastTradeMillis; - if(delta > 2000) { - Utils.drawStringCentered(EnumChatFormatting.GREEN+"Accept", Minecraft.getMinecraft().fontRendererObj, guiLeft+56, guiTop+99, - true, 4210752); - } else { - Utils.drawStringCentered(EnumChatFormatting.YELLOW+"Trade "+EnumChatFormatting.BOLD+(char)(9312+(2000-delta)/1000), - Minecraft.getMinecraft().fontRendererObj, guiLeft+56, guiTop+99, - true, 4210752); - } - } else { - Utils.drawStringCentered(EnumChatFormatting.YELLOW+"Trade "+EnumChatFormatting.BOLD+(char)(9314), Minecraft.getMinecraft().fontRendererObj, guiLeft+56, guiTop+99, - true, 4210752); - } - } - } - - ItemStack theirConfirmStack = chest.inventorySlots.getInventory().get(41); - if(theirConfirmStack != null) { - String confirmDisplay = theirConfirmStack.getDisplayName(); - if(mouseX > guiLeft+95 && mouseX < guiLeft+95+51) { - if (mouseY > guiTop+91 && mouseY < guiTop+91+14) { - tooltipToDisplay = theirConfirmStack.getTooltip(Minecraft.getMinecraft().thePlayer, - Minecraft.getMinecraft().gameSettings.advancedItemTooltips); - } - } - - GlStateManager.color(1, 1, 1, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(location); - Utils.drawTexturedRect(guiLeft+95, guiTop+91, 51, 14, - 0, 51/256f, ySize/256f, (ySize+14)/256f, GL11.GL_NEAREST); - - if(confirmDisplay.equals(EnumChatFormatting.YELLOW+"Pending their confirm")) { - Utils.drawStringCentered(EnumChatFormatting.YELLOW+"Pending", Minecraft.getMinecraft().fontRendererObj, guiLeft+120, guiTop+99, - true, 4210752); - } else if(confirmDisplay.equals(EnumChatFormatting.YELLOW+"Deal timer...")) { - Utils.drawStringCentered(EnumChatFormatting.YELLOW+"Pending", Minecraft.getMinecraft().fontRendererObj, guiLeft+120, guiTop+99, - true, 4210752); - } else if(confirmDisplay.equals(EnumChatFormatting.GREEN+"Other player confirmed!")) { - Utils.drawStringCentered(EnumChatFormatting.GREEN+"Accepted", Minecraft.getMinecraft().fontRendererObj, guiLeft+120, guiTop+99, - true, 4210752); - } - } - - for(int i=0; i<16; i++) { - int x = i % 4; - int y = i / 4; - - int containerIndex = theirTradeIndexes[i]; - - ItemStack stack = null; - if(containerIndex >= 0) { - stack = chest.inventorySlots.getInventory().get(containerIndex); - Utils.drawItemStack(stack, guiLeft+96+x*18, guiTop+15+y*18); - } - - if(currentTime % 400 > 200 && theirTradeChangesMillis[i] != null && theirTradeChangesMillis[i] > 0) { - GlStateManager.translate(0, 0, 200); - GlStateManager.color(1, 1, 1, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(location); - Utils.drawTexturedRect(guiLeft+96+x*18, guiTop+15+y*18, 16, 16, - 51/256f, 67/256f, 204/256f, 220/256f, GL11.GL_NEAREST); - GlStateManager.translate(0, 0, -200); - } - - if(mouseX > guiLeft+96+x*18-1 && mouseX < guiLeft+96+x*18+18) { - if(mouseY > guiTop+15+y*18-1 && mouseY < guiTop+15+y*18+18) { - if(stack != null) stackToRender = stack; - - GlStateManager.disableLighting(); - GlStateManager.disableDepth(); - GlStateManager.colorMask(true, true, true, false); - Utils.drawGradientRect(guiLeft+96+x*18, guiTop+15+y*18, - guiLeft+96+x*18 + 16, guiTop+15+y*18 + 16, -2130706433, -2130706433); - GlStateManager.colorMask(true, true, true, true); - GlStateManager.enableLighting(); - GlStateManager.enableDepth(); - } - } - } - - if(NotEnoughUpdates.INSTANCE.manager.config.customTradePrices.value) { - TreeMap> ourTopItems = new TreeMap<>(); - TreeMap ourTopItemsStack = new TreeMap<>(); - TreeMap ourTopItemsCount = new TreeMap<>(); - int ourPrice = 0; - for(int i=0; i<16; i++) { - int x = i % 4; - int y = i / 4; - int containerIndex = y*9+x; - - ItemStack stack = chest.inventorySlots.getInventory().get(containerIndex); - if(stack == null) continue; - - ourPrice += processTopItems(stack, ourTopItems, ourTopItemsStack, ourTopItemsCount); - } - TreeMap> theirTopItems = new TreeMap<>(); - TreeMap theirTopItemsStack = new TreeMap<>(); - TreeMap theirTopItemsCount = new TreeMap<>(); - int theirPrice = 0; - for(int i=0; i<16; i++) { - int x = i % 4; - int y = i / 4; - int containerIndex = y*9+x+5; - - ItemStack stack = chest.inventorySlots.getInventory().get(containerIndex); - if(stack == null) continue; - - theirPrice += processTopItems(stack, theirTopItems, theirTopItemsStack, theirTopItemsCount); - } - - NumberFormat format = NumberFormat.getInstance(Locale.US); - - GlStateManager.disableLighting(); - GlStateManager.color(1, 1, 1, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(location); - Utils.drawTexturedRect(guiLeft-80-3, guiTop, 80, 106, - 176/256f, 1, 0, 106/256f, GL11.GL_NEAREST); - drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+"Total Value", - guiLeft-40-3, guiTop+11, 72); - drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+format.format(ourPrice), - guiLeft-40-3, guiTop+21, 72); - - int ourTopIndex = Math.max(0, 3-ourTopItemsStack.size()); - out: - for(Map.Entry> entry : ourTopItems.descendingMap().entrySet()) { - for(String ourTopItemInternal : entry.getValue()) { - ItemStack stack = ourTopItemsStack.get(ourTopItemInternal); - if(stack == null) continue; - - if(NotEnoughUpdates.INSTANCE.manager.config.customTradePriceStyle.value) { - String countS = ""; - if(ourTopItemsCount.containsKey(ourTopItemInternal)) { - int count = ourTopItemsCount.get(ourTopItemInternal); - if(count > 999999) { - countS = Math.floor(count/10000f)/100f+"m"; - } else if(count > 999) { - countS = Math.floor(count/10f)/100f+"k"; - } else { - countS = ""+count; - } - } - - Utils.drawItemStackWithText(stack, guiLeft-75-3, guiTop+49+18*ourTopIndex, countS); - - GlStateManager.disableLighting(); - GlStateManager.disableBlend(); - GlStateManager.color(1, 1, 1, 1); - drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+format.format(entry.getKey()), - guiLeft-29-3, guiTop+57+18*ourTopIndex, 52); - GlStateManager.enableBlend(); - } else { - drawStringShadow(stack.getDisplayName() + EnumChatFormatting.GRAY+"x"+ourTopItemsCount.get(ourTopItemInternal), - guiLeft-40-3, guiTop+46+20*ourTopIndex, 72); - drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+format.format(entry.getKey()), - guiLeft-40-3, guiTop+56+20*ourTopIndex, 72); - } - - if(++ourTopIndex >= 3) break out; - } - } - - GlStateManager.color(1, 1, 1, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(location); - Utils.drawTexturedRect(guiLeft+xSize+3, guiTop, 80, 106, - 176/256f, 1, 0, 106/256f, GL11.GL_NEAREST); - drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+"Total Value", - guiLeft+xSize+3+40, guiTop+11, 72); - drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+format.format(theirPrice), - guiLeft+xSize+3+40, guiTop+21, 72); - - int theirTopIndex = Math.max(0, 3-theirTopItemsStack.size()); - out: - for(Map.Entry> entry : theirTopItems.descendingMap().entrySet()) { - for(String theirTopItemInternal : entry.getValue()) { - ItemStack stack = theirTopItemsStack.get(theirTopItemInternal); - if(stack == null) continue; - - if(NotEnoughUpdates.INSTANCE.manager.config.customTradePriceStyle.value) { - String countS = ""; - if(theirTopItemsCount.containsKey(theirTopItemInternal)) { - int count = theirTopItemsCount.get(theirTopItemInternal); - if(count > 999999) { - countS = Math.floor(count/10000f)/100f+"m"; - } else if(count > 999) { - countS = Math.floor(count/10f)/100f+"k"; - } else { - countS = ""+count; - } - } - - Utils.drawItemStackWithText(stack, guiLeft+xSize+25+3-16, guiTop+49+18*theirTopIndex, countS); - - GlStateManager.disableLighting(); - GlStateManager.disableBlend(); - GlStateManager.color(1, 1, 1, 1); - drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+format.format(entry.getKey()), - guiLeft+xSize+3+51, guiTop+57+18*theirTopIndex, 52); - GlStateManager.enableBlend(); - } else { - drawStringShadow(stack.getDisplayName(), - guiLeft+xSize+3+40, guiTop+46+20*theirTopIndex, 72); - drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+format.format(entry.getKey()), - guiLeft+xSize+3+40, guiTop+56+20*theirTopIndex, 72); - } - - if(++theirTopIndex >= 3) break out; - } - } - } - - - boolean button1 = NotEnoughUpdates.INSTANCE.manager.config.customTradePriceStyle.value; - boolean button2 = NotEnoughUpdates.INSTANCE.manager.config.customTradePrices.value; - boolean button3 = NotEnoughUpdates.INSTANCE.manager.config.useCustomTrade.value; - - GlStateManager.color(1, 1, 1, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(location); - Utils.drawTexturedRect(guiLeft+xSize+3, guiTop+ySize-19, 17, 17, - (button3?17:0)/256f, (button3?34:17)/256f, 218/256f, 235/256f, GL11.GL_NEAREST); - Utils.drawTexturedRect(guiLeft+xSize+3, guiTop+ySize-38, 17, 17, - (button2?17:0)/256f, (button2?34:17)/256f, 218/256f, 235/256f, GL11.GL_NEAREST); - Utils.drawTexturedRect(guiLeft+xSize+3, guiTop+ySize-57, 17, 17, - (button1?17:0)/256f, (button1?34:17)/256f, 218/256f, 235/256f, GL11.GL_NEAREST); - - if(mouseX >= guiLeft+xSize+3 && mouseX <= guiLeft+xSize+3+17) { - if(mouseY >= guiTop+ySize-19 && mouseY <= guiTop+ySize-19+17) { - tooltipToDisplay = new ArrayList<>(); - tooltipToDisplay.add(EnumChatFormatting.GOLD+NotEnoughUpdates.INSTANCE.manager.config.useCustomTrade.displayName); - tooltipToDisplay.add(EnumChatFormatting.GRAY+NotEnoughUpdates.INSTANCE.manager.config.useCustomTrade.desc); - tooltipLen = 200; - } else if(mouseY >= guiTop+ySize-38 && mouseY <= guiTop+ySize-38+17) { - tooltipToDisplay = new ArrayList<>(); - tooltipToDisplay.add(EnumChatFormatting.GOLD+NotEnoughUpdates.INSTANCE.manager.config.customTradePrices.displayName); - tooltipToDisplay.add(EnumChatFormatting.GRAY+NotEnoughUpdates.INSTANCE.manager.config.customTradePrices.desc); - tooltipLen = 200; - } else if(mouseY >= guiTop+ySize-57 && mouseY <= guiTop+ySize-57+17) { - tooltipToDisplay = new ArrayList<>(); - tooltipToDisplay.add(EnumChatFormatting.GOLD+NotEnoughUpdates.INSTANCE.manager.config.customTradePriceStyle.displayName); - tooltipToDisplay.add(EnumChatFormatting.GRAY+NotEnoughUpdates.INSTANCE.manager.config.customTradePriceStyle.desc); - tooltipLen = 200; - } - } - - if(stackToRender == null && !SBAIntegration.isFreezeBackpack()) lastBackpack = null; - if(SBAIntegration.isFreezeBackpack()) { - if(lastBackpack != null) { - SBAIntegration.setActiveBackpack(lastBackpack, lastBackpackX, lastBackpackY); - GlStateManager.translate(0, 0, 100); - SBAIntegration.renderActiveBackpack(mouseX, mouseY, Minecraft.getMinecraft().fontRendererObj); - GlStateManager.translate(0, 0, -100); - } - } else { - if(stackToRender != null) { - String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stackToRender); - boolean renderedBackpack; - if(internalname != null && (internalname.endsWith("BACKPACK") || internalname.equals("NEW_YEAR_CAKE_BAG"))) { - lastBackpack = stackToRender; - lastBackpackX = mouseX; - lastBackpackY = mouseY; - renderedBackpack = SBAIntegration.setActiveBackpack(lastBackpack, lastBackpackX, lastBackpackY); - if(renderedBackpack) { - GlStateManager.translate(0, 0, 100); - renderedBackpack = SBAIntegration.renderActiveBackpack(mouseX, mouseY, Minecraft.getMinecraft().fontRendererObj); - GlStateManager.translate(0, 0, -100); - } - } else { - renderedBackpack = false; - } - if(!renderedBackpack) { - lastBackpack = null; - tooltipToDisplay = stackToRender.getTooltip(Minecraft.getMinecraft().thePlayer, - Minecraft.getMinecraft().gameSettings.advancedItemTooltips); - } - } - } - - if(tooltipToDisplay != null) { - Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, scaledResolution.getScaledWidth(), scaledResolution.getScaledHeight(), - tooltipLen, Minecraft.getMinecraft().fontRendererObj); - } - } - - public static void handleMouseInput() { - if(!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return; - - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - int width = scaledResolution.getScaledWidth(); - int height = scaledResolution.getScaledHeight(); - - int mouseX = Mouse.getEventX() * width / Minecraft.getMinecraft().displayWidth; - int mouseY = height - Mouse.getEventY() * height / Minecraft.getMinecraft().displayHeight - 1; - - GuiContainer chest = ((GuiContainer)Minecraft.getMinecraft().currentScreen); - - if(Mouse.getEventButtonState() && Mouse.isButtonDown(0)) { - int index=0; - for(ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { - if(stack == null) { - index++; - continue; - } - - int x = 8+18*(index % 9); - int y = 104+18*(index / 9); - if(index < 9) y = 180; - - if(mouseX > guiLeft+x && mouseX < guiLeft+x+16) { - if(mouseY > guiTop+y && mouseY < guiTop+y+16) { - Slot slot = chest.inventorySlots.getSlotFromInventory(Minecraft.getMinecraft().thePlayer.inventory, index); - Minecraft.getMinecraft().playerController.windowClick( - chest.inventorySlots.windowId, - slot.slotNumber, 2, 3, Minecraft.getMinecraft().thePlayer); - return; - } - } - - index++; - } - - for(int i=0; i<16; i++) { - int x = i % 4; - int y = i / 4; - - int containerIndex = ourTradeIndexes[i]; - if(containerIndex < 0) continue; - - if(mouseX > guiLeft+10+x*18-1 && mouseX < guiLeft+10+x*18+18) { - if(mouseY > guiTop+15+y*18-1 && mouseY < guiTop+15+y*18+18) { - Minecraft.getMinecraft().playerController.windowClick( - chest.inventorySlots.windowId, - containerIndex, 2, 3, Minecraft.getMinecraft().thePlayer); - return; - } - } - } - - if(mouseX > guiLeft+10-1 && mouseX < guiLeft+10+18) { - if(mouseY > guiTop+90-1 && mouseY < guiTop+90+18) { - Minecraft.getMinecraft().playerController.windowClick( - chest.inventorySlots.windowId, - 36, 2, 3, Minecraft.getMinecraft().thePlayer); - return; - } - } - - ItemStack confirmStack = chest.inventorySlots.getInventory().get(39); - if(confirmStack != null) { - String confirmDisplay = confirmStack.getDisplayName(); - if(!confirmDisplay.equals(EnumChatFormatting.GREEN+"Trading!")) { - if(mouseX > guiLeft+42 && mouseX < guiLeft+42+40) { - if (mouseY > guiTop+92 && mouseY < guiTop+92+14) { - if((confirmDisplay.equals(EnumChatFormatting.YELLOW+"Warning!") || - confirmDisplay.equals(EnumChatFormatting.YELLOW+"Deal!")) && lastTradeMillis < 0) { - lastTradeMillis = System.currentTimeMillis(); - } else if(lastTradeMillis < 0 || System.currentTimeMillis() - lastTradeMillis > 2000) { - Minecraft.getMinecraft().playerController.windowClick( - chest.inventorySlots.windowId, - 39, 2, 3, Minecraft.getMinecraft().thePlayer); - return; - } - } - } - - } - } - - if(mouseX >= guiLeft+xSize+3 && mouseX <= guiLeft+xSize+3+17) { - if(mouseY >= guiTop+ySize-19 && mouseY <= guiTop+ySize-19+17) { - NotEnoughUpdates.INSTANCE.manager.config.useCustomTrade.value = - !NotEnoughUpdates.INSTANCE.manager.config.useCustomTrade.value; - return; - } else if(mouseY >= guiTop+ySize-38 && mouseY <= guiTop+ySize-38+17) { - NotEnoughUpdates.INSTANCE.manager.config.customTradePrices.value = - !NotEnoughUpdates.INSTANCE.manager.config.customTradePrices.value; - return; - } else if(mouseY >= guiTop+ySize-57 && mouseY <= guiTop+ySize-57+17) { - NotEnoughUpdates.INSTANCE.manager.config.customTradePriceStyle.value = - !NotEnoughUpdates.INSTANCE.manager.config.customTradePriceStyle.value; - return; - } - } - } - } - - public static boolean keyboardInput() { - return Keyboard.getEventKey() != Keyboard.KEY_ESCAPE; - } - -} 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 4013a790..32592397 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java @@ -4,6 +4,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NEUManager; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; @@ -173,8 +174,9 @@ public class APIManager { public void tick() { customAH.tick(); long currentTime = System.currentTimeMillis(); - if(manager.config.neuAuctionHouse.value && manager.config.apiKey.value != null && - !manager.config.apiKey.value.isEmpty()) { + if(NotEnoughUpdates.INSTANCE.config.neuAuctionHouse.enableNeuAuctionHouse && + NotEnoughUpdates.INSTANCE.config.apiKey.apiKey != null && + !NotEnoughUpdates.INSTANCE.config.apiKey.apiKey.isEmpty()) { if(currentTime - lastAuctionUpdate > 60*1000) { lastAuctionUpdate = currentTime; updatePageTick(); @@ -250,13 +252,13 @@ public class APIManager { private void ahNotification() { playerBidsNotified.retainAll(playerBids); playerBidsFinishedNotified.retainAll(playerBids); - if(manager.config.ahNotification.value <= 0) { + if(NotEnoughUpdates.INSTANCE.config.neuAuctionHouse.ahNotification <= 0) { return; } for(String aucid : playerBids) { Auction auc = auctionMap.get(aucid); if(!playerBidsNotified.contains(aucid)) { - if(auc != null && auc.end - System.currentTimeMillis() < 1000*60*manager.config.ahNotification.value) { + if(auc != null && auc.end - System.currentTimeMillis() < 1000*60*NotEnoughUpdates.INSTANCE.config.neuAuctionHouse.ahNotification) { ChatComponentText message = new ChatComponentText( EnumChatFormatting.YELLOW+"The " + auc.getStack().getDisplayName() + EnumChatFormatting.YELLOW + " you have bid on is ending soon! Click here to view."); ChatStyle clickEvent = new ChatStyle().setChatClickEvent( @@ -618,7 +620,7 @@ public class APIManager { } public void updateBazaar() { - manager.hypixelApi.getHypixelApiAsync(manager.config.apiKey.value, "skyblock/bazaar", new HashMap<>(), (jsonObject) -> { + manager.hypixelApi.getHypixelApiAsync(NotEnoughUpdates.INSTANCE.config.apiKey.apiKey, "skyblock/bazaar", new HashMap<>(), (jsonObject) -> { if(!jsonObject.get("success").getAsBoolean()) return; craftCost.clear(); @@ -890,7 +892,7 @@ public class APIManager { args.put("page", "0"); AtomicInteger totalPages = new AtomicInteger(1); AtomicInteger currentPages = new AtomicInteger(0); - manager.hypixelApi.getHypixelApiAsync(manager.config.apiKey.value, "skyblock/auctions", + manager.hypixelApi.getHypixelApiAsync(NotEnoughUpdates.INSTANCE.config.apiKey.apiKey, "skyblock/auctions", args, jsonObject -> { if (jsonObject.get("success").getAsBoolean()) { pages.put(0, jsonObject); @@ -901,7 +903,7 @@ public class APIManager { int j = i; HashMap args2 = new HashMap<>(); args2.put("page", "" + i); - manager.hypixelApi.getHypixelApiAsync(manager.config.apiKey.value, "skyblock/auctions", + manager.hypixelApi.getHypixelApiAsync(NotEnoughUpdates.INSTANCE.config.apiKey.apiKey, "skyblock/auctions", args2, jsonObject2 -> { if (jsonObject2.get("success").getAsBoolean()) { pages.put(j, jsonObject2); 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 f7b22db0..aad69686 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/CustomAH.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/CustomAH.java @@ -1,6 +1,7 @@ package io.github.moulberry.notenoughupdates.auction; import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.ItemPriceInformation; import io.github.moulberry.notenoughupdates.NEUManager; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.util.Utils; @@ -41,7 +42,7 @@ import java.util.concurrent.Executors; import java.util.regex.Matcher; import java.util.regex.Pattern; -import static io.github.moulberry.notenoughupdates.GuiTextures.*; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.*; public class CustomAH extends Gui { @@ -206,7 +207,7 @@ public class CustomAH extends Gui { } public void tick() { - if(!manager.config.neuAuctionHouse.value) return; + if(!NotEnoughUpdates.INSTANCE.config.neuAuctionHouse.enableNeuAuctionHouse) return; if(Minecraft.getMinecraft().currentScreen instanceof CustomAHGui || renderOverAuctionView) { if(shouldUpdateSearch) updateSearch(); if(shouldSortItems) { @@ -340,43 +341,14 @@ public class CustomAH extends Gui { } } - if(manager.config.auctionPriceInfo.value) { + if(NotEnoughUpdates.INSTANCE.config.tooltipTweaks.showPriceInfoAucItem) { String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(auc.getStack()); if(internalname != null) { - tooltip.add(""); if(!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) && !Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) { + tooltip.add(""); tooltip.add(EnumChatFormatting.GRAY+"[SHIFT for Price Info]"); } else { - JsonObject auctionInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalname); - - boolean hasAuctionPrice = auctionInfo != null; - - int lowestBin = NotEnoughUpdates.INSTANCE.manager.auctionManager.getLowestBin(internalname); - - APIManager.CraftInfo craftCost = NotEnoughUpdates.INSTANCE.manager.auctionManager.getCraftCost(internalname); - - if(lowestBin > 0) { - tooltip.add(EnumChatFormatting.GRAY+"Lowest BIN: "+ - EnumChatFormatting.GOLD+format.format(lowestBin)+" coins"); - } - if(hasAuctionPrice) { - int auctionPrice = (int)(auctionInfo.get("price").getAsFloat() / auctionInfo.get("count").getAsFloat()); - tooltip.add(EnumChatFormatting.GRAY+"AH Price: "+ - EnumChatFormatting.GOLD+format.format(auctionPrice)+" coins"); - tooltip.add(EnumChatFormatting.GRAY+"AH Sales: "+ - EnumChatFormatting.GOLD+format.format(auctionInfo.get("sales").getAsFloat())+" sales/day"); - if(auctionInfo.has("clean_price")) { - tooltip.add(EnumChatFormatting.GRAY+"AH Price (Clean): "+ - EnumChatFormatting.GOLD+format.format((int)auctionInfo.get("clean_price").getAsFloat())+" coins"); - tooltip.add(EnumChatFormatting.GRAY+"AH Sales (Clean): "+ - EnumChatFormatting.GOLD+format.format(auctionInfo.get("clean_sales").getAsFloat())+" sales/day"); - } - - } - if(craftCost.fromRecipe) { - tooltip.add(EnumChatFormatting.GRAY+"Raw Craft Cost: "+ - EnumChatFormatting.GOLD+format.format((int)craftCost.craftCost)+" coins"); - } + ItemPriceInformation.addToTooltip(tooltip, internalname); } } } @@ -858,7 +830,7 @@ public class CustomAH extends Gui { int maxItemScroll = Math.max(0, totalItems - (5+splits)*9); itemsScroll = Math.min(itemsScroll, maxItemScroll); - if(manager.config.neuAuctionHouse.value) { + if(NotEnoughUpdates.INSTANCE.config.neuAuctionHouse.enableNeuAuctionHouse) { out: for(int i=0; i<5+splits; i++) { int itemY = guiTop + i*18 + 18; @@ -904,7 +876,7 @@ public class CustomAH extends Gui { this.drawTexturedModalRect(guiLeft+175, guiTop+18+(int)((95+ySplitSize*2)*scrollAmount), 256-(scrollClicked?12:24), 0, 12, 15); - if(!manager.config.neuAuctionHouse.value) { + if(!NotEnoughUpdates.INSTANCE.config.neuAuctionHouse.enableNeuAuctionHouse) { Utils.drawStringCentered(EnumChatFormatting.RED+"NEUAH is DISABLED! Enable in /neusettings.", Minecraft.getMinecraft().fontRendererObj, guiLeft+getXSize()/2, guiTop+getYSize()/2-5, true, 0); } @@ -1052,7 +1024,7 @@ public class CustomAH extends Gui { } public void handleMouseInput() { - if(!manager.config.neuAuctionHouse.value) { + if(!NotEnoughUpdates.INSTANCE.config.neuAuctionHouse.enableNeuAuctionHouse) { return; } @@ -1076,7 +1048,7 @@ public class CustomAH extends Gui { mouseClickMove(mouseX, mouseY, this.eventButton, l); } - if(!manager.config.disableAhScroll.value) { + if(!NotEnoughUpdates.INSTANCE.config.neuAuctionHouse.disableAhScroll) { int dWheel = Mouse.getEventDWheel(); dWheel = Math.max(-1, Math.min(1, dWheel)); @@ -1213,7 +1185,7 @@ public class CustomAH extends Gui { private ExecutorService es = Executors.newSingleThreadExecutor(); public void updateSearch() { - if(!manager.config.neuAuctionHouse.value) { + if(!NotEnoughUpdates.INSTANCE.config.neuAuctionHouse.enableNeuAuctionHouse) { return; } @@ -1321,7 +1293,7 @@ public class CustomAH extends Gui { } public void sortItems() throws ConcurrentModificationException { - if(!manager.config.neuAuctionHouse.value) { + if(!NotEnoughUpdates.INSTANCE.config.neuAuctionHouse.enableNeuAuctionHouse) { return; } @@ -1372,7 +1344,7 @@ public class CustomAH extends Gui { } public boolean keyboardInput() { - if(!manager.config.neuAuctionHouse.value) { + if(!NotEnoughUpdates.INSTANCE.config.neuAuctionHouse.enableNeuAuctionHouse) { return false; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/BackgroundBlur.java b/src/main/java/io/github/moulberry/notenoughupdates/core/BackgroundBlur.java new file mode 100644 index 00000000..30d056b4 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/BackgroundBlur.java @@ -0,0 +1,181 @@ +package io.github.moulberry.notenoughupdates.core; + +import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.shader.Framebuffer; +import net.minecraft.client.shader.Shader; +import net.minecraft.util.Matrix4f; +import net.minecraftforge.client.event.EntityViewRenderEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.eventhandler.EventPriority; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL30; + +public class BackgroundBlur { + + private static int fogColour = 0; + private static boolean registered = false; + public static void registerListener() { + if(!registered) { + MinecraftForge.EVENT_BUS.register(new BackgroundBlur()); + } + } + + private boolean shouldBlur = true; + + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent event) { + if(Minecraft.getMinecraft().theWorld != null) { + shouldBlur = true; + } + } + + @SubscribeEvent(priority = EventPriority.HIGHEST) + public void onScreenRender(RenderGameOverlayEvent.Pre event) { + if(shouldBlur && event.type == RenderGameOverlayEvent.ElementType.ALL) { + shouldBlur = false; + blurBackground(); + } + } + + @SubscribeEvent + public void onFogColour(EntityViewRenderEvent.FogColors event) { + fogColour = 0xff000000; + fogColour |= ((int)(event.red*255) & 0xFF) << 16; + fogColour |= ((int)(event.green*255) & 0xFF) << 8; + fogColour |= (int)(event.blue*255) & 0xFF; + } + + private static Shader blurShaderHorz = null; + private static Framebuffer blurOutputHorz = null; + private static Shader blurShaderVert = null; + private static Framebuffer blurOutputVert = null; + + /** + * Creates a projection matrix that projects from our coordinate space [0->width; 0->height] to OpenGL coordinate + * space [-1 -> 1; 1 -> -1] (Note: flipped y-axis). + * + * This is so that we can render to and from the framebuffer in a way that is familiar to us, instead of needing to + * apply scales and translations manually. + */ + private static Matrix4f createProjectionMatrix(int width, int height) { + Matrix4f projMatrix = new Matrix4f(); + projMatrix.setIdentity(); + projMatrix.m00 = 2.0F / (float)width; + projMatrix.m11 = 2.0F / (float)(-height); + projMatrix.m22 = -0.0020001999F; + projMatrix.m33 = 1.0F; + projMatrix.m03 = -1.0F; + projMatrix.m13 = 1.0F; + projMatrix.m23 = -1.0001999F; + return projMatrix; + } + + private static double lastBgBlurFactor = -1; + private static void blurBackground() { + if(!OpenGlHelper.isFramebufferEnabled()) return; + + int width = Minecraft.getMinecraft().displayWidth; + int height = Minecraft.getMinecraft().displayHeight; + + GlStateManager.matrixMode(GL11.GL_PROJECTION); + GlStateManager.loadIdentity(); + GlStateManager.ortho(0.0D, width, height, 0.0D, 1000.0D, 3000.0D); + GlStateManager.matrixMode(GL11.GL_MODELVIEW); + GlStateManager.loadIdentity(); + GlStateManager.translate(0.0F, 0.0F, -2000.0F); + + if(blurOutputHorz == null) { + blurOutputHorz = new Framebuffer(width, height, false); + blurOutputHorz.setFramebufferFilter(GL11.GL_NEAREST); + } + if(blurOutputVert == null) { + blurOutputVert = new Framebuffer(width, height, false); + blurOutputVert.setFramebufferFilter(GL11.GL_NEAREST); + } + if(blurOutputHorz == null || blurOutputVert == null) { + return; + } + if(blurOutputHorz.framebufferWidth != width || blurOutputHorz.framebufferHeight != height) { + blurOutputHorz.createBindFramebuffer(width, height); + blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); + Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); + } + if(blurOutputVert.framebufferWidth != width || blurOutputVert.framebufferHeight != height) { + blurOutputVert.createBindFramebuffer(width, height); + blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height)); + Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); + } + + if(blurShaderHorz == null) { + try { + blurShaderHorz = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", + blurOutputVert, blurOutputHorz); + blurShaderHorz.getShaderManager().getShaderUniform("BlurDir").set(1, 0); + blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); + } catch(Exception e) { } + } + if(blurShaderVert == null) { + try { + blurShaderVert = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", + blurOutputHorz, blurOutputVert); + blurShaderVert.getShaderManager().getShaderUniform("BlurDir").set(0, 1); + blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height)); + } catch(Exception e) { } + } + if(blurShaderHorz != null && blurShaderVert != null) { + if(blurShaderHorz.getShaderManager().getShaderUniform("Radius") == null) { + //Corrupted shader? + return; + } + if(15 != lastBgBlurFactor) { + blurShaderHorz.getShaderManager().getShaderUniform("Radius").set((float)15); + blurShaderVert.getShaderManager().getShaderUniform("Radius").set((float)15); + lastBgBlurFactor = 15; + } + GL11.glPushMatrix(); + GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, Minecraft.getMinecraft().getFramebuffer().framebufferObject); + GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, blurOutputVert.framebufferObject); + GL30.glBlitFramebuffer(0, 0, width, height, + 0, 0, width, height, + GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST); + + blurShaderHorz.loadShader(0); + blurShaderVert.loadShader(0); + GlStateManager.enableDepth(); + GL11.glPopMatrix(); + + Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); + } + } + + /** + * Renders a subsection of the blurred framebuffer on to the corresponding section of the screen. + * Essentially, this method will "blur" the background inside the bounds specified by [x->x+blurWidth, y->y+blurHeight] + */ + public static void renderBlurredBackground(int screenWidth, int screenHeight, + int x, int y, int blurWidth, int blurHeight) { + if(!OpenGlHelper.isFramebufferEnabled()) return; + if(blurOutputVert == null) return; + + float uMin = x/(float)screenWidth; + float uMax = (x+blurWidth)/(float)screenWidth; + float vMin = (screenHeight-y)/(float)screenHeight; + float vMax = (screenHeight-y-blurHeight)/(float)screenHeight; + + GlStateManager.depthMask(false); + Gui.drawRect(x, y, x+blurWidth, y+blurHeight, fogColour); + blurOutputVert.bindFramebufferTexture(); + GlStateManager.color(1f, 1f, 1f, 1f); + RenderUtils.drawTexturedRect(x, y, blurWidth, blurHeight, uMin, uMax, vMin, vMax); + blurOutputVert.unbindFramebufferTexture(); + GlStateManager.depthMask(true); + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/ChromaColour.java b/src/main/java/io/github/moulberry/notenoughupdates/core/ChromaColour.java new file mode 100644 index 00000000..9509c332 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/ChromaColour.java @@ -0,0 +1,95 @@ +package io.github.moulberry.notenoughupdates.core; + +import java.awt.*; + +public class ChromaColour { + + 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 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); + } + + public static int rotateHue(int argb, int degrees) { + int a = (argb >> 24) & 0xFF; + int r = (argb >> 16) & 0xFF; + int g = (argb >> 8) & 0xFF; + int b = (argb) & 0xFF; + + float[] hsv = Color.RGBtoHSB(r, g, b, null); + + hsv[0] += degrees/360f; + hsv[0] %= 1; + + return (a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF); + } + + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/GlScissorStack.java b/src/main/java/io/github/moulberry/notenoughupdates/core/GlScissorStack.java new file mode 100644 index 00000000..f70bec40 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/GlScissorStack.java @@ -0,0 +1,87 @@ +package io.github.moulberry.notenoughupdates.core; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import org.lwjgl.opengl.GL11; + +import java.util.LinkedList; + +public class GlScissorStack { + + private static class Bounds { + int left; + int top; + int right; + int bottom; + + public Bounds(int left, int top, int right, int bottom) { + this.left = left; + this.top = top; + this.right = right; + this.bottom = bottom; + } + + public Bounds createSubBound(int left, int top, int right, int bottom) { + left = Math.max(left, this.left); + top = Math.max(top, this.top); + right = Math.min(right, this.right); + bottom = Math.min(bottom, this.bottom); + + if(top > bottom) { + top = bottom; + } + if(left > right) { + left = right; + } + + return new Bounds(left, top, right, bottom); + } + + public void set(ScaledResolution scaledResolution) { + int height = Minecraft.getMinecraft().displayHeight; + int scale = scaledResolution.getScaleFactor(); + GL11.glScissor(left*scale, height-bottom*scale, (right-left)*scale, (bottom-top)*scale); + } + } + + private static LinkedList boundsStack = new LinkedList<>(); + + public static void push(int left, int top, int right, int bottom, ScaledResolution scaledResolution) { + if(right < left) { + int temp = right; + right = left; + left = temp; + } + if(bottom < top) { + int temp = bottom; + bottom = top; + top = temp; + } + if(boundsStack.isEmpty()) { + boundsStack.push(new Bounds(left, top, right, bottom)); + } else { + boundsStack.push(boundsStack.peek().createSubBound(left, top, right, bottom)); + } + if(!boundsStack.isEmpty()) { + boundsStack.peek().set(scaledResolution); + } + GL11.glEnable(GL11.GL_SCISSOR_TEST); + } + + public static void pop(ScaledResolution scaledResolution) { + if(!boundsStack.isEmpty()) { + boundsStack.pop(); + } + if(boundsStack.isEmpty()) { + GL11.glDisable(GL11.GL_SCISSOR_TEST); + } else { + boundsStack.peek().set(scaledResolution); + } + } + + public static void clear() { + boundsStack.clear(); + GL11.glDisable(GL11.GL_SCISSOR_TEST); + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElement.java b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElement.java new file mode 100644 index 00000000..9210d1fb --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElement.java @@ -0,0 +1,8 @@ +package io.github.moulberry.notenoughupdates.core; + +public abstract class GuiElement { + + public abstract void render(); + public abstract boolean mouseInput(int mouseX, int mouseY); + public abstract boolean keyboardInput(); +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementBoolean.java b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementBoolean.java new file mode 100644 index 00000000..97fc3dcc --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementBoolean.java @@ -0,0 +1,118 @@ +package io.github.moulberry.notenoughupdates.core; + +import io.github.moulberry.notenoughupdates.core.util.lerp.LerpUtils; +import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; +import io.github.moulberry.notenoughupdates.util.GuiTextures; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Mouse; + +import java.util.function.Consumer; + +public class GuiElementBoolean extends GuiElement { + + public int x; + public int y; + private boolean value; + private int clickRadius; + private Consumer toggleCallback; + + private boolean previewValue; + private int animation = 0; + private long lastMillis = 0; + + private static final int xSize = 48; + private static final int ySize = 14; + + public GuiElementBoolean(int x, int y, boolean value, Consumer toggleCallback) { + this(x, y, value, 0, toggleCallback); + } + + public GuiElementBoolean(int x, int y, boolean value, int clickRadius, Consumer toggleCallback) { + this.x = x; + this.y = y; + this.value = value; + this.previewValue = value; + this.clickRadius = clickRadius; + this.toggleCallback = toggleCallback; + } + + @Override + public void render() { + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(GuiTextures.BAR); + RenderUtils.drawTexturedRect(x, y, xSize, ySize); + + ResourceLocation buttonLoc = GuiTextures.ON; + long currentMillis = System.currentTimeMillis(); + long deltaMillis = currentMillis - lastMillis; + lastMillis = currentMillis; + boolean passedLimit = false; + if(previewValue != value) { + if((previewValue && animation > 12) || + (!previewValue && animation < 24)) { + passedLimit = true; + } + } + if(previewValue != passedLimit) { + animation += deltaMillis/10; + } else { + animation -= deltaMillis/10; + } + lastMillis -= deltaMillis%10; + + if(previewValue == value) { + animation = Math.max(0, Math.min(36, animation)); + } else if(!passedLimit) { + if(previewValue) { + animation = Math.max(0, Math.min(12, animation)); + } else { + animation = Math.max(24, Math.min(36, animation)); + } + } else { + if(previewValue) { + animation = Math.max(12, animation); + } else { + animation = Math.min(24, animation); + } + } + + int animation = (int)(LerpUtils.sigmoidZeroOne(this.animation/36f)*36); + if(animation < 3) { + buttonLoc = GuiTextures.OFF; + } else if(animation < 13) { + buttonLoc = GuiTextures.ONE; + } else if(animation < 23) { + buttonLoc = GuiTextures.TWO; + } else if(animation < 33) { + buttonLoc = GuiTextures.THREE; + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(buttonLoc); + RenderUtils.drawTexturedRect(x+animation, y, 12, 14); + } + + @Override + public boolean mouseInput(int mouseX, int mouseY) { + if(mouseX > x-clickRadius && mouseX < x+xSize+clickRadius && + mouseY > y-clickRadius && mouseY < y+ySize+clickRadius) { + if(Mouse.getEventButton() == 0) { + if(Mouse.getEventButtonState()) { + previewValue = !value; + } else { + value = !value; + toggleCallback.accept(value); + } + } + } else { + previewValue = value; + } + return false; + } + + @Override + public boolean keyboardInput() { + return false; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementColour.java b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementColour.java new file mode 100644 index 00000000..8de2205d --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementColour.java @@ -0,0 +1,368 @@ +package io.github.moulberry.notenoughupdates.core; + +import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; +import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils; +import net.minecraft.client.Minecraft; +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.util.EnumChatFormatting; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +import java.awt.*; +import java.awt.image.BufferedImage; +import java.util.function.Consumer; + +public class GuiElementColour extends GuiElement { + + public static final ResourceLocation colour_selector_dot = new ResourceLocation("notenoughupdates:core/colour_selector_dot.png"); + public static final ResourceLocation colour_selector_bar = new ResourceLocation("notenoughupdates:core/colour_selector_bar.png"); + public static final ResourceLocation colour_selector_bar_alpha = new ResourceLocation("notenoughupdates:core/colour_selector_bar_alpha.png"); + public static final ResourceLocation colour_selector_chroma = new ResourceLocation("notenoughupdates:core/colour_selector_chroma.png"); + + private static final ResourceLocation colourPickerLocation = new ResourceLocation("mbcore:dynamic/colourpicker"); + private static final ResourceLocation colourPickerBarValueLocation = new ResourceLocation("mbcore:dynamic/colourpickervalue"); + private static final ResourceLocation colourPickerBarOpacityLocation = new ResourceLocation("mbcore:dynamic/colourpickeropacity"); + private final GuiElementTextField hexField = new GuiElementTextField("", + GuiElementTextField.SCALE_TEXT | GuiElementTextField.FORCE_CAPS | GuiElementTextField.NO_SPACE); + + private int x; + private int y; + private final int xSize = 119; + private final int ySize = 89; + + private float wheelAngle = 0; + private float wheelRadius = 0; + + private int clickedComponent = -1; + + private Consumer colourChangedCallback; + private Runnable closeCallback; + private String colour; + + public GuiElementColour(int x, int y, String initialColour, Consumer colourChangedCallback, + Runnable closeCallback) { + + final ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + + this.y = Math.max(10, Math.min(scaledResolution.getScaledHeight()-ySize-10, y)); + this.x = Math.max(10, Math.min(scaledResolution.getScaledWidth()-xSize-10, x)); + + this.colour = initialColour; + this.colourChangedCallback = colourChangedCallback; + this.closeCallback = closeCallback; + + int colour = ChromaColour.specialToSimpleRGB(initialColour); + Color c = new Color(colour); + float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); + updateAngleAndRadius(hsv); + } + + public void updateAngleAndRadius(float[] hsv) { + this.wheelRadius = hsv[1]; + this.wheelAngle = hsv[0]*360; + } + + public void render() { + RenderUtils.drawFloatingRectDark(x, y, xSize, ySize); + + int currentColour = ChromaColour.specialToSimpleRGB(colour); + Color c = new Color(currentColour, true); + float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); + + BufferedImage bufferedImage = new BufferedImage(288, 288, BufferedImage.TYPE_INT_ARGB); + float borderRadius = 0.05f; + if(Keyboard.isKeyDown(Keyboard.KEY_N)) borderRadius = 0; + for(int x=-16; x<272; x++) { + for(int y=-16; y<272; 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+16, y+16, rgb); + } else if(radius <= 1+borderRadius) { + float invBlackAlpha = Math.abs(radius-1-borderRadius/2)/borderRadius*2; + float blackAlpha = 1-invBlackAlpha; + + if(radius > 1+borderRadius/2) { + bufferedImage.setRGB(x+16, y+16, (int)(blackAlpha*255) << 24); + } else { + Color col = Color.getHSBColor(angle/360f, 1, hsv[2]); + int rgb = (int)(col.getRed()*invBlackAlpha) << 16 | + (int)(col.getGreen()*invBlackAlpha) << 8 | + (int)(col.getBlue()*invBlackAlpha); + bufferedImage.setRGB(x+16, y+16, 0xff000000 | 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(wheelAngle/360, wheelRadius, (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(wheelRadius, 1/1.5f)*32; + int selx = (int)(Math.cos(Math.toRadians(wheelAngle))*selradius); + int sely = (int)(Math.sin(Math.toRadians(wheelAngle))*selradius); + + Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_bar_alpha); + GlStateManager.color(1, 1, 1, 1); + RenderUtils.drawTexturedRect(x+5+64+5+10+5, 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); + RenderUtils.drawTexturedRect(x+5+64+5, 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); + RenderUtils.drawTexturedRect(x+5+64+5+10+5, y+5, 10, 64, GL11.GL_NEAREST); + + int chromaSpeed = ChromaColour.getSpeed(colour); + int currentColourChroma = ChromaColour.specialToChromaRGB(colour); + Color cChroma = new Color(currentColourChroma, true); + float hsvChroma[] = Color.RGBtoHSB(cChroma.getRed(), cChroma.getGreen(), cChroma.getBlue(), null); + + if(chromaSpeed > 0) { + Gui.drawRect(x+5+64+5+10+5+10+5+1, y+5+1, + x+5+64+5+10+5+10+5+10-1, y+5+64-1, + Color.HSBtoRGB(hsvChroma[0], 0.8f, 0.8f)); + } else { + Gui.drawRect(x+5+64+5+10+5+10+5+1, y+5+27+1, + x+5+64+5+10+5+10+5+10-1, y+5+37-1, + Color.HSBtoRGB((hsvChroma[0]+(System.currentTimeMillis()-ChromaColour.startTime)/1000f)%1, 0.8f, 0.8f)); + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_bar); + GlStateManager.color(1, 1, 1, 1); + RenderUtils.drawTexturedRect(x+5+64+5, y+5, 10, 64, GL11.GL_NEAREST); + RenderUtils.drawTexturedRect(x+5+64+5+10+5, y+5, 10, 64, GL11.GL_NEAREST); + + if(chromaSpeed > 0) { + RenderUtils.drawTexturedRect(x+5+64+5+10+5+10+5, y+5, 10, 64, GL11.GL_NEAREST); + } else { + Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_chroma); + RenderUtils.drawTexturedRect(x+5+64+5+10+5+10+5, y+5+27, 10, 10, GL11.GL_NEAREST); + } + + Gui.drawRect(x+5+64+5, y+5+64-(int)(64*hsv[2]), + x+5+64+5+10, y+5+64-(int)(64*hsv[2])+1, 0xFF000000); + Gui.drawRect(x+5+64+5+10+5, y+5+64-c.getAlpha()/4, + x+5+64+5+10+5+10, y+5+64-c.getAlpha()/4-1, 0xFF000000); + if(chromaSpeed > 0) { + Gui.drawRect(x+5+64+5+10+5+10+5, + y+5+64-(int)(chromaSpeed/255f*64), + x+5+64+5+10+5+10+5+10, + 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); + RenderUtils.drawTexturedRect(x+1, y+1, 72, 72, GL11.GL_LINEAR); + + Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_dot); + GlStateManager.color(1, 1, 1, 1); + RenderUtils.drawTexturedRect(x+5+32+selx-4, y+5+32+sely-4, 8, 8, GL11.GL_NEAREST); + + TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GRAY.toString()+Math.round(hsv[2]*100)+"", + Minecraft.getMinecraft().fontRendererObj, + x+5+64+5+5-(Math.round(hsv[2]*100)==100?1:0), y+5+64+5+5, true, 13, -1); + TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GRAY.toString()+Math.round(c.getAlpha()/255f*100)+"", + Minecraft.getMinecraft().fontRendererObj, + x+5+64+5+15+5, y+5+64+5+5, true, 13, -1); + if(chromaSpeed > 0) { + TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GRAY.toString()+ + (int)ChromaColour.getSecondsForSpeed(chromaSpeed)+"s", + Minecraft.getMinecraft().fontRendererObj, + x+5+64+5+30+6, 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(x+5+8, y+5+64+5); + } + + public boolean mouseInput(int mouseX, int mouseY) { + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + float mouseXF = (float)(Mouse.getX() * scaledResolution.getScaledWidth_double() / + Minecraft.getMinecraft().displayWidth); + float mouseYF = (float)(scaledResolution.getScaledHeight_double() - Mouse.getY() * + scaledResolution.getScaledHeight_double() / Minecraft.getMinecraft().displayHeight - 1); + + if((Mouse.getEventButton() == 0 || Mouse.getEventButton() == 1) && Mouse.getEventButtonState()) { + if(mouseX > x+5+8 && mouseX < x+5+8+48) { + if(mouseY > y+5+64+5 && mouseY < y+5+64+5+10) { + hexField.mouseClicked(mouseX, mouseY, Mouse.getEventButton()); + clickedComponent = -1; + return true; + } + } + } + if(!Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { + clickedComponent = -1; + } + if(Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { + if(mouseX >= x && mouseX <= x+119 && + mouseY >= y && mouseY <= y+89) { + hexField.unfocus(); + + int xWheel = mouseX - x - 5; + int yWheel = mouseY - y - 5; + + if(xWheel > 0 && xWheel < 64) { + if(yWheel > 0 && yWheel < 64) { + clickedComponent = 0; + } + } + + int xValue = mouseX - (x+5+64+5); + int y = mouseY - this.y - 5; + + if(y > -5 && y <= 69) { + if(xValue > 0 && xValue < 10) { + clickedComponent = 1; + } + + int xOpacity = mouseX - (x+5+64+5+10+5); + + if(xOpacity > 0 && xOpacity < 10) { + clickedComponent = 2; + } + } + + int chromaSpeed = ChromaColour.getSpeed(colour); + int xChroma = mouseX - (x+5+64+5+10+5+10+5); + if(xChroma > 0 && xChroma < 10) { + if(chromaSpeed > 0) { + if(y > -5 && y <= 69) { + clickedComponent = 3; + } + } else if(mouseY > this.y+5+27 && mouseY < this.y+5+37) { + int currentColour = ChromaColour.specialToSimpleRGB(colour); + Color c = new Color(currentColour, true); + colour = ChromaColour.special(200, c.getAlpha(), currentColour); + colourChangedCallback.accept(colour); + } + } + } else { + hexField.unfocus(); + closeCallback.run(); + return false; + } + } + if(Mouse.isButtonDown(0) && clickedComponent >= 0) { + int currentColour = ChromaColour.specialToSimpleRGB(colour); + Color c = new Color(currentColour, true); + float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); + + float xWheel = mouseXF - x - 5; + float yWheel = mouseYF - y - 5; + + if(clickedComponent == 0) { + float angle = (float) Math.toDegrees(Math.atan((32-xWheel)/(yWheel-32+1E-5))+Math.PI/2); + xWheel = Math.max(0, Math.min(64, xWheel)); + yWheel = Math.max(0, Math.min(64, yWheel)); + float radius = (float) Math.sqrt(((xWheel-32)*(xWheel-32)+(yWheel-32)*(yWheel-32))/1024f); + if(yWheel < 32) angle += 180; + + this.wheelAngle = angle; + this.wheelRadius = (float)Math.pow(Math.min(1, radius), 1.5f); + int rgb = Color.getHSBColor(angle/360f, wheelRadius, hsv[2]).getRGB(); + colour = ChromaColour.special(ChromaColour.getSpeed(colour), c.getAlpha(), rgb); + colourChangedCallback.accept(colour); + return true; + } + + float y = mouseYF - this.y - 5; + y = Math.max(0, Math.min(64, y)); + System.out.println(y); + + if(clickedComponent == 1) { + int rgb = Color.getHSBColor(wheelAngle/360, wheelRadius, 1-y/64f).getRGB(); + colour = ChromaColour.special(ChromaColour.getSpeed(colour), c.getAlpha(), rgb); + colourChangedCallback.accept(colour); + return true; + } + + if(clickedComponent == 2) { + colour = ChromaColour.special(ChromaColour.getSpeed(colour), + 255-Math.round(y/64f*255), currentColour); + colourChangedCallback.accept(colour); + return true; + } + + if(clickedComponent == 3) { + colour = ChromaColour.special(255-Math.round(y/64f*255), c.getAlpha(), currentColour); + colourChangedCallback.accept(colour); + } + return true; + } + return false; + } + + public boolean keyboardInput() { + if(Keyboard.getEventKeyState() && hexField.getFocus()) { + if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) { + hexField.unfocus(); + return true; + } + 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 = (ChromaColour.specialToSimpleRGB(colour) >> 24) & 0xFF; + colour = ChromaColour.special(ChromaColour.getSpeed(colour), alpha, rgb); + colourChangedCallback.accept(colour); + + Color c = new Color(rgb); + float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); + updateAngleAndRadius(hsv); + } catch(Exception e) {}; + } + + return true; + } + return false; + } + + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementTextField.java b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementTextField.java new file mode 100644 index 00000000..56dbe77d --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementTextField.java @@ -0,0 +1,519 @@ +package io.github.moulberry.notenoughupdates.core; + +import io.github.moulberry.notenoughupdates.core.util.StringUtils; +import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.GlStateManager; + +import java.awt.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class GuiElementTextField { + + public static final int SCALE_TEXT = 0b100000; + public static final int NUM_ONLY = 0b10000; + public static final int NO_SPACE = 0b01000; + public static final int FORCE_CAPS = 0b00100; + public static final int COLOUR = 0b00010; + public static final int MULTILINE = 0b00001; + + private int searchBarYSize; + private int searchBarXSize; + private static final int searchBarPadding = 2; + + private int options; + + private boolean focus = false; + + private int x; + private int y; + + private String prependText = ""; + + private final GuiTextField textField = new GuiTextField(0, Minecraft.getMinecraft().fontRendererObj, + 0 , 0, 0, 0); + + private int customBorderColour = -1; + + public GuiElementTextField(String initialText, int options) { + this(initialText, 100, 20, options); + } + + public GuiElementTextField(String initialText, int sizeX, int sizeY, int options) { + textField.setFocused(true); + textField.setCanLoseFocus(false); + textField.setMaxStringLength(999); + textField.setText(initialText); + this.searchBarXSize = sizeX; + this.searchBarYSize = sizeY; + this.options = options; + } + + public void setMaxStringLength(int len) { + textField.setMaxStringLength(len); + } + + public void setCustomBorderColour(int colour) { + this.customBorderColour = colour; + } + + public String getText() { + 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); + } + } + + public void setSize(int searchBarXSize, int searchBarYSize) { + this.searchBarXSize = searchBarXSize; + this.searchBarYSize = searchBarYSize; + } + + public void setOptions(int options) { + this.options = options; + } + + @Override + public String toString() { + return textField.getText(); + } + + public boolean getFocus() { + return focus; + } + + public int getHeight() { + ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); + int paddingUnscaled = searchBarPadding/scaledresolution.getScaleFactor(); + + int numLines = org.apache.commons.lang3.StringUtils.countMatches(textField.getText(), "\n")+1; + int extraSize = (searchBarYSize-8)/2+8; + int bottomTextBox = searchBarYSize + extraSize*(numLines-1); + + return bottomTextBox + paddingUnscaled*2; + } + + public int getWidth() { + ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); + int paddingUnscaled = searchBarPadding/scaledresolution.getScaleFactor(); + + return searchBarXSize + paddingUnscaled*2; + } + + private float getScaleFactor(String str) { + return Math.min(1, (searchBarXSize-2)/(float)Minecraft.getMinecraft().fontRendererObj.getStringWidth(str)); + } + + private boolean isScaling() { + return (options & SCALE_TEXT) != 0; + } + + private float getStringWidth(String str) { + if(isScaling()) { + return Minecraft.getMinecraft().fontRendererObj.getStringWidth(str)*getScaleFactor(str); + } else { + return Minecraft.getMinecraft().fontRendererObj.getStringWidth(str); + } + } + + public int getCursorPos(int mouseX, int mouseY) { + int xComp = mouseX - x; + int yComp = mouseY - y; + + 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 = 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); + if(!matcher.find() || matcher.groupCount() < 1) break; + String code = matcher.group(1); + textNoColour = matcher.replaceFirst("\u00B6"+code); + } + + int currentLine = 0; + int cursorIndex = 0; + for(; cursorIndex 0) { + textBeforeCursorWidth = 0; + lineBefore = split[split.length-1]; + thisLineBeforeCursor = ""; + } else if(split.length > 1) { + thisLineBeforeCursor = split[split.length-1]; + lineBefore = split[split.length-2]; + textBeforeCursorWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(thisLineBeforeCursor); + } else { + return; + } + String trimmed = Minecraft.getMinecraft().fontRendererObj + .trimStringToWidth(lineBefore, textBeforeCursorWidth); + int linePos = strLenNoColor(trimmed); + if(linePos != strLenNoColor(lineBefore)) { + char after = lineBefore.charAt(linePos); + int trimmedWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(trimmed); + int charWidth = Minecraft.getMinecraft().fontRendererObj.getCharWidth(after); + if(trimmedWidth + charWidth/2 < textBeforeCursorWidth) { + linePos++; + } + } + int newPos = textField.getSelectionEnd()-strLenNoColor(thisLineBeforeCursor) + -strLenNoColor(lineBefore)-1+linePos; + + if(GuiScreen.isShiftKeyDown()) { + textField.setSelectionPos(newPos); + } else { + textField.setCursorPosition(newPos); + } + } else if(keyCode == 208) { //Down + String textNCBeforeCursor = textNoColour.substring(0, textField.getSelectionEnd()); + int colorCodes = org.apache.commons.lang3.StringUtils.countMatches(textNCBeforeCursor, "\u00B6"); + String textBeforeCursor = text.substring(0, textField.getSelectionEnd()+colorCodes*2); + + int numLinesBeforeCursor = org.apache.commons.lang3.StringUtils.countMatches(textBeforeCursor, "\n"); + + String[] split = textBeforeCursor.split("\n"); + String thisLineBeforeCursor; + int textBeforeCursorWidth; + if(split.length == numLinesBeforeCursor) { + thisLineBeforeCursor = ""; + textBeforeCursorWidth = 0; + } else if(split.length > 0) { + thisLineBeforeCursor = split[split.length-1]; + textBeforeCursorWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(thisLineBeforeCursor); + } else { + return; + } + + String[] split2 = textNoColour.split("\n"); + if(split2.length > numLinesBeforeCursor+1) { + String lineAfter = split2[numLinesBeforeCursor+1]; + String trimmed = Minecraft.getMinecraft().fontRendererObj + .trimStringToWidth(lineAfter, textBeforeCursorWidth); + int linePos = strLenNoColor(trimmed); + if(linePos != strLenNoColor(lineAfter)) { + char after = lineAfter.charAt(linePos); + int trimmedWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(trimmed); + int charWidth = Minecraft.getMinecraft().fontRendererObj.getCharWidth(after); + if(trimmedWidth + charWidth/2 < textBeforeCursorWidth) { + linePos++; + } + } + int newPos = textField.getSelectionEnd()-strLenNoColor(thisLineBeforeCursor) + +strLenNoColor(split2[numLinesBeforeCursor])+1+linePos; + + if(GuiScreen.isShiftKeyDown()) { + textField.setSelectionPos(newPos); + } else { + textField.setCursorPosition(newPos); + } + } + } + } + + String old = textField.getText(); + if((options & FORCE_CAPS) != 0) typedChar = Character.toUpperCase(typedChar); + if((options & NO_SPACE) != 0 && typedChar == ' ') return; + + textField.setFocused(true); + textField.textboxKeyTyped(typedChar, keyCode); + + if((options & COLOUR) != 0) { + if(typedChar == '&') { + int pos = textField.getCursorPosition()-2; + if(pos >= 0 && pos < textField.getText().length()) { + if(textField.getText().charAt(pos) == '&') { + String before = textField.getText().substring(0, pos); + String after = ""; + if(pos+2 < textField.getText().length()) { + after = textField.getText().substring(pos+2); + } + textField.setText(before + "\u00A7" + after); + textField.setCursorPosition(pos+1); + } + } + } + } + + if((options & NUM_ONLY) != 0 && textField.getText().matches("[^0-9.]")) textField.setText(old); + } + } + + public void render(int x, int y) { + this.x = x; + this.y = y; + drawTextbox(x, y, searchBarXSize, searchBarYSize, searchBarPadding, textField, focus); + } + + 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(); + + /** + * Search bar + */ + int paddingUnscaled = searchBarPadding/scaledresolution.getScaleFactor(); + if(paddingUnscaled < 1) paddingUnscaled = 1; + + int numLines = org.apache.commons.lang3.StringUtils.countMatches(renderText, "\n")+1; + int extraSize = (searchBarYSize-8)/2+8; + int bottomTextBox = y + searchBarYSize + extraSize*(numLines-1); + + int borderColour = focus ? Color.GREEN.getRGB() : Color.WHITE.getRGB(); + if(customBorderColour != -1) { + borderColour = customBorderColour; + } + //bar background + Gui.drawRect(x - paddingUnscaled, + y - paddingUnscaled, + x + searchBarXSize + paddingUnscaled, + bottomTextBox + paddingUnscaled, borderColour); + Gui.drawRect(x, + y, + x + searchBarXSize, + bottomTextBox, Color.BLACK.getRGB()); + + //bar text + Pattern patternControlCode = Pattern.compile("(?i)\\u00A7([^\\u00B6\n])(?!\\u00B6)"); + + 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); + if(!matcher.find() || matcher.groupCount() < 1) break; + String code = matcher.group(1); + textNoColor = matcher.replaceFirst("\u00B6"+code); + } + + int xStartOffset = 5; + float scale = 1; + String[] texts = text.split("\n"); + for(int yOffI = 0; yOffI < texts.length; yOffI++) { + int yOff = yOffI*extraSize; + + if(isScaling() && Minecraft.getMinecraft().fontRendererObj.getStringWidth(texts[yOffI])>searchBarXSize-10) { + scale = (searchBarXSize-2)/(float)Minecraft.getMinecraft().fontRendererObj.getStringWidth(texts[yOffI]); + if(scale > 1) scale=1; + float newLen = Minecraft.getMinecraft().fontRendererObj.getStringWidth(texts[yOffI])*scale; + xStartOffset = (int)((searchBarXSize-newLen)/2f); + + TextRenderUtils.drawStringCenteredScaledMaxWidth(texts[yOffI], Minecraft.getMinecraft().fontRendererObj, x+searchBarXSize/2f, + y+searchBarYSize/2f+yOff, false, + searchBarXSize-2, Color.WHITE.getRGB()); + } else { + Minecraft.getMinecraft().fontRendererObj.drawString(StringUtils.trimToWidth(texts[yOffI], searchBarXSize-10), x + 5, + y+(searchBarYSize-8)/2+yOff, Color.WHITE.getRGB()); + } + } + + if(focus && System.currentTimeMillis()%1000>500) { + String textNCBeforeCursor = textNoColor.substring(0, textField.getCursorPosition()+prependText.length()); + int colorCodes = org.apache.commons.lang3.StringUtils.countMatches(textNCBeforeCursor, "\u00B6"); + String textBeforeCursor = text.substring(0, textField.getCursorPosition()+prependText.length()+(((options & COLOUR) != 0) ? colorCodes*2 : 0)); + + int numLinesBeforeCursor = org.apache.commons.lang3.StringUtils.countMatches(textBeforeCursor, "\n"); + int yOff = numLinesBeforeCursor*extraSize; + + String[] split = textBeforeCursor.split("\n"); + int textBeforeCursorWidth; + if(split.length <= numLinesBeforeCursor || split.length == 0) { + textBeforeCursorWidth = 0; + } else { + textBeforeCursorWidth = (int)(Minecraft.getMinecraft().fontRendererObj.getStringWidth(split[split.length-1])*scale); + } + Gui.drawRect(x + xStartOffset + textBeforeCursorWidth, + y+(searchBarYSize-8)/2-1 + yOff, + x + xStartOffset + textBeforeCursorWidth+1, + y+(searchBarYSize-8)/2+9 + yOff, Color.WHITE.getRGB()); + } + + String selectedText = textField.getSelectedText(); + if(!selectedText.isEmpty()) { + 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; + boolean sectionSignPrev = false; + boolean bold = false; + for(int i=0; i= leftIndex && i < rightIndex) { + Gui.drawRect(x + xStartOffset + (int)texX, + y+(searchBarYSize-8)/2-1 + texY, + x + xStartOffset + (int)texX + 3, + y+(searchBarYSize-8)/2+9 + texY, Color.LIGHT_GRAY.getRGB()); + } + + texX = 0; + texY += extraSize; + continue; + } + + //String c2 = bold ? EnumChatFormatting.BOLD.toString() : "" + c; + + int len = Minecraft.getMinecraft().fontRendererObj.getStringWidth(String.valueOf(c)); + if(bold) len++; + if(i >= leftIndex && i < rightIndex) { + Gui.drawRect(x + xStartOffset + (int)texX, + y+(searchBarYSize-8)/2-1 + texY, + x + xStartOffset + (int)(texX + len*scale), + y+(searchBarYSize-8)/2+9 + texY, Color.LIGHT_GRAY.getRGB()); + + TextRenderUtils.drawStringScaled(String.valueOf(c), Minecraft.getMinecraft().fontRendererObj, + x + xStartOffset + texX, + y+searchBarYSize/2f-scale*8/2f + texY, false, Color.BLACK.getRGB(), scale); + if(bold) { + TextRenderUtils.drawStringScaled(String.valueOf(c), Minecraft.getMinecraft().fontRendererObj, + x + xStartOffset + texX + 1, + y+searchBarYSize/2f-scale*8/2f + texY, false, Color.BLACK.getRGB(), scale); + } + } + + texX += len*scale; + } + } + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/GuiScreenElementWrapper.java b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiScreenElementWrapper.java new file mode 100644 index 00000000..c270397b --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiScreenElementWrapper.java @@ -0,0 +1,35 @@ +package io.github.moulberry.notenoughupdates.core; + +import net.minecraft.client.gui.GuiScreen; +import org.lwjgl.input.Mouse; + +import java.io.IOException; + +public class GuiScreenElementWrapper extends GuiScreen { + + private final GuiElement element; + + public GuiScreenElementWrapper(GuiElement element) { + this.element = element; + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + super.drawScreen(mouseX, mouseY, partialTicks); + element.render(); + } + + @Override + public void handleMouseInput() throws IOException { + super.handleMouseInput(); + int i = Mouse.getEventX() * this.width / this.mc.displayWidth; + int j = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; + element.mouseInput(i, j); + } + + @Override + public void handleKeyboardInput() throws IOException { + super.handleKeyboardInput(); + element.keyboardInput(); + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/Config.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/Config.java new file mode 100644 index 00000000..572c9af6 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/Config.java @@ -0,0 +1,4 @@ +package io.github.moulberry.notenoughupdates.core.config; + +public class Config { +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/Category.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/Category.java new file mode 100644 index 00000000..6a91cae5 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/Category.java @@ -0,0 +1,15 @@ +package io.github.moulberry.notenoughupdates.core.config.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface Category { + + String name(); + String desc(); + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigEditorBoolean.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigEditorBoolean.java new file mode 100644 index 00000000..3c6465e6 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigEditorBoolean.java @@ -0,0 +1,12 @@ +package io.github.moulberry.notenoughupdates.core.config.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigEditorBoolean { + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigEditorColour.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigEditorColour.java new file mode 100644 index 00000000..d1dd5808 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigEditorColour.java @@ -0,0 +1,13 @@ +package io.github.moulberry.notenoughupdates.core.config.annotations; + + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigEditorColour { + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigEditorDropdown.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigEditorDropdown.java new file mode 100644 index 00000000..d9d2235b --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigEditorDropdown.java @@ -0,0 +1,16 @@ +package io.github.moulberry.notenoughupdates.core.config.annotations; + + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigEditorDropdown { + + String[] values(); + int initialIndex() default 0; + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigEditorSlider.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigEditorSlider.java new file mode 100644 index 00000000..d671f65c --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigEditorSlider.java @@ -0,0 +1,18 @@ +package io.github.moulberry.notenoughupdates.core.config.annotations; + + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigEditorSlider { + + float minValue(); + float maxValue(); + + float minStep(); + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigEditorText.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigEditorText.java new file mode 100644 index 00000000..9227cf50 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigEditorText.java @@ -0,0 +1,13 @@ +package io.github.moulberry.notenoughupdates.core.config.annotations; + + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigEditorText { + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigOption.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigOption.java new file mode 100644 index 00000000..63c3366a --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/annotations/ConfigOption.java @@ -0,0 +1,17 @@ +package io.github.moulberry.notenoughupdates.core.config.annotations; + + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ConfigOption { + + String name(); + String desc(); + int subcategoryId() default -1; + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditor.java new file mode 100644 index 00000000..5b9509a3 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditor.java @@ -0,0 +1,61 @@ +package io.github.moulberry.notenoughupdates.core.config.gui; + +import io.github.moulberry.notenoughupdates.core.config.struct.ConfigProcessor; +import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; +import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.GlStateManager; + +public abstract class GuiOptionEditor { + + protected final ConfigProcessor.ProcessedOption option; + private static final int HEIGHT = 45; + + public GuiOptionEditor(ConfigProcessor.ProcessedOption option) { + this.option = option; + } + + public void render(int x, int y, int width) { + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + RenderUtils.drawFloatingRectDark(x, y, width, HEIGHT, true); + TextRenderUtils.drawStringCenteredScaledMaxWidth(option.name, + fr, x+width/6, y+13, true, width/3-10, 0xc0c0c0); + + int height = getHeight(); + + int maxLines = 5; + float scale = 1; + int lineCount = fr.listFormattedStringToWidth(option.desc, width*2/3-10).size(); + + if(lineCount <= 0) return; + + float paraHeight = 9 * lineCount - 1; + + while(paraHeight >= height-10) { + scale -= 1/8f; + lineCount = fr.listFormattedStringToWidth(option.desc, (int)(width*2/3/scale-10)).size(); + paraHeight = (int)(9*scale * lineCount - 1*scale); + } + + GlStateManager.pushMatrix(); + GlStateManager.translate(x+5+width/3f, y+HEIGHT/2f-paraHeight/2, 0); + GlStateManager.scale(scale, scale, 1); + + fr.drawSplitString(option.desc, 0, 0, (int)(width*2/3/scale-10), 0xc0c0c0); + + GlStateManager.popMatrix(); + } + + public int getHeight() { + return HEIGHT; + } + + public abstract boolean mouseInput(int x, int y, int width, int mouseX, int mouseY); + public abstract boolean keyboardInput(); + + public boolean mouseInputGlobal(int x, int y, int width, int mouseX, int mouseY) { + return false; + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorBoolean.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorBoolean.java new file mode 100644 index 00000000..ba2c9be9 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorBoolean.java @@ -0,0 +1,38 @@ +package io.github.moulberry.notenoughupdates.core.config.gui; + +import io.github.moulberry.notenoughupdates.core.GuiElementBoolean; +import io.github.moulberry.notenoughupdates.core.config.struct.ConfigProcessor; + +public class GuiOptionEditorBoolean extends GuiOptionEditor { + + private final GuiElementBoolean bool; + + public GuiOptionEditorBoolean(ConfigProcessor.ProcessedOption option) { + super(option); + + bool = new GuiElementBoolean(0, 0, (boolean)option.get(), 10, option::set); + } + + @Override + public void render(int x, int y, int width) { + super.render(x, y, width); + int height = getHeight(); + + bool.x = x+width/6-24; + bool.y = y+height-7-14; + bool.render(); + } + + @Override + public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { + int height = getHeight(); + bool.x = x+width/6-24; + bool.y = y+height-7-14; + return bool.mouseInput(mouseX, mouseY); + } + + @Override + public boolean keyboardInput() { + return false; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorColour.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorColour.java new file mode 100644 index 00000000..482f6823 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorColour.java @@ -0,0 +1,80 @@ +package io.github.moulberry.notenoughupdates.core.config.gui; + +import io.github.moulberry.notenoughupdates.core.ChromaColour; +import io.github.moulberry.notenoughupdates.core.GlScissorStack; +import io.github.moulberry.notenoughupdates.core.GuiElementBoolean; +import io.github.moulberry.notenoughupdates.core.GuiElementColour; +import io.github.moulberry.notenoughupdates.core.config.struct.ConfigProcessor; +import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +import static io.github.moulberry.notenoughupdates.util.GuiTextures.*; + +public class GuiOptionEditorColour extends GuiOptionEditor { + + private String chromaColour; + private GuiElementColour colourElement = null; + + public GuiOptionEditorColour(ConfigProcessor.ProcessedOption option) { + super(option); + + this.chromaColour = (String)option.get(); + } + + @Override + public void render(int x, int y, int width) { + super.render(x, y, width); + int height = getHeight(); + + int argb = ChromaColour.specialToChromaRGB(chromaColour); + int r = (argb >> 16) & 0xFF; + int g = (argb >> 8) & 0xFF; + int b = argb & 0xFF; + GlStateManager.color(r/255f, g/255f, b/255f, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(button_white); + RenderUtils.drawTexturedRect(x+width/6-24, y+height-7-14, 48, 16); + + if(colourElement != null) { + GL11.glDisable(GL11.GL_SCISSOR_TEST); + colourElement.render(); + GL11.glEnable(GL11.GL_SCISSOR_TEST); + } + } + + @Override + public boolean mouseInputGlobal(int x, int y, int width, int mouseX, int mouseY) { + if(colourElement != null && colourElement.mouseInput(mouseX, mouseY)) { + return true; + } + return false; + } + + @Override + public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { + int height = getHeight(); + + if(Mouse.getEventButtonState() && Mouse.getEventButton() == 0 && + mouseX > x+width/6-24 && mouseX < x+width/6+24 && + mouseY > y+height-7-14 && mouseY < y+height-7+2) { + colourElement = new GuiElementColour(mouseX, mouseY, (String) option.get(), (val) -> { + option.set(val); + chromaColour = val; + }, () -> colourElement = null); + } + + return false; + } + + @Override + public boolean keyboardInput() { + if(colourElement != null && colourElement.keyboardInput()) { + return true; + } + + return false; + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorDropdown.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorDropdown.java new file mode 100644 index 00000000..8b0d5eb3 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorDropdown.java @@ -0,0 +1,142 @@ +package io.github.moulberry.notenoughupdates.core.config.gui; + +import io.github.moulberry.notenoughupdates.core.config.struct.ConfigProcessor; +import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; +import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +public class GuiOptionEditorDropdown extends GuiOptionEditor { + + private final String[] values; + private final boolean useOrdinal; + private int selected; + private boolean open = false; + + public GuiOptionEditorDropdown(ConfigProcessor.ProcessedOption option, String[] values, int selected, boolean useOrdinal) { + super(option); + this.values = values; + this.selected = selected; + this.useOrdinal = useOrdinal; + } + + @Override + public void render(int x, int y, int width) { + super.render(x, y, width); + int height = getHeight(); + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + int dropdownWidth = Math.min(width/3-10, 80); + int left = x+width/6-dropdownWidth/2; + int top = y+height-7-14; + + String selectedString = " - Select - "; + if(selected >= 0 && selected < values.length) { + selectedString = values[selected]; + } + + if(open) { + GL11.glDisable(GL11.GL_SCISSOR_TEST); + GlStateManager.translate(0, 0, 10); + + int dropdownHeight = 13 + 12*values.length; + + int main = 0xffc0c0c0; + int blue = 0xff3365bd; + Gui.drawRect(left, top, left+1, top+dropdownHeight, blue); //Left + Gui.drawRect(left+1, top, left+dropdownWidth, top+1, blue); //Top + Gui.drawRect(left+dropdownWidth-1, top+1, left+dropdownWidth, top+dropdownHeight, blue); //Right + Gui.drawRect(left+1, top+dropdownHeight-1, left+dropdownWidth-1, top+dropdownHeight, blue); //Bottom + Gui.drawRect(left+1, top+1, left+dropdownWidth-1, top+dropdownHeight-1, main); //Middle + + Gui.drawRect(left+1, top+14-1, left+dropdownWidth-1, top+14, blue); //Bar + + int dropdownY = 13; + for(String option : values) { + if(option.isEmpty()) { + option = ""; + } + TextRenderUtils.drawStringScaledMaxWidth(option, fr, left+3, top+3+dropdownY, false, dropdownWidth-6, 0xff404040); + //fr.drawString(option, left+3, top+3+dropdownY, 0xff404040); + dropdownY += 12; + } + + TextRenderUtils.drawStringScaled("\u25B2", fr, left+dropdownWidth-10, y+height-7-15, false, 0xff404040, 2); + + + TextRenderUtils.drawStringScaledMaxWidth(selectedString, fr, left+3, top+3, false, + dropdownWidth-16, 0xff404040); + //fr.drawString(selectedString, left+3, top+3, 0xff404040); + + GlStateManager.translate(0, 0, -10); + GL11.glEnable(GL11.GL_SCISSOR_TEST); + } else { + RenderUtils.drawFloatingRectWithAlpha(left, top, dropdownWidth, 14, 0xff, false); + TextRenderUtils.drawStringScaled("\u25BC", fr, left+dropdownWidth-10, y+height-7-15, false, 0xff404040, 2); + + TextRenderUtils.drawStringScaledMaxWidth(selectedString, fr, left+3, top+3, false, + dropdownWidth-16, 0xff404040); + //fr.drawString(selectedString, left+3, top+3, 0xff404040); + } + } + + @Override + public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { + int height = getHeight(); + + int left = x+width/6-40; + int top = y+height-7-14; + + if(Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { + if(mouseX >= left && mouseX <= left+80 && + mouseY >= top && mouseY <= top+14) { + open = !open; + return true; + } + } + + return false; + } + + @Override + public boolean mouseInputGlobal(int x, int y, int width, int mouseX, int mouseY) { + int height = getHeight(); + + int left = x+width/6-40; + int top = y+height-7-14; + + if(Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { + if(!(mouseX >= left && mouseX <= left+80 && + mouseY >= top && mouseY <= top+14) && open) { + open = false; + if(mouseX >= left && mouseX <= left+80) { + int dropdownY = 13; + for(int ordinal=0; ordinal < values.length; ordinal++) { + if(mouseY >= top+3+dropdownY && mouseY <= top+3+dropdownY+12) { + selected = ordinal; + if(useOrdinal) { + option.set(selected); + } else { + option.set(values[selected]); + } + return true; + } + dropdownY += 12; + } + } + return true; + } + } + + return false; + } + + @Override + public boolean keyboardInput() { + return false; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorSlider.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorSlider.java new file mode 100644 index 00000000..a3665436 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorSlider.java @@ -0,0 +1,132 @@ +package io.github.moulberry.notenoughupdates.core.config.gui; + +import io.github.moulberry.notenoughupdates.core.GuiElementBoolean; +import io.github.moulberry.notenoughupdates.core.GuiElementTextField; +import io.github.moulberry.notenoughupdates.core.config.struct.ConfigProcessor; +import io.github.moulberry.notenoughupdates.core.util.GuiElementSlider; +import net.minecraft.client.Minecraft; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; + +public class GuiOptionEditorSlider extends GuiOptionEditor { + + private final GuiElementSlider slider; + private final GuiElementTextField textField; + + public GuiOptionEditorSlider(ConfigProcessor.ProcessedOption option, float minValue, float maxValue, float minStep) { + super(option); + if(minStep < 0) minStep = 0.01f; + + float floatVal = ((Number)option.get()).floatValue(); + { + String strVal; + if(floatVal % 1 == 0) { + strVal = Integer.toString((int)floatVal); + } else { + strVal = Float.toString(floatVal); + } + textField = new GuiElementTextField(strVal, + GuiElementTextField.NO_SPACE | GuiElementTextField.NUM_ONLY | GuiElementTextField.SCALE_TEXT); + } + + slider = new GuiElementSlider(0, 0, 80, minValue, maxValue, minStep, floatVal, (val) -> { + option.set(val); + + String strVal; + if(val % 1 == 0) { + strVal = Integer.toString(val.intValue()); + } else { + strVal = Float.toString(val); + strVal = strVal.replaceAll("(\\.\\d\\d\\d)(?:\\d)+", "$1"); + strVal = strVal.replaceAll("0+$", ""); + } + textField.setText(strVal); + }); + } + + @Override + public void render(int x, int y, int width) { + super.render(x, y, width); + int height = getHeight(); + + int fullWidth = Math.min(width/3-10, 80); + int sliderWidth = (fullWidth-5)*3/4; + int textFieldWidth = (fullWidth-5)/4; + + slider.x = x+width/6-fullWidth/2; + slider.y = y+height-7-14; + slider.width = sliderWidth; + slider.render(); + + if(textField.getFocus()) { + textField.setOptions(GuiElementTextField.NO_SPACE | GuiElementTextField.NUM_ONLY); + textField.setSize(Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText())+10, + 16); + } else { + textField.setSize(textFieldWidth, 16); + textField.setOptions(GuiElementTextField.NO_SPACE | GuiElementTextField.NUM_ONLY | GuiElementTextField.SCALE_TEXT); + } + + textField.render(x+width/6-fullWidth/2+sliderWidth+5, y+height-7-14); + } + + @Override + public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { + int height = getHeight(); + + int fullWidth = Math.min(width/3-10, 80); + int sliderWidth = (fullWidth-5)*3/4; + int textFieldWidth = (fullWidth-5)/4; + + slider.x = x+width/6-fullWidth/2; + slider.y = y+height-7-14; + slider.width = sliderWidth; + if(slider.mouseInput(mouseX, mouseY)) { + textField.unfocus(); + return true; + } + + if(textField.getFocus()) { + textFieldWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText())+10; + } + + int textFieldX = x+width/6-fullWidth/2+sliderWidth+5; + int textFieldY = y+height-7-14; + textField.setSize(textFieldWidth, 16); + + if(Mouse.getEventButtonState() && (Mouse.getEventButton() == 0 || Mouse.getEventButton() == 1)) { + if(mouseX > textFieldX && mouseX < textFieldX+textFieldWidth && + mouseY > textFieldY && mouseY < textFieldY+16) { + textField.mouseClicked(mouseX, mouseY, Mouse.getEventButton()); + return true; + } + textField.unfocus(); + } + + return false; + } + + @Override + public boolean keyboardInput() { + if(Keyboard.getEventKeyState() && textField.getFocus()) { + textField.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey()); + + try { + textField.setCustomBorderColour(0xffffffff); + float f = Float.parseFloat(textField.getText()); + if(option.set(f)) { + slider.setValue(f); + } else { + textField.setCustomBorderColour(0xff0000ff); + } + } catch(Exception e) { + textField.setCustomBorderColour(0xffff0000); + } + + return true; + } + return false; + } + + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorText.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorText.java new file mode 100644 index 00000000..bf50bda8 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorText.java @@ -0,0 +1,84 @@ +package io.github.moulberry.notenoughupdates.core.config.gui; + +import io.github.moulberry.notenoughupdates.core.GuiElementBoolean; +import io.github.moulberry.notenoughupdates.core.GuiElementTextField; +import io.github.moulberry.notenoughupdates.core.config.struct.ConfigProcessor; +import io.github.moulberry.notenoughupdates.core.util.GuiElementSlider; +import net.minecraft.client.Minecraft; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; + +public class GuiOptionEditorText extends GuiOptionEditor { + + private final GuiElementTextField textField; + + public GuiOptionEditorText(ConfigProcessor.ProcessedOption option) { + super(option); + + textField = new GuiElementTextField((String)option.get(), 0); + } + + @Override + public void render(int x, int y, int width) { + super.render(x, y, width); + int height = getHeight(); + + int fullWidth = Math.min(width/3-10, 80); + + int textFieldX = x+width/6-fullWidth/2; + if(textField.getFocus()) { + fullWidth = Math.max(fullWidth, Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText())+10); + } + + textField.setSize(fullWidth, 16); + + textField.render(textFieldX, y+height-7-14); + } + + @Override + public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { + int height = getHeight(); + + int fullWidth = Math.min(width/3-10, 80); + + int textFieldX = x+width/6-fullWidth/2; + + if(textField.getFocus()) { + fullWidth = Math.max(fullWidth, Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText())+10); + } + + int textFieldY = y+height-7-14; + textField.setSize(fullWidth, 16); + + if(Mouse.getEventButtonState() && (Mouse.getEventButton() == 0 || Mouse.getEventButton() == 1)) { + if(mouseX > textFieldX && mouseX < textFieldX+fullWidth && + mouseY > textFieldY && mouseY < textFieldY+16) { + textField.mouseClicked(mouseX, mouseY, Mouse.getEventButton()); + return true; + } + textField.unfocus(); + } + + return false; + } + + @Override + public boolean keyboardInput() { + if(Keyboard.getEventKeyState() && textField.getFocus()) { + Keyboard.enableRepeatEvents(true); + textField.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey()); + + try { + textField.setCustomBorderColour(0xffffffff); + option.set(textField.getText()); + } catch(Exception e) { + textField.setCustomBorderColour(0xffff0000); + } + + return true; + } + return false; + } + + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/ConfigProcessor.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/ConfigProcessor.java new file mode 100644 index 00000000..f91b8410 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/ConfigProcessor.java @@ -0,0 +1,157 @@ +package io.github.moulberry.notenoughupdates.core.config.struct; + +import com.google.gson.annotations.Expose; +import io.github.moulberry.notenoughupdates.core.config.Config; +import io.github.moulberry.notenoughupdates.core.config.annotations.*; +import io.github.moulberry.notenoughupdates.core.config.gui.*; +import io.github.moulberry.notenoughupdates.core.config.Config; + +import java.lang.reflect.Field; +import java.util.LinkedHashMap; + +public class ConfigProcessor { + + public static class ProcessedCategory { + public final String name; + public final String desc; + public final LinkedHashMap options = new LinkedHashMap<>(); + + public ProcessedCategory(String name, String desc) { + this.name = name; + this.desc = desc; + } + } + + public static class ProcessedOption { + public final String name; + public final String desc; + public final int subcategoryId; + public GuiOptionEditor editor; + + private final Field field; + private final Object container; + + public ProcessedOption(String name, String desc, int subcategoryId, Field field, Object container) { + this.name = name; + this.desc = desc; + this.subcategoryId = subcategoryId; + + this.field = field; + this.container = container; + } + + public Object get() { + try { + return field.get(container); + } catch(Exception e) { + return null; + } + } + + public boolean set(Object value) { + try { + if(field.getType() == int.class && value instanceof Number) { + field.set(container, ((Number)value).intValue()); + } else { + field.set(container, value); + } + return true; + } catch(Exception e) { + e.printStackTrace(); + return false; + } + } + } + + public static LinkedHashMap create(Config config) { + LinkedHashMap processedConfig = new LinkedHashMap<>(); + for(Field categoryField : config.getClass().getDeclaredFields()) { + boolean exposePresent = categoryField.isAnnotationPresent(Expose.class); + boolean categoryPresent = categoryField.isAnnotationPresent(Category.class); + + if(exposePresent && categoryPresent) { + Object categoryObj; + try { + categoryObj = categoryField.get(config); + } catch(Exception e) { + //System.err.printf("Failed to load config category %s. Field was not accessible.\n", categoryField.getName()); + continue; + } + + Category categoryAnnotation = categoryField.getAnnotation(Category.class); + ProcessedCategory cat = new ProcessedCategory( + categoryAnnotation.name(), + categoryAnnotation.desc() + ); + processedConfig.put(categoryField.getName(), cat); + + for(Field optionField : categoryObj.getClass().getDeclaredFields()) { + boolean optionExposePresent = optionField.isAnnotationPresent(Expose.class); + boolean optionPresent = optionField.isAnnotationPresent(ConfigOption.class); + + if(optionExposePresent && optionPresent) { + ConfigOption optionAnnotation = optionField.getAnnotation(ConfigOption.class); + ProcessedOption option = new ProcessedOption( + optionAnnotation.name(), + optionAnnotation.desc(), + optionAnnotation.subcategoryId(), + optionField, + categoryObj + ); + + GuiOptionEditor editor = null; + Class optionType = optionField.getType(); + if(optionType.isAssignableFrom(boolean.class) && + optionField.isAnnotationPresent(ConfigEditorBoolean.class)) { + editor = new GuiOptionEditorBoolean(option); + } + if(optionType.isAssignableFrom(int.class)) { + if(optionField.isAnnotationPresent(ConfigEditorDropdown.class)) { + ConfigEditorDropdown configEditorAnnotation = optionField.getAnnotation(ConfigEditorDropdown.class); + editor = new GuiOptionEditorDropdown(option, configEditorAnnotation.values(), (int)option.get(), true); + } + } + if(optionType.isAssignableFrom(String.class)) { + if(optionField.isAnnotationPresent(ConfigEditorDropdown.class)) { + ConfigEditorDropdown configEditorAnnotation = optionField.getAnnotation(ConfigEditorDropdown.class); + editor = new GuiOptionEditorDropdown(option, configEditorAnnotation.values(), + configEditorAnnotation.initialIndex(), false); + } else if(optionField.isAnnotationPresent(ConfigEditorColour.class)) { + editor = new GuiOptionEditorColour(option); + } else if(optionField.isAnnotationPresent(ConfigEditorText.class)) { + editor = new GuiOptionEditorText(option); + } + } + if(optionType.isAssignableFrom(int.class) || + optionType.isAssignableFrom(float.class) || + optionType.isAssignableFrom(double.class)) { + if(optionField.isAnnotationPresent(ConfigEditorSlider.class)) { + ConfigEditorSlider configEditorAnnotation = optionField.getAnnotation(ConfigEditorSlider.class); + editor = new GuiOptionEditorSlider(option, configEditorAnnotation.minValue(), + configEditorAnnotation.maxValue(), configEditorAnnotation.minStep()); + } + } + if(optionType.isAssignableFrom(String.class)) { + if(optionField.isAnnotationPresent(ConfigEditorDropdown.class)) { + ConfigEditorDropdown configEditorAnnotation = optionField.getAnnotation(ConfigEditorDropdown.class); + editor = new GuiOptionEditorDropdown(option, configEditorAnnotation.values(), 0,false); + } + } + if(editor == null) { + //System.err.printf("Failed to load config option %s. Could not find suitable editor.\n", optionField.getName()); + continue; + } + option.editor = editor; + cat.options.put(optionField.getName(), option); + } else if(optionExposePresent || optionPresent) { + //System.err.printf("Failed to load config option %s. Both @Expose and @ConfigOption must be present.\n", optionField.getName()); + } + } + } else if(exposePresent || categoryPresent) { + //System.err.printf("Failed to load config category %s. Both @Expose and @Category must be present.\n", categoryField.getName()); + } + } + return processedConfig; + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/GuiElementSlider.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/GuiElementSlider.java new file mode 100644 index 00000000..4cffb479 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/GuiElementSlider.java @@ -0,0 +1,124 @@ +package io.github.moulberry.notenoughupdates.core.util; + +import io.github.moulberry.notenoughupdates.core.GuiElement; +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 org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +import java.util.function.Consumer; + +import static io.github.moulberry.notenoughupdates.util.GuiTextures.*; + +public class GuiElementSlider extends GuiElement { + + public int x; + public int y; + public int width; + private static final int HEIGHT = 16; + + private float minValue; + private float maxValue; + private float minStep; + + private float value; + private Consumer setCallback; + + private boolean clicked = false; + + public GuiElementSlider(int x, int y, int width, float minValue, float maxValue, float minStep, + float value, Consumer setCallback) { + if(minStep < 0) minStep = 0.01f; + + this.x = x; + this.y = y; + this.width = width; + this.minValue = minValue; + this.maxValue = maxValue; + this.minStep = minStep; + this.value = value; + this.setCallback = setCallback; + } + + public void setValue(float value) { + this.value = value; + } + + @Override + public void render() { + final ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int mouseX = Mouse.getX() * scaledResolution.getScaledWidth() / Minecraft.getMinecraft().displayWidth; + + float value = this.value; + if(clicked) { + value = (mouseX-x)*(maxValue-minValue)/width+minValue; + value = Math.max(minValue, Math.min(maxValue, value)); + value = Math.round(value/minStep)*minStep; + } + + float sliderAmount = Math.max(0, Math.min(1, (value-minValue)/(maxValue-minValue))); + int sliderAmountI = (int)(width*sliderAmount); + + GlStateManager.color(1f, 1f, 1f, 1f); + Minecraft.getMinecraft().getTextureManager().bindTexture(slider_on_cap); + Utils.drawTexturedRect(x, y, 4, HEIGHT, GL11.GL_NEAREST); + Minecraft.getMinecraft().getTextureManager().bindTexture(slider_off_cap); + Utils.drawTexturedRect(x+width-4, y, 4, HEIGHT, GL11.GL_NEAREST); + + if(sliderAmountI > 5) { + Minecraft.getMinecraft().getTextureManager().bindTexture(slider_on_segment); + Utils.drawTexturedRect(x+4, y, sliderAmountI-4, HEIGHT, GL11.GL_NEAREST); + } + + if(sliderAmountI < width-5) { + Minecraft.getMinecraft().getTextureManager().bindTexture(slider_off_segment); + Utils.drawTexturedRect(x+sliderAmountI, y, width-4-sliderAmountI, HEIGHT, GL11.GL_NEAREST); + } + + for(int i=1; i<4; i++) { + int notchX = x+width*i/4-1; + Minecraft.getMinecraft().getTextureManager().bindTexture(notchX > x+sliderAmountI ? slider_off_notch : slider_on_notch); + Utils.drawTexturedRect(notchX, y+(HEIGHT-4)/2, 2, 4, GL11.GL_NEAREST); + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(slider_button); + Utils.drawTexturedRect(x+sliderAmountI-4, y, 8, HEIGHT, GL11.GL_NEAREST); + } + + @Override + public boolean mouseInput(int mouseX, int mouseY) { + if(!Mouse.isButtonDown(0)) { + clicked = false; + } + + if(Mouse.getEventButton() == 0) { + clicked = Mouse.getEventButtonState() && mouseX > x && mouseX < x+width && mouseY > y && mouseY < y+HEIGHT; + if(clicked) { + value = (mouseX-x)*(maxValue-minValue)/width+minValue; + value = Math.max(minValue, Math.min(maxValue, value)); + value = (float)(Math.round(value/minStep)*(double)minStep); + setCallback.accept(value); + return true; + } + } + + if(!Mouse.getEventButtonState() && Mouse.getEventButton() == -1 && clicked) { + value = (mouseX-x)*(maxValue-minValue)/width+minValue; + value = Math.max(minValue, Math.min(maxValue, value)); + value = Math.round(value/minStep)*minStep; + setCallback.accept(value); + return true; + } + + + return false; + } + + @Override + public boolean keyboardInput() { + return false; + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/MiscUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/MiscUtils.java new file mode 100644 index 00000000..3e9fc4ca --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/MiscUtils.java @@ -0,0 +1,104 @@ +package io.github.moulberry.notenoughupdates.core.util; + +import net.minecraft.client.Minecraft; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.BufferUtils; +import org.lwjgl.input.Cursor; +import org.lwjgl.input.Mouse; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.datatransfer.StringSelection; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.IntBuffer; +import java.nio.file.Files; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +public class MiscUtils { + + public static void copyToClipboard(String str) { + Toolkit.getDefaultToolkit().getSystemClipboard() + .setContents(new StringSelection(str), null); + } + private static void unzip(InputStream src, File dest) { + //buffer for read and write data to file + byte[] buffer = new byte[1024]; + try { + ZipInputStream zis = new ZipInputStream(src); + ZipEntry ze = zis.getNextEntry(); + while(ze != null){ + if(!ze.isDirectory()) { + String fileName = ze.getName(); + File newFile = new File(dest, fileName); + //create directories for sub directories in zip + new File(newFile.getParent()).mkdirs(); + FileOutputStream fos = new FileOutputStream(newFile); + int len; + while ((len = zis.read(buffer)) > 0) { + fos.write(buffer, 0, len); + } + fos.close(); + } + //close this ZipEntry + zis.closeEntry(); + ze = zis.getNextEntry(); + } + //close last ZipEntry + zis.closeEntry(); + zis.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void recursiveDelete(File file) { + if(file.isDirectory() && !Files.isSymbolicLink(file.toPath())) { + for(File child : file.listFiles()) { + recursiveDelete(child); + } + } + file.delete(); + } + + private static String currentCursor = null; + + public static void resetCursor() { + if(currentCursor == null) { + return; + } + currentCursor = null; + try { Mouse.setNativeCursor(null); } catch(Exception ignored) {} + } + + public static void setCursor(ResourceLocation loc, int hotspotX, int hotspotY) { + if(currentCursor != null && loc.getResourcePath().equals(currentCursor)) { + return; + } + currentCursor = loc.getResourcePath(); + try { + BufferedImage image = ImageIO.read(Minecraft.getMinecraft() + .getResourceManager().getResource(loc).getInputStream()); + int maxSize = Cursor.getMaxCursorSize(); + IntBuffer buffer = BufferUtils.createIntBuffer(maxSize*maxSize); + for(int i=0; i= image.getWidth() || cursorY >= image.getHeight()) { + buffer.put(0x00000000); + } else { + buffer.put(image.getRGB(cursorX, image.getHeight()-1-cursorY)); + } + } + buffer.flip(); + Mouse.setNativeCursor(new Cursor(maxSize, maxSize, hotspotX, hotspotY, 1, + buffer, null)); + } catch(Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/Splitters.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/Splitters.java new file mode 100644 index 00000000..555e0d79 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/Splitters.java @@ -0,0 +1,10 @@ +package io.github.moulberry.notenoughupdates.core.util; + +import com.google.common.base.Splitter; + +public class Splitters { + + public static final Splitter NEWLINE_SPLITTER = Splitter.on('\n'); + + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java new file mode 100644 index 00000000..a3d8204a --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java @@ -0,0 +1,39 @@ +package io.github.moulberry.notenoughupdates.core.util; + +import com.google.common.collect.Sets; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; + +import java.util.Set; + +public class StringUtils { + + public static final Set PROTOCOLS = Sets.newHashSet("http", "https"); + + public static String cleanColour(String in) { + return in.replaceAll("(?i)\\u00A7.", ""); + } + + public static String cleanColourNotModifiers(String in) { + return in.replaceAll("(?i)\\u00A7[0-9a-f]", "\u00A7r"); + } + + public static String trimToWidth(String str, int len) { + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + String trim = fr.trimStringToWidth(str, len); + + if(str.length() != trim.length() && !trim.endsWith(" ")) { + char next = str.charAt(trim.length()); + if(next != ' ') { + String[] split = trim.split(" "); + String last = split[split.length-1]; + if(last.length() < 8) { + trim = trim.substring(0, trim.length()-last.length()); + } + } + } + + return trim; + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/lerp/LerpUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/lerp/LerpUtils.java new file mode 100644 index 00000000..b7e05009 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/lerp/LerpUtils.java @@ -0,0 +1,22 @@ +package io.github.moulberry.notenoughupdates.core.util.lerp; + +public class LerpUtils { + + public static float clampZeroOne(float f) { + return Math.max(0, Math.min(1, f)); + } + + public static float sigmoid(float val) { + return (float)(1/(1 + Math.exp(-val))); + } + + private static final float sigmoidStr = 8; + private static final float sigmoidA = -1/(sigmoid(-0.5f * sigmoidStr) - sigmoid(0.5f * sigmoidStr)); + private static final float sigmoidB = sigmoidA*sigmoid(-0.5f * sigmoidStr); + public static float sigmoidZeroOne(float f) { + f = clampZeroOne(f); + return sigmoidA*sigmoid(sigmoidStr*(f-0.5f))-sigmoidB; + } + + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/lerp/LerpingFloat.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/lerp/LerpingFloat.java new file mode 100644 index 00000000..250facfc --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/lerp/LerpingFloat.java @@ -0,0 +1,68 @@ +package io.github.moulberry.notenoughupdates.core.util.lerp; + +public class LerpingFloat { + + private int timeSpent; + private long lastMillis; + private int timeToReachTarget; + + private float targetValue; + private float lerpValue; + + public LerpingFloat(float initialValue, int timeToReachTarget) { + this.targetValue = this.lerpValue = initialValue; + this.timeToReachTarget = timeToReachTarget; + } + + public LerpingFloat(int initialValue) { + this(initialValue, 200); + } + + public void tick() { + int lastTimeSpent = timeSpent; + this.timeSpent += System.currentTimeMillis() - lastMillis; + + float lastDistPercentToTarget = lastTimeSpent/(float)timeToReachTarget; + float distPercentToTarget = timeSpent/(float)timeToReachTarget; + float fac = (1-lastDistPercentToTarget)/lastDistPercentToTarget; + + float startValue = lerpValue - (targetValue - lerpValue)/fac; + + float dist = targetValue - startValue; + if(dist == 0) return; + + float oldLerpValue = lerpValue; + if(distPercentToTarget >= 1) { + lerpValue = targetValue; + } else { + lerpValue = startValue + dist*distPercentToTarget; + } + + if(lerpValue == oldLerpValue) { + timeSpent = lastTimeSpent; + } else { + this.lastMillis = System.currentTimeMillis(); + } + } + + public void resetTimer() { + this.timeSpent = 0; + this.lastMillis = System.currentTimeMillis(); + } + + public void setTarget(float targetValue) { + this.targetValue = targetValue; + } + + public void setValue(float value) { + this.targetValue = this.lerpValue = value; + } + + public float getValue() { + return lerpValue; + } + + public float getTarget() { + return targetValue; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/lerp/LerpingInteger.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/lerp/LerpingInteger.java new file mode 100644 index 00000000..cdc2c4fd --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/lerp/LerpingInteger.java @@ -0,0 +1,68 @@ +package io.github.moulberry.notenoughupdates.core.util.lerp; + +public class LerpingInteger { + + private int timeSpent; + private long lastMillis; + private int timeToReachTarget; + + private int targetValue; + private int lerpValue; + + public LerpingInteger(int initialValue, int timeToReachTarget) { + this.targetValue = this.lerpValue = initialValue; + this.timeToReachTarget = timeToReachTarget; + } + + public LerpingInteger(int initialValue) { + this(initialValue, 200); + } + + public void tick() { + int lastTimeSpent = timeSpent; + this.timeSpent += System.currentTimeMillis() - lastMillis; + + float lastDistPercentToTarget = lastTimeSpent/(float)timeToReachTarget; + float distPercentToTarget = timeSpent/(float)timeToReachTarget; + float fac = (1-lastDistPercentToTarget)/lastDistPercentToTarget; + + int startValue = lerpValue - (int)((targetValue - lerpValue)/fac); + + int dist = targetValue - startValue; + if(dist == 0) return; + + int oldLerpValue = lerpValue; + if(distPercentToTarget >= 1) { + lerpValue = targetValue; + } else { + lerpValue = startValue + (int)(dist*distPercentToTarget); + } + + if(lerpValue == oldLerpValue) { + timeSpent = lastTimeSpent; + } else { + this.lastMillis = System.currentTimeMillis(); + } + } + + public void resetTimer() { + this.timeSpent = 0; + this.lastMillis = System.currentTimeMillis(); + } + + public void setTarget(int targetValue) { + this.targetValue = targetValue; + } + + public void setValue(int value) { + this.targetValue = this.lerpValue = value; + } + + public int getValue() { + return lerpValue; + } + + public int getTarget() { + return targetValue; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/RenderUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/RenderUtils.java new file mode 100644 index 00000000..0cc34fa4 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/RenderUtils.java @@ -0,0 +1,144 @@ +package io.github.moulberry.notenoughupdates.core.util.render; + +import io.github.moulberry.notenoughupdates.core.BackgroundBlur; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +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.vertex.DefaultVertexFormats; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL14; + +public class RenderUtils { + + public static void drawFloatingRectDark(int x, int y, int width, int height) { + drawFloatingRectDark(x, y, width, height, true); + } + + public static void drawFloatingRectDark(int x, int y, int width, int height, boolean shadow) { + int alpha = 0xf0000000; + + if(OpenGlHelper.isFramebufferEnabled()) { + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + BackgroundBlur.renderBlurredBackground(scaledResolution.getScaledWidth(), + scaledResolution.getScaledHeight(), x, y, width, height); + } else { + alpha = 0xff000000; + } + + int main = alpha | 0x202026; + int light = 0xff303036; + int dark = 0xff101016; + Gui.drawRect(x, y, x+1, y+height, light); //Left + Gui.drawRect(x+1, y, x+width, y+1, light); //Top + Gui.drawRect(x+width-1, y+1, x+width, y+height, dark); //Right + Gui.drawRect(x+1, y+height-1, x+width-1, y+height, dark); //Bottom + Gui.drawRect(x+1, y+1, x+width-1, y+height-1, main); //Middle + if(shadow) { + Gui.drawRect(x+width, y+2, x+width+2, y+height+2, 0x70000000); //Right shadow + Gui.drawRect(x+2, y+height, x+width, y+height+2, 0x70000000); //Bottom shadow + } + } + + public static void drawFloatingRect(int x, int y, int width, int height) { + drawFloatingRectWithAlpha(x, y, width, height, 0xFF, true); + } + + public static void drawFloatingRectWithAlpha(int x, int y, int width, int height, int alpha, boolean shadow) { + int main = (alpha << 24) | 0xc0c0c0; + int light = (alpha << 24) | 0xf0f0f0; + int dark = (alpha << 24) | 0x909090; + Gui.drawRect(x, y, x+1, y+height, light); //Left + Gui.drawRect(x+1, y, x+width, y+1, light); //Top + Gui.drawRect(x+width-1, y+1, x+width, y+height, dark); //Right + Gui.drawRect(x+1, y+height-1, x+width-1, y+height, dark); //Bottom + Gui.drawRect(x+1, y+1, x+width-1, y+height-1, main); //Middle + if(shadow) { + Gui.drawRect(x+width, y+2, x+width+2, y+height+2, (alpha*3/5) << 24); //Right shadow + Gui.drawRect(x+2, y+height, x+width, y+height+2, (alpha*3/5) << 24); //Bottom shadow + } + } + + public static void drawTexturedRect(float x, float y, float width, float height) { + drawTexturedRect(x, y, width, height, 0, 1, 0 , 1); + } + + public static void drawTexturedRect(float x, float y, float width, float height, int filter) { + drawTexturedRect(x, y, width, height, 0, 1, 0 , 1, filter); + } + + public static void drawTexturedRect(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax) { + drawTexturedRect(x, y, width, height, uMin, uMax, vMin , vMax, GL11.GL_NEAREST); + } + + public static void drawTexturedRect(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax, int filter) { + GlStateManager.enableBlend(); + GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); + + drawTexturedRectNoBlend(x, y, width, height, uMin, uMax, vMin, vMax, filter); + + GlStateManager.disableBlend(); + } + + public static void drawTexturedRectNoBlend(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax, int filter) { + GlStateManager.enableTexture2D(); + + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filter); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filter); + + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX); + worldrenderer + .pos(x, y+height, 0.0D) + .tex(uMin, vMax).endVertex(); + worldrenderer + .pos(x+width, y+height, 0.0D) + .tex(uMax, vMax).endVertex(); + worldrenderer + .pos(x+width, y, 0.0D) + .tex(uMax, vMin).endVertex(); + worldrenderer + .pos(x, y, 0.0D) + .tex(uMin, vMin).endVertex(); + tessellator.draw(); + + 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); + } + + public static void drawGradientRect(int zLevel, int left, int top, int right, int bottom, int startColor, int endColor) { + float startAlpha = (float)(startColor >> 24 & 255) / 255.0F; + float startRed = (float)(startColor >> 16 & 255) / 255.0F; + float startGreen = (float)(startColor >> 8 & 255) / 255.0F; + float startBlue = (float)(startColor & 255) / 255.0F; + float endAlpha = (float)(endColor >> 24 & 255) / 255.0F; + float endRed = (float)(endColor >> 16 & 255) / 255.0F; + float endGreen = (float)(endColor >> 8 & 255) / 255.0F; + float endBlue = (float)(endColor & 255) / 255.0F; + + GlStateManager.disableTexture2D(); + GlStateManager.enableBlend(); + GlStateManager.disableAlpha(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GlStateManager.shadeModel(7425); + + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR); + worldrenderer.pos(right, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex(); + worldrenderer.pos(left, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex(); + worldrenderer.pos(left, bottom, zLevel).color(endRed, endGreen, endBlue, endAlpha).endVertex(); + worldrenderer.pos(right, bottom, zLevel).color(endRed, endGreen, endBlue, endAlpha).endVertex(); + tessellator.draw(); + + GlStateManager.shadeModel(7424); + GlStateManager.disableBlend(); + GlStateManager.enableAlpha(); + GlStateManager.enableTexture2D(); + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/TextRenderUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/TextRenderUtils.java new file mode 100644 index 00000000..541fd67a --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/TextRenderUtils.java @@ -0,0 +1,215 @@ +package io.github.moulberry.notenoughupdates.core.util.render; + +import io.github.moulberry.notenoughupdates.core.util.StringUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import org.lwjgl.opengl.GL11; + +import java.util.ArrayList; +import java.util.List; + +public class TextRenderUtils { + + public static int getCharVertLen(char c) { + if("acegmnopqrsuvwxyz".indexOf(c) >= 0) { + return 5; + } else { + return 7; + } + } + + public static float getVerticalHeight(String str) { + str = StringUtils.cleanColour(str); + float height = 0; + for(int i=0; i list = stack.getTooltip(Minecraft.getMinecraft().thePlayer, + Minecraft.getMinecraft().gameSettings.advancedItemTooltips); + + for (int i = 0; i < list.size(); ++i) { + if (i == 0) { + list.set(i, stack.getRarity().rarityColor + list.get(i)); + } else { + list.set(i, EnumChatFormatting.GRAY + list.get(i)); + } + } + + FontRenderer font = stack.getItem().getFontRenderer(stack); + drawHoveringText(list, mouseX, mouseY, screenWidth, screenHeight, -1, font == null ? fontStd : font); + } + + public static void drawHoveringText(List textLines, final int mouseX, final int mouseY, final int screenWidth, final int screenHeight, final int maxTextWidth, FontRenderer font) { + if (!textLines.isEmpty()) { + GlStateManager.disableRescaleNormal(); + RenderHelper.disableStandardItemLighting(); + GlStateManager.disableLighting(); + GlStateManager.disableDepth(); + int tooltipTextWidth = 0; + + for (String textLine : textLines) { + int textLineWidth = font.getStringWidth(textLine); + + if (textLineWidth > tooltipTextWidth) { + tooltipTextWidth = textLineWidth; + } + } + + boolean needsWrap = false; + + int titleLinesCount = 1; + int tooltipX = mouseX + 12; + if (tooltipX + tooltipTextWidth + 4 > screenWidth) { + tooltipX = mouseX - 16 - tooltipTextWidth; + if (tooltipX < 4) // if the tooltip doesn't fit on the screen + { + if (mouseX > screenWidth / 2) { + tooltipTextWidth = mouseX - 12 - 8; + } else { + tooltipTextWidth = screenWidth - 16 - mouseX; + } + needsWrap = true; + } + } + + if (maxTextWidth > 0 && tooltipTextWidth > maxTextWidth) { + tooltipTextWidth = maxTextWidth; + needsWrap = true; + } + + if (needsWrap) { + int wrappedTooltipWidth = 0; + List wrappedTextLines = new ArrayList(); + for (int i = 0; i < textLines.size(); i++) { + String textLine = textLines.get(i); + List wrappedLine = font.listFormattedStringToWidth(textLine, tooltipTextWidth); + if (i == 0) { + titleLinesCount = wrappedLine.size(); + } + + for (String line : wrappedLine) { + int lineWidth = font.getStringWidth(line); + if (lineWidth > wrappedTooltipWidth) { + wrappedTooltipWidth = lineWidth; + } + wrappedTextLines.add(line); + } + } + tooltipTextWidth = wrappedTooltipWidth; + textLines = wrappedTextLines; + + if (mouseX > screenWidth / 2) { + tooltipX = mouseX - 16 - tooltipTextWidth; + } else { + tooltipX = mouseX + 12; + } + } + + int tooltipY = mouseY - 12; + int tooltipHeight = 8; + + if (textLines.size() > 1) { + tooltipHeight += (textLines.size() - 1) * 10; + if (textLines.size() > titleLinesCount) { + tooltipHeight += 2; // gap between title lines and next lines + } + } + + if (tooltipY + tooltipHeight + 6 > screenHeight) { + tooltipY = screenHeight - tooltipHeight - 6; + } + + final int zLevel = 300; + final int backgroundColor = 0xF0100010; + RenderUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 4, tooltipX + tooltipTextWidth + 3, tooltipY - 3, backgroundColor, backgroundColor); + RenderUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 4, backgroundColor, backgroundColor); + RenderUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor); + RenderUtils.drawGradientRect(zLevel, tooltipX - 4, tooltipY - 3, tooltipX - 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor); + RenderUtils.drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 3, tooltipY - 3, tooltipX + tooltipTextWidth + 4, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor); + final int borderColorStart = 0x505000FF; + final int borderColorEnd = (borderColorStart & 0xFEFEFE) >> 1 | borderColorStart & 0xFF000000; + RenderUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3 + 1, tooltipX - 3 + 1, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd); + RenderUtils.drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 2, tooltipY - 3 + 1, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd); + RenderUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColorStart, borderColorStart); + RenderUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 2, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, borderColorEnd, borderColorEnd); + + for (int lineNumber = 0; lineNumber < textLines.size(); ++lineNumber) { + String line = textLines.get(lineNumber); + font.drawStringWithShadow(line, (float) tooltipX, (float) tooltipY, -1); + + if (lineNumber + 1 == titleLinesCount) { + tooltipY += 2; + } + + tooltipY += 10; + } + + GlStateManager.enableLighting(); + GlStateManager.enableDepth(); + RenderHelper.enableStandardItemLighting(); + GlStateManager.enableRescaleNormal(); + } + GlStateManager.disableLighting(); + } + +} 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 76885703..6f2ab3f1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/CapeManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/CapeManager.java @@ -1,14 +1,22 @@ package io.github.moulberry.notenoughupdates.cosmetics; +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import com.google.common.collect.Maps; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NEUManager; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.util.HypixelApi; import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.shader.Framebuffer; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.client.event.RenderPlayerEvent; +import net.minecraftforge.client.event.RenderWorldEvent; +import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import org.apache.commons.lang3.ArrayUtils; @@ -36,8 +44,8 @@ public class CapeManager { private HashSet availableCapes = new HashSet<>(); private String[] capes = new String[]{"patreon1", "patreon2", "fade", "contrib", "nullzee", - "gravy", "space", "mcworld", "lava", "packshq", "mbstaff", "thebakery", "negative" }; - public Boolean[] specialCapes = new Boolean[]{ true, true, false, true, true, true, false, false, false, true, true, true, false }; + "gravy", "space", "mcworld", "lava", "packshq", "mbstaff", "thebakery", "negative", "void" }; + public Boolean[] specialCapes = new Boolean[]{ true, true, false, true, true, true, false, false, false, true, true, true, false, false }; public static CapeManager getInstance() { return INSTANCE; @@ -109,8 +117,7 @@ public class CapeManager { updateConfig = updateConfig && playerUUID.equals(Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-", "")); if(updateConfig) { - NotEnoughUpdates.INSTANCE.manager.config.selectedCape.value = String.valueOf(capename); - try { NotEnoughUpdates.INSTANCE.manager.saveConfig(); } catch(IOException ignored) {} + NotEnoughUpdates.INSTANCE.config.hidden.selectedCape = String.valueOf(capename); } if(updateConfig) { @@ -138,13 +145,14 @@ public class CapeManager { return null; } + private static BiMap playerMap = null; + public EntityPlayer getPlayerForUUID(String uuid) { - if(Minecraft.getMinecraft().theWorld != null) { - for(EntityPlayer player : Minecraft.getMinecraft().theWorld.playerEntities) { - if(player.getUniqueID().toString().replace("-", "").equals(uuid)) { - return player; - } - } + if(playerMap == null) { + return null; + } + if(playerMap.containsKey(uuid)) { + return playerMap.get(uuid); } return null; } @@ -161,21 +169,26 @@ public class CapeManager { return framebuffer; } + public boolean updateWorldFramebuffer = false; public Framebuffer backgroundFramebuffer = null; - @SubscribeEvent - public void onRenderPlayer(RenderPlayerEvent.Pre e) { + + public void postRenderBlocks() { int width = Minecraft.getMinecraft().displayWidth; int height = Minecraft.getMinecraft().displayHeight; backgroundFramebuffer = checkFramebufferSizes(backgroundFramebuffer, width, height); - GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, Minecraft.getMinecraft().getFramebuffer().framebufferObject); - GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, backgroundFramebuffer.framebufferObject); - GL30.glBlitFramebuffer(0, 0, width, height, - 0, 0, width, height, - GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST); + if(OpenGlHelper.isFramebufferEnabled() && updateWorldFramebuffer) { + GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, Minecraft.getMinecraft().getFramebuffer().framebufferObject); + GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, backgroundFramebuffer.framebufferObject); + GL30.glBlitFramebuffer(0, 0, width, height, + 0, 0, width, height, + GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST); + + Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(true); + } - Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(true); + updateWorldFramebuffer = false; } @SubscribeEvent @@ -186,7 +199,7 @@ public class CapeManager { String clientUuid = Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-", ""); if(Minecraft.getMinecraft().thePlayer != null && uuid.equals(clientUuid)) { - String selCape = NotEnoughUpdates.INSTANCE.manager.config.selectedCape.value; + String selCape = NotEnoughUpdates.INSTANCE.config.hidden.selectedCape; if(selCape != null && !selCape.isEmpty()) { if(localCape == null) { localCape = new MutablePair<>(new NEUCape(selCape), selCape); @@ -205,20 +218,41 @@ public class CapeManager { @SubscribeEvent public void onTick(TickEvent.ClientTickEvent event) { if (event.phase != TickEvent.Phase.END) return; + if(Minecraft.getMinecraft().theWorld == null) return; String clientUuid = null; if(Minecraft.getMinecraft().thePlayer != null) { clientUuid = Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-", ""); } + if(playerMap == null) { + playerMap = HashBiMap.create(Minecraft.getMinecraft().theWorld.playerEntities.size()); + } + HashSet contains = new HashSet<>(); + for(EntityPlayer player : Minecraft.getMinecraft().theWorld.playerEntities) { + String uuid = player.getUniqueID().toString().replace("-", ""); + contains.add(uuid); + if(!playerMap.containsValue(player)) { + playerMap.put(uuid, player); + } + } + playerMap.keySet().retainAll(contains); + + boolean hasLocalCape = localCape != null && localCape.getRight() != null && !localCape.getRight().equals("null"); + Set toRemove = new HashSet<>(); try { for(String playerUUID : capeMap.keySet()) { - EntityPlayer player = getPlayerForUUID(playerUUID); + EntityPlayer player; + if(playerUUID.equals(clientUuid)) { + player = Minecraft.getMinecraft().thePlayer; + } else { + 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")) { + if(player == Minecraft.getMinecraft().thePlayer && hasLocalCape) { continue; } capeMap.get(playerUUID).getLeft().setCapeTexture(capeName); @@ -230,7 +264,7 @@ public class CapeManager { } } catch(Exception e) {} - if(localCape != null) { + if(hasLocalCape) { localCape.getLeft().setCapeTexture(localCape.getValue()); localCape.getLeft().onTick(event, Minecraft.getMinecraft().thePlayer); } 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 9de2731c..d93b8bb0 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/NEUCape.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/NEUCape.java @@ -88,6 +88,8 @@ public class NEUCape { shaderName = "biscuit_cape"; } else if(capeName.equalsIgnoreCase("negative")) { shaderName = "negative"; + } else if(capeName.equalsIgnoreCase("void")) { + shaderName = "void"; } else { shaderName = "shiny_cape"; } @@ -119,7 +121,10 @@ public class NEUCape { private void bindTexture() { if(capeName.equalsIgnoreCase("negative")) { - CapeManager.getInstance().backgroundFramebuffer.bindFramebufferTexture(); + CapeManager.getInstance().updateWorldFramebuffer = true; + if(CapeManager.getInstance().backgroundFramebuffer != null) { + CapeManager.getInstance().backgroundFramebuffer.bindFramebufferTexture(); + } } else if(capeTextures != null && capeTextures.length>0) { long currentTime = System.currentTimeMillis(); if(currentTime - lastFrameUpdate > 100) { @@ -325,6 +330,12 @@ public class NEUCape { Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight )); + } else if(shaderName.equalsIgnoreCase("void")) { + shaderManager.loadData(shaderName, "millis", (int) (System.currentTimeMillis() - startTime)); + shaderManager.loadData(shaderName, "screensize", new Vector2f( + Minecraft.getMinecraft().displayWidth, + Minecraft.getMinecraft().displayHeight + )); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonBlocks.java b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonBlocks.java index fb9de198..6fd3db78 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonBlocks.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonBlocks.java @@ -1,7 +1,7 @@ package io.github.moulberry.notenoughupdates.dungeons; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.questing.SBInfo; +import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.SpecialColour; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; @@ -9,17 +9,12 @@ import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; 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.input.Keyboard; import org.lwjgl.opengl.*; -import java.awt.*; import java.nio.FloatBuffer; -import java.nio.IntBuffer; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -47,8 +42,8 @@ public class DungeonBlocks { } public static boolean isOverriding() { - return OpenGlHelper.isFramebufferEnabled() && !NotEnoughUpdates.INSTANCE.manager.config.disableDungeonBlocks.value && - (NotEnoughUpdates.INSTANCE.manager.config.dungeonBlocksEverywhere.value || + return OpenGlHelper.isFramebufferEnabled() && NotEnoughUpdates.INSTANCE.config.dungeonBlock.enableDungBlockOverlay && + (NotEnoughUpdates.INSTANCE.config.dungeonBlock.dungeonBlocksEverywhere || (SBInfo.getInstance().getLocation() != null && SBInfo.getInstance().getLocation().equals("dungeon"))); } @@ -146,15 +141,15 @@ public class DungeonBlocks { static { dynamicPreloadMap.put(new ResourceLocation("textures/entity/bat.png"), - NotEnoughUpdates.INSTANCE.manager.config.dungBatColour.value); + NotEnoughUpdates.INSTANCE.config.dungeonBlock.dungBatColour); dynamicPreloadMap.put(new ResourceLocation("textures/entity/chest/normal.png"), - NotEnoughUpdates.INSTANCE.manager.config.dungChestColour.value); + NotEnoughUpdates.INSTANCE.config.dungeonBlock.dungChestColour); dynamicPreloadMap.put(new ResourceLocation("textures/entity/chest/normal_double.png"), - NotEnoughUpdates.INSTANCE.manager.config.dungChestColour.value); + NotEnoughUpdates.INSTANCE.config.dungeonBlock.dungChestColour); dynamicPreloadMap.put(new ResourceLocation("textures/entity/chest/trapped.png"), - NotEnoughUpdates.INSTANCE.manager.config.dungTrappedChestColour.value); + NotEnoughUpdates.INSTANCE.config.dungeonBlock.dungTrappedChestColour); dynamicPreloadMap.put(new ResourceLocation("textures/entity/chest/trapped_double.png"), - NotEnoughUpdates.INSTANCE.manager.config.dungTrappedChestColour.value); + NotEnoughUpdates.INSTANCE.config.dungeonBlock.dungTrappedChestColour); } public static void tick() { @@ -197,13 +192,13 @@ public class DungeonBlocks { HashMap spriteMap = new HashMap<>(); spriteMap.put(Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("minecraft:blocks/stonebrick_cracked"), - SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.manager.config.dungCrackedColour.value)); + SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.dungeonBlock.dungCrackedColour)); spriteMap.put(Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("minecraft:blocks/dispenser_front_horizontal"), - SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.manager.config.dungDispenserColour.value)); + SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.dungeonBlock.dungDispenserColour)); spriteMap.put(Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("minecraft:blocks/lever"), - SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.manager.config.dungLeverColour.value)); + SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.dungeonBlock.dungLeverColour)); spriteMap.put(Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("minecraft:blocks/trip_wire"), - SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.manager.config.dungTripWireColour.value)); + SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.dungeonBlock.dungTripWireColour)); for(Map.Entry entry : spriteMap.entrySet()) { if(((entry.getValue() >> 24) & 0xFF) < 10) continue; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonMap.java b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonMap.java index 4a209cd9..bbb5fd31 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonMap.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonMap.java @@ -1,30 +1,23 @@ package io.github.moulberry.notenoughupdates.dungeons; import com.google.common.collect.Iterables; -import com.google.common.math.BigIntegerMath; import com.google.gson.JsonObject; -import io.github.moulberry.notenoughupdates.NEUResourceManager; +import io.github.moulberry.notenoughupdates.util.NEUResourceManager; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.questing.SBInfo; import io.github.moulberry.notenoughupdates.util.SpecialColour; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.block.material.MapColor; -import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.MapItemRenderer; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.*; -import net.minecraft.client.renderer.entity.RenderItem; -import net.minecraft.client.renderer.texture.DynamicTexture; import net.minecraft.client.renderer.texture.TextureUtil; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.resources.DefaultPlayerSkin; import net.minecraft.client.shader.Framebuffer; import net.minecraft.client.shader.Shader; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemMap; import net.minecraft.item.ItemStack; @@ -35,19 +28,12 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import org.lwjgl.BufferUtils; -import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL14; -import org.lwjgl.opengl.GL30; -import org.lwjgl.opengl.GL45; import java.awt.*; -import java.awt.image.BufferedImage; import java.io.BufferedReader; import java.io.InputStreamReader; -import java.nio.ByteBuffer; -import java.nio.IntBuffer; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.List; @@ -198,7 +184,7 @@ public class DungeonMap { float x = 0; float y = 0; - if(NotEnoughUpdates.INSTANCE.manager.config.dmCenterCheck.value) { + if(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmCenterCheck) { if(fillCorner) { x += -(roomSize+connectorSize)/2f*Math.cos(Math.toRadians(rotation-45))*1.414f; y += (roomSize+connectorSize)/2f*Math.sin(Math.toRadians(rotation-45))*1.414; @@ -212,17 +198,17 @@ public class DungeonMap { } } GlStateManager.translate(x, y, 0); - if(!NotEnoughUpdates.INSTANCE.manager.config.dmOrientCheck.value) { + if(!NotEnoughUpdates.INSTANCE.config.dungeonMap.dmOrientCheck) { GlStateManager.rotate(-rotation+180, 0, 0, 1); } GlStateManager.pushMatrix(); - GlStateManager.scale(NotEnoughUpdates.INSTANCE.manager.config.dmIconScale.value, - NotEnoughUpdates.INSTANCE.manager.config.dmIconScale.value, 1); + GlStateManager.scale(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmIconScale, + NotEnoughUpdates.INSTANCE.config.dungeonMap.dmIconScale, 1); Utils.drawTexturedRect(-5, -5, 10, 10, GL11.GL_NEAREST); GlStateManager.popMatrix(); - if(!NotEnoughUpdates.INSTANCE.manager.config.dmOrientCheck.value) { + if(!NotEnoughUpdates.INSTANCE.config.dungeonMap.dmOrientCheck) { GlStateManager.rotate(rotation-180, 0, 0, 1); } GlStateManager.translate(-x, -y, 0); @@ -361,23 +347,23 @@ public class DungeonMap { } public int getRenderRoomSize() { - double roomSizeOption = NotEnoughUpdates.INSTANCE.manager.config.dmRoomSize.value; + double roomSizeOption = NotEnoughUpdates.INSTANCE.config.dungeonMap.dmRoomSize; if(roomSizeOption <= 0) return 12; return 12 + (int)Math.round(roomSizeOption*4); } public int getRenderConnSize() { - int roomSizeOption = (int)Math.round(NotEnoughUpdates.INSTANCE.manager.config.dmRoomSize.value); + int roomSizeOption = (int)Math.round(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmRoomSize); if(roomSizeOption <= 0) return 3; return 3 + roomSizeOption; } private HashMap borderRadiusCache = new HashMap<>(); public float getBorderRadius() { - int borderSizeOption = (int)Math.round(NotEnoughUpdates.INSTANCE.manager.config.dmBorderSize.value.doubleValue()); + int borderSizeOption = NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBorderSize; String sizeId = borderSizeOption == 0 ? "small" : borderSizeOption == 2 ? "large" : "medium"; - int style = NotEnoughUpdates.INSTANCE.manager.config.dmBorderStyle.value.intValue(); + int style = NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBorderStyle; if(borderRadiusCache.containsKey(style)) { return borderRadiusCache.get(style); } @@ -396,8 +382,8 @@ public class DungeonMap { } public void render(int centerX, int centerY) { - boolean useFb = NotEnoughUpdates.INSTANCE.manager.config.dmCompat.value <= 1; - boolean useShd = NotEnoughUpdates.INSTANCE.manager.config.dmCompat.value <= 0; + boolean useFb = NotEnoughUpdates.INSTANCE.config.dungeonMap.dmCompat <= 1; + boolean useShd = NotEnoughUpdates.INSTANCE.config.dungeonMap.dmCompat <= 0; if((useFb && !OpenGlHelper.isFramebufferEnabled()) || (useShd && !OpenGlHelper.areShadersSupported())) { Utils.drawStringCentered(EnumChatFormatting.RED+"NEU Dungeon Map requires framebuffers & shaders", @@ -422,7 +408,7 @@ public class DungeonMap { maxRoomY = Math.max(offset.y, maxRoomY); } - int borderSizeOption = NotEnoughUpdates.INSTANCE.manager.config.dmBorderSize.value.intValue(); + int borderSizeOption = NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBorderSize; int renderRoomSize = getRenderRoomSize(); int renderConnSize = getRenderConnSize(); @@ -435,14 +421,14 @@ public class DungeonMap { } int rotation = 180; - if(playerPos != null && NotEnoughUpdates.INSTANCE.manager.config.dmRotatePlayer.value) { + if(playerPos != null && NotEnoughUpdates.INSTANCE.config.dungeonMap.dmRotatePlayer) { rotation = (int)playerPos.rotation; } int mapSizeX; int mapSizeY; - if(NotEnoughUpdates.INSTANCE.manager.config.dmBorderStyle.value <= 1) { - mapSizeX = 80 + (int)Math.round(40*NotEnoughUpdates.INSTANCE.manager.config.dmBorderSize.value); + if(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBorderStyle <= 1) { + mapSizeX = 80 + (int)Math.round(40*NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBorderSize); } else { mapSizeX = borderSizeOption == 0 ? 90 : borderSizeOption == 1 ? 120 : borderSizeOption == 2 ? 160 : 240; } @@ -470,7 +456,7 @@ public class DungeonMap { return; } - int backgroundColour = SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.manager.config.dmBackgroundColour.value); + int backgroundColour = SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBackgroundColour); mapFramebuffer1.framebufferColor[0] = ((backgroundColour >> 16) & 0xFF)/255f; mapFramebuffer1.framebufferColor[1] = ((backgroundColour >> 8) & 0xFF)/255f; @@ -506,7 +492,7 @@ public class DungeonMap { GlStateManager.translate(centerX-mapSizeX/2, centerY-mapSizeY/2, 100); } - if(NotEnoughUpdates.INSTANCE.manager.config.dmBackgroundBlur.value > 0.1) { + if(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBackgroundBlur > 0.1) { GlStateManager.translate(-centerX+mapSizeX/2, -centerY+mapSizeY/2, 0); renderBlurredBackground(scaledResolution.getScaledWidth(), scaledResolution.getScaledHeight(), centerX-mapSizeX/2, centerY-mapSizeY/2, mapSizeX, mapSizeY); @@ -515,7 +501,7 @@ public class DungeonMap { GlStateManager.translate(mapCenterX, mapCenterY, 10); - if(!useFb || NotEnoughUpdates.INSTANCE.manager.config.dmBackgroundBlur.value > 0.1) { + if(!useFb || NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBackgroundBlur > 0.1) { GlStateManager.enableBlend(); GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); } @@ -523,7 +509,7 @@ public class DungeonMap { GlStateManager.rotate(-rotation+180, 0, 0, 1); - if(NotEnoughUpdates.INSTANCE.manager.config.dmCenterPlayer.value && playerPos != null) { + if(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmCenterPlayer && playerPos != null) { float x = playerPos.getRenderX(); float y = playerPos.getRenderY(); x -= minRoomX*(renderRoomSize+renderConnSize); @@ -597,7 +583,7 @@ public class DungeonMap { float y = pos.getRenderY(); float angle = pos.rotation; - boolean doInterp = NotEnoughUpdates.INSTANCE.manager.config.dmPlayerInterp.value; + boolean doInterp = NotEnoughUpdates.INSTANCE.config.dungeonMap.dmPlayerInterp; if(playerEntityMapPositions.containsKey(name)) { MapPosition entityPos = playerEntityMapPositions.get(name); angle = entityPos.rotation; @@ -605,7 +591,7 @@ public class DungeonMap { float deltaX = entityPos.getRenderX() - pos.getRenderX(); float deltaY = entityPos.getRenderY() - pos.getRenderY(); - if(deltaX > (renderRoomSize + renderConnSize)/2) { + /*if(deltaX > (renderRoomSize + renderConnSize)/2) { deltaX -= (renderRoomSize + renderConnSize); } else if(deltaX < -(renderRoomSize + renderConnSize)/2) { deltaX += (renderRoomSize + renderConnSize); @@ -614,7 +600,7 @@ public class DungeonMap { deltaY -= (renderRoomSize + renderConnSize); } else if(deltaY < -(renderRoomSize + renderConnSize)/2) { deltaY += (renderRoomSize + renderConnSize); - } + }*/ x += deltaX; y += deltaY; @@ -661,7 +647,7 @@ public class DungeonMap { pixelWidth = pixelHeight = 12; } GlStateManager.color(1, 1, 1, 1); - if(NotEnoughUpdates.INSTANCE.manager.config.dmPlayerHeads.value >= 1 && + if(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmPlayerHeads >= 1 && playerSkinMap.containsKey(entry.getKey())) { Minecraft.getMinecraft().getTextureManager().bindTexture(playerSkinMap.get(entry.getKey())); @@ -671,7 +657,7 @@ public class DungeonMap { maxV = 16/64f; headLayer = true; - if(NotEnoughUpdates.INSTANCE.manager.config.dmPlayerHeads.value >= 2) { + if(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmPlayerHeads >= 2) { blackBorder = true; } } else { @@ -688,8 +674,8 @@ public class DungeonMap { GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); GlStateManager.translate(x, y, -0.02F); - GlStateManager.scale(NotEnoughUpdates.INSTANCE.manager.config.dmIconScale.value, - NotEnoughUpdates.INSTANCE.manager.config.dmIconScale.value, 1); + GlStateManager.scale(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmIconScale, + NotEnoughUpdates.INSTANCE.config.dungeonMap.dmIconScale, 1); GlStateManager.rotate(angle, 0.0F, 0.0F, 1.0F); GlStateManager.translate(-0.5F, 0.5F, 0.0F); @@ -757,8 +743,8 @@ public class DungeonMap { GlStateManager.translate(centerX, centerY, 100); - if(NotEnoughUpdates.INSTANCE.manager.config.dmChromaBorder.value) { - int colour = SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.manager.config.dmBorderColour.value); + if(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmChromaBorder) { + int colour = SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBorderColour); Gui.drawRect(-mapCenterX-2, -mapCenterY-2, -mapCenterX, -mapCenterY, colour); //topleft @@ -789,19 +775,19 @@ public class DungeonMap { } else { Gui.drawRect(-mapCenterX-2, -mapCenterY, -mapCenterX, mapCenterY, - SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.manager.config.dmBorderColour.value)); //left + SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBorderColour)); //left Gui.drawRect(mapCenterX, -mapCenterY, mapCenterX+2, mapCenterY, - SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.manager.config.dmBorderColour.value)); //right + SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBorderColour)); //right Gui.drawRect(-mapCenterX-2, -mapCenterY-2, mapCenterX+2, -mapCenterY, - SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.manager.config.dmBorderColour.value)); //top + SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBorderColour)); //top Gui.drawRect(-mapCenterX-2, mapCenterY, mapCenterX+2, mapCenterY+2, - SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.manager.config.dmBorderColour.value)); //bottom + SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBorderColour)); //bottom } String sizeId = borderSizeOption == 0 ? "small" : borderSizeOption == 2 ? "large" : "medium"; ResourceLocation rl = new ResourceLocation("notenoughupdates:dungeon_map/borders/"+sizeId+"/"+ - NotEnoughUpdates.INSTANCE.manager.config.dmBorderStyle.value.intValue()+".png"); + NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBorderStyle+".png"); if(Minecraft.getMinecraft().getTextureManager().getTexture(rl) != TextureUtil.missingTexture) { Minecraft.getMinecraft().getTextureManager().bindTexture(rl); GlStateManager.color(1, 1, 1, 1); @@ -1010,7 +996,7 @@ public class DungeonMap { private long lastClearCache = 0; public void renderMap(int centerX, int centerY, Color[][] colourMap, Map mapDecorations, int roomSizeBlocks, Set actualPlayers, boolean usePlayerPositions, float partialTicks) { - if(!NotEnoughUpdates.INSTANCE.manager.config.dmEnable.value) return; + if(!NotEnoughUpdates.INSTANCE.config.dungeonMap.dmEnable) return; if(colourMap == null) return; if(colourMap.length != 128) return; if(colourMap[0].length != 128) return; @@ -1364,8 +1350,8 @@ public class DungeonMap { @SubscribeEvent(priority=EventPriority.HIGH) public void onRenderOverlayPre(RenderGameOverlayEvent.Pre event) { if(event.type == RenderGameOverlayEvent.ElementType.ALL && - NotEnoughUpdates.INSTANCE.manager.config.dmEnable.value && - NotEnoughUpdates.INSTANCE.manager.config.dmBackgroundBlur.value > 0.1) { + NotEnoughUpdates.INSTANCE.config.dungeonMap.dmEnable && + NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBackgroundBlur > 0.1) { blurBackground(); GlStateManager.enableBlend(); GlStateManager.enableTexture2D(); @@ -1378,9 +1364,9 @@ public class DungeonMap { } @SubscribeEvent - public void onRenderOverlay(RenderGameOverlayEvent event) { + public void onRenderOverlay(RenderGameOverlayEvent.Post event) { if(event.type == RenderGameOverlayEvent.ElementType.ALL) { - if(!NotEnoughUpdates.INSTANCE.manager.config.dmEnable.value) return; + if(!NotEnoughUpdates.INSTANCE.config.dungeonMap.dmEnable) return; if(Minecraft.getMinecraft().gameSettings.showDebugInfo || (Minecraft.getMinecraft().gameSettings.keyBindPlayerList.isKeyDown() && @@ -1489,8 +1475,8 @@ public class DungeonMap { } } - renderMap((int)(NotEnoughUpdates.INSTANCE.manager.config.dmCenterX.value/100*Minecraft.getMinecraft().displayWidth/2), - (int)(NotEnoughUpdates.INSTANCE.manager.config.dmCenterY.value/100*Minecraft.getMinecraft().displayHeight/2), + renderMap((int)(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmCenterX/100*Minecraft.getMinecraft().displayWidth/2), + (int)(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmCenterY/100*Minecraft.getMinecraft().displayHeight/2), colourMap, decorations, roomSizeBlocks, actualPlayers, true, event.partialTicks); } } @@ -1591,7 +1577,7 @@ public class DungeonMap { } catch(Exception e) { } } if(blurShaderHorz != null && blurShaderVert != null) { - float blur = NotEnoughUpdates.INSTANCE.manager.config.dmBackgroundBlur.value.floatValue(); + float blur = NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBackgroundBlur; blur = Math.max(0, Math.min(50, blur)); if(blur != lastBgBlurFactor) { blurShaderHorz.getShaderManager().getShaderUniform("Radius").set(blur); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonWin.java b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonWin.java index fec10027..284ec1a3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonWin.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonWin.java @@ -77,13 +77,13 @@ public class DungeonWin { } public static void displayWin() { - if(NotEnoughUpdates.INSTANCE.manager.config.dungeonWinMillis.value < 100) return; + if(NotEnoughUpdates.INSTANCE.config.dungeonWin.dungeonWinMillis < 100 || !NotEnoughUpdates.INSTANCE.config.dungeonWin.enableDungeonWin) return; startTime = System.currentTimeMillis(); confetti.clear(); } public static void tick() { - if(NotEnoughUpdates.INSTANCE.manager.config.dungeonWinMillis.value < 100) return; + if(NotEnoughUpdates.INSTANCE.config.dungeonWin.dungeonWinMillis < 100 || !NotEnoughUpdates.INSTANCE.config.dungeonWin.enableDungeonWin) return; if(System.currentTimeMillis() - startTime > 5000) return; int deltaTime = (int)(System.currentTimeMillis() - startTime); @@ -140,7 +140,7 @@ public class DungeonWin { } public static void onChatMessage(ClientChatReceivedEvent e) { - if(NotEnoughUpdates.INSTANCE.manager.config.dungeonWinMillis.value < 100) return; + if(NotEnoughUpdates.INSTANCE.config.dungeonWin.dungeonWinMillis < 100 || !NotEnoughUpdates.INSTANCE.config.dungeonWin.enableDungeonWin) return; long currentTime = System.currentTimeMillis(); String unformatted = Utils.cleanColour(e.message.getUnformattedText()); if(e.message.getFormattedText().startsWith(EnumChatFormatting.RESET+" ")) { @@ -195,8 +195,8 @@ public class DungeonWin { } public static void render(float partialTicks) { - if(NotEnoughUpdates.INSTANCE.manager.config.dungeonWinMillis.value < 100) return; - int maxTime = Math.min(30000, NotEnoughUpdates.INSTANCE.manager.config.dungeonWinMillis.value.intValue()); + if(NotEnoughUpdates.INSTANCE.config.dungeonWin.dungeonWinMillis < 100 || !NotEnoughUpdates.INSTANCE.config.dungeonWin.enableDungeonWin) return; + int maxTime = Math.min(30000, NotEnoughUpdates.INSTANCE.config.dungeonWin.dungeonWinMillis); if(System.currentTimeMillis() - startTime > maxTime) return; int deltaTime = (int)(System.currentTimeMillis() - startTime); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/GuiDungeonMapEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/GuiDungeonMapEditor.java index 0bd7ed6f..e962f793 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/GuiDungeonMapEditor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/GuiDungeonMapEditor.java @@ -1,18 +1,18 @@ package io.github.moulberry.notenoughupdates.dungeons; +import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.GuiElementColour; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorSlider; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigOption; import io.github.moulberry.notenoughupdates.itemeditor.GuiElementTextField; -import io.github.moulberry.notenoughupdates.options.Options; import io.github.moulberry.notenoughupdates.util.SpecialColour; 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.GuiScreen; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.client.renderer.texture.DynamicTexture; import net.minecraft.client.shader.Framebuffer; import net.minecraft.client.shader.Shader; import net.minecraft.util.EnumChatFormatting; @@ -24,14 +24,11 @@ import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import java.awt.*; -import java.awt.image.BufferedImage; import java.io.IOException; +import java.lang.reflect.Field; import java.util.*; import java.util.List; -import static io.github.moulberry.notenoughupdates.GuiTextures.*; - -import static io.github.moulberry.notenoughupdates.GuiTextures.*; -import static io.github.moulberry.notenoughupdates.GuiTextures.colour_selector_dot; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.*; public class GuiDungeonMapEditor extends GuiScreen { @@ -57,23 +54,9 @@ public class GuiDungeonMapEditor extends GuiScreen { private GuiElementTextField xField = new GuiElementTextField("", GuiElementTextField.NUM_ONLY | GuiElementTextField.NO_SPACE); private GuiElementTextField yField = new GuiElementTextField("", GuiElementTextField.NUM_ONLY | GuiElementTextField.NO_SPACE); private GuiElementTextField blurField = new GuiElementTextField("", GuiElementTextField.NUM_ONLY | GuiElementTextField.NO_SPACE); - private ColourEditor activeColourEditor = null; - - private Options.Option clickedSlider = null; - - private class ColourEditor { - public int x; - public int y; - public Options.Option option; - public String special; + private GuiElementColour activeColourEditor = null; - public ColourEditor(int x, int y, Options.Option option, String special) { - this.x = x; - this.y = y; - this.option = option; - this.special = special; - } - } + private Field clickedSlider; class Button { private int id; @@ -81,18 +64,26 @@ public class GuiDungeonMapEditor extends GuiScreen { private int y; private String text; private Color colour = new Color(-1, true); - private Options.Option option; + private Field option; + private String displayName; + private String desc; public Button(int id, int x, int y, String text) { this(id, x, y, text, null); } - public Button(int id, int x, int y, String text, Options.Option option) { + public Button(int id, int x, int y, String text, Field option) { this.id = id; this.x = x; this.y = y; this.text = text; this.option = option; + + if(option != null) { + ConfigOption optionAnnotation = option.getAnnotation(ConfigOption.class); + displayName = optionAnnotation.name(); + desc = optionAnnotation.desc(); + } } public List getTooltip() { @@ -101,8 +92,8 @@ public class GuiDungeonMapEditor extends GuiScreen { } List tooltip = new ArrayList<>(); - tooltip.add(EnumChatFormatting.YELLOW+option.displayName); - for(String line : option.desc.split("\n")) { + tooltip.add(EnumChatFormatting.YELLOW+displayName); + for(String line : desc.split("\n")) { tooltip.add(EnumChatFormatting.AQUA+line); } return tooltip; @@ -129,7 +120,7 @@ public class GuiDungeonMapEditor extends GuiScreen { } public GuiDungeonMapEditor() { - Options options = NotEnoughUpdates.INSTANCE.manager.config; + NEUConfig.DungeonMap options = NotEnoughUpdates.INSTANCE.config.dungeonMap; //Map Border Size //buttons.add(new Button(0, 6, 37, "Small", options.dmBorderSize)); //buttons.add(new Button(1, 52, 37, "Medium", options.dmBorderSize)); @@ -154,42 +145,41 @@ public class GuiDungeonMapEditor extends GuiScreen { buttons.add(new Button(16, 52, 154+30, "Ornate")); buttons.add(new Button(17, 98, 154+30, "Dragon")); - //Dungeon Map - buttons.add(new Button(18, 20+139, 36, "Yes/No", options.dmEnable)); - //Center - buttons.add(new Button(19, 84+139, 36, "Player/Map", options.dmCenterPlayer)); - //Rotate - buttons.add(new Button(20, 20+139, 65, "Player/No Rotate", options.dmRotatePlayer)); - //Icon Style - buttons.add(new Button(21, 84+139, 65, "Default/Heads", options.dmPlayerHeads)); - //Check Orient - buttons.add(new Button(22, 20+139, 94, "Normal/Reorient", options.dmOrientCheck)); - //Check Center - buttons.add(new Button(23, 84+139, 94, "Yes/No", options.dmCenterCheck)); - //Interpolation - buttons.add(new Button(24, 20+139, 123, "Yes/No", options.dmPlayerInterp)); - //Compatibility - buttons.add(new Button(25, 84+139, 123, "Normal/No SHD/No FB/SHD", options.dmCompat)); - - //Background - buttons.add(new Button(26, 20+139, 152, "", options.dmBackgroundColour)); - //Border - buttons.add(new Button(27, 84+139, 152, "", options.dmBorderColour)); - - //Chroma Mode - buttons.add(new Button(28, 84+139, 181, "Normal/Scroll", options.dmChromaBorder)); + try { + //Dungeon Map + buttons.add(new Button(18, 20+139, 36, "Yes/No", NEUConfig.DungeonMap.class.getDeclaredField("dmEnable"))); + //Center + buttons.add(new Button(19, 84+139, 36, "Player/Map", NEUConfig.DungeonMap.class.getDeclaredField("dmCenterPlayer"))); + //Rotate + buttons.add(new Button(20, 20+139, 65, "Player/No Rotate", NEUConfig.DungeonMap.class.getDeclaredField("dmRotatePlayer"))); + //Icon Style + buttons.add(new Button(21, 84+139, 65, "Default/Heads", NEUConfig.DungeonMap.class.getDeclaredField("dmPlayerHeads"))); + //Check Orient + buttons.add(new Button(22, 20+139, 94, "Normal/Reorient", NEUConfig.DungeonMap.class.getDeclaredField("dmOrientCheck"))); + //Check Center + buttons.add(new Button(23, 84+139, 94, "Yes/No", NEUConfig.DungeonMap.class.getDeclaredField("dmCenterCheck"))); + //Interpolation + buttons.add(new Button(24, 20+139, 123, "Yes/No", NEUConfig.DungeonMap.class.getDeclaredField("dmPlayerInterp"))); + //Compatibility + buttons.add(new Button(25, 84+139, 123, "Normal/No SHD/No FB/SHD", NEUConfig.DungeonMap.class.getDeclaredField("dmCompat"))); + + //Background + buttons.add(new Button(26, 20+139, 152, "", NEUConfig.DungeonMap.class.getDeclaredField("dmBackgroundColour"))); + //Border + buttons.add(new Button(27, 84+139, 152, "", NEUConfig.DungeonMap.class.getDeclaredField("dmBorderColour"))); + + //Chroma Mode + buttons.add(new Button(28, 84+139, 181, "Normal/Scroll", NEUConfig.DungeonMap.class.getDeclaredField("dmChromaBorder"))); + } catch(Exception e) { + e.printStackTrace(); + } //buttons.add(new Button(29, 52, 86+19, "XLarge", options.dmRoomSize)); //buttons.add(new Button(30, 52, 56, "XLarge", options.dmBorderSize)); - xField.setText(String.valueOf(NotEnoughUpdates.INSTANCE.manager.config.dmCenterX.value)); - yField.setText(String.valueOf(NotEnoughUpdates.INSTANCE.manager.config.dmCenterY.value)); - blurField.setText(String.valueOf(NotEnoughUpdates.INSTANCE.manager.config.dmBackgroundBlur.value)); - } - - private void showColourEditor(int mouseX, int mouseY, Options.Option option, String special) { - activeColourEditor = new ColourEditor(mouseX, mouseY, option, special); - hexField.otherComponentClick(); + xField.setText(String.valueOf(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmCenterX)); + yField.setText(String.valueOf(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmCenterY)); + blurField.setText(String.valueOf(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBackgroundBlur)); } @Override @@ -311,24 +301,28 @@ public class GuiDungeonMapEditor extends GuiScreen { Utils.drawStringCenteredScaledMaxWidth("Y (%)", Minecraft.getMinecraft().fontRendererObj, guiLeft+108, guiTop+209, false, 60, 0xFFB4B4B4); - drawSlider(NotEnoughUpdates.INSTANCE.manager.config.dmBorderSize, guiLeft+76, guiTop+45); - drawSlider(NotEnoughUpdates.INSTANCE.manager.config.dmRoomSize, guiLeft+76, guiTop+75); - drawSlider(NotEnoughUpdates.INSTANCE.manager.config.dmIconScale, guiLeft+76, guiTop+105); + try { + drawSlider(NEUConfig.DungeonMap.class.getDeclaredField("dmBorderSize"), guiLeft+76, guiTop+45); + drawSlider(NEUConfig.DungeonMap.class.getDeclaredField("dmRoomSize"), guiLeft+76, guiTop+75); + drawSlider(NEUConfig.DungeonMap.class.getDeclaredField("dmIconScale"), guiLeft+76, guiTop+105); + } catch(Exception e) { + e.printStackTrace(); + } - Options options = NotEnoughUpdates.INSTANCE.manager.config; - buttons.get(18-6).text = options.dmEnable.value ? "Enabled" : "Disabled"; - buttons.get(19-6).text = options.dmCenterPlayer.value ? "Player" : "Map"; - buttons.get(20-6).text = options.dmRotatePlayer.value ? "Player" : "Vertical"; - buttons.get(21-6).text = options.dmPlayerHeads.value <= 0 ? "Default" : options.dmPlayerHeads.value == 1 ? "Heads" : "Heads w/ Border"; - buttons.get(22-6).text = options.dmOrientCheck.value ? "Orient" : "Off"; - buttons.get(23-6).text = options.dmCenterCheck.value ? "Center" : "Off"; - buttons.get(24-6).text = options.dmPlayerInterp.value ? "Interp" : "No Interp"; - buttons.get(25-6).text = options.dmCompat.value <= 0 ? "Normal" : options.dmCompat.value >= 2 ? "No FB/SHD" : "No SHD"; + NEUConfig.DungeonMap options = NotEnoughUpdates.INSTANCE.config.dungeonMap; + buttons.get(18-6).text = options.dmEnable ? "Enabled" : "Disabled"; + buttons.get(19-6).text = options.dmCenterPlayer ? "Player" : "Map"; + buttons.get(20-6).text = options.dmRotatePlayer ? "Player" : "Vertical"; + buttons.get(21-6).text = options.dmPlayerHeads <= 0 ? "Default" : options.dmPlayerHeads == 1 ? "Heads" : "Heads w/ Border"; + buttons.get(22-6).text = options.dmOrientCheck ? "Orient" : "Off"; + buttons.get(23-6).text = options.dmCenterCheck ? "Center" : "Off"; + buttons.get(24-6).text = options.dmPlayerInterp ? "Interp" : "No Interp"; + buttons.get(25-6).text = options.dmCompat <= 0 ? "Normal" : options.dmCompat >= 2 ? "No FB/SHD" : "No SHD"; - buttons.get(26-6).colour = new Color(SpecialColour.specialToChromaRGB(options.dmBackgroundColour.value)); - buttons.get(27-6).colour = new Color(SpecialColour.specialToChromaRGB(options.dmBorderColour.value)); + buttons.get(26-6).colour = new Color(SpecialColour.specialToChromaRGB(options.dmBackgroundColour)); + buttons.get(27-6).colour = new Color(SpecialColour.specialToChromaRGB(options.dmBorderColour)); - buttons.get(28-6).text = options.dmChromaBorder.value ? "Scroll" : "Normal"; + buttons.get(28-6).text = options.dmChromaBorder ? "Scroll" : "Normal"; blurField.setSize(48, 16); xField.setSize(48, 16); @@ -358,140 +352,28 @@ public class GuiDungeonMapEditor extends GuiScreen { } 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); + activeColourEditor.render(); } Utils.pushGuiScale(-1); } - public void drawSlider(Options.Option option, int centerX, int centerY) { - float sliderAmount = (float)Math.max(0, Math.min(1, (option.value-option.minValue)/(option.maxValue-option.minValue))); + public void drawSlider(Field option, int centerX, int centerY) { + float value; + float minValue; + float maxValue; + try { + value = ((Number)option.get(NotEnoughUpdates.INSTANCE.config.dungeonMap)).floatValue(); + + ConfigEditorSlider sliderAnnotation = option.getAnnotation(ConfigEditorSlider.class); + minValue = sliderAnnotation.minValue(); + maxValue = sliderAnnotation.maxValue(); + } catch(Exception e) { + e.printStackTrace(); + return; + } + + float sliderAmount = Math.max(0, Math.min(1, (value-minValue)/(maxValue-minValue))); int sliderAmountI = (int)(96*sliderAmount); GlStateManager.color(1f, 1f, 1f, 1f); @@ -513,12 +395,32 @@ public class GuiDungeonMapEditor extends GuiScreen { super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); if(clickedSlider != null) { + float minValue; + float maxValue; + try { + ConfigEditorSlider sliderAnnotation = clickedSlider.getAnnotation(ConfigEditorSlider.class); + minValue = sliderAnnotation.minValue(); + maxValue = sliderAnnotation.maxValue(); + } catch(Exception e) { + e.printStackTrace(); + return; + } + float sliderAmount = (mouseX - (guiLeft+76-48))/96f; - double val = clickedSlider.minValue+(clickedSlider.maxValue-clickedSlider.minValue)*sliderAmount; + double val = minValue+(maxValue-minValue)*sliderAmount; if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { val = Math.round(val); } - clickedSlider.value = Math.max(clickedSlider.minValue, Math.min(clickedSlider.maxValue, val)); + float value = (float)Math.max(minValue, Math.min(maxValue, val)); + try { + if(clickedSlider.getType() == int.class) { + clickedSlider.set(NotEnoughUpdates.INSTANCE.config.dungeonMap, Math.round(value)); + } else { + clickedSlider.set(NotEnoughUpdates.INSTANCE.config.dungeonMap, value); + } + } catch(Exception e) { + e.printStackTrace(); + } } } @@ -539,15 +441,19 @@ public class GuiDungeonMapEditor extends GuiScreen { clickedSlider = null; if(mouseX >= guiLeft+76-48 && mouseX <= guiLeft+76+48) { - if(mouseY > guiTop+45-8 && mouseY < guiTop+45+8) { - clickedSlider = NotEnoughUpdates.INSTANCE.manager.config.dmBorderSize; - return; - } else if(mouseY > guiTop+75-8 && mouseY < guiTop+75+8) { - clickedSlider = NotEnoughUpdates.INSTANCE.manager.config.dmRoomSize; - return; - } else if(mouseY > guiTop+105-8 && mouseY < guiTop+105+8) { - clickedSlider = NotEnoughUpdates.INSTANCE.manager.config.dmIconScale; - return; + try { + if(mouseY > guiTop+45-8 && mouseY < guiTop+45+8) { + clickedSlider = NEUConfig.DungeonMap.class.getDeclaredField("dmBorderSize"); + return; + } else if(mouseY > guiTop+75-8 && mouseY < guiTop+75+8) { + clickedSlider = NEUConfig.DungeonMap.class.getDeclaredField("dmRoomSize"); + return; + } else if(mouseY > guiTop+105-8 && mouseY < guiTop+105+8) { + clickedSlider = NEUConfig.DungeonMap.class.getDeclaredField("dmIconScale"); + return; + } + } catch(Exception e) { + e.printStackTrace(); } } @@ -583,83 +489,8 @@ public class GuiDungeonMapEditor extends GuiScreen { int mouseX = Mouse.getEventX() * this.width / this.mc.displayWidth; int mouseY = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; - 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()); - Utils.pushGuiScale(-1); - 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; - } - } - - try { NotEnoughUpdates.INSTANCE.manager.saveConfig(); } catch(IOException ignored) {} - return; - } - } - if(Mouse.getEventButtonState()) { - activeColourEditor = null; - hexField.otherComponentClick(); - } + if(activeColourEditor != null) { + activeColourEditor.mouseInput(mouseX, mouseY); } } @@ -667,23 +498,8 @@ public class GuiDungeonMapEditor extends GuiScreen { public void handleKeyboardInput() throws IOException { super.handleKeyboardInput(); - 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) {}; - } + if(activeColourEditor != null) { + activeColourEditor.keyboardInput(); } } @@ -696,8 +512,7 @@ public class GuiDungeonMapEditor extends GuiScreen { try { xField.setCustomBorderColour(-1); - NotEnoughUpdates.INSTANCE.manager.config.dmCenterX.setValue(xField.getText()); - try { NotEnoughUpdates.INSTANCE.manager.saveConfig(); } catch(IOException ignored) {} + NotEnoughUpdates.INSTANCE.config.dungeonMap.dmCenterX = Float.parseFloat(xField.getText()); } catch(Exception e) { xField.setCustomBorderColour(Color.RED.getRGB()); } @@ -706,8 +521,7 @@ public class GuiDungeonMapEditor extends GuiScreen { try { yField.setCustomBorderColour(-1); - NotEnoughUpdates.INSTANCE.manager.config.dmCenterY.setValue(yField.getText()); - try { NotEnoughUpdates.INSTANCE.manager.saveConfig(); } catch(IOException ignored) {} + NotEnoughUpdates.INSTANCE.config.dungeonMap.dmCenterY = Float.parseFloat(yField.getText()); } catch(Exception e) { yField.setCustomBorderColour(Color.RED.getRGB()); } @@ -716,8 +530,7 @@ public class GuiDungeonMapEditor extends GuiScreen { try { blurField.setCustomBorderColour(-1); - NotEnoughUpdates.INSTANCE.manager.config.dmBackgroundBlur.setValue(blurField.getText()); - try { NotEnoughUpdates.INSTANCE.manager.saveConfig(); } catch(IOException ignored) {} + NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBackgroundBlur = (int)Float.parseFloat(blurField.getText()); } catch(Exception e) { blurField.setCustomBorderColour(Color.RED.getRGB()); } @@ -725,71 +538,73 @@ public class GuiDungeonMapEditor extends GuiScreen { } private void buttonClicked(int mouseX, int mouseY, int id) { - Options options = NotEnoughUpdates.INSTANCE.manager.config; + NEUConfig.DungeonMap options = NotEnoughUpdates.INSTANCE.config.dungeonMap; switch (id) { case 0: - options.dmBorderSize.value = 0.0; break; + options.dmBorderSize = 0; break; case 1: - options.dmBorderSize.value = 1.0; break; + options.dmBorderSize = 1; break; case 2: - options.dmBorderSize.value = 2.0; break; + options.dmBorderSize = 2; break; case 30: - options.dmBorderSize.value = 3.0; break; + options.dmBorderSize = 3; break; case 3: - options.dmRoomSize.value = 0.0; break; + options.dmRoomSize = 0; break; case 4: - options.dmRoomSize.value = 1.0; break; + options.dmRoomSize = 1; break; case 5: - options.dmRoomSize.value = 2.0; break; + options.dmRoomSize = 2; break; case 29: - options.dmRoomSize.value = 3.0; break; + options.dmRoomSize = 3; break; case 18: - options.dmEnable.value = !options.dmEnable.value; break; + options.dmEnable = !options.dmEnable; break; case 19: - options.dmCenterPlayer.value = !options.dmCenterPlayer.value; break; + options.dmCenterPlayer = !options.dmCenterPlayer; break; case 20: - options.dmRotatePlayer.value = !options.dmRotatePlayer.value; break; + options.dmRotatePlayer = !options.dmRotatePlayer; break; case 21: - options.dmPlayerHeads.value++; - if(options.dmPlayerHeads.value > 2) options.dmPlayerHeads.value = 0.0; break; + options.dmPlayerHeads++; + if(options.dmPlayerHeads > 2) options.dmPlayerHeads = 0; break; case 22: - options.dmOrientCheck.value = !options.dmOrientCheck.value; break; + options.dmOrientCheck = !options.dmOrientCheck; break; case 23: - options.dmCenterCheck.value = !options.dmCenterCheck.value; break; + options.dmCenterCheck = !options.dmCenterCheck; break; case 24: - options.dmPlayerInterp.value = !options.dmPlayerInterp.value; break; + options.dmPlayerInterp = !options.dmPlayerInterp; break; case 25: - options.dmCompat.value++; - if(options.dmCompat.value > 2) options.dmCompat.value = 0.0; + options.dmCompat++; + if(options.dmCompat > 2) options.dmCompat = 0; break; case 26: - showColourEditor(mouseX, mouseY, options.dmBackgroundColour, options.dmBackgroundColour.value); break; + activeColourEditor = new GuiElementColour(mouseX, mouseY, options.dmBackgroundColour, + (col) -> options.dmBackgroundColour = col, () -> activeColourEditor = null); + break; case 27: - showColourEditor(mouseX, mouseY, options.dmBorderColour, options.dmBorderColour.value); break; + activeColourEditor = new GuiElementColour(mouseX, mouseY, options.dmBorderColour, + (col) -> options.dmBorderColour = col, () -> activeColourEditor = null); + break; case 28: - options.dmChromaBorder.value = !options.dmChromaBorder.value; break; + options.dmChromaBorder = !options.dmChromaBorder; break; default: if(id >= 6 && id <= 17) { - options.dmBorderStyle.value = (double)id-6; break; + options.dmBorderStyle = id-6; break; } - } - try { NotEnoughUpdates.INSTANCE.manager.saveConfig(); } catch(IOException ignored) {}; - + }; } private boolean isButtonPressed(int id) { - Options options = NotEnoughUpdates.INSTANCE.manager.config; + NEUConfig.DungeonMap options = NotEnoughUpdates.INSTANCE.config.dungeonMap; if(id >= 0 && id <= 2) { - return options.dmBorderSize.value == id; + return options.dmBorderSize == id; } else if(id >= 3 && id <= 5) { - return options.dmRoomSize.value == id-3; + return options.dmRoomSize == id-3; } else if(id >= 6 && id <= 17) { - return options.dmBorderStyle.value == id-6; + return options.dmBorderStyle == id-6; } else if(id == 29) { - return options.dmRoomSize.value == 3; + return options.dmRoomSize == 3; } else if(id == 30) { - return options.dmBorderSize.value == 3; + return options.dmBorderSize == 3; } return false; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/gamemodes/GuiGamemodes.java b/src/main/java/io/github/moulberry/notenoughupdates/gamemodes/GuiGamemodes.java index 0f479f53..ff010fc7 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/gamemodes/GuiGamemodes.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/gamemodes/GuiGamemodes.java @@ -10,7 +10,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import static io.github.moulberry.notenoughupdates.GuiTextures.*; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.*; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; 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 692c1d4f..0c645255 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/gamemodes/SBGamemodes.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/gamemodes/SBGamemodes.java @@ -3,7 +3,7 @@ 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.questing.SBInfo; +import io.github.moulberry.notenoughupdates.util.SBInfo; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiChest; 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 d0600796..fadb148d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/CollectionLogInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/CollectionLogInfoPane.java @@ -4,7 +4,7 @@ import com.google.gson.JsonArray; 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.NEUResourceManager; import io.github.moulberry.notenoughupdates.util.SpecialColour; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; @@ -14,7 +14,6 @@ import net.minecraft.client.shader.Framebuffer; import net.minecraft.client.shader.Shader; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.Matrix4f; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; @@ -25,7 +24,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; -import static io.github.moulberry.notenoughupdates.GuiTextures.item_mask; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.item_mask; public class CollectionLogInfoPane extends ScrollableInfoPane { @@ -114,7 +113,7 @@ public class CollectionLogInfoPane extends ScrollableInfoPane { } private Map> getAcquiredItems() { - return manager.config.collectionLog.value; + return null;//manager.config.collectionLog.value; } private Comparator getItemComparator() { @@ -267,13 +266,13 @@ public class CollectionLogInfoPane extends ScrollableInfoPane { itemFramebufferGrayscale = checkFramebufferSizes(itemFramebufferGrayscale, width, height, scaledresolution.getScaleFactor()); - if(!manager.config.cacheRenderedItempane.value || previousAcquiredCount != getCurrentAcquiredCount() || + /*if(!manager.config.cacheRenderedItempane.value || previousAcquiredCount != getCurrentAcquiredCount() || previousScroll != scrollHeight.getValue() || previousX != left || previousFilter != filterMode || System.currentTimeMillis() - lastUpdate > 5000) { lastUpdate = System.currentTimeMillis(); renderItemsToImage(itemFramebuffer, fg, left+5, right, top+1, bottom); renderItemBGToImage(itemBGFramebuffer, fg, left+5, right, top+1, bottom); - } + }*/ previousAcquiredCount = getCurrentAcquiredCount(); previousScroll = scrollHeight.getValue(); previousX = left; @@ -396,8 +395,8 @@ public class CollectionLogInfoPane extends ScrollableInfoPane { } private void renderItemBackgrounds(Color fg, int left, int right, int top, int bottom) { - Color fgCustomOpacity = new Color(SpecialColour.specialToChromaRGB(manager.config.itemBackgroundColour.value), true); - Color fgGold = new Color(SpecialColour.specialToChromaRGB(manager.config.itemFavouriteColour.value), true); + Color fgCustomOpacity = null;//new Color(SpecialColour.specialToChromaRGB(manager.config.itemBackgroundColour.value), true); + Color fgGold = null;//new Color(SpecialColour.specialToChromaRGB(manager.config.itemFavouriteColour.value), true); String[] items = getItemList(); iterateItemSlots(new ItemSlotConsumer() { @@ -413,13 +412,13 @@ public class CollectionLogInfoPane extends ScrollableInfoPane { } Minecraft.getMinecraft().getTextureManager().bindTexture(item_mask); - if(manager.config.itemStyle.value) { + /*if(manager.config.itemStyle.value) { GlStateManager.color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); Utils.drawTexturedRect(x - 1, y - 1, overlay.ITEM_SIZE + 2, overlay.ITEM_SIZE + 2, GL11.GL_NEAREST); } else { drawRect(x-1, y-1, x+overlay.ITEM_SIZE+1, y+overlay.ITEM_SIZE+1, color.getRGB()); - } + }*/ GlStateManager.bindTexture(0); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/FlipperInfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/FlipperInfoPane.java index b5d20a97..b6db53f3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/FlipperInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/FlipperInfoPane.java @@ -9,7 +9,7 @@ import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; -import static io.github.moulberry.notenoughupdates.GuiTextures.*; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.*; import static io.github.moulberry.notenoughupdates.itemeditor.GuiElementTextField.*; import java.awt.*; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/HTMLInfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/HTMLInfoPane.java index c03b98fb..9981e6f9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/HTMLInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/HTMLInfoPane.java @@ -8,7 +8,7 @@ import info.bliki.wiki.model.WikiModel; import info.bliki.wiki.tags.HTMLBlockTag; import info.bliki.wiki.tags.HTMLTag; import info.bliki.wiki.tags.IgnoreTag; -import io.github.moulberry.notenoughupdates.AllowEmptyHTMLTag; +import io.github.moulberry.notenoughupdates.util.AllowEmptyHTMLTag; import io.github.moulberry.notenoughupdates.NEUManager; import io.github.moulberry.notenoughupdates.NEUOverlay; import io.github.moulberry.notenoughupdates.util.Utils; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/ScrollableInfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/ScrollableInfoPane.java index 056aeaf1..12d42551 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/ScrollableInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/ScrollableInfoPane.java @@ -1,8 +1,8 @@ package io.github.moulberry.notenoughupdates.infopanes; -import io.github.moulberry.notenoughupdates.util.LerpingInteger; import io.github.moulberry.notenoughupdates.NEUManager; import io.github.moulberry.notenoughupdates.NEUOverlay; +import io.github.moulberry.notenoughupdates.core.util.lerp.LerpingInteger; import org.lwjgl.input.Mouse; public abstract class ScrollableInfoPane extends InfoPane { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/SettingsInfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/SettingsInfoPane.java deleted file mode 100644 index 4938770d..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/SettingsInfoPane.java +++ /dev/null @@ -1,851 +0,0 @@ -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.NotEnoughUpdates; -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; -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; -import static io.github.moulberry.notenoughupdates.GuiTextures.*; - -public class SettingsInfoPane extends InfoPane { - - private int currentCategory = Options.CAT_ALL; - private final String[] CATEGORY_NAMES = {"All", "Misc", "Features", "Sliders", "Colours"}; - - private GuiElementTextField searchBar = new GuiElementTextField("", 0); - - private final Map, GuiElementTextField> textConfigMap = new HashMap<>(); - private int page = 0; - private int maxPages = 1; - - private Options.Option clickedSlider = null; - 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 option; - public String special; - - public ColourEditor(int x, int y, Options.Option 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 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) { - Utils.pushGuiScale(2); - - int widthN = Utils.peekGuiScale().getScaledWidth(); - int heightN = Utils.peekGuiScale().getScaledHeight(); - int mouseXN = Mouse.getX() * widthN / Minecraft.getMinecraft().displayWidth; - int mouseYN = heightN - Mouse.getY() * heightN / Minecraft.getMinecraft().displayHeight - 1; - - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - - int paneWidth = (int)(widthN/3*overlay.getWidthMult()); - int rightSide = (int)(widthN*overlay.getInfoPaneOffsetFactor()); - int leftSide = rightSide - paneWidth; - - this.renderDefaultBackground(widthN, heightN, bg); - - if(page > maxPages-1) page = maxPages-1; - if(page < 0) page = 0; - - overlay.renderNavElement(leftSide+overlay.getBoxPadding(), rightSide-overlay.getBoxPadding(), - maxPages,page+1,"Settings: "); - - int area = rightSide-leftSide-overlay.getBoxPadding()*2; - int categoryArea = (area-3*4)/5; - int ySize = overlay.getSearchBarYSize(); - int yStartCat = overlay.getBoxPadding()+overlay.getSearchBarYSize()+3; - for(int i=0; i<5; i++) { - boolean pressed = currentCategory == i; - drawRect(leftSide+overlay.getBoxPadding()+i*(categoryArea+3), yStartCat, - leftSide+overlay.getBoxPadding()+i*(categoryArea+3)+categoryArea, yStartCat+ySize, fg.getRGB()); - GlStateManager.color(1, 1, 1, 1); - Minecraft.getMinecraft().getTextureManager().bindTexture(rightarrow_overlay); - Utils.drawTexturedRect(leftSide+overlay.getBoxPadding()+i*(categoryArea+3), - yStartCat, categoryArea, ySize, pressed?0:1, pressed?1:0, pressed?0:1, pressed?1:0, GL11.GL_NEAREST); - - Utils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.BOLD+CATEGORY_NAMES[i], - Minecraft.getMinecraft().fontRendererObj, - leftSide+overlay.getBoxPadding()+i*(categoryArea+3)+categoryArea/2f, - yStartCat+ySize/2f, false, categoryArea-6, 0); - } - - searchBar.setSize(area-5, ySize); - searchBar.setMaxStringLength(45); - searchBar.render(leftSide+overlay.getBoxPadding()+1, overlay.getBoxPadding()+overlay.getSearchBarYSize()*2+7); - - AtomicReference> textToDisplay = new AtomicReference<>(null); - AtomicReference tfTop = new AtomicReference<>(); - AtomicInteger tfTopX = new AtomicInteger(); - AtomicInteger tfTopY = new AtomicInteger(); - iterateSettingTile(new SettingsTileConsumer() { - public void consume(int x, int y, int tileWidth, int tileHeight, Options.Option option, Options.Button button) { - float mult = tileWidth/90f; - - drawRect(x+2, y+2, x+tileWidth-2, y+tileHeight-2, fg.getRGB()); - - Minecraft.getMinecraft().getTextureManager().bindTexture(setting_border); - GlStateManager.color(1, 1, 1, 1); - - Utils.drawTexturedRect(x, y, tileWidth, 5, 0, 1, 0, 5/75f, GL11.GL_NEAREST); - Utils.drawTexturedRect(x, y+tileHeight-5, tileWidth, 5, 0, 1, 70/75f, 1, GL11.GL_NEAREST); - Utils.drawTexturedRect(x, y+5, tileWidth, tileHeight-10, 0, 1, 5/75f, 70/75f, GL11.GL_NEAREST); - Utils.drawTexturedRect(x+5, y, tileWidth-10, tileHeight, 5/100f, 95/100f, 0, 1, GL11.GL_NEAREST); - - if(manager.config.hideApiKey.value && option==manager.config.apiKey) return; - - if(option == null) { - Utils.renderStringTrimWidth(button.displayName, fr, true, x+(int)(8*mult), y+(int)(8*mult), - tileWidth-(int)(16*mult), new Color(100,255,150).getRGB(), 3, - 2f/Utils.peekGuiScale().getScaleFactor()); - - GlStateManager.color(1f, 1f, 1f, 1f); - Minecraft.getMinecraft().getTextureManager().bindTexture(button_tex); - Utils.drawTexturedRect(x + tileWidth/2f - (int) (32 * mult), y + tileHeight - (int) (20 * mult), (int) (48 * mult), (int) (16 * mult)); - - 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 (mouseXN > x + tileWidth / 2 + (int) (19 * mult) && mouseXN < x + tileWidth / 2 + (int) (19 * mult) + (int) (14 * mult)) { - if (mouseYN > y + tileHeight - (int) (19 * mult) && mouseYN < y + tileHeight - (int) (19 * mult) + (int) (14 * mult)) { - List textLines = new ArrayList<>(); - textLines.add(button.displayName); - textLines.add(EnumChatFormatting.GRAY + button.desc); - textToDisplay.set(textLines); - } - } - return; - } - - 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/Utils.peekGuiScale().getScaleFactor()); - - if(option.value instanceof Boolean) { - GlStateManager.color(1f, 1f, 1f, 1f); - Minecraft.getMinecraft().getTextureManager().bindTexture(((Boolean) option.value) ? on : off); - Utils.drawTexturedRect(x + tileWidth/2f - (int) (32 * mult), y + tileHeight - (int) (20 * mult), (int) (48 * mult), (int) (16 * mult)); - - 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 (mouseXN > x + tileWidth / 2 + (int) (19 * mult) && mouseXN < x + tileWidth / 2 + (int) (19 * mult) + (int) (14 * mult)) { - if (mouseYN > y + tileHeight - (int) (19 * mult) && mouseYN < y + tileHeight - (int) (19 * mult) + (int) (14 * mult)) { - List textLines = new ArrayList<>(); - textLines.add(option.displayName); - textLines.add(EnumChatFormatting.GRAY + option.desc); - textToDisplay.set(textLines); - } - } - } else if(option.value instanceof Double) { - if(!textConfigMap.containsKey(option)) { - 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)); - } - if(tf.getFocus()) { - tf.setSize(Math.max((int)(20*mult), fr.getStringWidth(tf.getText())+10), (int)(16*mult)); - tfTop.set(tf); - tfTopX.set(x+(int)(65*mult)); - tfTopY.set(y+tileHeight-(int)(20*mult)); - } else { - tf.setSize((int)(20*mult), (int)(16*mult)); - tf.render(x+(int)(65*mult), y+tileHeight-(int)(20*mult)); - } - - double sliderAmount = (((Options.Option)option).value-option.minValue)/(option.maxValue-option.minValue); - sliderAmount = Math.max(0, Math.min(1, sliderAmount)); - - GlStateManager.color(1f, 1f, 1f, 1f); - Minecraft.getMinecraft().getTextureManager().bindTexture(slider_on); - Utils.drawTexturedRect(x+5*mult, y + tileHeight-20*mult, (float)(54*mult*sliderAmount), 16*mult, - 0, (float)sliderAmount, 0, 1); - - Minecraft.getMinecraft().getTextureManager().bindTexture(slider_off); - Utils.drawTexturedRect((float)(x+5*mult+54*mult*sliderAmount), y + tileHeight - 20*mult, - (float)(54*mult*(1-sliderAmount)), 16*mult, - (float)(sliderAmount), 1, 0, 1); - - Minecraft.getMinecraft().getTextureManager().bindTexture(slider_button); - Utils.drawTexturedRect(x+1*mult+(float)(54*sliderAmount*mult), y + tileHeight - 20*mult, - 8*mult, 16*mult); - } else { - 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/Utils.peekGuiScale().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 (mouseXN > x + tileWidth / 2 + (int) (19 * mult) && mouseXN < x + tileWidth / 2 + (int) (19 * mult) + (int) (14 * mult)) { - if (mouseYN > y + tileHeight - (int) (19 * mult) && mouseYN < y + tileHeight - (int) (19 * mult) + (int) (14 * mult)) { - List textLines = new ArrayList<>(); - textLines.add(option.displayName); - textLines.add(EnumChatFormatting.GRAY + option.desc); - textToDisplay.set(textLines); - } - } - } 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)); - } else { - tf.setSize(tileWidth-(int)(20*mult), (int)(16*mult)); - tf.render(x+(int)(10*mult), y+tileHeight-(int)(20*mult)); - } - } - } - } - }); - 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(), mouseXN, mouseYN, widthN, heightN, 200, fr); - } - - Utils.pushGuiScale(-1); - } - - private void onTextfieldChange(GuiElementTextField tf, Options.Option option) { - try { - tf.setCustomBorderColour(-1); - option.setValue(tf.getText()); - overlay.redrawItems(); - BetterContainers.reset(); - } catch(Exception e) { - tf.setCustomBorderColour(Color.RED.getRGB()); - } - } - - @Override - public void mouseInputOutside() { - for(GuiElementTextField tf : textConfigMap.values()) { - tf.otherComponentClick(); - } - activeColourEditor = null; - hexField.otherComponentClick(); - searchBar.otherComponentClick(); - } - - public void mouseInput(int width, int height, int mouseX, int mouseY, boolean mouseDown) { - Utils.pushGuiScale(2); - - int widthN = Utils.peekGuiScale().getScaledWidth(); - int heightN = Utils.peekGuiScale().getScaledHeight(); - int mouseXN = Mouse.getX() * widthN / Minecraft.getMinecraft().displayWidth; - int mouseYN = heightN - Mouse.getY() * heightN / Minecraft.getMinecraft().displayHeight - 1; - - int paneWidth = (int)(widthN/3*overlay.getWidthMult()); - int rightSide = (int)(widthN*overlay.getInfoPaneOffsetFactor()); - int leftSide = rightSide - paneWidth; - - int area = rightSide-leftSide-overlay.getBoxPadding()*2; - int categoryArea = (area-3*4)/5; - int ySize = overlay.getSearchBarYSize(); - int yStartCat = overlay.getBoxPadding()+overlay.getSearchBarYSize()+3; - for(int i=0; i<5; i++) { - if(mouseDown && mouseXN > leftSide + overlay.getBoxPadding() + i * (categoryArea + 3) && - mouseXN < leftSide + overlay.getBoxPadding() + i * (categoryArea + 3) + categoryArea && - mouseYN > yStartCat && mouseYN < yStartCat + ySize) { - currentCategory = i; - searchBar.otherComponentClick(); - Utils.pushGuiScale(-1); - return; - } - } - - if(mouseDown) { - if(mouseXN > leftSide+overlay.getBoxPadding() && mouseXN < leftSide+overlay.getBoxPadding()+area-3) { - if(mouseYN > overlay.getBoxPadding()+overlay.getSearchBarYSize()*2+7 && - mouseYN < overlay.getBoxPadding()+overlay.getSearchBarYSize()*2+7+ySize) { - searchBar.mouseClicked(mouseXN, mouseYN, Mouse.getEventButton()); - Utils.pushGuiScale(-1); - return; - } - } - searchBar.otherComponentClick(); - } - - if(activeColourEditor != null && (Mouse.isButtonDown(0) || Mouse.isButtonDown(1))) { - if(mouseXN >= activeColourEditor.x && mouseXN <= activeColourEditor.x+119) { - if(mouseYN >= activeColourEditor.y && mouseYN <= activeColourEditor.y+89) { - if(Mouse.getEventButtonState()) { - if(mouseXN > activeColourEditor.x+5+8 && mouseXN < activeColourEditor.x+5+8+48) { - if(mouseYN > activeColourEditor.y+5+64+5 && mouseYN < activeColourEditor.y+5+64+5+10) { - hexField.mouseClicked(mouseXN, mouseYN, Mouse.getEventButton()); - Utils.pushGuiScale(-1); - 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 = mouseXN - activeColourEditor.x - 5; - int yWheel = mouseYN - 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 = mouseXN - (activeColourEditor.x+5+64+5); - int y = mouseYN - 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 = mouseXN - (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 = mouseXN - (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(mouseYN > activeColourEditor.y+5+27 && mouseYN < activeColourEditor.y+5+37) { - activeColourEditor.special = SpecialColour.special(200, c.getAlpha(), currentColour); - activeColourEditor.option.value = activeColourEditor.special; - } - } - - Utils.pushGuiScale(-1); - 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) { - float mult = tileWidth/90f; - if(option == null) { - if(Mouse.getEventButtonState()) { - if(mouseXN > x+tileWidth/2-(int)(32*mult) && mouseXN < x+tileWidth/2-(int)(32*mult)+(int)(48*mult)) { - if(mouseYN > y+tileHeight-(int)(20*mult) && mouseYN < y+tileHeight-(int)(20*mult)+(int)(16*mult)) { - button.click.run(); - Utils.pushGuiScale(-1); - return; - } - } - } - } else if(option.value instanceof Boolean) { - if(Mouse.getEventButtonState()) { - if(mouseXN > x+tileWidth/2-(int)(32*mult) && mouseXN < x+tileWidth/2-(int)(32*mult)+(int)(48*mult)) { - if(mouseYN > y+tileHeight-(int)(20*mult) && mouseYN < y+tileHeight-(int)(20*mult)+(int)(16*mult)) { - ((Options.Option)option).value = !((Boolean)option.value); - overlay.redrawItems(); - Utils.pushGuiScale(-1); - return; - } - } - } - } else if(option.value instanceof Double) { - if(!textConfigMap.containsKey(option)) { - textConfigMap.put(option, new GuiElementTextField(String.valueOf(option.value), - GuiElementTextField.NUM_ONLY | GuiElementTextField.NO_SPACE | GuiElementTextField.SCALE_TEXT)); - } - - GuiElementTextField tf = textConfigMap.get(option); - int tfX = x+(int)(65*mult); - int tfY = y+tileHeight-(int)(20*mult); - int tfWidth = tf.getWidth(); - int tfHeight = tf.getHeight(); - if(mouseYN > tfY && mouseYN < tfY+tfHeight) { - if(mouseXN > tfX && mouseXN < tfX+tfWidth) { - if(Mouse.getEventButtonState()) { - tf.mouseClicked(mouseXN, mouseYN, Mouse.getEventButton()); - onTextfieldChange(tf, option); - Utils.pushGuiScale(-1); - return; - } else if(Mouse.getEventButton() == -1 && mouseDown) { - tf.mouseClickMove(mouseXN, mouseYN, 0, 0); //last 2 values are unused - Utils.pushGuiScale(-1); - return; - } - } else if(clickedSlider != option && Mouse.getEventButtonState() && mouseXN > x+1*mult && mouseXN < x+63*mult) { - clickedSlider = option; - clickedSliderX = x; - clickedSliderMult = mult; - } - } - - if(clickedSlider == option) { - float xMin = clickedSliderX+5*clickedSliderMult; - float xMax = clickedSliderX+59*clickedSliderMult; - - float sliderAmount = (mouseXN - xMin)/(xMax - xMin); - sliderAmount = Math.max(0, Math.min(1, sliderAmount)); - - double range = option.maxValue - option.minValue; - double value = option.minValue + sliderAmount*range; - - if(range >= 10 || (option.flags & Options.FLAG_INT) != 0) { - value = Math.round(value); - } else if(range >= 1) { - value = Math.round(value*10)/10.0; - } else { - value = Math.round(value*100)/100.0; - } - - value = Math.max(option.minValue, Math.min(option.maxValue, value)); - - tf.setText(String.valueOf(value)); - onTextfieldChange(tf, option); - - if(Mouse.getEventButton() == 0 && !Mouse.getEventButtonState()) { - clickedSlider = null; - } - } - - if(Mouse.getEventButtonState()) tf.otherComponentClick(); - } else { - if((option.flags & Options.FLAG_COLOUR) != 0) { - if(Mouse.getEventButtonState()) { - if(mouseXN > x+tileWidth/2-(int)(32*mult) && mouseXN < x+tileWidth/2-(int)(32*mult)+(int)(48*mult)) { - if(mouseYN > y+tileHeight-(int)(20*mult) && mouseYN < y+tileHeight-(int)(20*mult)+(int)(16*mult)) { - int editorX = (int)Math.min(mouseXN, widthN*overlay.getInfoPaneOffsetFactor()-129); - int editorY = Math.min(mouseYN, heightN-99); - showColourEditor(editorX, editorY, (Options.Option) option, (String)option.value); - Utils.pushGuiScale(-1); - 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(mouseXN > tfX && mouseXN < tfX+tfWidth) { - if(mouseYN > tfY && mouseYN < tfY+tfHeight) { - if(Mouse.getEventButtonState()) { - tf.mouseClicked(mouseXN, mouseYN, Mouse.getEventButton()); - onTextfieldChange(tf, option); - Utils.pushGuiScale(-1); - return; - } else if(Mouse.getEventButton() == -1 && mouseDown) { - tf.mouseClickMove(mouseXN, mouseYN, 0, 0); //last 2 values are unused - Utils.pushGuiScale(-1); - return; - } - } - } - if(Mouse.getEventButtonState()) tf.otherComponentClick(); - } - } - } - }); - - if(Mouse.getEventButtonState()) { - rightSide -= overlay.getBoxPadding(); - leftSide += overlay.getBoxPadding(); - - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - float maxStrLen = fr.getStringWidth(EnumChatFormatting.BOLD+"Settings: " + maxPages + "/" + maxPages); - float maxButtonXSize = (rightSide-leftSide+2 - maxStrLen*0.5f - 10)/2f; - int buttonXSize = (int)Math.min(maxButtonXSize, overlay.getSearchBarYSize()*480/160f); - int ySize2 = (int)(buttonXSize/480f*160); - int yOffset = (int)((overlay.getSearchBarYSize()-ySize2)/2f); - int top = overlay.getBoxPadding()+yOffset; - - if(mouseYN >= top && mouseYN <= top+ySize2) { - int leftPrev = leftSide-1; - if(mouseXN > leftPrev && mouseXN < leftPrev+buttonXSize) { //"Previous" button - page--; - } - int leftNext = rightSide+1-buttonXSize; - if(mouseXN > leftNext && mouseXN < leftNext+buttonXSize) { //"Next" button - page++; - } - } - } - - Utils.pushGuiScale(-1); - } - - public boolean keyboardInput() { - if(searchBar.getFocus()) { - searchBar.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey()); - return true; - } - - AtomicBoolean ret = new AtomicBoolean(false); - iterateSettingTile(new SettingsTileConsumer() { - @Override - public void consume(int x, int y, int tileWidth, int tileHeight, Options.Option option, Options.Button button) { - if(option == null) return; - - if(!textConfigMap.containsKey(option)) { - return; - } - GuiElementTextField tf = textConfigMap.get(option); - - if(!(option.value instanceof Boolean)) { - if(tf.getFocus()) { - tf.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey()); - onTextfieldChange(tf, option); - ret.set(true); - } - } - } - }); - 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(); - } - - private abstract static class SettingsTileConsumer { - public abstract void consume(int x, int y, int tileWidth, int tileHeight, Options.Option option, Options.Button button); - } - - public void iterateSettingTile(SettingsTileConsumer settingsTileConsumer) { - ScaledResolution scaledresolution = Utils.pushGuiScale(2); - int width = scaledresolution.getScaledWidth(); - int height = scaledresolution.getScaledHeight(); - - int numHorz = scaledresolution.getScaleFactor() >= 3 ? 2 : 3; - - int paneWidth = (int)(width/3*overlay.getWidthMult()); - int rightSide = (int)(width*overlay.getInfoPaneOffsetFactor()); - int leftSide = rightSide - paneWidth; - - int padding = overlay.getBoxPadding(); - - int boxLeft = leftSide+padding-5; - int boxRight = rightSide-padding+5; - - int boxBottom = height - padding + 5; - - int boxWidth = boxRight-boxLeft; - int tilePadding = 7; - int tileWidth = (boxWidth-tilePadding*4)/numHorz; - int tileHeight = tileWidth*3/4; - - int top = tilePadding+padding+overlay.getSearchBarYSize()*3+3*2; - int bottom = height - padding; - int leftover = (bottom-top)%(tileHeight+tilePadding); - - top += leftover/2; - - maxPages=1; - int currPage=0; - int x=0; - int y=top; - int tileCount = 0; - out: - for(int i=0; i option = manager.config.getOptions().get(i-manager.config.getButtons().size()); - if(searchBar.getText().trim().length() != 0) { - for(String s : searchBar.getText().split(" ")) { - s = s.replaceAll("[^A-Za-z]", "").toLowerCase(); - boolean contains = false; - for(String tag : option.tags) { - if(tag.contains(s)) { - contains = true; - break; - } - } - if(!contains) { - continue out; - } - } - } - if(currentCategory != Options.CAT_ALL && currentCategory != option.category) { - continue; - } - } - - if(tileCount != 0 && tileCount % numHorz == 0) { - x = 0; - y += tileHeight+tilePadding; - } - if(y + tileHeight > boxBottom) { - x=0; - y=top; - currPage++; - maxPages = currPage+1; - } - x+=tilePadding; - - if(currPage == page) { - if(i < manager.config.getButtons().size()) { - settingsTileConsumer.consume(boxLeft+x, y, tileWidth, tileHeight, - null, manager.config.getButtons().get(i)); - } else { - settingsTileConsumer.consume(boxLeft+x, y, tileWidth, tileHeight, - manager.config.getOptions().get(i-manager.config.getButtons().size()), null); - } - } - - tileCount++; - x+=tileWidth; - } - - Utils.pushGuiScale(-1); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/NEUItemEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/NEUItemEditor.java index 1d67b8c4..37ffc938 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/NEUItemEditor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/itemeditor/NEUItemEditor.java @@ -2,8 +2,8 @@ package io.github.moulberry.notenoughupdates.itemeditor; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import io.github.moulberry.notenoughupdates.util.LerpingInteger; import io.github.moulberry.notenoughupdates.NEUManager; +import io.github.moulberry.notenoughupdates.core.util.lerp.LerpingInteger; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.*; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java index 293fc241..8a972f78 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java @@ -1,6 +1,6 @@ package io.github.moulberry.notenoughupdates.mbgui; -import io.github.moulberry.notenoughupdates.GuiItemRecipe; +import io.github.moulberry.notenoughupdates.miscgui.GuiItemRecipe; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.auction.CustomAHGui; import io.github.moulberry.notenoughupdates.util.Utils; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BetterContainers.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BetterContainers.java new file mode 100644 index 00000000..2b682e4f --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BetterContainers.java @@ -0,0 +1,473 @@ +package io.github.moulberry.notenoughupdates.miscfeatures; + +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +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.gui.inventory.GuiChest; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.texture.DynamicTexture; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.inventory.Container; +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 org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL14; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +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; + private static long clickedSlotMillis = 0; + public static long lastRenderMillis = 0; + + public static HashMap itemCache = new HashMap<>(); + public static boolean lastUsingCached = false; + public static boolean usingCached = false; + + public static void clickSlot(int slot) { + clickedSlotMillis = System.currentTimeMillis(); + clickedSlot = slot; + } + + public static int getClickedSlot() { + if(System.currentTimeMillis() - clickedSlotMillis < 500) { + return clickedSlot; + } + return -1; + } + + public static void bindHook(TextureManager textureManager, ResourceLocation location) { + if(isChestOpen()) { + Container container = ((GuiChest)Minecraft.getMinecraft().currentScreen).inventorySlots; + if(container instanceof ContainerChest) { + usingCached = true; + IInventory lower = ((ContainerChest)container).getLowerChestInventory(); + int size = lower.getSizeInventory(); + for(int index=0; index 9 && index < size-9) { + buttons[index%9][index/9] = false; + } + + if(buttons[index%9][index/9] && lastClickedSlot == index) { + //buttons[index%9][index/9] = false; + //slots[index%9][index/9] = true; + } else { + slots[index%9][index/9] = !isBlankStack(stack) && !buttons[index%9][index/9]; + } + } + for (int index = 0; index < size; index++) { + ItemStack stack = getStackCached(lower, 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]; + boolean down = yi < buttons[xi].length-1 && buttons[xi][yi+1]; + boolean left = xi > 0 && buttons[xi-1][yi]; + + boolean upleft = yi > 0 && xi > 0 && buttons[xi-1][yi-1]; + boolean upright = yi > 0 && xi < buttons.length-1 && buttons[xi+1][yi-1]; + boolean downright = xi < buttons.length-1 && yi < buttons[xi+1].length-1 && buttons[xi+1][yi+1]; + boolean downleft = xi > 0 && yi < buttons[xi-1].length-1 && buttons[xi-1][yi+1]; + + int ctmIndex = getCTMIndex(up, right, down, left, upleft, upright, downright, downleft); + 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]; + boolean down = yi < slots[xi].length-1 && slots[xi][yi+1]; + boolean left = xi > 0 && slots[xi-1][yi]; + + boolean upleft = yi > 0 && xi > 0 && slots[xi-1][yi-1]; + boolean upright = yi > 0 && xi < slots.length-1 && slots[xi+1][yi-1]; + boolean downright = xi < slots.length-1 && yi < slots[xi+1].length-1 && slots[xi+1][yi+1]; + boolean downleft = xi > 0 && yi < slots[xi-1].length-1 && slots[xi-1][yi+1]; + + int ctmIndex = getCTMIndex(up, right, down, left, upleft, upright, downright, downleft); + int[] rgbs = bufferedImageSlot.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); + } + } + } + texture = new DynamicTexture(bufferedImageNew); + } catch(Exception e) { + e.printStackTrace(); + } + } + } + + public static void reset() { + texture = null; + loaded = false; + clickedSlot = -1; + clickedSlotMillis = 0; + textColour = 4210752; + } + + private static boolean isChestOpen() { + return Minecraft.getMinecraft().currentScreen instanceof GuiChest && + NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() && + NotEnoughUpdates.INSTANCE.config.improvedSBMenu.enableSbMenus; + } + + private static boolean hasItem() { + if(!isChestOpen()) return false; + Container container = ((GuiChest)Minecraft.getMinecraft().currentScreen).inventorySlots; + if(container instanceof ContainerChest) { + IInventory lower = ((ContainerChest)container).getLowerChestInventory(); + int size = lower.getSizeInventory(); + for(int index=0; index NotEnoughUpdates.INSTANCE.config.smoothAOTE.smoothTpMillis*2) { + aoteTeleportationMillis = NotEnoughUpdates.INSTANCE.config.smoothAOTE.smoothTpMillis*2; + } + if(aoteTeleportationMillis < 0) aoteTeleportationMillis = 0; + + if(currentTime - aoteUseMillis > 1000 && aoteTeleportationMillis <= 0) { + aoteTeleportationCurr = null; + } + + if(aoteTeleportationCurr != null) { + if(aoteTeleportationMillis > 0) { + int deltaMin = Math.min(delta, aoteTeleportationMillis); + + float factor = deltaMin/(float)aoteTeleportationMillis; + + float dX = aoteTeleportationCurr.x - (float)Minecraft.getMinecraft().thePlayer.posX; + float dY = aoteTeleportationCurr.y - (float)Minecraft.getMinecraft().thePlayer.posY; + float dZ = aoteTeleportationCurr.z - (float)Minecraft.getMinecraft().thePlayer.posZ; + + aoteTeleportationCurr.x -= dX*factor; + aoteTeleportationCurr.y -= dY*factor; + aoteTeleportationCurr.z -= dZ*factor; + + if(Minecraft.getMinecraft().theWorld.getBlockState(new BlockPos(aoteTeleportationCurr.x, + aoteTeleportationCurr.y, aoteTeleportationCurr.z)).getBlock().getMaterial() != Material.air) { + aoteTeleportationCurr.y = (float)Math.ceil(aoteTeleportationCurr.y); + } + + aoteTeleportationMillis -= deltaMin; + } else { + aoteTeleportationCurr.x = (float) Minecraft.getMinecraft().thePlayer.posX; + aoteTeleportationCurr.y = (float) Minecraft.getMinecraft().thePlayer.posY; + aoteTeleportationCurr.z = (float) Minecraft.getMinecraft().thePlayer.posZ; + } + } else { + aoteUseMillis = 0; + aoteTeleportationMillis = 0; + } + } + + @SubscribeEvent + public void onPlayerInteract(PlayerInteractEvent event) { + if(event.action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR || event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) { + ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem(); + String internal = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(held); + if(internal != null) { + if(internal.equals("HYPERION")) { + lastUsedHyperion = System.currentTimeMillis(); + } + + if(NotEnoughUpdates.INSTANCE.config.smoothAOTE.smoothTpMillis <= 0 + || Minecraft.getMinecraft().gameSettings.thirdPersonView != 0) return; + + boolean aote = NotEnoughUpdates.INSTANCE.config.smoothAOTE.enableSmoothAOTE && internal.equals("ASPECT_OF_THE_END"); + boolean hyp = NotEnoughUpdates.INSTANCE.config.smoothAOTE.enableSmoothHyperion && internal.equals("HYPERION"); + if(aote || hyp) { + aoteUseMillis = System.currentTimeMillis(); + if(aoteTeleportationCurr == null) { + aoteTeleportationCurr = new Vector3f(); + aoteTeleportationCurr.x = (float) Minecraft.getMinecraft().thePlayer.posX; + aoteTeleportationCurr.y = (float) Minecraft.getMinecraft().thePlayer.posY; + aoteTeleportationCurr.z = (float) Minecraft.getMinecraft().thePlayer.posZ; + } + } + } + } + } + + @SubscribeEvent + public void onOverlayDrawn(RenderGameOverlayEvent event) { + if(NotEnoughUpdates.INSTANCE.config.builderWand.enableWandOverlay && + Minecraft.getMinecraft().objectMouseOver != null && + Minecraft.getMinecraft().objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && + ((event.type == null && Loader.isModLoaded("labymod")) || + event.type == RenderGameOverlayEvent.ElementType.CROSSHAIRS)) { + + IBlockState hover = Minecraft.getMinecraft().theWorld.getBlockState( + Minecraft.getMinecraft().objectMouseOver.getBlockPos().offset( + Minecraft.getMinecraft().objectMouseOver.sideHit, 1)); + if(hover.getBlock() == Blocks.air) { + ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem(); + String heldInternal = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(held); + + if(heldInternal != null && heldInternal.equals("BUILDERS_WAND")) { + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + + HashSet candidatesOld = new HashSet<>(); + TreeMap> candidatesOldSorted = new TreeMap<>(); + + IBlockState match = Minecraft.getMinecraft().theWorld.getBlockState(Minecraft.getMinecraft().objectMouseOver.getBlockPos()); + Item matchItem = Item.getItemFromBlock(match.getBlock()); + if(matchItem != null) { + ItemStack matchStack = new ItemStack(matchItem, 1, + match.getBlock().getDamageValue(Minecraft.getMinecraft().theWorld, Minecraft.getMinecraft().objectMouseOver.getBlockPos())); + + getBuildersWandCandidates(Minecraft.getMinecraft().thePlayer, Minecraft.getMinecraft().objectMouseOver, event.partialTicks, + candidatesOld, candidatesOldSorted, 999-MAX_BUILDERS_BLOCKS); + + boolean usingDirtWand = false; + int itemCount; + if(match.getBlock() == Blocks.dirt && matchStack.getItemDamage() == 0 && hasDirtWand()) { + itemCount = candidatesOld.size(); + usingDirtWand = true; + } else { + itemCount = countItemsInInventoryAndStorage(matchStack); + } + + if(candidatesOld.size() > MAX_BUILDERS_BLOCKS) { + Utils.drawStringCentered(EnumChatFormatting.RED.toString()+candidatesOld.size()+"/"+MAX_BUILDERS_BLOCKS, + Minecraft.getMinecraft().fontRendererObj, + scaledResolution.getScaledWidth()/2f, scaledResolution.getScaledHeight()/2f+10, true, 0); + } else { + String pre = EnumChatFormatting.GREEN.toString(); + if(itemCount < candidatesOld.size()) { + pre = EnumChatFormatting.RED.toString(); + } + Utils.drawStringCentered(pre+Math.min(candidatesOld.size(), itemCount)+"/"+ + Math.min(candidatesOld.size(), MAX_BUILDERS_BLOCKS), + Minecraft.getMinecraft().fontRendererObj, + scaledResolution.getScaledWidth()/2f, scaledResolution.getScaledHeight()/2f+10, true, 0); + } + + String itemCountS = EnumChatFormatting.DARK_GRAY+"x"+EnumChatFormatting.RESET+itemCount; + int itemCountLen = Minecraft.getMinecraft().fontRendererObj.getStringWidth(itemCountS); + + if(NotEnoughUpdates.INSTANCE.config.builderWand.wandBlockCount) { + if(usingDirtWand) { + Utils.drawItemStack(new ItemStack(Items.gold_nugget), scaledResolution.getScaledWidth()/2 - (itemCountLen+16)/2, + scaledResolution.getScaledHeight()/2+10+4); + Minecraft.getMinecraft().fontRendererObj.drawString(itemCountS, + scaledResolution.getScaledWidth()/2f - (itemCountLen+16)/2f+11, scaledResolution.getScaledHeight()/2f+10+8, + -1, + true); + } else { + Utils.drawItemStack(matchStack, scaledResolution.getScaledWidth()/2 - (itemCountLen+16)/2, + scaledResolution.getScaledHeight()/2+10+4); + Minecraft.getMinecraft().fontRendererObj.drawString(itemCountS, + scaledResolution.getScaledWidth()/2f - (itemCountLen+16)/2f+16, scaledResolution.getScaledHeight()/2f+10+8, + -1, + true); + } + + } + + GlStateManager.color(1, 1, 1, 1); + } + + } + } + } + } + + public int countItemsInInventoryAndStorage(ItemStack match) { + int count = 0; + + for(ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { + if(match.isItemEqual(stack)) { + count += stack.stackSize; + } + } + + ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem(); + String heldInternal = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(held); + + if(heldInternal != null && heldInternal.equals("BUILDERS_WAND")) { + if(held.hasTagCompound() && held.getTagCompound().hasKey("ExtraAttributes", 10) && + held.getTagCompound().getCompoundTag("ExtraAttributes").hasKey("builder's_wand_data", 7)) { + byte[] bytes = held.getTagCompound().getCompoundTag("ExtraAttributes").getByteArray("builder's_wand_data"); + try { + NBTTagCompound contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(bytes)); + NBTTagList items = contents_nbt.getTagList("i", 10); + for(int j=0; j 0) { + if(buildersItem.getInteger("id") == Item.getIdFromItem(match.getItem()) && + buildersItem.getInteger("Damage") == match.getItemDamage()) { + count += items.getCompoundTagAt(j).getByte("Count"); + } + } + } + } catch(Exception e) { + return count; + } + } + } + + return count; + } + + public boolean hasDirtWand() { + for(ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { + String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); + if(internalname != null && internalname.equals("INFINIDIRT_WAND")) { + return true; + } + } + + ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem(); + String heldInternal = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(held); + + if(heldInternal != null && heldInternal.equals("BUILDERS_WAND")) { + if(held.hasTagCompound() && held.getTagCompound().hasKey("ExtraAttributes", 10) && + held.getTagCompound().getCompoundTag("ExtraAttributes").hasKey("builder's_wand_data", 7)) { + byte[] bytes = held.getTagCompound().getCompoundTag("ExtraAttributes").getByteArray("builder's_wand_data"); + try { + NBTTagCompound contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(bytes)); + NBTTagList items = contents_nbt.getTagList("i", 10); + for(int j=0; j 0) { + String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalnameFromNBT(buildersItem.getCompoundTag("tag")); + if(internalname != null && internalname.equals("INFINIDIRT_WAND")) { + return true; + } + } + } + } catch(Exception e) { + } + } + } + + return false; + } + + @SubscribeEvent + public void renderBlockOverlay(DrawBlockHighlightEvent event) { + if(aoteTeleportationCurr != null && aoteTeleportationMillis > 0) { + event.setCanceled(true); + } + ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem(); + String heldInternal = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(held); + if(heldInternal != null) { + EntityPlayer player = event.player; + double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double)event.partialTicks; + double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double)event.partialTicks; + double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double)event.partialTicks; + + if(NotEnoughUpdates.INSTANCE.config.treecapOverlay.enableTreecapOverlay && + (heldInternal.equals("JUNGLE_AXE") || heldInternal.equals("TREECAPITATOR_AXE"))) { + int maxWood = 10; + if(heldInternal.equals("TREECAPITATOR_AXE")) maxWood = 35; + + if (event.target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GlStateManager.color(0.0F, 0.0F, 0.0F, 0.4F); + GlStateManager.disableTexture2D(); + GlStateManager.depthMask(false); + + if(Minecraft.getMinecraft().theWorld.getBlockState(event.target.getBlockPos()).getBlock() == Blocks.log || + Minecraft.getMinecraft().theWorld.getBlockState(event.target.getBlockPos()).getBlock() == Blocks.log2) { + + int woods = 0; + + HashSet candidatesOld = new HashSet<>(); + LinkedList candidates = new LinkedList<>(); + LinkedList candidatesNew = new LinkedList<>(); + + candidatesNew.add(event.target.getBlockPos()); + + while(woods < maxWood) { + if(candidatesNew.isEmpty()) { + break; + } + + candidates.addAll(candidatesNew); + candidatesNew.clear(); + + woods += candidates.size(); + boolean random = woods > maxWood; + + while(!candidates.isEmpty()) { + BlockPos candidate = candidates.pop(); + Block block = Minecraft.getMinecraft().theWorld.getBlockState(candidate).getBlock(); + + candidatesOld.add(candidate); + + for(int x = -1; x <= 1; x++) { + for(int y = -1; y <= 1; y++) { + for(int z = -1; z <= 1; z++) { + if(x != 0 || y != 0 || z != 0) { + BlockPos posNew = candidate.add(x, y, z); + if(!candidatesOld.contains(posNew) && !candidates.contains(posNew) && !candidatesNew.contains(posNew)) { + Block blockNew = Minecraft.getMinecraft().theWorld.getBlockState(posNew).getBlock(); + if(blockNew == Blocks.log || blockNew == Blocks.log2) { + candidatesNew.add(posNew); + } + } + } + } + } + } + + block.setBlockBoundsBasedOnState(Minecraft.getMinecraft().theWorld, candidate); + + drawFilledBoundingBox(block.getSelectedBoundingBox(Minecraft.getMinecraft().theWorld, candidate) + .expand(0.001D, 0.001D, 0.001D).offset(-d0, -d1, -d2), + random ? 0.5f : 1f, NotEnoughUpdates.INSTANCE.config.treecapOverlay.treecapOverlayColour); + } + } + } + + GlStateManager.depthMask(true); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + } + } else if(NotEnoughUpdates.INSTANCE.config.builderWand.enableWandOverlay) { + if(heldInternal.equals("BUILDERS_WAND")) { + int maxBlocks = 164; + if (event.target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { + IBlockState hover = Minecraft.getMinecraft().theWorld.getBlockState(event.target.getBlockPos().offset(event.target.sideHit, 1)); + if(hover.getBlock() == Blocks.air) { + IBlockState match = Minecraft.getMinecraft().theWorld.getBlockState(event.target.getBlockPos()); + Item matchItem = Item.getItemFromBlock(match.getBlock()); + if(matchItem != null) { + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GlStateManager.disableTexture2D(); + GlStateManager.depthMask(false); + + HashSet candidatesOld = new HashSet<>(); + TreeMap> candidatesOldSorted = new TreeMap<>(); + + getBuildersWandCandidates(player, event.target, event.partialTicks, candidatesOld, candidatesOldSorted, 10); + + ItemStack matchStack = new ItemStack(matchItem, 1, + match.getBlock().getDamageValue(Minecraft.getMinecraft().theWorld, event.target.getBlockPos())); + int itemCount; + if(match.getBlock() == Blocks.dirt && matchStack.getItemDamage() == 0 && hasDirtWand()) { + itemCount = candidatesOld.size(); + } else { + itemCount = countItemsInInventoryAndStorage(matchStack); + } + + String special = (candidatesOld.size() <= itemCount) ? NotEnoughUpdates.INSTANCE.config.builderWand.wandOverlayColour : + "0:255:255:0:0"; + + if(candidatesOld.size() <= maxBlocks) { + for(Set candidatesSorted : candidatesOldSorted.values()) { + for(BlockPos candidate : candidatesSorted) { + match.getBlock().setBlockBoundsBasedOnState(Minecraft.getMinecraft().theWorld, candidate); + AxisAlignedBB bb = match.getBlock().getSelectedBoundingBox(Minecraft.getMinecraft().theWorld, candidate) + .offset(event.target.sideHit.getFrontOffsetX(), event.target.sideHit.getFrontOffsetY(), + event.target.sideHit.getFrontOffsetZ()); + + drawBlock((int)bb.minX, (int)bb.minY, (int)bb.minZ+1, match, event.partialTicks, 0.75f); + } + } + + for(BlockPos candidate : candidatesOld) { + match.getBlock().setBlockBoundsBasedOnState(Minecraft.getMinecraft().theWorld, candidate); + AxisAlignedBB bb = match.getBlock().getSelectedBoundingBox(Minecraft.getMinecraft().theWorld, candidate) + .expand(0.001D, 0.001D, 0.001D).offset(-d0, -d1, -d2) + .offset(event.target.sideHit.getFrontOffsetX(), event.target.sideHit.getFrontOffsetY(), + event.target.sideHit.getFrontOffsetZ()); + + drawOutlineBoundingBox(bb, 1f, special); + } + } + + GlStateManager.depthMask(true); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + } + } + } + } else if(heldInternal.equals("INFINIDIRT_WAND") && event.target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { + BlockPos hover = event.target.getBlockPos().offset(event.target.sideHit, 1); + IBlockState hoverState = Minecraft.getMinecraft().theWorld.getBlockState(event.target.getBlockPos().offset(event.target.sideHit, 1)); + if(hoverState.getBlock() == Blocks.air) { + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GlStateManager.disableTexture2D(); + GlStateManager.depthMask(false); + + String special = NotEnoughUpdates.INSTANCE.config.builderWand.wandOverlayColour; + + AxisAlignedBB bb = Blocks.dirt.getSelectedBoundingBox(Minecraft.getMinecraft().theWorld, hover); + drawBlock((int)bb.minX, (int)bb.minY, (int)bb.minZ+1, Blocks.dirt.getDefaultState(), + event.partialTicks, 0.75f); + + AxisAlignedBB bbExpanded = Blocks.dirt.getSelectedBoundingBox(Minecraft.getMinecraft().theWorld, hover) + .expand(0.001D, 0.001D, 0.001D).offset(-d0, -d1, -d2); + drawOutlineBoundingBox(bbExpanded, 1f, special); + + GlStateManager.depthMask(true); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + } + } else if((heldInternal.equals("WATER_BUCKET") || heldInternal.equals("MAGICAL_WATER_BUCKET")) && + event.target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { + BlockPos hover = event.target.getBlockPos().offset(event.target.sideHit, 1); + + HashSet verticalSources = new HashSet<>(); + TreeMap> watersSorted = new TreeMap<>(); + + for(int xOff=-1; xOff<=1; xOff++) { + for(int yOff=0; yOff<=1; yOff++) { + for(int zOff=-1; zOff<=1; zOff++) { + if((xOff == 0 && yOff == 0) || + (xOff == 0 && zOff == 0) || + (zOff == 0 && yOff == 0)) { + + BlockPos checkPos = hover.add(-xOff, -yOff, -zOff); + IBlockState check = Minecraft.getMinecraft().theWorld.getBlockState(checkPos); + if(check.getBlock() == Blocks.prismarine && check.getBlock().getMetaFromState(check) == 2) { + for(int i=0; i<300; i++) { + BlockPos renderPos = hover.add(xOff*i, yOff*i, zOff*i); + + if(Math.abs(renderPos.getX()) > 128) { + break; + } + if(Math.abs(renderPos.getY()) > 255) { + break; + } + if(Math.abs(renderPos.getZ()) > 128) { + break; + } + + IBlockState renderState = Minecraft.getMinecraft().theWorld.getBlockState(renderPos); + + if(renderState.getBlock() != Blocks.air && renderState.getBlock() != Blocks.water && + renderState.getBlock() != Blocks.flowing_water) { + break; + } + + if(yOff != 0) { + verticalSources.add(renderPos); + } else { + IBlockState belowState = Minecraft.getMinecraft().theWorld.getBlockState(renderPos.add(0, -1, 0)); + if(belowState.getBlock() == Blocks.air) { + break; + } + } + + for(EnumFacing facing : EnumFacing.values()) { + float xDist = (float)(renderPos.getX()+0.5f+0.5f*facing.getFrontOffsetX()-d0); + float yDist = (float)(renderPos.getY()+0.5f+0.5f*facing.getFrontOffsetY()-d1-player.getEyeHeight()); + float zDist = (float)(renderPos.getZ()+0.5f+0.5f*facing.getFrontOffsetZ()-d2); + + float distSq = xDist*xDist + yDist*yDist + zDist*zDist; + + watersSorted.computeIfAbsent(distSq, k->new HashMap<>()).put(renderPos, facing); + } + + } + } + } + } + } + } + + GlStateManager.enableDepth(); + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GlStateManager.disableTexture2D(); + GlStateManager.depthMask(true); + + for(HashMap blockPoses : watersSorted.values()) { + for(Map.Entry entry : blockPoses.entrySet()) { + boolean vertical = verticalSources.contains(entry.getKey()); + AxisAlignedBB bbExpanded = Blocks.water.getSelectedBoundingBox(Minecraft.getMinecraft().theWorld, entry.getKey()) + .expand(-0.001D, -0.001D-(vertical?0:0.0625D), -0.001D) + .offset(-d0, -d1-(vertical?0:0.0625), -d2); + drawFilledBoundingBoxSide(bbExpanded, entry.getValue(), 1f, "0:100:20:50:160"); + } + } + + GlStateManager.depthMask(true); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + } else if((heldInternal.equals("HOE_OF_GREAT_TILLING") || heldInternal.equals("HOE_OF_GREATER_TILLING")) && + event.target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { + BlockPos target = event.target.getBlockPos(); + IBlockState targetState = Minecraft.getMinecraft().theWorld.getBlockState(target); + + int radius = heldInternal.equals("HOE_OF_GREAT_TILLING") ? 1 : 2; + + if(targetState.getBlock() == Blocks.dirt || targetState.getBlock() == Blocks.grass) { + GlStateManager.enableDepth(); + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GlStateManager.disableTexture2D(); + GlStateManager.depthMask(true); + + for(int xOff=-radius; xOff<=radius; xOff++) { + for(int zOff=-radius; zOff<=radius; zOff++) { + BlockPos renderPos = target.add(xOff, 0, zOff); + IBlockState renderState = Minecraft.getMinecraft().theWorld.getBlockState(renderPos); + if(renderState.getBlock() == Blocks.dirt || renderState.getBlock() == Blocks.grass) { + AxisAlignedBB bbExpanded = Blocks.dirt.getSelectedBoundingBox(Minecraft.getMinecraft().theWorld, renderPos) + .expand(0.001D, 0.001D, 0.001D) + .offset(-d0, -d1, -d2); + drawFilledBoundingBox(bbExpanded, 1f, "0:100:178:34:34"); + } + } + } + + GlStateManager.depthMask(true); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + } + } + } + } + } + + public void getBuildersWandCandidates(EntityPlayer player, MovingObjectPosition target, float partialTicks, + HashSet candidatesOld, TreeMap> candidatesOldSorted, int extraMax) { + IBlockState match = Minecraft.getMinecraft().theWorld.getBlockState(target.getBlockPos()); + + candidatesOld.clear(); + candidatesOldSorted.clear(); + LinkedList candidates = new LinkedList<>(); + LinkedList candidatesNew = new LinkedList<>(); + + candidatesNew.add(target.getBlockPos()); + + double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double)partialTicks; + double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double)partialTicks; + double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double)partialTicks; + + while(candidatesOld.size() <= MAX_BUILDERS_BLOCKS+extraMax) { + if(candidatesNew.isEmpty()) { + break; + } + + candidates.addAll(candidatesNew); + candidatesNew.clear(); + + while(!candidates.isEmpty()) { + if(candidatesOld.size() > MAX_BUILDERS_BLOCKS+extraMax) break; + + BlockPos candidate = candidates.pop(); + + float distSq = (float)((candidate.getX()+0.5f-d0)*(candidate.getX()+0.5f-d0) + + (candidate.getY()+0.5f-d1-player.getEyeHeight())*(candidate.getY()+0.5f-d1-player.getEyeHeight()) + + (candidate.getZ()+0.5f-d2)*(candidate.getZ()+0.5f-d2)); + candidatesOldSorted.computeIfAbsent(distSq, k->new HashSet<>()).add(candidate); + + candidatesOld.add(candidate); + + for(int x = -1; x <= 1; x++) { + for(int y = -1; y <= 1; y++) { + for(int z = -1; z <= 1; z++) { + if(x*x+y*y+z*z == 1) { + if(((x == 0) && (target.sideHit.getAxis() == EnumFacing.Axis.X)) || + ((y == 0) && (target.sideHit.getAxis() == EnumFacing.Axis.Y)) || + ((z == 0) && (target.sideHit.getAxis() == EnumFacing.Axis.Z))) { + if(Minecraft.getMinecraft().theWorld.getBlockState(candidate.add( + x+target.sideHit.getFrontOffsetX(), + y+target.sideHit.getFrontOffsetY(), + z+target.sideHit.getFrontOffsetZ())).getBlock() == Blocks.air) { + BlockPos posNew = candidate.add(x, y, z); + if(!candidatesOld.contains(posNew) && !candidates.contains(posNew) && !candidatesNew.contains(posNew)) { + IBlockState blockNew = Minecraft.getMinecraft().theWorld.getBlockState(posNew); + if(blockNew == match) { + candidatesNew.add(posNew); + } + } + } + } + } + } + } + } + } + } + } + + public static void drawBlock(int x, int y, int z, IBlockState state, float partialTicks, float brightness) { + EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; + double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double)partialTicks; + double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double)partialTicks; + double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double)partialTicks; + + BlockRendererDispatcher blockrendererdispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher(); + + GlStateManager.enableTexture2D(); + GlStateManager.disableLighting(); + GlStateManager.enableBlend(); + GlStateManager.blendFunc(770, 771); + + GlStateManager.enableDepth(); + GlStateManager.depthMask(true); + GlStateManager.enableCull(); + GlStateManager.cullFace(GL11.GL_BACK); + + GlStateManager.pushMatrix(); + GlStateManager.translate(x-d0, y-d1, z-d2); + + int i = state.getBlock().getRenderType(); + if(i == 3) { + IBakedModel ibakedmodel = blockrendererdispatcher.getModelFromBlockState(state, Minecraft.getMinecraft().theWorld, null); + + Block block = state.getBlock(); + block.setBlockBoundsForItemRender(); + GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F); + int colour = block.getRenderColor(block.getStateForEntityRender(state)); + + if (EntityRenderer.anaglyphEnable) { + colour = TextureUtil.anaglyphColor(i); + } + + colour = (colour & 0x00FFFFFF) | (100 << 24); //Set alpha to 100 + + for (EnumFacing enumfacing : EnumFacing.values()) { + renderModelBrightnessColorQuads(colour, ibakedmodel.getFaceQuads(enumfacing)); + } + + renderModelBrightnessColorQuads(colour, ibakedmodel.getGeneralQuads()); + } + + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.translate(-x+d0, -y+d1, -z+d2); + GlStateManager.popMatrix(); + } + + private static void renderModelBrightnessColorQuads(int c, List listQuads) { + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + + for (BakedQuad bakedquad : listQuads) { + worldrenderer.begin(7, DefaultVertexFormats.ITEM); + worldrenderer.addVertexData(bakedquad.getVertexData()); + + worldrenderer.putColor4(c); + + Vec3i vec3i = bakedquad.getFace().getDirectionVec(); + worldrenderer.putNormal((float)vec3i.getX(), (float)vec3i.getY(), (float)vec3i.getZ()); + tessellator.draw(); + } + } + + public static void drawFilledBoundingBox(AxisAlignedBB p_181561_0_, float alpha, String special) { + Color c = new Color(SpecialColour.specialToChromaRGB(special), true); + GlStateManager.color(c.getRed()/255f, c.getGreen()/255f, c.getBlue()/255f, c.getAlpha()/255f*alpha); + + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GlStateManager.disableTexture2D(); + + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + + //vertical + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); + tessellator.draw(); + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); + tessellator.draw(); + //x + + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); + tessellator.draw(); + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); + tessellator.draw(); + + //z + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); + tessellator.draw(); + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); + tessellator.draw(); + + } + + public static void drawFilledBoundingBoxSide(AxisAlignedBB p_181561_0_, EnumFacing facing, float alpha, String special) { + Color c = new Color(SpecialColour.specialToChromaRGB(special), true); + GlStateManager.color(c.getRed()/255f, c.getGreen()/255f, c.getBlue()/255f, c.getAlpha()/255f*alpha); + + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GlStateManager.disableTexture2D(); + + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); + switch(facing) { + case UP: + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); + break; + case DOWN: + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); + break; + case EAST: + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); + break; + case WEST: + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); + break; + case SOUTH: + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); + break; + case NORTH: + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); + break; + } + tessellator.draw(); + } + + public static void drawOutlineBoundingBox(AxisAlignedBB p_181561_0_, float alpha, String special) { + Color c = new Color(SpecialColour.specialToChromaRGB(special), true); + GlStateManager.color(c.getRed()/255f, c.getGreen()/255f, c.getBlue()/255f, c.getAlpha()/255f*alpha); + + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GlStateManager.disableTexture2D(); + GlStateManager.depthMask(false); + + GL11.glLineWidth(3); + + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + worldrenderer.begin(3, DefaultVertexFormats.POSITION); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); + tessellator.draw(); + worldrenderer.begin(3, DefaultVertexFormats.POSITION); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); + tessellator.draw(); + worldrenderer.begin(1, DefaultVertexFormats.POSITION); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.minZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); + worldrenderer.pos(p_181561_0_.maxX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.minY, p_181561_0_.maxZ).endVertex(); + worldrenderer.pos(p_181561_0_.minX, p_181561_0_.maxY, p_181561_0_.maxZ).endVertex(); + tessellator.draw(); + + GL11.glLineWidth(1); + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java new file mode 100644 index 00000000..79dc2bba --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java @@ -0,0 +1,542 @@ +package io.github.moulberry.notenoughupdates.miscfeatures; + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.inventory.GuiChest; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.ContainerChest; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraftforge.client.event.GuiOpenEvent; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; + +import java.util.*; + +public class EnchantingSolvers { + + private static SolverType currentSolver = SolverType.NONE; + + private enum SolverType { + NONE, + CHRONOMATRON, + ULTRASEQUENCER, + SUPERPAIRS + } + + private static final NBTTagCompound enchTag = new NBTTagCompound(); + static { + enchTag.setTag("ench", new NBTTagList()); + } + + //Chronomatron + private static boolean addToChronomatron = false; + private static boolean chronomatronStartSeq = false; + private static List chronomatronOrder = new ArrayList<>(); + private static int chronomatronReplayIndex = 0; + private static int lastChronomatronSize = 0; + private static long millisLastClick = 0; + + //Ultrasequencer + private static class UltrasequencerItem { + ItemStack stack; + int containerIndex; + + public UltrasequencerItem(ItemStack stack, int containerIndex) { + this.stack = stack; + this.containerIndex = containerIndex; + } + } + + private static Map ultraSequencerOrder = new HashMap<>(); + private static int ultrasequencerReplayIndex = 0; + + //Superpairs + private static Map superpairStacks = new HashMap<>(); + private static int lastSlotClicked = -1; + private static HashSet successfulMatches = new HashSet<>(); + private static HashSet possibleMatches = new HashSet<>(); + private static HashSet powerupMatches = new HashSet<>(); + + @SubscribeEvent + public void onGuiOpen(GuiOpenEvent event) { + chronomatronOrder.clear(); + currentSolver = SolverType.NONE; + + if(!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) { + return; + } + + if(event.gui instanceof GuiChest) { + GuiChest chest = (GuiChest) event.gui; + ContainerChest container = (ContainerChest) chest.inventorySlots; + String containerName = container.getLowerChestInventory().getDisplayName().getUnformattedText(); + String lower = containerName.toLowerCase(); + + if(!lower.contains("stakes")) { + if(lower.startsWith("chronomatron")) { + currentSolver = SolverType.CHRONOMATRON; + } else if(lower.startsWith("ultrasequencer")) { + currentSolver = SolverType.ULTRASEQUENCER; + } else if(lower.startsWith("superpairs")) { + currentSolver = SolverType.SUPERPAIRS; + } + } + } + } + + public static ItemStack overrideStack(IInventory inventory, int slotIndex, ItemStack stack) { + if(!NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enableEnchantingSolvers) { + return null; + } + + if(!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) { + return null; + } + + if(stack != null && stack.getDisplayName() != null) { + if(Minecraft.getMinecraft().currentScreen instanceof GuiChest) { + GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; + ContainerChest container = (ContainerChest) chest.inventorySlots; + IInventory lower = container.getLowerChestInventory(); + + if(lower != inventory) { + return null; + } + + String displayName = stack.getDisplayName(); + + if(currentSolver == SolverType.CHRONOMATRON) { + ItemStack timerStack = lower.getStackInSlot(lower.getSizeInventory()-5); + if(timerStack == null) { + return null; + } + + boolean yepClock = timerStack.getItem() == Items.clock; + if(yepClock && (addToChronomatron && chronomatronOrder.size() >= lastChronomatronSize+1)) { + if(chronomatronReplayIndex < chronomatronOrder.size()) { + String chronomatronCurrent = chronomatronOrder.get(chronomatronReplayIndex); + if(stack.getItem() == Item.getItemFromBlock(Blocks.stained_glass) || + stack.getItem() == Item.getItemFromBlock(Blocks.stained_hardened_clay)) { + long currentTime = System.currentTimeMillis(); + + boolean lastSame = chronomatronReplayIndex > 0 && + chronomatronCurrent.equals(chronomatronOrder.get(chronomatronReplayIndex-1)); + + if(chronomatronCurrent.equals(displayName)) { + if(!lastSame || currentTime - millisLastClick > 300) { + ItemStack retStack = new ItemStack(Item.getItemFromBlock(Blocks.stained_hardened_clay), 1, stack.getItemDamage()); + retStack.setTagCompound(enchTag); + retStack.setStackDisplayName(stack.getDisplayName()); + return retStack; + } else { + ItemStack retStack = new ItemStack(Item.getItemFromBlock(Blocks.stained_glass), 1, stack.getItemDamage()); + retStack.setStackDisplayName(stack.getDisplayName()); + return retStack; + } + } else { + if(chronomatronReplayIndex+1 < chronomatronOrder.size()) { + String chronomatronNext = chronomatronOrder.get(chronomatronReplayIndex+1); + if(chronomatronNext.equals(displayName)) { + ItemStack retStack = new ItemStack(Item.getItemFromBlock(Blocks.stained_glass), 1, stack.getItemDamage()); + retStack.setStackDisplayName(stack.getDisplayName()); + return retStack; + } + } + ItemStack retStack = new ItemStack(Item.getItemFromBlock(Blocks.stained_glass), 1, 8); + retStack.setStackDisplayName(stack.getDisplayName()); + return retStack; + } + } + + } + } + } else if(currentSolver == SolverType.ULTRASEQUENCER) { + ItemStack timerStack = lower.getStackInSlot(lower.getSizeInventory()-5); + if(timerStack == null) { + return null; + } + + boolean yepClock = timerStack.getItem() == Items.clock; + if(stack.getItem() == Item.getItemFromBlock(Blocks.stained_glass_pane) && stack.getItemDamage() != 15) { + if(yepClock) { + for(int solveIndex : ultraSequencerOrder.keySet()) { + UltrasequencerItem item = ultraSequencerOrder.get(solveIndex); + if(item.containerIndex == slotIndex) { + ItemStack newStack = item.stack; + if(solveIndex == ultrasequencerReplayIndex) { + newStack.setTagCompound(enchTag); + } else { + newStack.setTagCompound(null); + } + return newStack; + } + } + ItemStack retStack = new ItemStack(Item.getItemFromBlock(Blocks.stained_glass_pane), 1, 15); + retStack.setStackDisplayName(stack.getDisplayName()); + return retStack; + } + } + } else if(currentSolver == SolverType.SUPERPAIRS) { + if(stack.getItem() == Item.getItemFromBlock(Blocks.stained_glass) && + superpairStacks.containsKey(slotIndex)) { + return superpairStacks.get(slotIndex); + } + } + } + } + return null; + } + + public static boolean onStackRender(ItemStack stack, IInventory inventory, int slotIndex, int x, int y) { + if(!NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enableEnchantingSolvers) { + return false; + } + + if(!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) { + return false; + } + + if(stack != null && stack.getDisplayName() != null) { + if(Minecraft.getMinecraft().currentScreen instanceof GuiChest) { + GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; + ContainerChest container = (ContainerChest) chest.inventorySlots; + IInventory lower = container.getLowerChestInventory(); + + if(lower != inventory) { + return false; + } + + if(currentSolver == SolverType.ULTRASEQUENCER) { + ItemStack timerStack = lower.getStackInSlot(lower.getSizeInventory()-5); + if(timerStack == null) { + return false; + } + + boolean yepClock = timerStack.getItem() == Items.clock; + if(stack.getItem() == Item.getItemFromBlock(Blocks.stained_glass_pane) && stack.getItemDamage() != 15) { + if(yepClock) { + for(int solveIndex : ultraSequencerOrder.keySet()) { + UltrasequencerItem item = ultraSequencerOrder.get(solveIndex); + if(item.containerIndex == slotIndex) { + int meta = 0; + if(solveIndex == ultrasequencerReplayIndex) { + meta = NotEnoughUpdates.INSTANCE.config.enchantingSolvers.seqNext; + } else if(solveIndex == ultrasequencerReplayIndex+1) { + meta = NotEnoughUpdates.INSTANCE.config.enchantingSolvers.seqUpcoming; + } + if(meta > 0) { + Utils.drawItemStack(new ItemStack(Item.getItemFromBlock(Blocks.stained_glass_pane), 1, meta-1), x, y); + } + if(NotEnoughUpdates.INSTANCE.config.enchantingSolvers.seqNumbers && + solveIndex >= ultrasequencerReplayIndex) { + int w = Minecraft.getMinecraft().fontRendererObj.getStringWidth((solveIndex+1)+""); + GlStateManager.disableDepth(); + GlStateManager.enableBlend(); + GlStateManager.disableLighting(); + Utils.drawStringScaled((solveIndex+1)+"", Minecraft.getMinecraft().fontRendererObj, + x+8.5f-w/2f, y+8.5f-4, true, 0xffc0c0c0, 1f); + return true; + } + } + } + } + } + } else if(currentSolver == SolverType.SUPERPAIRS) { + int meta = 0; + if(stack.getItem() == Item.getItemFromBlock(Blocks.stained_glass) && + superpairStacks.containsKey(slotIndex)) { + if(possibleMatches.contains(slotIndex)) { + meta = NotEnoughUpdates.INSTANCE.config.enchantingSolvers.supPossible; + } else { + meta = NotEnoughUpdates.INSTANCE.config.enchantingSolvers.supUnmatched; + } + } else { + if(powerupMatches.contains(slotIndex)) { + meta = NotEnoughUpdates.INSTANCE.config.enchantingSolvers.supPower; + } else if(successfulMatches.contains(slotIndex)) { + meta = NotEnoughUpdates.INSTANCE.config.enchantingSolvers.supMatched; + } + } + if(meta > 0) { + Utils.drawItemStack(new ItemStack(Item.getItemFromBlock(Blocks.stained_glass_pane), 1, meta-1), x, y); + } + } + } + } + return false; + } + + public static boolean onStackClick(ItemStack stack, int windowId, int slotId, int mouseButtonClicked, int mode) { + if(!NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enableEnchantingSolvers) { + return false; + } + + if(!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) { + return false; + } + + if(stack != null && stack.getDisplayName() != null) { + String displayName = stack.getDisplayName(); + if(Minecraft.getMinecraft().currentScreen instanceof GuiChest) { + GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; + ContainerChest container = (ContainerChest) chest.inventorySlots; + IInventory lower = container.getLowerChestInventory(); + + if(currentSolver == SolverType.CHRONOMATRON) { + ItemStack timerStack = lower.getStackInSlot(lower.getSizeInventory()-5); + if(timerStack == null) { + return false; + } + + boolean yepClock = timerStack.getItem() == Items.clock; + if(timerStack.getItem() == Item.getItemFromBlock(Blocks.glowstone) || + (yepClock && (!addToChronomatron || chronomatronOrder.size() < lastChronomatronSize+1))) { + return true; + } else if(yepClock) { + long currentTime = System.currentTimeMillis(); + if(currentTime - millisLastClick < 150) { + return true; + } + + if(chronomatronReplayIndex < chronomatronOrder.size()) { + String chronomatronCurrent = chronomatronOrder.get(chronomatronReplayIndex); + if(!NotEnoughUpdates.INSTANCE.config.enchantingSolvers.preventMisclicks || + chronomatronCurrent.equals(displayName)) { + chronomatronReplayIndex++; + Minecraft.getMinecraft().playerController.windowClick(windowId, slotId, + 2, mode, Minecraft.getMinecraft().thePlayer); + millisLastClick = currentTime; + } + } + return true; + } + } else if(currentSolver == SolverType.ULTRASEQUENCER) { + ItemStack timerStack = lower.getStackInSlot(lower.getSizeInventory()-5); + if(timerStack == null) { + return false; + } + + boolean yepClock = timerStack.getItem() == Items.clock; + if(yepClock) { + UltrasequencerItem current = ultraSequencerOrder.get(ultrasequencerReplayIndex); + if(current == null) { + return true; + } + long currentTime = System.currentTimeMillis(); + if(currentTime - millisLastClick > 150 && + (!NotEnoughUpdates.INSTANCE.config.enchantingSolvers.preventMisclicks || + current.containerIndex == slotId)) { + ultrasequencerReplayIndex++; + Minecraft.getMinecraft().playerController.windowClick(windowId, slotId, + 2, mode, Minecraft.getMinecraft().thePlayer); + millisLastClick = currentTime; + } + return true; + } else { + return true; + } + } else if(currentSolver == SolverType.SUPERPAIRS) { + lastSlotClicked = slotId; + } + } + } + return false; + } + + public static void processInventoryContents() { + if(!NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enableEnchantingSolvers) { + return; + } + + if(!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) { + return; + } + + if(Minecraft.getMinecraft().currentScreen instanceof GuiChest) { + GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; + ContainerChest container = (ContainerChest) chest.inventorySlots; + IInventory lower = container.getLowerChestInventory(); + + if(currentSolver == SolverType.CHRONOMATRON) { + ItemStack timerStack = lower.getStackInSlot(lower.getSizeInventory() - 5); + if (timerStack == null) { + return; + } + + String stainedHardenedClayName = null; + for (int index = 0; index < lower.getSizeInventory(); index++) { + ItemStack stack = lower.getStackInSlot(index); + if (stack != null && stack.getItem() == Item.getItemFromBlock(Blocks.stained_hardened_clay)) { + if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("ench")) { + if (stainedHardenedClayName != null && !stack.getDisplayName().equals(stainedHardenedClayName)) { + return; + } + stainedHardenedClayName = stack.getDisplayName(); + } + } + } + + boolean yepClock = timerStack.getItem() == Items.clock; + if (timerStack.getItem() == Item.getItemFromBlock(Blocks.glowstone) || + (yepClock && (!addToChronomatron || chronomatronOrder.size() < lastChronomatronSize + 1))) { + if (chronomatronStartSeq) { + chronomatronStartSeq = false; + addToChronomatron = false; + lastChronomatronSize = chronomatronOrder.size(); + chronomatronOrder.clear(); + } + + if (stainedHardenedClayName != null) { + if (addToChronomatron) { + chronomatronOrder.add(stainedHardenedClayName); + } + addToChronomatron = false; + } else { + addToChronomatron = true; + chronomatronReplayIndex = 0; + } + } else if (yepClock) { + chronomatronStartSeq = true; + } + } else { + chronomatronStartSeq = true; + addToChronomatron = true; + } + if(currentSolver == SolverType.ULTRASEQUENCER) { + ItemStack timerStack = lower.getStackInSlot(lower.getSizeInventory() - 5); + if (timerStack == null) { + return; + } + if(timerStack.getItem() == Item.getItemFromBlock(Blocks.glowstone)) { + ultrasequencerReplayIndex = 0; + } + + for (int index = 0; index < lower.getSizeInventory(); index++) { + ItemStack stack = lower.getStackInSlot(index); + if (stack != null && stack.getItem() == Items.dye) { + if(ultraSequencerOrder.containsKey(stack.stackSize-1)) { + UltrasequencerItem ultrasequencerItem = ultraSequencerOrder.get(stack.stackSize-1); + ultrasequencerItem.containerIndex = index; + ultrasequencerItem.stack = stack; + } else { + ultraSequencerOrder.put(stack.stackSize-1, new UltrasequencerItem(stack, index)); + } + } + } + } else { + ultraSequencerOrder.clear(); + } + if(currentSolver == SolverType.SUPERPAIRS) { + successfulMatches.clear(); + possibleMatches.clear(); + powerupMatches.clear(); + out: + for (int index = 0; index < lower.getSizeInventory(); index++) { + ItemStack stack = lower.getStackInSlot(index); + if(stack == null) continue; + if (stack.getItem() != Item.getItemFromBlock(Blocks.stained_glass) && + stack.getItem() != Item.getItemFromBlock(Blocks.stained_glass_pane)) { + superpairStacks.put(index, stack); + + NBTTagCompound tag = stack.getTagCompound(); + if(tag != null) { + NBTTagCompound display = tag.getCompoundTag("display"); + if (display.hasKey("Lore", 9)) { + NBTTagList list = display.getTagList("Lore", 8); + for (int i = 0; i < list.tagCount(); i++) { + if(list.getStringTagAt(i).toLowerCase().contains("powerup")) { + powerupMatches.add(index); + continue out; + } + } + } + } + + int numMatches = 0; + for (int index2 = 0; index2 < lower.getSizeInventory(); index2++) { + ItemStack stack2 = lower.getStackInSlot(index2); + if(stack2 != null && stack2.getDisplayName().equals(stack.getDisplayName()) && + stack.getItem() == stack2.getItem()) { + numMatches++; + } + } + boolean oddMatches = (numMatches % 2) == 1; + + if((!oddMatches || index != lastSlotClicked) && !successfulMatches.contains(index)) { + for (int index2 = 0; index2 < lower.getSizeInventory(); index2++) { + if(index == index2) continue; + if(oddMatches && index2 == lastSlotClicked) continue; + + ItemStack stack2 = lower.getStackInSlot(index2); + if(stack2 != null && stack2.getDisplayName().equals(stack.getDisplayName()) && + stack.getItem() == stack2.getItem()) { + successfulMatches.add(index); + successfulMatches.add(index2); + } + } + } + } else { + if(superpairStacks.containsKey(index) && superpairStacks.get(index) != null && + !possibleMatches.contains(index)) { + ItemStack stack1 = superpairStacks.get(index); + for (int index2 = 0; index2 < lower.getSizeInventory(); index2++) { + if(index == index2) continue; + + if(superpairStacks.containsKey(index2) && superpairStacks.get(index2) != null) { + ItemStack stack2 = superpairStacks.get(index2); + if(stack1.getDisplayName().equals(stack2.getDisplayName()) && + stack1.getItem() == stack2.getItem()) { + possibleMatches.add(index); + possibleMatches.add(index2); + } + } + } + } + } + } + } else { + superpairStacks.clear(); + successfulMatches.clear(); + powerupMatches.clear(); + lastSlotClicked = -1; + } + } + } + + + @SubscribeEvent + public void onItemTooltip(ItemTooltipEvent event) { + if(NotEnoughUpdates.INSTANCE.config.enchantingSolvers.hideTooltips && + (currentSolver == SolverType.CHRONOMATRON || currentSolver == SolverType.ULTRASEQUENCER)) { + String internal = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(event.itemStack); + if(internal == null && event.toolTip.size() > 0 && !event.toolTip.get(0).trim().replaceAll("\\(#.+\\)$", "").trim().contains(" ")) { + event.toolTip.clear(); + } + } + } + + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent event) { + if(!(Minecraft.getMinecraft().currentScreen instanceof GuiChest)) { + currentSolver = SolverType.NONE; + } + + if(event.phase != TickEvent.Phase.END) { + return; + } + + processInventoryContents(); + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemRarityHalo.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemRarityHalo.java new file mode 100644 index 00000000..244d6906 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemRarityHalo.java @@ -0,0 +1,252 @@ +package io.github.moulberry.notenoughupdates.miscfeatures; + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.util.NEUResourceManager; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.*; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.client.renderer.texture.TextureUtil; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.client.shader.Framebuffer; +import net.minecraft.client.shader.Shader; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Matrix4f; +import org.lwjgl.BufferUtils; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL14; +import org.lwjgl.opengl.GL30; +import org.lwjgl.opengl.GL45; + +import java.awt.*; +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.util.HashMap; + +public class ItemRarityHalo { + + public static Framebuffer itemFramebuffer1 = null; + public static Framebuffer itemFramebuffer2 = null; + public static HashMap itemHaloTexMap = new HashMap<>(); + public static Matrix4f projectionMatrix = null; + + public static Shader colourShader = null; + public static Shader blurShaderHorz = null; + public static Shader blurShaderVert = null; + + private static int oldScaledResolution = 0; + + public static void onItemRender(ItemStack stack, int x, int y) { + if(x == 0 && y == 0) return; + + if(!OpenGlHelper.isFramebufferEnabled() || !OpenGlHelper.areShadersSupported()) return; + NotEnoughUpdates neu = NotEnoughUpdates.INSTANCE; + if(!neu.isOnSkyblock()) return; + //if(neu.manager.config.itemHighlightOpacity.value <= 1) return; + if(neu.manager.getInternalNameForItem(stack) == null) return; + + ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); + int size = 16*scaledresolution.getScaleFactor(); + + if(projectionMatrix == null) { + projectionMatrix = Utils.createProjectionMatrix(size, size); + } + + itemFramebuffer1 = checkFramebufferSizes(itemFramebuffer1, size, size); + itemFramebuffer2 = checkFramebufferSizes(itemFramebuffer2, size, size); + + try { + if(colourShader == null) { + colourShader = new Shader(new NEUResourceManager(Minecraft.getMinecraft().getResourceManager()), + "setrgbtoalpha", itemFramebuffer1, itemFramebuffer2); + upload(colourShader, size, size); + } + + if(blurShaderHorz == null) { + blurShaderHorz = new Shader(new NEUResourceManager(Minecraft.getMinecraft().getResourceManager()), + "blur", itemFramebuffer2, itemFramebuffer1); + blurShaderHorz.getShaderManager().getShaderUniform("BlurDir").set(1, 0); + blurShaderHorz.getShaderManager().getShaderUniform("Radius").set(5f); + blurShaderHorz.getShaderManager().getShaderUniform("AlphaMult").set(2f); + upload(blurShaderHorz, size, size); + } + + if(blurShaderVert == null) { + blurShaderVert = new Shader(new NEUResourceManager(Minecraft.getMinecraft().getResourceManager()), + "blur", itemFramebuffer1, itemFramebuffer2); + blurShaderVert.getShaderManager().getShaderUniform("BlurDir").set(0, 1); + blurShaderVert.getShaderManager().getShaderUniform("Radius").set(5f); + blurShaderVert.getShaderManager().getShaderUniform("AlphaMult").set(2f); + upload(blurShaderVert, size, size); + } + } catch(Exception e) { return; } + + if(oldScaledResolution != scaledresolution.getScaleFactor()) { + resetItemHaloCache(); + oldScaledResolution = scaledresolution.getScaleFactor(); + } + + int currentBuffer = GL11.glGetInteger(GL30.GL_FRAMEBUFFER_BINDING); + IntBuffer currentViewport = BufferUtils.createIntBuffer(16); + GL11.glGetInteger(GL11.GL_VIEWPORT, currentViewport); + try { + if(!itemHaloTexMap.containsKey(stack)) { + int texture1 = TextureUtil.glGenTextures(); + int texture2 = TextureUtil.glGenTextures(); + + GlStateManager.bindTexture(texture1); + GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, size, size, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, ((ByteBuffer)null)); + itemFramebuffer1.bindFramebuffer(false); + OpenGlHelper.glFramebufferTexture2D(OpenGlHelper.GL_FRAMEBUFFER, OpenGlHelper.GL_COLOR_ATTACHMENT0, 3553, texture1, 0); + + GlStateManager.bindTexture(texture2); + GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, size, size, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, ((ByteBuffer)null)); + itemFramebuffer2.bindFramebuffer(false); + OpenGlHelper.glFramebufferTexture2D(OpenGlHelper.GL_FRAMEBUFFER, OpenGlHelper.GL_COLOR_ATTACHMENT0, 3553, texture2, 0); + + itemFramebuffer1.framebufferClear(); + itemFramebuffer2.framebufferClear(); + + GlStateManager.pushMatrix(); { + GlStateManager.matrixMode(5889); + GlStateManager.loadIdentity(); + GlStateManager.ortho(0.0D, size, size, 0.0D, 1000.0D, 3000.0D); + GlStateManager.matrixMode(5888); + GlStateManager.loadIdentity(); + GlStateManager.translate(0.0F, 0.0F, -2000.0F); + + GL11.glScalef(scaledresolution.getScaleFactor(), scaledresolution.getScaleFactor(), 1); + + itemFramebuffer1.bindFramebuffer(true); + + RenderItem itemRender = Minecraft.getMinecraft().getRenderItem(); + RenderHelper.enableGUIStandardItemLighting(); + float zLevel = itemRender.zLevel; + itemRender.zLevel = -145; //Negates the z-offset of the below method. + itemRender.renderItemAndEffectIntoGUI(stack, 0, 0); + itemRender.zLevel = zLevel; + RenderHelper.disableStandardItemLighting(); + } GlStateManager.popMatrix(); + + GlStateManager.pushMatrix(); { + GL45.glTextureBarrier(); GL11.glFlush(); GL11.glFinish(); + executeShader(colourShader); + //GL45.glTextureBarrier(); GL11.glFlush(); GL11.glFinish(); + //executeShader(blurShaderHorz); + //GL45.glTextureBarrier(); GL11.glFlush(); GL11.glFinish(); + //executeShader(blurShaderVert); + //GL45.glTextureBarrier(); GL11.glFlush(); GL11.glFinish(); + } GlStateManager.popMatrix(); + + GlStateManager.matrixMode(5889); + GlStateManager.loadIdentity(); + GlStateManager.ortho(0.0D, scaledresolution.getScaledWidth_double(), scaledresolution.getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D); + GlStateManager.matrixMode(5888); + + OpenGlHelper.glBindFramebuffer(OpenGlHelper.GL_FRAMEBUFFER, currentBuffer); + GlStateManager.viewport(currentViewport.get(), currentViewport.get(), currentViewport.get(), currentViewport.get()); + + //TextureUtil.deleteTexture(texture1); + itemHaloTexMap.put(stack, texture2); + } + + OpenGlHelper.glBindFramebuffer(OpenGlHelper.GL_FRAMEBUFFER, currentBuffer); + GlStateManager.viewport(currentViewport.get(), currentViewport.get(), currentViewport.get(), currentViewport.get()); + + GlStateManager.bindTexture(itemHaloTexMap.get(stack)); + Color color = Utils.getPrimaryColour(stack.getDisplayName()); + //GlStateManager.color(color.getRed()/255f, color.getGreen()/255f, color.getBlue()/255f, + // NotEnoughUpdates.INSTANCE.manager.config.itemHighlightOpacity.value.floatValue()/255f); + Utils.drawTexturedRect(x, y, 16, 16, + 0, 1, 1, 0, GL11.GL_NEAREST); + GlStateManager.bindTexture(0); + } catch(Exception e) { + e.printStackTrace(); + OpenGlHelper.glBindFramebuffer(OpenGlHelper.GL_FRAMEBUFFER, currentBuffer); + GlStateManager.viewport(currentViewport.get(), currentViewport.get(), currentViewport.get(), currentViewport.get()); + } + } + + 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, true); + } else { + framebuffer.createBindFramebuffer(width, height); + } + framebuffer.setFramebufferFilter(GL11.GL_NEAREST); + } + return framebuffer; + } + + public static void resetItemHaloCache() { + ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); + int size = 16*scaledresolution.getScaleFactor(); + + for(int tex : itemHaloTexMap.values()) { + TextureUtil.deleteTexture(tex); + } + itemHaloTexMap.clear(); + + if(NotEnoughUpdates.INSTANCE.isOnSkyblock()) { + projectionMatrix = Utils.createProjectionMatrix(size, size); + upload(colourShader, size, size); + upload(blurShaderHorz, size, size); + upload(blurShaderVert, size, size); + } + } + + private static void upload(Shader shader, int width, int height) { + if(shader == null) return; + shader.getShaderManager().getShaderUniformOrDefault("ProjMat").set(projectionMatrix); + shader.getShaderManager().getShaderUniformOrDefault("InSize").set(width, height); + shader.getShaderManager().getShaderUniformOrDefault("OutSize").set(width, height); + shader.getShaderManager().getShaderUniformOrDefault("ScreenSize").set((float)width, (float)height); + } + + private static void executeShader(Shader shader) { + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.disableBlend(); + GlStateManager.disableDepth(); + GlStateManager.disableAlpha(); + GlStateManager.disableFog(); + GlStateManager.disableLighting(); + GlStateManager.disableColorMaterial(); + GlStateManager.enableTexture2D(); + GlStateManager.bindTexture(0); + + float f = (float)shader.framebufferOut.framebufferTextureWidth; + float f1 = (float)shader.framebufferOut.framebufferTextureHeight; + GlStateManager.viewport(0, 0, (int)f, (int)f1); + + shader.getShaderManager().useShader(); + shader.getShaderManager().addSamplerTexture("DiffuseSampler", shader.framebufferIn); + + shader.framebufferOut.framebufferClear(); + shader.framebufferOut.bindFramebuffer(false); + + GlStateManager.depthMask(false); + + GlStateManager.enableAlpha(); + GlStateManager.enableBlend(); + GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); + + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR); + worldrenderer.pos(0.0D, (double)f1, 500.0D).color(255, 255, 255, 255).endVertex(); + worldrenderer.pos((double)f, (double)f1, 500.0D).color(255, 255, 255, 255).endVertex(); + worldrenderer.pos((double)f, 0.0D, 500.0D).color(255, 255, 255, 255).endVertex(); + worldrenderer.pos(0.0D, 0.0D, 500.0D).color(255, 255, 255, 255).endVertex(); + tessellator.draw(); + + GlStateManager.depthMask(true); + + shader.getShaderManager().endShader(); + + shader.framebufferOut.unbindFramebuffer(); + shader.framebufferIn.unbindFramebufferTexture(); + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/StreamerMode.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/StreamerMode.java new file mode 100644 index 00000000..40b75e50 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/StreamerMode.java @@ -0,0 +1,40 @@ +package io.github.moulberry.notenoughupdates.miscfeatures; + +import io.github.moulberry.notenoughupdates.util.Utils; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class StreamerMode { + + private static final Pattern lobbyPattern = Pattern.compile("(mini|mega|m|M)([0-9]{1,3}[A-Z])"); + + public static String filterLobbyNames(String line) { + Matcher matcher = lobbyPattern.matcher(line); + if(matcher.find() && matcher.groupCount() == 2) { + String lobbyType = matcher.group(1); + String lobbyId = matcher.group(2); + long lobbyNum = Long.parseLong(lobbyId.substring(0, lobbyId.length()-1)); + + long obfLobbyNum = (lobbyNum*9182739 + 11) % 500; + char obfLobbyLetter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt((int)(obfLobbyNum%26)); + + line = line.replaceAll("(mini|mega|m|M)([0-9]{1,3}[A-Z])", lobbyType+obfLobbyNum+obfLobbyLetter); + } + return line; + } + + public static String filterScoreboard(String line) { + line = filterLobbyNames(Utils.cleanDuplicateColourCodes(line)); + return line; + } + + public static String filterChat(String line) { + line = filterLobbyNames(line); + return line; + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SunTzu.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SunTzu.java new file mode 100644 index 00000000..8b690765 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SunTzu.java @@ -0,0 +1,93 @@ +package io.github.moulberry.notenoughupdates.miscfeatures; + +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.event.world.WorldEvent; +import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +import java.util.Random; + +public class SunTzu { + + private static boolean enabled = false; + private static int quoteNum = 0; + + private static Random rand = new Random(); + + private static String[] quotes = new String[] { + "Appear weak when you are strong, and strong when you are weak.", + "The supreme art of war is to subdue the enemy without fighting.", + "If you know the enemy and know yourself, you need not fear the result of a hundred battles.", + "Let your plans be dark and impenetrable as night, and when you move, fall like a thunderbolt.", + "All warfare is based on deception.", + "In the midst of chaos, there is also opportunity.", + "The greatest victory is that which requires no battle.", + "To know your Enemy, you must become your Enemy.", + "There is no instance of a nation benefitting from prolonged warfare.", + "Even the finest sword plunged into salt water will eventually rust.", + "Opportunities multiply as they are seized.", + "When the enemy is relaxed, make them toil. When full, starve them. When settled, make them move.", + "He who wishes to fight must first count the cost", + "If you wait by the river long enough, the bodies of your enemies will float by.", + "Be extremely subtle even to the point of formlessness. Be extremely mysterious even to the point of soundlessness. Thereby you can be the director of the opponent's fate.", + "Build your opponent a golden bridge to retreat across.", + "The wise warrior avoids the battle.", + "Great results, can be achieved with small forces.", + "Attack is the secret of defense; defense is the planning of an attack.", + "Subscribe to Moulberry on YouTube." + }; + + public static void setEnabled(boolean enabled) { + SunTzu.enabled = enabled; + } + + public static void randomizeQuote() { + for(int i=0; i<3; i++) { + int newQuote = rand.nextInt(quotes.length); + + if(newQuote != quoteNum) { + quoteNum = newQuote; + return; + } + } + } + + private static String getQuote() { + return quotes[quoteNum]; + } + + @SubscribeEvent + public void onOverlayDrawn(RenderGameOverlayEvent event) { + if(enabled && ((event.type == null && Loader.isModLoaded("labymod")) || + event.type == RenderGameOverlayEvent.ElementType.ALL)) { + if(Minecraft.getMinecraft().gameSettings.showDebugInfo || + (Minecraft.getMinecraft().gameSettings.keyBindPlayerList.isKeyDown() && + (!Minecraft.getMinecraft().isIntegratedServerRunning() || + Minecraft.getMinecraft().thePlayer.sendQueue.getPlayerInfoMap().size() > 1))) { + return; + } + + ScaledResolution sr = Utils.pushGuiScale(2); + + int height = Utils.renderStringTrimWidth(EnumChatFormatting.YELLOW+getQuote(), Minecraft.getMinecraft().fontRendererObj, + true, sr.getScaledWidth()/2-100, 5, 200, -1, -1); + String sunTzu = "- Sun Tzu, The Art of War"; + int sunTzuLength = Minecraft.getMinecraft().fontRendererObj.getStringWidth(sunTzu); + Minecraft.getMinecraft().fontRendererObj.drawString(EnumChatFormatting.GOLD+sunTzu, + sr.getScaledWidth()/2f+100-sunTzuLength, 15+height, 0, true); + + Utils.pushGuiScale(-1); + } + } + + @SubscribeEvent + public void switchWorld(WorldEvent.Load event) { + randomizeQuote(); + } + + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/AccessoryBagOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/AccessoryBagOverlay.java new file mode 100644 index 00000000..612dd8d7 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/AccessoryBagOverlay.java @@ -0,0 +1,825 @@ +package io.github.moulberry.notenoughupdates.miscgui; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.profileviewer.PlayerStats; +import io.github.moulberry.notenoughupdates.util.Constants; +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; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.inventory.ContainerChest; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.EnumChatFormatting; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL14; + +import java.awt.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.*; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static io.github.moulberry.notenoughupdates.util.GuiTextures.*; + +public class AccessoryBagOverlay { + + private static final int TAB_BASIC = 0; + private static final int TAB_TOTAL = 1; + 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", + 10, EnumChatFormatting.GREEN+"- Talis count by rarity"), + Utils.createItemStack(Items.diamond_sword, EnumChatFormatting.DARK_AQUA+"Total Stat Bonuses", + 0), + Utils.createItemStack(Item.getItemFromBlock(Blocks.anvil), EnumChatFormatting.DARK_AQUA+"Total Stat Bonuses (from reforges)", + 0), + Utils.createItemStack(Items.dye, EnumChatFormatting.DARK_AQUA+"Duplicates", + 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; + + public static boolean mouseClick() { + 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")) { + return false; + } + } else { + return false; + } + + if(!Mouse.getEventButtonState()) return false; + try { + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + + int mouseX = Mouse.getX() / scaledResolution.getScaleFactor(); + int mouseY = height - Mouse.getY() / scaledResolution.getScaleFactor(); + + int xSize = (int) Utils.getField(GuiContainer.class, Minecraft.getMinecraft().currentScreen, "xSize", "field_146999_f"); + int ySize = (int) Utils.getField(GuiContainer.class, Minecraft.getMinecraft().currentScreen, "ySize", "field_147000_g"); + int guiLeft = (int) Utils.getField(GuiContainer.class, Minecraft.getMinecraft().currentScreen, "guiLeft", "field_147003_i"); + int guiTop = (int) Utils.getField(GuiContainer.class, Minecraft.getMinecraft().currentScreen, "guiTop", "field_147009_r"); + + if(mouseX < guiLeft+xSize+3 || mouseX > guiLeft+xSize+80+28) return false; + if(mouseY < guiTop || mouseY > guiTop+166) return false; + + if(mouseX > guiLeft+xSize+83 && mouseY < guiTop+20*TAB_MISSING+22) { + currentTab = (mouseY - guiTop)/20; + if(currentTab < 0) currentTab = 0; + 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; + } + } + + public static void resetCache() { + accessoryStacks = new HashSet<>(); + pagesVisited = new HashSet<>(); + talismanCountRarity = null; + totalStats = null; + reforgeStats = null; + duplicates = null; + missing = null; + } + + private static Set accessoryStacks = new HashSet<>(); + private static Set pagesVisited = new HashSet<>(); + + public static void renderVisitOverlay(int x, int y) { + Utils.drawStringCenteredScaledMaxWidth("Please visit all", Minecraft.getMinecraft().fontRendererObj, x+40, y+78, true, 70, -1); + Utils.drawStringCenteredScaledMaxWidth("pages of the bag", Minecraft.getMinecraft().fontRendererObj, x+40, y+86, true, 70, -1); + } + + private static TreeMap talismanCountRarity = null; + public static void renderBasicOverlay(int x, int y) { + if(talismanCountRarity == null) { + talismanCountRarity = new TreeMap<>(); + for(ItemStack stack : accessoryStacks) { + int rarity = getRarity(stack); + if(rarity >= 0) { + talismanCountRarity.put(rarity, talismanCountRarity.getOrDefault(rarity, 0)+1); + } + } + } + + Utils.drawStringCenteredScaledMaxWidth("# By Rarity", Minecraft.getMinecraft().fontRendererObj, x+40, y+12, false, 70, + new Color(80, 80, 80).getRGB()); + + int yIndex = 0; + for(Map.Entry entry : talismanCountRarity.descendingMap().entrySet()) { + String rarityName = rarityArrC[entry.getKey()]; + renderAlignedString(rarityName, EnumChatFormatting.WHITE.toString()+entry.getValue(), x+5, y+20+11*yIndex, 70); + yIndex++; + } + } + + + private static PlayerStats.Stats totalStats = null; + public static void renderTotalStatsOverlay(int x, int y) { + if(totalStats == null) { + totalStats = new PlayerStats.Stats(); + for(ItemStack stack : accessoryStacks) { + if(stack != null) totalStats.add(getStatForItem(stack, STAT_PATTERN_MAP, true)); + } + } + + 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 = null; + public static void renderDuplicatesOverlay(int x, int y) { + if(duplicates == null) { + JsonObject misc = Constants.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 = Constants.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() { + 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")) { + try { + int xSize = (int) Utils.getField(GuiContainer.class, eventGui, "xSize", "field_146999_f"); + int ySize = (int) Utils.getField(GuiContainer.class, eventGui, "ySize", "field_147000_g"); + int guiLeft = (int) Utils.getField(GuiContainer.class, eventGui, "guiLeft", "field_147003_i"); + int guiTop = (int) Utils.getField(GuiContainer.class, eventGui, "guiTop", "field_147009_r"); + + if(accessoryStacks.isEmpty()) { + for(ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { + if(stack != null && isAccessory(stack)) { + accessoryStacks.add(stack); + } + } + } + + if(containerName.trim().contains("(")) { + String first = containerName.trim().split("\\(")[1].split("/")[0]; + Integer currentPageNumber = Integer.parseInt(first); + //System.out.println("current:"+currentPageNumber); + if(!pagesVisited.contains(currentPageNumber)) { + boolean hasStack = false; + if(Minecraft.getMinecraft().thePlayer.openContainer instanceof ContainerChest) { + IInventory inv = ((ContainerChest)Minecraft.getMinecraft().thePlayer.openContainer).getLowerChestInventory(); + for(int i=0; i pagesVisited.size()) { + Minecraft.getMinecraft().getTextureManager().bindTexture(accessory_bag_overlay); + Utils.drawTexturedRect(guiLeft+xSize+3, guiTop, 80, 149, 0, 80/256f, 0, 149/256f, GL11.GL_NEAREST); + + renderVisitOverlay(guiLeft+xSize+3, guiTop); + return; + } + } else if(pagesVisited.isEmpty()) { + boolean hasStack = false; + if(Minecraft.getMinecraft().thePlayer.openContainer instanceof ContainerChest) { + IInventory inv = ((ContainerChest)Minecraft.getMinecraft().thePlayer.openContainer).getLowerChestInventory(); + for(int i=0; i= length) { + for(int xOff=-2; xOff<=2; xOff++) { + for(int yOff=-2; yOff<=2; yOff++) { + if(Math.abs(xOff) != Math.abs(yOff)) { + Utils.drawStringCenteredScaledMaxWidth(Utils.cleanColourNotModifiers(first + " " + second), Minecraft.getMinecraft().fontRendererObj, + x+length/2f+xOff/2f, y+4+yOff/2f, false, length, + new Color(0, 0, 0, 200/Math.max(Math.abs(xOff), Math.abs(yOff))).getRGB()); + } + } + } + + GlStateManager.color(1, 1, 1, 1); + Utils.drawStringCenteredScaledMaxWidth(first + " " + second, Minecraft.getMinecraft().fontRendererObj, + x+length/2f, y+4, false, length, 4210752); + } else { + for(int xOff=-2; xOff<=2; xOff++) { + for(int yOff=-2; yOff<=2; yOff++) { + if(Math.abs(xOff) != Math.abs(yOff)) { + fontRendererObj.drawString(Utils.cleanColourNotModifiers(first), + x+xOff/2f, y+yOff/2f, + new Color(0, 0, 0, 200/Math.max(Math.abs(xOff), Math.abs(yOff))).getRGB(), false); + } + } + } + + int secondLen = fontRendererObj.getStringWidth(second); + GlStateManager.color(1, 1, 1, 1); + fontRendererObj.drawString(first, x, y, 4210752, false); + for(int xOff=-2; xOff<=2; xOff++) { + for(int yOff=-2; yOff<=2; yOff++) { + if(Math.abs(xOff) != Math.abs(yOff)) { + fontRendererObj.drawString(Utils.cleanColourNotModifiers(second), + x+length-secondLen+xOff/2f, y+yOff/2f, + new Color(0, 0, 0, 200/Math.max(Math.abs(xOff), Math.abs(yOff))).getRGB(), false); + } + } + } + + GlStateManager.color(1, 1, 1, 1); + fontRendererObj.drawString(second, x+length-secondLen, y, 4210752, false); + } + } + + private static final Pattern HEALTH_PATTERN_BONUS = Pattern.compile("^Health: (?:\\+|-)[0-9]+ HP \\([a-zA-Z]+ ((?:\\+|-)[0-9]+)"); + private static final Pattern DEFENCE_PATTERN_BONUS = Pattern.compile("^Defense: (?:\\+|-)[0-9]+ \\([a-zA-Z]+ ((?:\\+|-)[0-9]+)"); + private static final Pattern STRENGTH_PATTERN_BONUS = Pattern.compile("^Strength: (?:\\+|-)[0-9]+ \\([a-zA-Z]+ ((?:\\+|-)[0-9]+)"); + private static final Pattern SPEED_PATTERN_BONUS = Pattern.compile("^Speed: (?:\\+|-)[0-9]+ \\([a-zA-Z]+ ((?:\\+|-)[0-9]+)"); + private static final Pattern CC_PATTERN_BONUS = Pattern.compile("^Crit Chance: (?:\\+|-)[0-9]+% \\([a-zA-Z]+ ((?:\\+|-)[0-9]+)"); + private static final Pattern CD_PATTERN_BONUS = Pattern.compile("^Crit Damage: (?:\\+|-)[0-9]+% \\([a-zA-Z]+ ((?:\\+|-)[0-9]+)"); + private static final Pattern ATKSPEED_PATTERN_BONUS = Pattern.compile("^Bonus Attack Speed: (?:\\+|-)[0-9]+% \\([a-zA-Z]+ ((?:\\+|-)[0-9]+)"); + private static final Pattern INTELLIGENCE_PATTERN_BONUS = Pattern.compile("^Intelligence: (?:\\+|-)[0-9]+ \\([a-zA-Z]+ ((?:\\+|-)[0-9]+)"); + private static final Pattern SCC_PATTERN_BONUS = Pattern.compile("^Sea Creature Chance: (?:\\+|-)[0-9]+ \\([a-zA-Z]+ ((?:\\+|-)[0-9]+)"); + private static final HashMap STAT_PATTERN_MAP_BONUS = new HashMap<>(); + static { + STAT_PATTERN_MAP_BONUS.put("health", HEALTH_PATTERN_BONUS); + STAT_PATTERN_MAP_BONUS.put("defence", DEFENCE_PATTERN_BONUS); + STAT_PATTERN_MAP_BONUS.put("strength", STRENGTH_PATTERN_BONUS); + STAT_PATTERN_MAP_BONUS.put("speed", SPEED_PATTERN_BONUS); + STAT_PATTERN_MAP_BONUS.put("crit_chance", CC_PATTERN_BONUS); + STAT_PATTERN_MAP_BONUS.put("crit_damage", CD_PATTERN_BONUS); + STAT_PATTERN_MAP_BONUS.put("bonus_attack_speed", ATKSPEED_PATTERN_BONUS); + STAT_PATTERN_MAP_BONUS.put("intelligence", INTELLIGENCE_PATTERN_BONUS); + STAT_PATTERN_MAP_BONUS.put("sea_creature_chance", SCC_PATTERN_BONUS); + } + + private static final Pattern HEALTH_PATTERN = Pattern.compile("^Health: ((?:\\+|-)[0-9]+)"); + private static final Pattern DEFENCE_PATTERN = Pattern.compile("^Defense: ((?:\\+|-)[0-9]+)"); + private static final Pattern STRENGTH_PATTERN = Pattern.compile("^Strength: ((?:\\+|-)[0-9]+)"); + private static final Pattern SPEED_PATTERN = Pattern.compile("^Speed: ((?:\\+|-)[0-9]+)"); + private static final Pattern CC_PATTERN = Pattern.compile("^Crit Chance: ((?:\\+|-)[0-9]+)"); + private static final Pattern CD_PATTERN = Pattern.compile("^Crit Damage: ((?:\\+|-)[0-9]+)"); + private static final Pattern ATKSPEED_PATTERN = Pattern.compile("^Bonus Attack Speed: ((?:\\+|-)[0-9]+)"); + private static final Pattern INTELLIGENCE_PATTERN = Pattern.compile("^Intelligence: ((?:\\+|-)[0-9]+)"); + private static final Pattern SCC_PATTERN = Pattern.compile("^Sea Creature Chance: ((?:\\+|-)[0-9]+)"); + private static final HashMap STAT_PATTERN_MAP = new HashMap<>(); + static { + STAT_PATTERN_MAP.put("health", HEALTH_PATTERN); + STAT_PATTERN_MAP.put("defence", DEFENCE_PATTERN); + STAT_PATTERN_MAP.put("strength", STRENGTH_PATTERN); + STAT_PATTERN_MAP.put("speed", SPEED_PATTERN); + STAT_PATTERN_MAP.put("crit_chance", CC_PATTERN); + STAT_PATTERN_MAP.put("crit_damage", CD_PATTERN); + STAT_PATTERN_MAP.put("bonus_attack_speed", ATKSPEED_PATTERN); + STAT_PATTERN_MAP.put("intelligence", INTELLIGENCE_PATTERN); + STAT_PATTERN_MAP.put("sea_creature_chance", SCC_PATTERN); + } + private static PlayerStats.Stats getStatForItem(ItemStack stack, HashMap patternMap, boolean addExtras) { + String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); + NBTTagCompound tag = stack.getTagCompound(); + PlayerStats.Stats stats = new PlayerStats.Stats(); + + if(internalname == null) { + return stats; + } + + if(tag != null) { + NBTTagCompound display = tag.getCompoundTag("display"); + if (display.hasKey("Lore", 9)) { + NBTTagList list = display.getTagList("Lore", 8); + for (int i = 0; i < list.tagCount(); i++) { + String line = list.getStringTagAt(i); + for(Map.Entry entry : patternMap.entrySet()) { + Matcher matcher = entry.getValue().matcher(Utils.cleanColour(line)); + if(matcher.find()) { + int bonus = Integer.parseInt(matcher.group(1)); + stats.addStat(entry.getKey(), bonus); + } + } + } + } + } + + if(!addExtras) return stats; + + if(internalname.equals("DAY_CRYSTAL") || internalname.equals("NIGHT_CRYSTAL")) { + stats.addStat(PlayerStats.STRENGTH, 2.5f); + stats.addStat(PlayerStats.DEFENCE, 2.5f); + } + + if(internalname.equals("NEW_YEAR_CAKE_BAG") && tag != null && tag.hasKey("ExtraAttributes", 10)) { + NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); + + byte[] bytes = null; + for (String key : ea.getKeySet()) { + if (key.endsWith("backpack_data") || key.equals("new_year_cake_bag_data")) { + bytes = ea.getByteArray(key); + try { + NBTTagCompound contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(bytes)); + NBTTagList items = contents_nbt.getTagList("i", 10); + HashSet cakes = new HashSet<>(); + for(int j=0; j 0) { + NBTTagCompound nbt = items.getCompoundTagAt(j).getCompoundTag("tag"); + if(nbt != null && nbt.hasKey("ExtraAttributes", 10)) { + NBTTagCompound ea2 = nbt.getCompoundTag("ExtraAttributes"); + if (ea2.hasKey("new_years_cake")) { + cakes.add(ea2.getInteger("new_years_cake")); + } + } + } + } + stats.addStat(PlayerStats.HEALTH, cakes.size()); + } catch(IOException e) { + e.printStackTrace(); + return stats; + } + break; + } + } + } + return stats; + } + + private static String[] rarityArr = new String[] { + "COMMON", "UNCOMMON", "RARE", "EPIC", "LEGENDARY", "MYTHIC", "SPECIAL", "VERY SPECIAL", + }; + private static String[] rarityArrC = new String[] { + EnumChatFormatting.WHITE+EnumChatFormatting.BOLD.toString()+"COMMON", + EnumChatFormatting.GREEN+EnumChatFormatting.BOLD.toString()+"UNCOMMON", + EnumChatFormatting.BLUE+EnumChatFormatting.BOLD.toString()+"RARE", + EnumChatFormatting.DARK_PURPLE+EnumChatFormatting.BOLD.toString()+"EPIC", + EnumChatFormatting.GOLD+EnumChatFormatting.BOLD.toString()+"LEGENDARY", + EnumChatFormatting.LIGHT_PURPLE+EnumChatFormatting.BOLD.toString()+"MYTHIC", + EnumChatFormatting.RED+EnumChatFormatting.BOLD.toString()+"SPECIAL", + EnumChatFormatting.RED+EnumChatFormatting.BOLD.toString()+"VERY SPECIAL", + EnumChatFormatting.DARK_RED+EnumChatFormatting.BOLD.toString()+"SUPREME", + }; + public static int checkItemType(ItemStack stack, boolean contains, String... typeMatches) { + NBTTagCompound tag = stack.getTagCompound(); + if(tag != null) { + NBTTagCompound display = tag.getCompoundTag("display"); + if (display.hasKey("Lore", 9)) { + NBTTagList list = display.getTagList("Lore", 8); + for (int i = list.tagCount()-1; i >= 0; i--) { + String line = list.getStringTagAt(i); + for(String rarity : rarityArr) { + for(int j=0; j=0; i--) { + String line = lore.get(i).getAsString(); + + for(String rarity : rarityArr) { + for(int j=0; j= 0; + } + + public static int getRarity(ItemStack stack) { + NBTTagCompound tag = stack.getTagCompound(); + if(tag != null) { + NBTTagCompound display = tag.getCompoundTag("display"); + if (display.hasKey("Lore", 9)) { + NBTTagList list = display.getTagList("Lore", 8); + for (int i = list.tagCount(); i >= 0; i--) { + String line = list.getStringTagAt(i); + for(int j=0; j desc; + long lastsFor; + + public SBEvent(String id, String display, ItemStack stack, List desc) { + this(id, display, stack, desc, -1); + } + + public SBEvent(String id, String display, ItemStack stack, List desc, long lastsFor) { + this.id = id; + this.display = display; + this.stack = stack; + this.desc = desc; + this.lastsFor = lastsFor; + } + } + + private int jingleIndex = -1; + + private TreeMap> eventMap = new TreeMap<>(); + private List jfFavouriteSelect = null; + private int jfFavouriteSelectIndex = 0; + private int jfFavouriteSelectX = 0; + private int jfFavouriteSelectY = 0; + + private boolean drawTimerForeground = false; + + private static long spookyStart = 0; + + private static long SECOND = 1000; + private static long MINUTE = SECOND*60; + private static long HOUR = MINUTE*60; + private static long DAY = HOUR*24; + + private static long DA_OFFSET = 1000*60*55; + private static long JF_OFFSET = 1000*60*15; + + private static ItemStack DA_STACK; + private static ItemStack JF_STACK; + static { + NBTTagCompound tag = new NBTTagCompound(); + tag.setString("event_id", "dark_auction"); + //tag.setTag("ench", new NBTTagList()); + + DA_STACK = new ItemStack(Items.netherbrick); + DA_STACK.setTagCompound(tag); + + tag.setString("event_id", "jacob_farming"); + JF_STACK = new ItemStack(Items.wheat); + JF_STACK.setTagCompound(tag); + } + + public long getTimeOffset(String time) { + long offset = 0; + + StringBuilder numS = new StringBuilder(); + for(int timeIndex=0; timeIndex= '0' && c <= '9') { + numS.append(c); + } else { + try { + int num = Integer.parseInt(numS.toString()); + switch (c) { + case 'd': + offset += num * DAY; continue; + case 'h': + offset += num * HOUR; continue; + case 'm': + offset += num * MINUTE; continue; + case 's': + offset += num * SECOND; continue; + } + } catch(Exception ignored) {} + numS = new StringBuilder(); + } + } + + return offset; + } + + private static Pattern CALENDAR_PATTERN = Pattern.compile("([A-Za-z ]+), Year ([0-9]+)"); + private static long SKYBLOCK_START = 1559829300000L; //Day 0, Year 0 + + @SubscribeEvent + public void tick(TickEvent.ClientTickEvent event) { + if(event.phase != TickEvent.Phase.START) return; + + if(jingleIndex == 0) { + if (NotEnoughUpdates.INSTANCE.config.calendar.eventNotificationSounds) { + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create( + new ResourceLocation("notenoughupdates:calendar_notif_jingle") + )); + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create( + new ResourceLocation("notenoughupdates:calendar_notif_in") + )); + } + jingleIndex = -15*20; + } else if(jingleIndex >= 1) { + if (NotEnoughUpdates.INSTANCE.config.calendar.eventNotificationSounds) { + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create( + new ResourceLocation("notenoughupdates:calendar_notif_in") + )); + } + jingleIndex = -15*20; + } else if(jingleIndex < -1) { + jingleIndex++; + } + if(jingleIndex == -20*6-10) { + if(NotEnoughUpdates.INSTANCE.config.calendar.eventNotificationSounds) { + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create( + new ResourceLocation("notenoughupdates:calendar_notif_out") + )); + } + } + + if(farmingEventTypes == null) { + farmingEventTypes = NotEnoughUpdates.INSTANCE.manager.getJsonFromFile(new File(NotEnoughUpdates.INSTANCE.manager.configLocation, + "farmingEventTypes.json")); + if(farmingEventTypes == null) { + farmingEventTypes = new JsonObject(); + } + } + + if(!(Minecraft.getMinecraft().currentScreen instanceof GuiChest)) { + jfFavouriteSelect = null; + if(eventMap.isEmpty() || eventMap.size() <= 20) { + long currentTime = System.currentTimeMillis(); + long floorHour = (currentTime/HOUR)*HOUR; + for(int i=0; i<15; i++) { + long daEvent = floorHour+i*HOUR+DA_OFFSET; + long jfEvent = floorHour+i*HOUR+JF_OFFSET; + + if(daEvent > currentTime) { + eventMap.computeIfAbsent(daEvent, k->new HashSet<>()).add(new SBEvent("dark_auction", + EnumChatFormatting.DARK_PURPLE+"Dark Auction", DA_STACK, null, MINUTE*5)); + } + if(jfEvent > currentTime) { + SBEvent jf = new SBEvent("jacob_farming", + EnumChatFormatting.YELLOW+"Jacob's Farming Contest", JF_STACK, null, MINUTE*20); + if(farmingEventTypes != null && farmingEventTypes.has(""+jfEvent) && + farmingEventTypes.get(""+jfEvent).isJsonArray()) { + JsonArray arr = farmingEventTypes.get(""+jfEvent).getAsJsonArray(); + jf.desc = new ArrayList<>(); + for(JsonElement e : arr) { + jf.desc.add(EnumChatFormatting.YELLOW+"\u25CB "+e.getAsString()); + jf.id += ":" + e.getAsString(); + } + } + eventMap.computeIfAbsent(jfEvent, k->new HashSet<>()).add(jf); + } + } + } + return; + } + + GuiChest eventGui = (GuiChest) Minecraft.getMinecraft().currentScreen; + ContainerChest cc = (ContainerChest) eventGui.inventorySlots; + String containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText(); + + Matcher matcher = CALENDAR_PATTERN.matcher(Utils.cleanColour(containerName)); + if(farmingEventTypes != null && matcher.matches()) { + try { + int year = Integer.parseInt(matcher.group(2)); + int skyblockDays = year * 12 * 31; + + String month = matcher.group(1); + boolean spring = month.endsWith("Spring"); + boolean summer = month.endsWith("Summer"); + boolean autumn = month.endsWith("Autumn"); + boolean winter = month.endsWith("Winter"); + if(spring || summer || autumn || winter) { + if(spring) { + skyblockDays += 1*31; + } else if(summer) { + skyblockDays += 4*31; + } else if(autumn) { + skyblockDays += 7*31; + } else { + skyblockDays += 10*31; + } + if(month.startsWith("Early")) { + skyblockDays -= 31; + } else if(month.startsWith("Late")) { + skyblockDays += 31; + } + + long start = SKYBLOCK_START + skyblockDays*20*MINUTE; + + boolean changed = false; + for(int i=0; i<31; i++) { + ItemStack item = cc.getLowerChestInventory().getStackInSlot(1+(i%7)+(i/7)*9); + + JsonArray array = new JsonArray(); + if(item.getTagCompound() != null) { + NBTTagCompound tag = item.getTagCompound(); + + if(tag.hasKey("display", 10)) { + NBTTagCompound display = tag.getCompoundTag("display"); + if (display.hasKey("Lore", 9)) { + NBTTagList list = display.getTagList("Lore", 8); + for(int j=0; j currentTime) { + eventMap.computeIfAbsent(daEvent, k->new HashSet<>()).add(new SBEvent("dark_auction", + EnumChatFormatting.DARK_PURPLE+"Dark Auction", DA_STACK, null, MINUTE*5)); + } + if(jfEvent > currentTime) { + SBEvent jf = new SBEvent("jacob_farming", + EnumChatFormatting.YELLOW+"Jacob's Farming Contest", JF_STACK, null, MINUTE*20); + if(farmingEventTypes != null && farmingEventTypes.has(""+jfEvent) && + farmingEventTypes.get(""+jfEvent).isJsonArray()) { + JsonArray arr = farmingEventTypes.get(""+jfEvent).getAsJsonArray(); + jf.desc = new ArrayList<>(); + for(JsonElement e : arr) { + jf.desc.add(EnumChatFormatting.YELLOW+"\u25CB "+e.getAsString()); + jf.id += ":" + e.getAsString(); + } + } + eventMap.computeIfAbsent(jfEvent, k->new HashSet<>()).add(jf); + } + } + } + return; + } + + if(!containerName.trim().equals("Calendar and Events")) { + setEnabled(false); + return; + } + + eventMap.clear(); + + long currentTime = System.currentTimeMillis(); + long floorHour = (currentTime/HOUR)*HOUR; + for(int i=0; i<15; i++) { + long daEvent = floorHour+i*HOUR+DA_OFFSET; + long jfEvent = floorHour+i*HOUR+JF_OFFSET; + + if(daEvent > currentTime) { + eventMap.computeIfAbsent(daEvent, k->new HashSet<>()).add(new SBEvent("dark_auction", + EnumChatFormatting.DARK_PURPLE+"Dark Auction", DA_STACK, null, MINUTE*5)); + } + if(jfEvent > currentTime) { + SBEvent jf = new SBEvent("jacob_farming", + EnumChatFormatting.YELLOW+"Jacob's Farming Contest", JF_STACK, null, MINUTE*20); + if(farmingEventTypes != null && farmingEventTypes.has(""+jfEvent) && + farmingEventTypes.get(""+jfEvent).isJsonArray()) { + JsonArray arr = farmingEventTypes.get(""+jfEvent).getAsJsonArray(); + jf.desc = new ArrayList<>(); + for(JsonElement e : arr) { + jf.desc.add(EnumChatFormatting.YELLOW+"\u25CB "+e.getAsString()); + jf.id += ":" + e.getAsString(); + } + } + eventMap.computeIfAbsent(jfEvent, k->new HashSet<>()).add(jf); + } + } + + String lastsForText = EnumChatFormatting.GRAY+"Event lasts for "+EnumChatFormatting.YELLOW; + String startsInText = EnumChatFormatting.GRAY+"Starts in: "+EnumChatFormatting.YELLOW; + for(int i=0; i<21; i++) { + int itemIndex = 10+i+(i/7)*2; + ItemStack item = cc.getLowerChestInventory().getStackInSlot(itemIndex); + + if(item != null && item.getTagCompound() != null) { + NBTTagCompound tag = item.getTagCompound(); + + if(tag.hasKey("display", 10)) { + NBTTagCompound display = tag.getCompoundTag("display"); + if (display.hasKey("Lore", 9)) { + NBTTagList list = display.getTagList("Lore", 8); + + String first = list.getStringTagAt(0); + if(first.startsWith(startsInText)) { + String time = Utils.cleanColour(first.substring(startsInText.length())); + long eventTime = currentTime + getTimeOffset(time); + + long lastsFor = -1; + + List desc = new ArrayList<>(); + boolean foundBreak = false; + for(int index=1; indexnew HashSet<>()).add(new SBEvent( + getIdForDisplayName(item.getDisplayName()), item.getDisplayName(), + item, desc, lastsFor)); + } + } + } + } + } + } + + private static String getIdForDisplayName(String displayName) { + return Utils.cleanColour(displayName) + .toLowerCase() + .replaceAll("[0-9]+th", "") + .replaceAll("[0-9]+nd", "") + .replaceAll("[0-9]+rd", "") + .replaceAll("[0-9]+st", "") + .replaceAll("[^a-z ]", "") + .trim() + .replace(" ", "_"); + } + + + @SubscribeEvent + public void onGuiScreenMouse(GuiScreenEvent.MouseInputEvent.Pre event) { + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; + int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; + + if(!enabled) { + if(Mouse.getEventButtonState() && NotEnoughUpdates.INSTANCE.config.calendar.showEventTimerInInventory && + Minecraft.getMinecraft().currentScreen instanceof GuiContainer) { + xSize = 168; + ySize = 20; + + guiLeft = (width - xSize)/2; + guiTop = 5; + + if(mouseX >= guiLeft && mouseX <= guiLeft+xSize) { + if(mouseY >= guiTop && mouseY <= guiTop+ySize) { + ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, "/neucalendar"); + } + } + } + + return; + } + + if(!(Minecraft.getMinecraft().currentScreen instanceof GuiChest)) { + return; + } + + GuiChest eventGui = (GuiChest) Minecraft.getMinecraft().currentScreen; + ContainerChest cc = (ContainerChest) eventGui.inventorySlots; + String containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText(); + if(!containerName.trim().equals("Calendar and Events")) { + setEnabled(false); + return; + } + + event.setCanceled(true); + + xSize = 168; + ySize = 170; + guiLeft = (width - xSize) / 2; + guiTop = (height - ySize) / 2; + + if(Mouse.getEventButtonState()) { + if(jfFavouriteSelect != null) { + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + int arrowLen = fr.getStringWidth("> "); + int selectSizeX = 0; + int selectStringIndex = 0; + for (String s : jfFavouriteSelect) { + int sWidth = fr.getStringWidth(s); + if (selectStringIndex + 1 == jfFavouriteSelectIndex) sWidth += arrowLen; + if (sWidth > selectSizeX) { + selectSizeX = sWidth; + } + selectStringIndex++; + } + selectSizeX += +10; + + if(mouseX > jfFavouriteSelectX && mouseX < jfFavouriteSelectX + selectSizeX && + mouseY > jfFavouriteSelectY && mouseY < jfFavouriteSelectY + 18 + jfFavouriteSelect.size() * 10) { + jfFavouriteSelectIndex = Math.max(0, (mouseY - jfFavouriteSelectY - 5)/10); + + List eventFavourites = NotEnoughUpdates.INSTANCE.config.hidden.eventFavourites; + String id = null; + if(jfFavouriteSelectIndex == 0) { + id = "jacob_farming"; + } else if(jfFavouriteSelectIndex-1 < jfFavouriteSelect.size()) { + id = "jacob_farming:"+jfFavouriteSelect.get(jfFavouriteSelectIndex-1); + } + if(id != null) { + if (eventFavourites.contains(id)) { + eventFavourites.remove(id); + } else { + eventFavourites.add(id); + } + } + } else { + jfFavouriteSelect = null; + } + } + if(mouseY >= guiTop+26 && mouseY <= guiTop+26+141) { + if(mouseX >= guiLeft+151 && mouseX <= guiLeft+151+14) { + if(mouseY <= guiTop+26+70) { + Minecraft.getMinecraft().playerController.windowClick(cc.windowId, + 50, 2, 3, Minecraft.getMinecraft().thePlayer); + } else { + Minecraft.getMinecraft().playerController.windowClick(cc.windowId, + 45, 2, 3, Minecraft.getMinecraft().thePlayer); + } + } + } + } + } + + @SubscribeEvent + public void onGuiScreenKeyboard(GuiScreenEvent.KeyboardInputEvent.Pre event) { + if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) { + if(jfFavouriteSelect != null) { + jfFavouriteSelect = null; + event.setCanceled(true); + } + } else { + if (!enabled) { + return; + } + + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiChest)) { + return; + } + + GuiChest eventGui = (GuiChest) Minecraft.getMinecraft().currentScreen; + ContainerChest cc = (ContainerChest) eventGui.inventorySlots; + String containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText(); + if (!containerName.trim().equals("Calendar and Events")) { + setEnabled(false); + return; + } + + event.setCanceled(true); + xSize = 168; + ySize = 170; + + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; + int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; + guiLeft = (width - xSize) / 2; + guiTop = (height - ySize) / 2; + + int keyPressed = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey(); + if(Keyboard.getEventKeyState()) { + if(jfFavouriteSelect != null) { + if(keyPressed == Keyboard.KEY_DOWN) { + jfFavouriteSelectIndex++; + jfFavouriteSelectIndex %= jfFavouriteSelect.size()+1; + } else if(keyPressed == Keyboard.KEY_UP) { + jfFavouriteSelectIndex--; + if(jfFavouriteSelectIndex < 0) jfFavouriteSelectIndex = jfFavouriteSelect.size(); + } else if(keyPressed == Keyboard.KEY_RIGHT || keyPressed == Keyboard.KEY_RETURN) { + List eventFavourites = NotEnoughUpdates.INSTANCE.config.hidden.eventFavourites; + String id = null; + if(jfFavouriteSelectIndex == 0) { + id = "jacob_farming"; + } else if(jfFavouriteSelectIndex-1 < jfFavouriteSelect.size()) { + id = "jacob_farming:"+jfFavouriteSelect.get(jfFavouriteSelectIndex-1); + } + if(id != null) { + if (eventFavourites.contains(id)) { + eventFavourites.remove(id); + } else { + eventFavourites.add(id); + } + } + } else if(keyPressed == Keyboard.KEY_LEFT || + keyPressed == NotEnoughUpdates.INSTANCE.manager.keybindFavourite.getKeyCode()) { + jfFavouriteSelect = null; + } + } else if(keyPressed == NotEnoughUpdates.INSTANCE.manager.keybindFavourite.getKeyCode()) { + String id = null; + + //Daily Events + int index = 0; + out: + for (Map.Entry> sbEvents : eventMap.entrySet()) { + for (SBEvent sbEvent : sbEvents.getValue()) { + int x = guiLeft + 29 + 17 * (index % 3); + int y = guiTop + 44 + 17 * (index / 3); + + if (mouseX >= x && mouseX <= x + 16) { + if (mouseY >= y && mouseY <= y + 16) { + id = sbEvent.id; + } + } + + if (++index >= 21) break out; + } + } + + //Special Events + for (int i = 0; i < 21; i++) { + int itemIndex = 10 + i + (i / 7) * 2; + ItemStack item = cc.getLowerChestInventory().getStackInSlot(itemIndex); + if (item == null) continue; + + int x = guiLeft + 89 + 17 * (i % 3); + int y = guiTop + 44 + 17 * (i / 3); + + if (mouseX >= x && mouseX <= x + 16) { + if (mouseY >= y && mouseY <= y + 16) { + id = getIdForDisplayName(item.getDisplayName()); + } + } + } + + if (id != null) { + String[] split = id.split(":"); + if(split.length > 1 && split[0].equals("jacob_farming")) { + jfFavouriteSelect = new ArrayList<>(); + for(int i=1; i eventFavourites = NotEnoughUpdates.INSTANCE.config.hidden.eventFavourites; + if (eventFavourites.contains(id)) { + eventFavourites.remove(id); + } else { + eventFavourites.add(id); + } + } + } + } + } + } + } + + @SubscribeEvent(priority = EventPriority.LOW) + public void onGuiDraw(RenderGameOverlayEvent.Post event) { + if(NotEnoughUpdates.INSTANCE.config.calendar.eventNotifications && + event.type == RenderGameOverlayEvent.ElementType.ALL) { + GlStateManager.pushMatrix(); + GlStateManager.translate(0, 0, 10); + if(!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer) && NotEnoughUpdates.INSTANCE.isOnSkyblock()) { + long currentTime = System.currentTimeMillis(); + + long timeUntilNext = 0; + SBEvent nextEvent = null; + long timeUntilFirst = 0; + SBEvent firstEvent = null; + + List eventFavourites = NotEnoughUpdates.INSTANCE.config.hidden.eventFavourites; + + //Daily Events + out: + for(Map.Entry> sbEvents : eventMap.entrySet()) { + for(SBEvent sbEvent : sbEvents.getValue()) { + long timeUntilMillis = sbEvents.getKey() - currentTime; + + if(timeUntilMillis < -10*SECOND) { + continue; + } + + if(firstEvent == null) { + firstEvent = sbEvent; + timeUntilFirst = timeUntilMillis; + } + + String[] split = sbEvent.id.split(":"); + boolean containsId = false; + for(int i=1; i 0 && currentTime - spookyStart < HOUR && + NotEnoughUpdates.INSTANCE.config.calendar.spookyNightNotification) { + long delta = (currentTime - SKYBLOCK_START) % (20*MINUTE) - 19*50*SECOND - 10*SECOND; + if(delta < 500 && delta > -8500) { + event = new SBEvent("spooky_festival_7pm", "Spooky Festival 7pm", new ItemStack(Items.bone), null); + timeUntil = delta; + } + } + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + + int ySize = 32; + int xSize = 160; + int guiLeft = (width - xSize)/2; + int guiTop = 5; + + boolean preNotification = false; + long preNotificationTime = SECOND*NotEnoughUpdates.INSTANCE.config.calendar.startingSoonTime; + + if(preNotificationTime > 500 && timeUntil > 500) { + timeUntil = timeUntil - preNotificationTime; + preNotification = true; + } + + if(timeUntil < 500 && timeUntil > -8500) { + if(jingleIndex == -1) { + if(preNotification) { + jingleIndex = 1; + } else { + jingleIndex = 0; + } + } + + float offset; + float factor = 0; + if(timeUntil > 0) { + factor = (timeUntil/500f); + } else if(timeUntil < -8000) { + factor = -((timeUntil+8000)/500f); + } + factor = (float)(1.06f/(1+Math.exp(-7*(factor-0.5f)))-0.03f); + offset = -(ySize+5)*factor; + float y = guiTop+offset; + + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(TOAST); + Utils.drawTexturedRect(guiLeft, y, xSize, ySize, GL11.GL_NEAREST); + + GlStateManager.translate(0, y, 0); + Utils.drawItemStack(event.stack, guiLeft+6, 8); + GlStateManager.translate(0, -y, 0); + + if(preNotification) { + String starting = EnumChatFormatting.YELLOW+"Event Starting in "+prettyTime(preNotificationTime, true)+"!"; + int startingWidth = fr.getStringWidth(starting); + fr.drawString(starting, Math.max(guiLeft+23, width/2f-startingWidth/2f), y+7, -1, false); + } else { + Utils.drawStringCentered(EnumChatFormatting.YELLOW+"Event Starting Now!", fr, width/2, y+11, false, -1); + } + + int displayWidth = fr.getStringWidth(event.display); + fr.drawString(event.display, Math.max(guiLeft+23, width/2f-displayWidth/2f), y+17, -1, false); + + + return true; + } + return false; + } + + @SubscribeEvent + public void onGuiScreenDrawTimer(GuiScreenEvent.BackgroundDrawnEvent event) { + blurBackground(); + if(!drawTimerForeground) { + drawTimer(); + } + GlStateManager.color(1, 1, 1, 1); + GlStateManager.enableBlend(); + } + + @SubscribeEvent + public void onGuiScreenDrawTimer(GuiScreenEvent.DrawScreenEvent.Post event) { + if(drawTimerForeground) { + drawTimer(); + } + } + + public void drawTimer() { + GlStateManager.pushMatrix(); + GlStateManager.translate(0, 0, 10); + if(Minecraft.getMinecraft().currentScreen instanceof GuiContainer && NotEnoughUpdates.INSTANCE.isOnSkyblock()) { + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; + int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; + long currentTime = System.currentTimeMillis(); + + xSize = 168; + ySize = 20; + + long timeUntilNext = 0; + SBEvent nextEvent = null; + long timeUntilFirst = 0; + SBEvent firstEvent = null; + List nextFavourites = new ArrayList<>(); + List nextFavouritesTime = new ArrayList<>(); + long timeUntilMajor = 0; + SBEvent nextMajorEvent = null; + + List eventFavourites = NotEnoughUpdates.INSTANCE.config.hidden.eventFavourites; + + guiLeft = (width - xSize)/2; + guiTop = 5; + + //Daily Events + out: + for(Map.Entry> sbEvents : eventMap.entrySet()) { + for(SBEvent sbEvent : sbEvents.getValue()) { + long timeUntilMillis = sbEvents.getKey() - currentTime; + + if(timeUntilMillis < -10*SECOND) { + continue; + } + + if(sbEvent.id.equals("spooky_festival")) { + if(sbEvents.getKey() > currentTime-HOUR && (sbEvents.getKey() < spookyStart || spookyStart == 0)) { + spookyStart = sbEvents.getKey(); + } + } + + if(nextMajorEvent == null && !sbEvent.id.split(":")[0].equals("jacob_farming") && + !sbEvent.id.equals("dark_auction")) { + nextMajorEvent = sbEvent; + timeUntilMajor = timeUntilMillis; + } + + if(firstEvent == null) { + firstEvent = sbEvent; + timeUntilFirst = timeUntilMillis; + } + + String[] split = sbEvent.id.split(":"); + boolean containsId = false; + for(int i=1; i= 3 && nextMajorEvent != null) { + break out; + } + } + } + + if(nextEvent == null) { + nextEvent = firstEvent; + timeUntilNext = timeUntilFirst; + } + + if(nextEvent != null) { + GlStateManager.translate(0, 0, 50); + boolean toastRendered = renderToast(nextEvent, timeUntilNext); + GlStateManager.translate(0, 0, -50); + if(!toastRendered && !enabled && NotEnoughUpdates.INSTANCE.config.calendar.showEventTimerInInventory) { + List tooltipToDisplay = null; + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.disableFog(); + GlStateManager.disableLighting(); + GlStateManager.disableColorMaterial(); + + renderBlurredBackground(width, height, guiLeft+3, guiTop+3, xSize-6, ySize-6); + + Minecraft.getMinecraft().getTextureManager().bindTexture(DISPLAYBAR); + Utils.drawTexturedRect(guiLeft, guiTop, xSize, 20, GL11.GL_NEAREST); + + String nextS = EnumChatFormatting.YELLOW+"Next: "; + int nextSLen = fr.getStringWidth(nextS); + fr.drawString(nextS, guiLeft+8, guiTop+6, -1, false); + + String until = " "+EnumChatFormatting.YELLOW+prettyTime(timeUntilNext, false); + int untilLen = fr.getStringWidth(until); + + fr.drawString(until, guiLeft+xSize-8-untilLen, guiTop+6, -1, false); + + int eventTitleLen = xSize-16-untilLen-nextSLen; + int displayWidth = fr.getStringWidth(nextEvent.display); + int spaceLen = fr.getCharWidth(' '); + if(displayWidth > eventTitleLen) { + GL11.glEnable(GL11.GL_SCISSOR_TEST); + GL11.glScissor((guiLeft+8+nextSLen)*scaledResolution.getScaleFactor(), + 0, + eventTitleLen*scaledResolution.getScaleFactor(), + Minecraft.getMinecraft().displayHeight); + fr.drawString(nextEvent.display + " " + nextEvent.display, + guiLeft+8+nextSLen-(float)(currentTime/50.0 % (displayWidth+spaceLen)), guiTop+6, -1, false); + GL11.glDisable(GL11.GL_SCISSOR_TEST); + } else { + if(guiLeft+xSize-8-untilLen > (width+displayWidth)/2) { + Utils.drawStringCentered(nextEvent.display, fr,width/2f, guiTop+10, false, -1); + } else { + fr.drawString(nextEvent.display, guiLeft+8+nextSLen, guiTop+6, -1, false); + } + } + + if(mouseX > guiLeft && mouseX < guiLeft+168) { + if(mouseY > guiTop && mouseY < guiTop+20) { + tooltipToDisplay = new ArrayList<>(); + for(int i=0; i= 0) { + tooltipToDisplay.add( EnumChatFormatting.GRAY+"Lasts for: "+EnumChatFormatting.YELLOW+ + prettyTime(sbEvent.lastsFor, true)); + } + if(sbEvent.id.split(":")[0].equals("jacob_farming") && sbEvent.desc != null) { + tooltipToDisplay.addAll(sbEvent.desc); + } + if(nextMajorEvent != null || i < nextFavourites.size()-1) { + tooltipToDisplay.add(""); + } + } + if(nextMajorEvent != null) { + tooltipToDisplay.add(EnumChatFormatting.YELLOW.toString()+EnumChatFormatting.BOLD+"Next Major:"); + tooltipToDisplay.add(nextMajorEvent.display); + tooltipToDisplay.add(EnumChatFormatting.GRAY+"Starts in: "+EnumChatFormatting.YELLOW+prettyTime(timeUntilMajor, false)); + if(nextMajorEvent.lastsFor >= 0) { + tooltipToDisplay.add( EnumChatFormatting.GRAY+"Lasts for: "+EnumChatFormatting.YELLOW+ + prettyTime(nextMajorEvent.lastsFor, true)); + } + } + + + } + } + + drawTimerForeground = false; + if(tooltipToDisplay != null) { + drawTimerForeground = true; + GlStateManager.translate(0, 0, 100); + Utils.drawHoveringText(tooltipToDisplay, mouseX, Math.max(17, mouseY), width, height, -1, fr); + GlStateManager.translate(0, 0, -100); + } + } + } + } + GlStateManager.translate(0, 0, -10); + GlStateManager.popMatrix(); + } + + @SubscribeEvent + public void onGuiDraw(GuiScreenEvent.DrawScreenEvent.Pre event) { + if(!(Minecraft.getMinecraft().currentScreen instanceof GuiChest)) { + return; + } + + if(!enabled) { + return; + } + + GuiChest eventGui = (GuiChest) Minecraft.getMinecraft().currentScreen; + ContainerChest cc = (ContainerChest) eventGui.inventorySlots; + String containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText(); + if(!containerName.trim().equals("Calendar and Events")) { + setEnabled(false); + return; + } + + event.setCanceled(true); + + List tooltipToDisplay = null; + int mouseX = event.mouseX; + int mouseY = event.mouseY; + long currentTime = System.currentTimeMillis(); + + xSize = 168; + ySize = 170; + + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + guiLeft = (width - xSize)/2; + guiTop = (height - ySize)/2; + + Utils.drawGradientRect(0, 0, width, height, -1072689136, -804253680); + + renderBlurredBackground(width, height, guiLeft+3, guiTop+3, 162, 14); + renderBlurredBackground(width, height, guiLeft+3, guiTop+26, 14, 141); + renderBlurredBackground(width, height, guiLeft+151, guiTop+26, 14, 141); + renderBlurredBackground(width, height, guiLeft+26, guiTop+26, 116, 141); + + Minecraft.getMinecraft().getTextureManager().bindTexture(BACKGROUND); + Utils.drawTexturedRect(guiLeft, guiTop, xSize, ySize, GL11.GL_NEAREST); + + GlStateManager.translate(0, 0, 10); + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + + fr.drawString("Daily", guiLeft+29, guiTop+30, 0xffffaa00); + int specialLen = fr.getStringWidth("Special"); + fr.drawString("Special", guiLeft+139-specialLen, guiTop+30, 0xffffaa00); + + ItemStack mayorStack = cc.getLowerChestInventory().getStackInSlot(46); + if(mayorStack != null) { + String mayor = mayorStack.getDisplayName(); + float verticalHeight = Utils.getVerticalHeight(mayor); + Utils.drawStringVertical(mayor, fr, guiLeft+8, guiTop+96-verticalHeight/2, + false, -1); + } + + String calendar = EnumChatFormatting.GREEN+"Calendar"; + float calendarHeight = Utils.getVerticalHeight(calendar); + Utils.drawStringVertical(calendar, fr, guiLeft+xSize-12, guiTop+60-calendarHeight/2, + false, -1); + + String rewards = EnumChatFormatting.GOLD+"Rewards"; + float rewardsHeight = Utils.getVerticalHeight(rewards); + Utils.drawStringVertical(rewards, fr, guiLeft+xSize-12, guiTop+132-rewardsHeight/2, + false, -1); + + if(mouseY >= guiTop+26 && mouseY <= guiTop+26+141) { + if(mouseX >= guiLeft+3 && mouseX <= guiLeft+3+14) { + if(mayorStack != null) tooltipToDisplay = mayorStack.getTooltip(Minecraft.getMinecraft().thePlayer, false); + } else if(mouseX >= guiLeft+151 && mouseX <= guiLeft+151+14) { + if(mouseY <= guiTop+26+70) { + ItemStack calendarStack = cc.getLowerChestInventory().getStackInSlot(50); + if(calendarStack != null) tooltipToDisplay = calendarStack.getTooltip(Minecraft.getMinecraft().thePlayer, false); + } else { + ItemStack rewardsStack = cc.getLowerChestInventory().getStackInSlot(45); + if(rewardsStack != null) tooltipToDisplay = rewardsStack.getTooltip(Minecraft.getMinecraft().thePlayer, false); + } + } + } + + long timeUntilNext = 0; + SBEvent nextEvent = null; + long timeUntilFirst = 0; + SBEvent firstEvent = null; + List eventFavourites = NotEnoughUpdates.INSTANCE.config.hidden.eventFavourites; + + //Daily Events + int index = 0; + out: + for(Map.Entry> sbEvents : eventMap.entrySet()) { + for(SBEvent sbEvent : sbEvents.getValue()) { + long timeUntilMillis = sbEvents.getKey() - currentTime; + + int x = guiLeft+29+17*(index%3); + int y = guiTop+44+17*(index/3); + + if(sbEvent.id.equals("spooky_festival")) { + if(sbEvents.getKey() > currentTime-HOUR && (sbEvents.getKey() < spookyStart || spookyStart == 0)) { + spookyStart = sbEvents.getKey(); + } + } + + if(index >= 21) { + if(nextEvent != null) break; + if(eventFavourites.isEmpty()) { + nextEvent = sbEvent; + timeUntilNext = timeUntilMillis; + } else if(eventFavourites.contains(sbEvent.id)) { + nextEvent = sbEvent; + timeUntilNext = timeUntilMillis; + } + continue; + } + + if(firstEvent == null) { + firstEvent = sbEvent; + timeUntilFirst = timeUntilMillis; + } + + String[] split = sbEvent.id.split(":"); + boolean containsId = false; + for(int i=1; i= x && mouseX <= x+16) { + if(mouseY >= y && mouseY <= y+16) { + tooltipToDisplay = Utils.createList(sbEvent.display, + EnumChatFormatting.GRAY+"Starts in: "+EnumChatFormatting.YELLOW+prettyTime(timeUntilMillis, false)); + if(sbEvent.lastsFor >= 0) { + tooltipToDisplay.add( EnumChatFormatting.GRAY+"Lasts for: "+EnumChatFormatting.YELLOW+ + prettyTime(sbEvent.lastsFor, true)); + } + if(sbEvent.desc != null) { + tooltipToDisplay.add(""); + tooltipToDisplay.addAll(sbEvent.desc); + } + } + } + + index++; + } + } + + //Special Events + for(int i=0; i<21; i++) { + int itemIndex = 10+i+(i/7)*2; + ItemStack item = cc.getLowerChestInventory().getStackInSlot(itemIndex); + if(item == null) continue; + + String eventId = getIdForDisplayName(item.getDisplayName()); + + NBTTagCompound tag = item.getTagCompound(); + tag.setString("event_id", eventId); + item.setTagCompound(tag); + + int x = guiLeft+89+17*(i%3); + int y = guiTop+44+17*(i/3); + + if(eventFavourites.contains(eventId)) { + GlStateManager.depthMask(false); + GlStateManager.translate(0, 0, -2); + Gui.drawRect(x, y, x+16, y+16, 0xcfffbf49); + GlStateManager.translate(0, 0, 2); + GlStateManager.depthMask(true); + } + + Utils.drawItemStackWithText(item, x, y, ""+(i+1)); + + if(mouseX >= x && mouseX <= x+16) { + if(mouseY >= y && mouseY <= y+16) { + tooltipToDisplay = item.getTooltip(Minecraft.getMinecraft().thePlayer, false); + } + } + } + + if(nextEvent == null) { + nextEvent = firstEvent; + timeUntilNext = timeUntilFirst; + } + + if(nextEvent != null) { + String nextS = EnumChatFormatting.YELLOW+"Next: "; + int nextSLen = fr.getStringWidth(nextS); + fr.drawString(nextS, guiLeft+8, guiTop+6, -1, false); + + String until = " "+EnumChatFormatting.YELLOW+prettyTime(timeUntilNext, false); + int untilLen = fr.getStringWidth(until); + + fr.drawString(until, guiLeft+xSize-8-untilLen, guiTop+6, -1, false); + + int eventTitleLen = xSize-16-untilLen-nextSLen; + int displayWidth = fr.getStringWidth(nextEvent.display); + int spaceLen = fr.getCharWidth(' '); + if(displayWidth > eventTitleLen) { + GL11.glEnable(GL11.GL_SCISSOR_TEST); + GL11.glScissor((guiLeft+8+nextSLen)*scaledResolution.getScaleFactor(), + 0, + eventTitleLen*scaledResolution.getScaleFactor(), + Minecraft.getMinecraft().displayHeight); + fr.drawString(nextEvent.display + " " + nextEvent.display, + guiLeft+8+nextSLen-(float)(currentTime/50.0 % (displayWidth+spaceLen)), guiTop+6, -1, false); + GL11.glDisable(GL11.GL_SCISSOR_TEST); + } else { + fr.drawString(nextEvent.display, guiLeft+8+nextSLen, guiTop+6, -1, false); + } + + if(mouseX > guiLeft && mouseX < guiLeft+168) { + if(mouseY > guiTop && mouseY < guiTop+20) { + tooltipToDisplay = Utils.createList(nextEvent.display, + EnumChatFormatting.GRAY+"Starts in: "+EnumChatFormatting.YELLOW+prettyTime(timeUntilNext, false)); + if(nextEvent.lastsFor >= 0) { + tooltipToDisplay.add( EnumChatFormatting.GRAY+"Lasts for: "+EnumChatFormatting.YELLOW+ + prettyTime(nextEvent.lastsFor, true)); + } + if(nextEvent.desc != null) { + tooltipToDisplay.add(""); + tooltipToDisplay.addAll(nextEvent.desc); + } + } + } + } + + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(help); + Utils.drawTexturedRect(guiLeft+xSize-18, guiTop+ySize+2, 16, 16, GL11.GL_LINEAR); + + if(mouseX >= guiLeft+xSize-18 && mouseX < guiLeft+xSize-2) { + if(mouseY >= guiTop+ySize+2 && mouseY <= guiTop+ySize+18) { + tooltipToDisplay = new ArrayList<>(); + tooltipToDisplay.add(EnumChatFormatting.AQUA+"NEU Calendar Help"); + tooltipToDisplay.add(EnumChatFormatting.YELLOW+"This calendar displays various skyblock events"); + tooltipToDisplay.add(EnumChatFormatting.YELLOW+"'Daily' events are events that happen frequently"); + tooltipToDisplay.add(EnumChatFormatting.YELLOW+"'Special' events are events that happen infrequently"); + tooltipToDisplay.add(EnumChatFormatting.YELLOW+""); + tooltipToDisplay.add(EnumChatFormatting.YELLOW+"The eventbar at the top will also show in your inventory"); + tooltipToDisplay.add(EnumChatFormatting.YELLOW+""); + tooltipToDisplay.add(EnumChatFormatting.YELLOW+"Press 'F' on an event to mark it as a favourite"); + tooltipToDisplay.add(EnumChatFormatting.YELLOW+"Favourited events will show over normal events"); + tooltipToDisplay.add(EnumChatFormatting.YELLOW+"Favourited events will also give a notification when it"); + tooltipToDisplay.add(EnumChatFormatting.YELLOW+"is about to start and when it does start"); + tooltipToDisplay.add(EnumChatFormatting.YELLOW+""); + tooltipToDisplay.add(EnumChatFormatting.DARK_GRAY+"In order to show crop types for Jacob's Farming"); + tooltipToDisplay.add(EnumChatFormatting.DARK_GRAY+"contest, visit the full skyblock calendar and go all"); + tooltipToDisplay.add(EnumChatFormatting.DARK_GRAY+"the way to the end of the skyblock year"); + Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, fr); + tooltipToDisplay = null; + } + } + + if(jfFavouriteSelect != null) { + int arrowLen = fr.getStringWidth("> "); + int selectSizeX = 0; + int selectStringIndex=0; + for(String s : jfFavouriteSelect) { + int sWidth = fr.getStringWidth(s); + if(selectStringIndex+1 == jfFavouriteSelectIndex) sWidth += arrowLen; + if(sWidth > selectSizeX) { + selectSizeX = sWidth; + } + selectStringIndex++; + } + selectSizeX += +10; + + GlStateManager.translate(0, 0, 19); + + Gui.drawRect(jfFavouriteSelectX+2, jfFavouriteSelectY+2, jfFavouriteSelectX+selectSizeX+2, + jfFavouriteSelectY+18+jfFavouriteSelect.size()*10+2, 0xa0000000); + + GlStateManager.depthFunc(GL11.GL_LESS); + GlStateManager.translate(0, 0, 1); + Gui.drawRect(jfFavouriteSelectX+1, jfFavouriteSelectY+1, jfFavouriteSelectX+selectSizeX-1, + jfFavouriteSelectY+18+jfFavouriteSelect.size()*10-1, 0xffc0c0c0); + Gui.drawRect(jfFavouriteSelectX, jfFavouriteSelectY, jfFavouriteSelectX+selectSizeX-1, + jfFavouriteSelectY+18+jfFavouriteSelect.size()*10-1, 0xfff0f0f0); + Gui.drawRect(jfFavouriteSelectX, jfFavouriteSelectY, jfFavouriteSelectX+selectSizeX, + jfFavouriteSelectY+18+jfFavouriteSelect.size()*10, 0xff909090); + GlStateManager.depthFunc(GL11.GL_LEQUAL); + + String all = (NotEnoughUpdates.INSTANCE.config.hidden.eventFavourites.contains("jacob_farming")? + EnumChatFormatting.DARK_GREEN:EnumChatFormatting.DARK_GRAY)+"All"; + if(jfFavouriteSelectIndex == 0) { + fr.drawString(EnumChatFormatting.BLACK+"> "+all, jfFavouriteSelectX+5, jfFavouriteSelectY+5, 0xff000000); + } else { + fr.drawString(all, jfFavouriteSelectX+5, jfFavouriteSelectY+5, 0xff000000); + } + + fr.drawString(EnumChatFormatting.BLACK+"> ", jfFavouriteSelectX+6, + jfFavouriteSelectY+10*jfFavouriteSelectIndex+5, 0xff000000); + + selectStringIndex=0; + for(String s : jfFavouriteSelect) { + EnumChatFormatting colour = NotEnoughUpdates.INSTANCE.config.hidden.eventFavourites.contains("jacob_farming:"+s) + ? EnumChatFormatting.DARK_GREEN : EnumChatFormatting.DARK_GRAY; + s = (selectStringIndex+1 == jfFavouriteSelectIndex ? EnumChatFormatting.BLACK+"> " : "") + colour + s; + fr.drawString(s, jfFavouriteSelectX+5, jfFavouriteSelectY+10*selectStringIndex+15, 0xff000000); + selectStringIndex++; + } + GlStateManager.translate(0, 0, -20); + } else if(tooltipToDisplay != null) { + Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, fr); + } + + GlStateManager.translate(0, 0, -10); + + } + + private String prettyTime(long millis, boolean trimmed) { + long seconds = millis / 1000 % 60; + long minutes = (millis / 1000 / 60) % 60; + long hours = (millis / 1000 / 60 / 60) % 24; + long days = (millis / 1000 / 60 / 60 / 24); + + String endsIn = ""; + if(millis < 0) { + endsIn += "Now!"; + } else if(minutes == 0 && hours == 0 && days == 0) { + endsIn += seconds + "s"; + } else if(hours==0 && days==0) { + if(trimmed && seconds == 0) { + endsIn += minutes + "m"; + } else { + endsIn += minutes + "m" + seconds + "s"; + } + } else if(days==0) { + if(hours <= 6) { + if(trimmed && seconds == 0) { + if(minutes == 0) { + endsIn += hours + "h"; + } else { + endsIn += hours + "h" + minutes + "m"; + } + } else { + endsIn += hours + "h" + minutes + "m" + seconds + "s"; + } + } else { + endsIn += hours + "h"; + } + } else { + endsIn += days + "d" + hours + "h"; + } + + return endsIn; + } + + Shader blurShaderHorz = null; + Framebuffer blurOutputHorz = null; + Shader blurShaderVert = null; + Framebuffer blurOutputVert = null; + + /** + * Creates a projection matrix that projects from our coordinate space [0->width; 0->height] to OpenGL coordinate + * space [-1 -> 1; 1 -> -1] (Note: flipped y-axis). + * + * This is so that we can render to and from the framebuffer in a way that is familiar to us, instead of needing to + * apply scales and translations manually. + */ + private Matrix4f createProjectionMatrix(int width, int height) { + Matrix4f projMatrix = new Matrix4f(); + projMatrix.setIdentity(); + projMatrix.m00 = 2.0F / (float)width; + projMatrix.m11 = 2.0F / (float)(-height); + projMatrix.m22 = -0.0020001999F; + projMatrix.m33 = 1.0F; + projMatrix.m03 = -1.0F; + projMatrix.m13 = 1.0F; + projMatrix.m23 = -1.0001999F; + return projMatrix; + } + + private double lastBgBlurFactor = -1; + private void blurBackground() { + if(!OpenGlHelper.isFramebufferEnabled()) return; + + int width = Minecraft.getMinecraft().displayWidth; + int height = Minecraft.getMinecraft().displayHeight; + + if(blurOutputHorz == null) { + blurOutputHorz = new Framebuffer(width, height, false); + blurOutputHorz.setFramebufferFilter(GL11.GL_NEAREST); + } + if(blurOutputVert == null) { + blurOutputVert = new Framebuffer(width, height, false); + blurOutputVert.setFramebufferFilter(GL11.GL_NEAREST); + } + if(blurOutputHorz.framebufferWidth != width || blurOutputHorz.framebufferHeight != height) { + blurOutputHorz.createBindFramebuffer(width, height); + blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); + Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); + } + if(blurOutputVert.framebufferWidth != width || blurOutputVert.framebufferHeight != height) { + blurOutputVert.createBindFramebuffer(width, height); + blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height)); + Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); + } + + if(blurShaderHorz == null) { + try { + blurShaderHorz = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", + Minecraft.getMinecraft().getFramebuffer(), blurOutputHorz); + blurShaderHorz.getShaderManager().getShaderUniform("BlurDir").set(1, 0); + blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); + } catch(Exception e) { } + } + if(blurShaderVert == null) { + try { + blurShaderVert = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", + blurOutputHorz, blurOutputVert); + blurShaderVert.getShaderManager().getShaderUniform("BlurDir").set(0, 1); + blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height)); + } catch(Exception e) { } + } + if(blurShaderHorz != null && blurShaderVert != null) { + if(15 != lastBgBlurFactor) { + blurShaderHorz.getShaderManager().getShaderUniform("Radius").set((float)15); + blurShaderVert.getShaderManager().getShaderUniform("Radius").set((float)15); + lastBgBlurFactor = 15; + } + GL11.glPushMatrix(); + blurShaderHorz.loadShader(0); + blurShaderVert.loadShader(0); + GlStateManager.enableDepth(); + GL11.glPopMatrix(); + + Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); + } + } + + /** + * Renders a subsection of the blurred framebuffer on to the corresponding section of the screen. + * Essentially, this method will "blur" the background inside the bounds specified by [x->x+blurWidth, y->y+blurHeight] + */ + public void renderBlurredBackground(int width, int height, int x, int y, int blurWidth, int blurHeight) { + if(!OpenGlHelper.isFramebufferEnabled()) return; + + float uMin = x/(float)width; + float uMax = (x+blurWidth)/(float)width; + float vMin = (height-y)/(float)height; + float vMax = (height-y-blurHeight)/(float)height; + + GlStateManager.depthMask(false); + blurOutputVert.bindFramebufferTexture(); + GlStateManager.color(1f, 1f, 1f, 1f); + Utils.drawTexturedRect(x, y, blurWidth, blurHeight, uMin, uMax, vMin, vMax); + blurOutputVert.unbindFramebufferTexture(); + GlStateManager.depthMask(true); + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiEnchantColour.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiEnchantColour.java new file mode 100644 index 00000000..e6beb660 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiEnchantColour.java @@ -0,0 +1,249 @@ +package io.github.moulberry.notenoughupdates.miscgui; + +import com.google.common.base.Splitter; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.util.lerp.LerpingInteger; +import io.github.moulberry.notenoughupdates.itemeditor.GuiElementTextField; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class GuiEnchantColour extends GuiScreen { + + public static final ResourceLocation custom_ench_colour = new ResourceLocation("notenoughupdates:custom_ench_colour.png"); + + private int guiLeft; + private int guiTop; + private final int xSize = 176; + private int ySize = 0; + + private List getEnchantColours() { + return NotEnoughUpdates.INSTANCE.config.hidden.enchantColours; + } + + public static final Splitter splitter = Splitter.on(":").limit(4); + + private HashMap comparators = new HashMap<>(); + private List guiElementTextFields = new ArrayList<>(); + + private LerpingInteger scroll = new LerpingInteger(0, 100); + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + drawDefaultBackground(); + + List enchantColours = getEnchantColours(); + + ySize = 53+25*enchantColours.size(); + guiLeft = (width-xSize)/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(); + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(custom_ench_colour); + Utils.drawTexturedRect(guiLeft, guiTop, xSize, 21, 0, 1, 0, 21/78f, GL11.GL_NEAREST); + Utils.drawTexturedRect(guiLeft, guiTop+ySize-32, xSize, 32, 0, 1, 46/78f, 1, GL11.GL_NEAREST); + + fontRendererObj.drawString("Ench Name", guiLeft+10, guiTop+7, 4210752); + fontRendererObj.drawString("CMP", guiLeft+71, guiTop+7, 4210752); + fontRendererObj.drawString("LVL", guiLeft+96, guiTop+7, 4210752); + fontRendererObj.drawString("COL", guiLeft+121, guiTop+7, 4210752); + fontRendererObj.drawString("DEL", guiLeft+146, guiTop+7, 4210752); + + Utils.drawStringCentered("Add Ench Colour", fontRendererObj, guiLeft+xSize/2, guiTop+ySize-20, false, 4210752); + + int yIndex = 0; + for(String str : enchantColours) { + Minecraft.getMinecraft().getTextureManager().bindTexture(custom_ench_colour); + GlStateManager.color(1, 1, 1, 1); + Utils.drawTexturedRect(guiLeft, guiTop+21+yIndex*25, xSize, 25, 0, 1, 21/78f, 46/78f, GL11.GL_NEAREST); + + List colourOps = splitter.splitToList(str); + String enchantName = getColourOpIndex(colourOps, 0); + String comparator = getColourOpIndex(colourOps, 1); + String comparison = getColourOpIndex(colourOps, 2); + String colourCode = getColourOpIndex(colourOps, 3); + + if(colourCode.length() > 1) colourCode = String.valueOf(colourCode.toLowerCase().charAt(0)); + if(comparator.length() > 1) comparator = String.valueOf(comparator.toLowerCase().charAt(0)); + + Utils.drawStringCentered(comparator, fontRendererObj, guiLeft+81, guiTop+33+25*yIndex, false, 4210752); + + if(guiElementTextFields.size() <= yIndex) { + guiElementTextFields.add(new GuiElementTextField[3]); + } + if(guiElementTextFields.get(yIndex)[0] == null) { + guiElementTextFields.get(yIndex)[0] = new GuiElementTextField(enchantName, GuiElementTextField.SCALE_TEXT); + guiElementTextFields.get(yIndex)[0].setSize(56, 20); + } + if(guiElementTextFields.get(yIndex)[1] == null) { + guiElementTextFields.get(yIndex)[1] = new GuiElementTextField(comparison, + GuiElementTextField.SCALE_TEXT|GuiElementTextField.NUM_ONLY|GuiElementTextField.NO_SPACE); + guiElementTextFields.get(yIndex)[1].setSize(20, 20); + } + if(guiElementTextFields.get(yIndex)[2] == null) { + guiElementTextFields.get(yIndex)[2] = new GuiElementTextField(colourCode, GuiElementTextField.SCALE_TEXT); + guiElementTextFields.get(yIndex)[2].setSize(20, 20); + } + guiElementTextFields.get(yIndex)[0].setText(enchantName); + guiElementTextFields.get(yIndex)[1].setText(comparison); + comparators.put(yIndex, comparator); + guiElementTextFields.get(yIndex)[2].setText(colourCode); + + guiElementTextFields.get(yIndex)[0].render(guiLeft+10, guiTop+23+25*yIndex); + guiElementTextFields.get(yIndex)[1].render(guiLeft+96, guiTop+23+25*yIndex); + guiElementTextFields.get(yIndex)[2].render(guiLeft+121, guiTop+23+25*yIndex); + + yIndex++; + } + } + + @Override + protected void keyTyped(char typedChar, int keyCode) throws IOException { + super.keyTyped(typedChar, keyCode); + for(int yIndex=0; yIndex NotEnoughUpdates.INSTANCE.config.hidden.enchantColours.size()) { + addOffset = NotEnoughUpdates.INSTANCE.config.hidden.enchantColours.size()-yIndex; + } + System.out.println(addOffset); + NotEnoughUpdates.INSTANCE.config.hidden.enchantColours.add(yIndex+addOffset, + getEnchantOpString(guiElementTextFields.get(yIndex), comparators.get(yIndex))); + if(addOffset != 0) { + GuiElementTextField[] guiElementTextFieldArray = guiElementTextFields.remove(yIndex); + guiElementTextFields.add(yIndex+addOffset, guiElementTextFieldArray); + } + return; + } + } + } + } + + public String getEnchantOpString(GuiElementTextField[] tfs, String comparator) { + StringBuilder enchantOp = new StringBuilder(); + enchantOp.append(tfs[0].getText()); + enchantOp.append(":"); + enchantOp.append(comparator); + enchantOp.append(":"); + enchantOp.append(tfs[1].getText()); + enchantOp.append(":"); + enchantOp.append(tfs[2].getText()); + return enchantOp.toString(); + } + + @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 x && mouseX < x+guiElementTextFields.get(yIndex)[i].getWidth()) { + if(mouseY > guiTop+23+25*yIndex && mouseY < guiTop+23+25*yIndex+20) { + guiElementTextFields.get(yIndex)[i].mouseClicked(mouseX, mouseY, mouseButton); + if(mouseButton == 1) { + NotEnoughUpdates.INSTANCE.config.hidden.enchantColours.remove(yIndex); + NotEnoughUpdates.INSTANCE.config.hidden.enchantColours.add(yIndex, + getEnchantOpString(guiElementTextFields.get(yIndex), comparators.get(yIndex))); + } + continue; + } + } + guiElementTextFields.get(yIndex)[i].otherComponentClick(); + } + comparators.computeIfAbsent(yIndex, k->">"); + if(mouseY > guiTop+23+25*yIndex && mouseY < guiTop+23+25*yIndex+20) { + if(mouseX > guiLeft+71 && mouseX < guiLeft+71+20) { + switch (comparators.get(yIndex)) { + case ">": + comparators.put(yIndex, "="); break; + case "=": + comparators.put(yIndex, "<"); break; + default: + comparators.put(yIndex, ">"); break; + } + NotEnoughUpdates.INSTANCE.config.hidden.enchantColours.remove(yIndex); + NotEnoughUpdates.INSTANCE.config.hidden.enchantColours.add(yIndex, + getEnchantOpString(guiElementTextFields.get(yIndex), comparators.get(yIndex))); + } else if(mouseX > guiLeft+146 && mouseX < guiLeft+146+20) { + NotEnoughUpdates.INSTANCE.config.hidden.enchantColours.remove(yIndex); + guiElementTextFields.remove(yIndex); + comparators.remove(yIndex); + } + } + } + if(mouseX >= guiLeft+42 && mouseX <= guiLeft+42+88) { + if(mouseY >= guiTop+ySize-30 && mouseY <= guiTop+ySize-10) { + NotEnoughUpdates.INSTANCE.config.hidden.enchantColours.add("[a-zA-Z\\- ]+:>:5:9"); + } + } + } + + public static String getColourOpIndex(List colourOps, int index) { + if(colourOps.size() > index) { + return colourOps.get(index); + } else { + switch(index) { + case 0: + return "[a-zA-Z\\- ]+"; + case 1: + return ">"; + case 2: + return "5"; + case 3: + return "9"; + } + } + return null; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java new file mode 100644 index 00000000..8992db2a --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java @@ -0,0 +1,242 @@ +package io.github.moulberry.notenoughupdates.miscgui; + +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.NEUManager; +import io.github.moulberry.notenoughupdates.util.TexLoc; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +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.resources.I18n; +import net.minecraft.inventory.ContainerWorkbench; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.inventory.SlotCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.vector.Vector2f; +import org.lwjgl.util.vector.Vector3f; + +import java.awt.*; +import java.io.IOException; +import java.util.List; + +public class GuiItemRecipe extends GuiScreen { + + private static final ResourceLocation resourcePacksTexture = new ResourceLocation("textures/gui/resource_packs.png"); + private static final ResourceLocation craftingTableGuiTextures = new ResourceLocation("textures/gui/container/crafting_table.png"); + + private List craftMatrices; + private List results; + private int currentIndex = 0; + + private String title; + private NEUManager manager; + + public int guiLeft = 0; + public int guiTop = 0; + public int xSize = 176; + public int ySize = 166; + + public GuiItemRecipe(String title, List craftMatrices, List results, NEUManager manager) { + this.craftMatrices = craftMatrices; + this.results = results; + this.manager = manager; + this.title = title; + } + + private String getCraftText() { + if(results.get(currentIndex).has("crafttext")) { + return results.get(currentIndex).get("crafttext").getAsString(); + } else { + return ""; + } + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + drawDefaultBackground(); + + if(currentIndex < 0) { + currentIndex = 0; + } else if(currentIndex >= craftMatrices.size()) { + currentIndex = craftMatrices.size()-1; + } + + FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRendererObj; + + this.guiLeft = (width - this.xSize) / 2; + this.guiTop = (height - this.ySize) / 2; + + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + Minecraft.getMinecraft().getTextureManager().bindTexture(craftingTableGuiTextures); + this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, this.xSize, this.ySize); + + List tooltipToRender = null; + for(int index=0; index <= 45; index++) { + Vector2f pos = getPositionForIndex(index); + Utils.drawItemStack(getStackForIndex(index), (int)pos.x, (int)pos.y); + + if(mouseX > pos.x && mouseX < pos.x+16) { + if(mouseY > pos.y && mouseY < pos.y+16) { + ItemStack stack = getStackForIndex(index); + if(stack != null) { + tooltipToRender = stack.getTooltip(Minecraft.getMinecraft().thePlayer, false); + } + } + } + } + + if(craftMatrices.size() > 1) { + int guiX = mouseX - guiLeft; + int guiY = mouseY - guiTop; + + int buttonWidth = 7; + int buttonHeight = 11; + + boolean leftSelected = false; + boolean rightSelected = false; + + if(guiY > + 63 && guiY < + 63 + buttonHeight) { + if(guiX > + 110 && guiX < 110 + buttonWidth) { + leftSelected = true; + } else if(guiX > 147 && guiX < 147 + buttonWidth) { + rightSelected = true; + } + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(resourcePacksTexture); + //Left arrow + Utils.drawTexturedRect(guiLeft+110, guiTop+63, 7, 11, 34/256f, 48/256f, + 5/256f + (leftSelected ? 32/256f : 0), 27/256f + (leftSelected ? 32/256f : 0)); + //Right arrow + Utils.drawTexturedRect(guiLeft+147, guiTop+63, 7, 11, 10/256f, 24/256f, + 5/256f + (rightSelected ? 32/256f : 0), 27/256f + (rightSelected ? 32/256f : 0)); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); + + String str = (currentIndex+1)+"/"+craftMatrices.size(); + Utils.drawStringCenteredScaledMaxWidth(str, fontRendererObj, guiLeft+132, guiTop+69, + false, 24, Color.BLACK.getRGB()); + } + + Utils.drawStringCenteredScaledMaxWidth(getCraftText(), fontRendererObj, guiLeft+132, guiTop+25, + false, 75, 4210752); + + Utils.drawStringScaledMaxWidth(title, fontRendererObj, guiLeft+28, guiTop+6, title.contains("\u00a7"), xSize-38, 4210752); + + if(tooltipToRender != null) { + Utils.drawHoveringText(tooltipToRender, mouseX, mouseY, width, height, -1, fontRendererObj); + } + } + + public ItemStack getStackForIndex(int index) { + if(index == 0) { + return manager.jsonToStack(results.get(currentIndex)); + } else if(index >= 1 && index <= 9) { + return craftMatrices.get(currentIndex)[index-1]; + } else { + return Minecraft.getMinecraft().thePlayer.inventory.getStackInSlot(index-10); + } + } + + public Vector2f getPositionForIndex(int index) { + //0 = result + //1-9 = craft matrix + //10-18 = hotbar + //19-45 = player inv + + if(index == 0) { + return new Vector2f(guiLeft+124, guiTop+35); + } else if(index >= 1 && index <= 9) { + index -= 1; + int x = index % 3; + int y = index / 3; + return new Vector2f(guiLeft+30 + x*18, guiTop+17 + y * 18); + } else if(index >= 10 && index <= 18) { + index -= 10; + return new Vector2f(guiLeft+8 + index*18, guiTop+142); + } else if(index >= 19 && index <= 45) { + index -= 19; + int x = index % 9; + int y = index / 9; + return new Vector2f(guiLeft+8 + x*18, guiTop+84 + y*18); + } + return null; + } + + @Override + public void handleKeyboardInput() throws IOException { + super.handleKeyboardInput(); + + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; + int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; + + int keyPressed = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter()+256 : Keyboard.getEventKey(); + + for(int index=0; index <= 45; index++) { + Vector2f pos = getPositionForIndex(index); + if(mouseX > pos.x && mouseX < pos.x+16) { + if(mouseY > pos.y && mouseY < pos.y+16) { + ItemStack stack = getStackForIndex(index); + if(stack != null) { + if(keyPressed == manager.keybindViewRecipe.getKeyCode()) { + manager.displayGuiItemRecipe(manager.getInternalNameForItem(stack), ""); + } else if(keyPressed == manager.keybindViewUsages.getKeyCode()) { + manager.displayGuiItemUsages(manager.getInternalNameForItem(stack)); + } + } + return; + } + } + } + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + super.mouseClicked(mouseX, mouseY, mouseButton); + + int guiX = mouseX - guiLeft; + int guiY = mouseY - guiTop; + + int buttonWidth = 7; + int buttonHeight = 11; + + if(guiY > + 63 && guiY < + 63 + buttonHeight) { + if(guiX > + 110 && guiX < 110 + buttonWidth) { + currentIndex--; + Utils.playPressSound(); + return; + } else if(guiX > 147 && guiX < 147 + buttonWidth) { + currentIndex++; + Utils.playPressSound(); + return; + } + } + + for(int index=0; index <= 45; index++) { + Vector2f pos = getPositionForIndex(index); + if(mouseX > pos.x && mouseX < pos.x+16) { + if(mouseY > pos.y && mouseY < pos.y+16) { + ItemStack stack = getStackForIndex(index); + if(stack != null) { + if(mouseButton == 0) { + manager.displayGuiItemRecipe(manager.getInternalNameForItem(stack), ""); + } else if(mouseButton == 1) { + manager.displayGuiItemUsages(manager.getInternalNameForItem(stack)); + } + } + return; + } + } + } + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/HelpGUI.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/HelpGUI.java new file mode 100644 index 00000000..cc41a76f --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/HelpGUI.java @@ -0,0 +1,189 @@ +package io.github.moulberry.notenoughupdates.miscgui; + +import io.github.moulberry.notenoughupdates.util.TexLoc; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.util.vector.Vector2f; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class HelpGUI extends GuiScreen { + + private int guiLeft = 0; + private int guiTop = 0; + private int sizeX = 0; + private int sizeY = 0; + + private int page = 0; + private ResourceLocation screenshotBorder = new ResourceLocation("notenoughupdates:ss_border.jpg"); + private ResourceLocation[] screenshots = null; + + int scaleFactor = 0; + + @Override + public void setWorldAndResolution(Minecraft mc, int width, int height) { + super.setWorldAndResolution(mc, width, height); + + screenshots = new ResourceLocation[18]; + for(int i=0; i<=17; i++) { + screenshots[i] = new ResourceLocation("notenoughupdates:ss_small/ss"+(i+1)+"-0.jpg"); + } + } + + @Override + protected void keyTyped(char typedChar, int keyCode) throws IOException { + Keyboard.enableRepeatEvents(true); + super.keyTyped(typedChar, keyCode); + if(keyCode == Keyboard.KEY_LEFT) { + page--; + } else if(keyCode == Keyboard.KEY_RIGHT) { + page++; + } + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + super.drawScreen(mouseX, mouseY, partialTicks); + + drawDefaultBackground(); + + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + scaleFactor = scaledResolution.getScaleFactor(); + + sizeX = width/2+40/scaleFactor; + sizeY = height/2+40/scaleFactor; + guiLeft = width/4-20/scaleFactor; + guiTop = height/4-20/scaleFactor; + + Minecraft.getMinecraft().getTextureManager().bindTexture(screenshotBorder); + Utils.drawTexturedRect(guiLeft, guiTop, sizeX, sizeY); + + page = Math.max(0, Math.min(17, page)); + + Minecraft.getMinecraft().getTextureManager().bindTexture(screenshots[page]); + Utils.drawTexturedRect(guiLeft+20f/scaleFactor, guiTop+20f/scaleFactor, sizeX-40f/scaleFactor, sizeY-40f/scaleFactor); + + Utils.drawStringCentered(EnumChatFormatting.GOLD+"NEU Tutorial - Page "+(page+1)+"/18 - Use arrow keys", Minecraft.getMinecraft().fontRendererObj, + width/2, guiTop+8, true, 0); + if(scaleFactor != 2) Utils.drawStringCentered(EnumChatFormatting.GOLD+"Use GUI Scale normal for better reading experience", Minecraft.getMinecraft().fontRendererObj, + width/2, guiTop+18, true, 0); + + for(Map.Entry> entry : texts[page].entrySet()) { + Vector2f location = entry.getKey(); + List text = entry.getValue(); + + float x = guiLeft+20f/scaleFactor+(sizeX-40f/scaleFactor)*location.x; + float y = guiTop+20f/scaleFactor+(sizeY-40f/scaleFactor)*location.y; + + Utils.drawHoveringText(text, (int)x, (int)y+12, 100000, 100000, 200, Minecraft.getMinecraft().fontRendererObj); + } + } + + + private static HashMap>[] texts = new HashMap[18]; + static { + for(int i=0; i<18; i++) { + texts[i] = new HashMap<>(); + } + texts[0].put(new Vector2f(0.73f, 0.60f), Utils.createList( + EnumChatFormatting.GOLD+"Itemlist", + EnumChatFormatting.GRAY+"Here you will find a list of (most) skyblock items", + EnumChatFormatting.GRAY+"The itemlist can be accessed by opening your inventory or most menus while on skyblock")); + texts[1].put(new Vector2f(0.73f, 0.16f), Utils.createList( + EnumChatFormatting.GOLD+"Itemlist", + EnumChatFormatting.GRAY+"These are the page controls for the itemlist", + EnumChatFormatting.GRAY+"Clicking these controls will bring you to other pages of the itemlist")); + texts[2].put(new Vector2f(0.73f, 1.05f), Utils.createList( + EnumChatFormatting.GOLD+"Itemlist", + EnumChatFormatting.GRAY+"These are the sorting controls for the itemlist", + EnumChatFormatting.GRAY+"The buttons on the left control the ordering of the items", + EnumChatFormatting.GRAY+"The buttons on the right can be used to filter a certain type of item")); + texts[3].put(new Vector2f(0.39f, 1.04f), Utils.createList( + EnumChatFormatting.GOLD+"Itemlist", + EnumChatFormatting.GRAY+"This is the search bar for the itemlist", + EnumChatFormatting.GRAY+"Double-click the bar to enable inventory search mode", + EnumChatFormatting.GRAY+"The button on the left opens up the mod settings", + EnumChatFormatting.GRAY+"The button on the right displays this tutorial")); + texts[4].put(new Vector2f(0.39f, 0.99f), Utils.createList( + EnumChatFormatting.GOLD+"QuickCommands", + EnumChatFormatting.GRAY+"These are the QuickCommands", + EnumChatFormatting.GRAY+"They let you warp around or access certain menus more easily")); + texts[5].put(new Vector2f(0.7f, 0.71f), Utils.createList( + EnumChatFormatting.GOLD+"Itemlist", + EnumChatFormatting.GRAY+"Hover over an item in the list to display it's lore", + EnumChatFormatting.GRAY+"Left clicking some items will display the recipe for that item", + EnumChatFormatting.GRAY+"Right clicking some items will display a wiki page for that item", + EnumChatFormatting.GRAY+"'F' will favourite an item, putting it to the top of the itemlist")); + texts[6].put(new Vector2f(0.17f, 0.21f), Utils.createList( + EnumChatFormatting.GOLD+"Collection Log", + EnumChatFormatting.GRAY+"This is the collection log. It can be accessed using the /neucl command, or via the QuickCommand", + EnumChatFormatting.GRAY+"The collection log keeps track of all items that enter your inventory while you are playing skyblock", + EnumChatFormatting.GRAY+"If you are a completionist, this feature is for you")); + texts[7].put(new Vector2f(0.05f, 0.13f), Utils.createList( + EnumChatFormatting.GOLD+"Collection Log", + EnumChatFormatting.GRAY+"Clicking on 'Filter' will change the items that", + EnumChatFormatting.GRAY+"appear in the list")); + texts[8].put(new Vector2f(0.35f, 0.74f), Utils.createList( + EnumChatFormatting.GOLD+"NeuAH", + EnumChatFormatting.GRAY+"This is the NEU Auction House (NeuAH)", + EnumChatFormatting.GRAY+"This AH can be accessed from anywhere using the /neuah command, or via the QuickCommand", + EnumChatFormatting.GRAY+"The items here refresh automatically, so there is no need to close the GUI to see the latest auctions", + EnumChatFormatting.GRAY+"Sometimes, you might have to wait until the list is populated with items from the API")); + texts[9].put(new Vector2f(0.41f, 0.40f), Utils.createList( + EnumChatFormatting.GOLD+"NeuAH", + EnumChatFormatting.GRAY+"These tabs control the items that appear in NeuAH", + EnumChatFormatting.GRAY+"You can find the main categories on the top of the GUI and subcategories appear on the side of the GUI once a main category is selected")); + texts[10].put(new Vector2f(0.57f, 0.38f), Utils.createList( + EnumChatFormatting.GOLD+"NeuAH", + EnumChatFormatting.GRAY+"Search for items using the search bar at the top", + EnumChatFormatting.GRAY+"Boolean operators such as &, | or ! work here.")); + texts[10].put(new Vector2f(0.40f, 0.72f), Utils.createList( + EnumChatFormatting.GOLD+"NeuAH", + EnumChatFormatting.GRAY+"This toolbar contains many useful features", + EnumChatFormatting.GRAY+"which control the sorting and ordering of", + EnumChatFormatting.GRAY+"the auction house, similar to the normal AH")); + texts[11].put(new Vector2f(0.55f, 0.72f), Utils.createList( + EnumChatFormatting.GOLD+"NeuAH", + EnumChatFormatting.GRAY+"Clicking on an item will bring up the auction view", + EnumChatFormatting.GRAY+"Here you can viewer the buyer/seller and place bids or make purchases", + EnumChatFormatting.GRAY+"Trying to purchase an item will result in a confirmation GUI similar to the normal AH")); + texts[12].put(new Vector2f(0.28f, 0.82f), Utils.createList( + EnumChatFormatting.GOLD+"Profile Viewer", + EnumChatFormatting.GRAY+"Access the profile viewer using /neuprofile (ign) or /pv (ign)", + EnumChatFormatting.GRAY+"This is the main page of the profile viewer", + EnumChatFormatting.GRAY+"This page contains basic information like stats and skill levels")); + texts[12].put(new Vector2f(0.72f, 0.55f), Utils.createList( + EnumChatFormatting.GOLD+"Profile Viewer", + EnumChatFormatting.GRAY+"Click the button on the left to switch profiles and use the bar on the right to switch players")); + texts[13].put(new Vector2f(0.28f, 0.82f), Utils.createList( + EnumChatFormatting.GOLD+"Profile Viewer", + EnumChatFormatting.GRAY+"This is the extra info page of the profile viewer", + EnumChatFormatting.GRAY+"This page contains all the small bits of information about a player that don't fit anywhere else")); + texts[14].put(new Vector2f(0.28f, 0.82f), Utils.createList( + EnumChatFormatting.GOLD+"Profile Viewer", + EnumChatFormatting.GRAY+"This is the inventories page of the profile viewer", + EnumChatFormatting.GRAY+"Click on the inventory icons in the top-left or use your keyboard to switch the inventory type", + EnumChatFormatting.GRAY+"The bar on the bottom-left searches the current inventory for matching items")); + texts[15].put(new Vector2f(0.28f, 0.82f), Utils.createList( + EnumChatFormatting.GOLD+"Profile Viewer", + EnumChatFormatting.GRAY+"This is the collections page of the profile viewer", + EnumChatFormatting.GRAY+"Click on the icons on the left or use the keyboard shortcut to switch collection type")); + texts[16].put(new Vector2f(0.28f, 0.82f), Utils.createList( + EnumChatFormatting.GOLD+"Profile Viewer", + EnumChatFormatting.GRAY+"This is the pets page of the profile viewer", + EnumChatFormatting.GRAY+"Click to select the pet on the left", + EnumChatFormatting.GRAY+"The selected pet's stats will display on the right")); + texts[17].put(new Vector2f(0.27f, 0.40f), Utils.createList( + EnumChatFormatting.GOLD+"Overlay", + EnumChatFormatting.GRAY+"Rearrange certain GUI elements of the main overlay using /neuoverlay", + EnumChatFormatting.GRAY+"If you accidentally move them off screen, use the button in the top left to reset the GUI")); + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/NEUOverlayPlacements.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/NEUOverlayPlacements.java new file mode 100644 index 00000000..995ed5e3 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/NEUOverlayPlacements.java @@ -0,0 +1,219 @@ +package io.github.moulberry.notenoughupdates.miscgui; + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.mbgui.*; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.EnumChatFormatting; +import org.lwjgl.input.Keyboard; +import org.lwjgl.util.vector.Vector2f; + +import java.awt.*; +import java.io.IOException; + +public class NEUOverlayPlacements extends GuiScreen { + + private int clickedX; + private int clickedY; + private int clickedAnchorX; + private int clickedAnchorY; + private MBGuiElement clickedElement; + private GuiButton guiButton = new GuiButton(0, 5, 5, "Reset to Default"); + + private boolean dropdownMenuShown = false; + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + super.drawScreen(mouseX, mouseY, partialTicks); + drawDefaultBackground(); + + /*GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + Minecraft.getMinecraft().getTextureManager().bindTexture(icons); + GlStateManager.enableBlend(); + + GlStateManager.tryBlendFuncSeparate(775, 769, 1, 0); + GlStateManager.enableAlpha(); + this.drawTexturedModalRect(width / 2 - 7, height / 2 - 7, 0, 0, 16, 16);*/ + + if(mouseX < 300 && mouseY < 300 && clickedElement != null) { + guiButton.yPosition = height - 5 - guiButton.height; + } else { + guiButton.yPosition = 5; + } + + EnumChatFormatting GOLD = EnumChatFormatting.GOLD; + + guiButton.drawButton(Minecraft.getMinecraft(), mouseX, mouseY); + + NotEnoughUpdates.INSTANCE.overlay.updateGuiGroupSize(); + + drawRect((width-176)/2, (height-166)/2, + (width+176)/2, (height+166)/2, new Color(100, 100, 100, 200).getRGB()); + Utils.drawStringCentered(GOLD+"Inventory", Minecraft.getMinecraft().fontRendererObj, width/2f, height/2f, false, 0); + + MBGuiGroupFloating mainGroup = NotEnoughUpdates.INSTANCE.overlay.guiGroup; + mainGroup.render(0, 0); + GlStateManager.translate(0, 0, 500); + for(MBGuiElement element : mainGroup.getChildren()) { + MBAnchorPoint anchorPoint = mainGroup.getChildrenMap().get(element); + Vector2f position = mainGroup.getChildrenPosition().get(element); + + drawRect((int)position.x, (int)position.y, + (int)position.x+element.getWidth(), (int)position.y+element.getHeight(), new Color(100, 100, 100, 200).getRGB()); + + switch(anchorPoint.anchorPoint) { + case TOPLEFT: + case TOPRIGHT: + case BOTLEFT: + case BOTRIGHT: + drawRect((int)(position.x+element.getWidth()*anchorPoint.anchorPoint.x*0.9f), + (int)(position.y+element.getHeight()*anchorPoint.anchorPoint.y*0.9f), + (int)(position.x+element.getWidth()*anchorPoint.anchorPoint.x*0.9f+element.getWidth()*0.1f), + (int)(position.y+element.getHeight()*anchorPoint.anchorPoint.y*0.9f+element.getHeight()*0.1f), + new Color(200, 200, 200, 100).getRGB()); + break; + case TOPMID: + drawRect((int)position.x, (int)position.y, + (int)position.x+element.getWidth(), (int)(position.y+element.getHeight()*0.1f), + new Color(200, 200, 200, 100).getRGB()); + break; + case MIDLEFT: + drawRect((int)position.x, (int)position.y, + (int)(position.x+element.getWidth()*0.1f), (int)position.y+element.getHeight(), + new Color(200, 200, 200, 100).getRGB()); + break; + case MIDRIGHT: + drawRect((int)(position.x+element.getWidth()*0.9f), (int)position.y, + (int)position.x+element.getWidth(), (int)position.y+element.getHeight(), + new Color(200, 200, 200, 100).getRGB()); + break; + case BOTMID: + drawRect((int)position.x, (int)(position.y+element.getHeight()*0.9f), + (int)position.x+element.getWidth(), (int)position.y+element.getHeight(), + new Color(200, 200, 200, 100).getRGB()); + break; + case MIDMID: + drawRect((int)(position.x+element.getWidth()*0.45f), (int)(position.y+element.getHeight()*0.45f), + (int)(position.x+element.getWidth()*0.55f), (int)(position.y+element.getHeight()*0.55f), + new Color(200, 200, 200, 100).getRGB()); + break; + + } + + if(anchorPoint.inventoryRelative) { + Utils.drawStringCentered(GOLD+"Inv-Relative", Minecraft.getMinecraft().fontRendererObj, + position.x+element.getWidth()*0.5f, position.y+element.getHeight()*0.5f, false, 0); + } + } + GlStateManager.translate(0, 0, -500); + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + super.mouseClicked(mouseX, mouseY, mouseButton); + + if(mouseButton != 0 && mouseButton != 1) return; + + MBGuiGroupFloating mainGroup = NotEnoughUpdates.INSTANCE.overlay.guiGroup; + int index=0; + for(MBGuiElement element : mainGroup.getChildren()) { + MBAnchorPoint anchorPoint = mainGroup.getChildrenMap().get(element); + Vector2f position = mainGroup.getChildrenPosition().get(element); + + if(mouseX > position.x && mouseX < position.x + element.getWidth()) { + if(mouseY > position.y && mouseY < position.y + element.getHeight()) { + if(mouseButton == 0) { + clickedElement = element; + clickedX = mouseX; + clickedY = mouseY; + clickedAnchorX = (int)anchorPoint.offset.x; + clickedAnchorY = (int)anchorPoint.offset.y; + } else { + if(Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) { + anchorPoint.inventoryRelative = !anchorPoint.inventoryRelative; + } else { + MBAnchorPoint.AnchorPoint[] vals = MBAnchorPoint.AnchorPoint.values(); + anchorPoint.anchorPoint = vals[(anchorPoint.anchorPoint.ordinal()+1)%vals.length]; + + mainGroup.recalculate(); + + anchorPoint.offset.x += position.x - mainGroup.getChildrenPosition().get(element).x; + anchorPoint.offset.y += position.y - mainGroup.getChildrenPosition().get(element).y; + + mainGroup.recalculate(); + + if(index == 0) { + NotEnoughUpdates.INSTANCE.config.hidden.overlaySearchBar = anchorPoint.toString(); + } else if(index == 1) { + NotEnoughUpdates.INSTANCE.config.hidden.overlayQuickCommand = anchorPoint.toString(); + } + } + } + return; + } + } + index++; + } + + if(guiButton.mousePressed(Minecraft.getMinecraft(), mouseX, mouseY)) { + NotEnoughUpdates.INSTANCE.config.hidden.overlayQuickCommand = ""; + NotEnoughUpdates.INSTANCE.config.hidden.overlaySearchBar = ""; + NotEnoughUpdates.INSTANCE.overlay.resetAnchors(false); + + mainGroup.recalculate(); + } + clickedElement = null; + } + + @Override + protected void mouseReleased(int mouseX, int mouseY, int state) { + clickedElement = null; + } + + @Override + protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { + super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); + if(clickedElement != null) { + MBGuiGroupFloating mainGroup = NotEnoughUpdates.INSTANCE.overlay.guiGroup; + MBAnchorPoint anchorPoint = mainGroup.getChildrenMap().get(clickedElement); + + if(Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) { + int dX = mouseX - clickedX; + int dY = mouseY - clickedY; + if(Math.abs(dX) > Math.abs(dY)) { + anchorPoint.offset.x = mouseX - clickedX + clickedAnchorX; + anchorPoint.offset.y = clickedAnchorY; + } else { + anchorPoint.offset.x = clickedAnchorX; + anchorPoint.offset.y = mouseY - clickedY + clickedAnchorY; + } + } else { + anchorPoint.offset.x = mouseX - clickedX + clickedAnchorX; + anchorPoint.offset.y = mouseY - clickedY + clickedAnchorY; + } + + int index = 0; + for(MBGuiElement element : mainGroup.getChildren()) { + if(element == clickedElement) { + if(index == 0) { + NotEnoughUpdates.INSTANCE.config.hidden.overlaySearchBar = anchorPoint.toString(); + } else if(index == 1) { + NotEnoughUpdates.INSTANCE.config.hidden.overlayQuickCommand = anchorPoint.toString(); + } + break; + } + index++; + } + try { MBDeserializer.serializeAndSave(mainGroup, "overlay"); } catch(Exception e) {} + mainGroup.recalculate(); + } + } + + @Override + public boolean doesGuiPauseGame() { + return false; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java new file mode 100644 index 00000000..371da939 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/TradeWindow.java @@ -0,0 +1,1040 @@ +package io.github.moulberry.notenoughupdates.miscgui; + +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.util.SBAIntegration; +import io.github.moulberry.notenoughupdates.util.TexLoc; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.gui.inventory.GuiChest; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.inventory.ContainerChest; +import net.minecraft.inventory.Slot; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.ChatComponentTranslation; +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.awt.*; +import java.io.ByteArrayInputStream; +import java.text.NumberFormat; +import java.util.*; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class TradeWindow { + + private static ResourceLocation location = new ResourceLocation("notenoughupdates", "custom_trade.png"); + + private static final int xSize = 176; + private static final int ySize = 204; + private static int guiLeft; + private static int guiTop; + + private static long lastTradeMillis = -1; + + private static final long CHANGE_EXCLAM_MILLIS = 5000; + + private static Integer[] ourTradeIndexes = new Integer[16]; + private static Integer[] theirTradeIndexes = new Integer[16]; + private static String[] theirTradeOld = new String[16]; + private static Long[] theirTradeChangesMillis = new Long[16]; + + private static ItemStack lastBackpack; + private static int lastBackpackX; + private static int lastBackpackY; + + public static boolean tradeWindowActive() { + if(!NotEnoughUpdates.INSTANCE.isOnSkyblock()) return false; + if(!NotEnoughUpdates.INSTANCE.config.tradeMenu.enableCustomTrade) return false; + + GuiScreen guiScreen = Minecraft.getMinecraft().currentScreen; + if(guiScreen instanceof GuiChest) { + GuiChest eventGui = (GuiChest) guiScreen; + ContainerChest cc = (ContainerChest) eventGui.inventorySlots; + String containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText(); + if(containerName.trim().startsWith("You ")) { + return true; + } + } + + lastTradeMillis = -1; + ourTradeIndexes = new Integer[16]; + theirTradeIndexes = new Integer[16]; + theirTradeOld = new String[16]; + theirTradeChangesMillis = new Long[16]; + + return false; + } + + private static TexLoc tl = new TexLoc(0, 0, Keyboard.KEY_M); + + private static void drawStringShadow(String str, float x, float y, int len) { + for(int xOff=-2; xOff<=2; xOff++) { + for(int yOff=-2; yOff<=2; yOff++) { + if(Math.abs(xOff) != Math.abs(yOff)) { + Utils.drawStringCenteredScaledMaxWidth(Utils.cleanColourNotModifiers(str), + Minecraft.getMinecraft().fontRendererObj, + x+xOff/2f, y+yOff/2f, false, len, + new Color(20, 20, 20, 100/Math.max(Math.abs(xOff), Math.abs(yOff))).getRGB()); + } + } + } + + Utils.drawStringCenteredScaledMaxWidth(str, + Minecraft.getMinecraft().fontRendererObj, + x, y, false, len, + new Color(64, 64, 64, 255).getRGB()); + } + + private static int processTopItems(ItemStack stack, Map> topItems, + Map topItemsStack, Map topItemsCount) { + String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); + if(internalname == null) { + if(stack.getDisplayName().endsWith(" coins")) { + String clean = Utils.cleanColour(stack.getDisplayName()); + + int mult = 1; + StringBuilder sb = new StringBuilder(); + for(int index = 0; index < clean.length(); index++) { + char c = clean.charAt(index); + if("0123456789.".indexOf(c) >= 0) { + sb.append(c); + } else { + switch(c) { + case 'K': + case 'k': + mult = 1000; break; + case 'M': + case 'm': + mult = 1000000; break; + case 'B': + case 'b': + mult = 1000000000; break; + default: + break; + } + break; + } + } + try { + int coins = (int)(Float.parseFloat(sb.toString())*mult); + + topItemsStack.putIfAbsent("TRADE_COINS", stack); + + int existingPrice = coins; + Set toRemove = new HashSet<>(); + for(Map.Entry> entry : topItems.entrySet()) { + if(entry.getValue().contains("TRADE_COINS")) { + entry.getValue().remove("TRADE_COINS"); + existingPrice += entry.getKey(); + } + if(entry.getValue().isEmpty()) toRemove.add(entry.getKey()); + } + topItems.keySet().removeAll(toRemove); + + Set items = topItems.computeIfAbsent(existingPrice, k->new HashSet<>()); + items.add("TRADE_COINS"); + + return coins; + + } catch(Exception ignored) {} + } + } else { + JsonObject info = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalname); + int pricePer = -1; + if(info != null && !NotEnoughUpdates.INSTANCE.manager.auctionManager.isVanillaItem(internalname) && + info.has("price") && info.has("count")) { + int auctionPricePer = (int)(info.get("price").getAsFloat() / info.get("count").getAsFloat()); + + pricePer = auctionPricePer; + } else { + JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalname); + if(bazaarInfo != null && bazaarInfo.has("avg_buy")) { + pricePer = (int)bazaarInfo.get("avg_buy").getAsFloat(); + } + } + if(pricePer > 0) { + topItemsStack.putIfAbsent(internalname, stack); + + int price = pricePer * stack.stackSize; + int priceInclBackpack = price; + + NBTTagCompound tag = stack.getTagCompound(); + if(tag != null && tag.hasKey("ExtraAttributes", 10)) { + NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); + + byte[] bytes = null; + for (String key : ea.getKeySet()) { + if (key.endsWith("backpack_data") || key.equals("new_year_cake_bag_data")) { + bytes = ea.getByteArray(key); + break; + } + } + if(bytes != null) { + try { + NBTTagCompound contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(bytes)); + NBTTagList items = contents_nbt.getTagList("i", 10); + for(int k=0; k 0) { + NBTTagCompound nbt = items.getCompoundTagAt(k).getCompoundTag("tag"); + + int id2 = items.getCompoundTagAt(k).getShort("id"); + int count2 = items.getCompoundTagAt(k).getByte("Count"); + int damage2 = items.getCompoundTagAt(k).getShort("Damage"); + + if(id2 == 141) id2 = 391; //for some reason hypixel thinks carrots have id 141 + + Item mcItem = Item.getItemById(id2); + if(mcItem == null) continue; + + ItemStack stack2 = new ItemStack(mcItem, count2, damage2); + stack2.setTagCompound(nbt); + + priceInclBackpack += processTopItems(stack2, topItems, topItemsStack, topItemsCount); + } + } + } catch(Exception e) { } + } + } + + int existingPrice = price; + Set toRemove = new HashSet<>(); + for(Map.Entry> entry : topItems.entrySet()) { + if(entry.getValue().contains(internalname)) { + entry.getValue().remove(internalname); + existingPrice += entry.getKey(); + } + if(entry.getValue().isEmpty()) toRemove.add(entry.getKey()); + } + topItems.keySet().removeAll(toRemove); + + Set items = topItems.computeIfAbsent(existingPrice, k->new HashSet<>()); + items.add(internalname); + + int count = topItemsCount.computeIfAbsent(internalname, l->0); + topItemsCount.put(internalname, count+stack.stackSize); + + return priceInclBackpack; + } + } + return 0; + } + + private static int getBackpackValue(ItemStack stack) { + int price = 0; + + NBTTagCompound tag = stack.getTagCompound(); + if(tag != null && tag.hasKey("ExtraAttributes", 10)) { + NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); + + byte[] bytes = null; + for (String key : ea.getKeySet()) { + if (key.endsWith("backpack_data") || key.equals("new_year_cake_bag_data")) { + bytes = ea.getByteArray(key); + break; + } + } + if(bytes != null) { + try { + NBTTagCompound contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(bytes)); + NBTTagList items = contents_nbt.getTagList("i", 10); + for(int k=0; k 0) { + NBTTagCompound nbt = items.getCompoundTagAt(k).getCompoundTag("tag"); + String internalname2 = NotEnoughUpdates.INSTANCE.manager.getInternalnameFromNBT(nbt); + if(internalname2 != null) { + JsonObject info2 = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalname2); + + int pricePer2 = -1; + if(info2 != null && info2.has("price") && info2.has("count")) { + int auctionPricePer2 = (int)(info2.get("price").getAsFloat() / info2.get("count").getAsFloat()); + + pricePer2 = auctionPricePer2; + } else { + JsonObject bazaarInfo2 = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalname2); + if(bazaarInfo2 != null && bazaarInfo2.has("avg_buy")) { + pricePer2 = (int)bazaarInfo2.get("avg_buy").getAsFloat(); + } + } + if(pricePer2 > 0) { + int count2 = items.getCompoundTagAt(k).getByte("Count"); + price += pricePer2 * count2; + } + } + } + } + } catch(Exception e) { } + } + } + return price; + } + + public static void render(int mouseX, int mouseY) { + if(!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return; + + GuiContainer chest = ((GuiContainer)Minecraft.getMinecraft().currentScreen); + ContainerChest cc = (ContainerChest) chest.inventorySlots; + String containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText(); + + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + + guiLeft = (scaledResolution.getScaledWidth()-xSize)/2; + guiTop = (scaledResolution.getScaledHeight()-ySize)/2; + + List tooltipToDisplay = null; + ItemStack stackToRender = null; + int tooltipLen = -1; + tl.handleKeyboardInput(); + + //Set index mappings + //Our slots + TreeMap> ourTradeMap = new TreeMap<>(); + for(int i=0; i<16; i++) { + ourTradeIndexes[i] = -1; + + int x = i % 4; + int y = i / 4; + int containerIndex = y*9+x; + + ItemStack stack = chest.inventorySlots.getInventory().get(containerIndex); + if(stack == null) continue; + + String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); + if(internalname == null) { + if(stack.getDisplayName().endsWith(" coins")) { + String clean = Utils.cleanColour(stack.getDisplayName()); + + int mult = 1; + StringBuilder sb = new StringBuilder(); + for(int index = 0; index < clean.length(); index++) { + char c = clean.charAt(index); + if("0123456789.".indexOf(c) >= 0) { + sb.append(c); + } else { + switch(c) { + case 'K': + case 'k': + mult = 1000; break; + case 'M': + case 'm': + mult = 1000000; break; + case 'B': + case 'b': + mult = 1000000000; break; + default: + break; + } + break; + } + } + try { + int coins = (int)(Float.parseFloat(sb.toString())*mult); + + List list = ourTradeMap.computeIfAbsent(coins, k -> new ArrayList<>()); + list.add(containerIndex); + + } catch(Exception ignored) { + List list = ourTradeMap.computeIfAbsent(-1, k -> new ArrayList<>()); + list.add(containerIndex); + } + } else { + List list = ourTradeMap.computeIfAbsent(-1, k -> new ArrayList<>()); + list.add(containerIndex); + } + } else { + JsonObject info = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalname); + int price = -1; + if(info != null && info.has("price") && info.has("count")) { + int auctionPricePer = (int)(info.get("price").getAsFloat() / info.get("count").getAsFloat()); + + price = auctionPricePer * stack.stackSize; + } else { + JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalname); + if(bazaarInfo != null && bazaarInfo.has("avg_buy")) { + price = (int)bazaarInfo.get("avg_buy").getAsFloat() * stack.stackSize; + } + } + + price += getBackpackValue(stack); + + List list = ourTradeMap.computeIfAbsent(price, k -> new ArrayList<>()); + list.add(containerIndex); + } + } + long currentTime = System.currentTimeMillis(); + List theirTradeCurrent = new ArrayList<>(); + TreeMap> theirTradeMap = new TreeMap<>(); + HashMap displayCountMap = new HashMap<>(); + for(int i=0; i<16; i++) { + theirTradeIndexes[i] = -1; + if(theirTradeChangesMillis[i] == null || currentTime - theirTradeChangesMillis[i] > CHANGE_EXCLAM_MILLIS) { + theirTradeChangesMillis[i] = -1L; + } + + int x = i % 4; + int y = i / 4; + int containerIndex = y*9+x+5; + + ItemStack stack = chest.inventorySlots.getInventory().get(containerIndex); + if(stack == null) continue; + + NBTTagCompound tag = stack.getTagCompound(); + String uuid = null; + if(tag != null && tag.hasKey("ExtraAttributes", 10)) { + NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); + + if (ea.hasKey("uuid", 8)) { + uuid = ea.getString("uuid"); + } else { + int displayCount = displayCountMap.computeIfAbsent(stack.getDisplayName(), k->0); + uuid = stack.getDisplayName() + ":" + displayCount; + displayCountMap.put(stack.getDisplayName(), displayCount+1); + } + } else { + int displayCount = displayCountMap.computeIfAbsent(stack.getDisplayName(), k->0); + uuid = stack.getDisplayName() + ":" + displayCount; + displayCountMap.put(stack.getDisplayName(), displayCount+1); + } + if(uuid != null) theirTradeCurrent.add(uuid); + + String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); + if(internalname == null) { + if(stack.getDisplayName().endsWith(" coins")) { + String clean = Utils.cleanColour(stack.getDisplayName()); + + int mult = 1; + StringBuilder sb = new StringBuilder(); + for(int index = 0; index < clean.length(); index++) { + char c = clean.charAt(index); + if("0123456789.".indexOf(c) >= 0) { + sb.append(c); + } else { + switch(c) { + case 'K': + case 'k': + mult = 1000; break; + case 'M': + case 'm': + mult = 1000000; break; + case 'B': + case 'b': + mult = 1000000000; break; + default: + break; + } + break; + } + } + try { + int coins = (int)(Float.parseFloat(sb.toString())*mult); + + List list = theirTradeMap.computeIfAbsent(coins, k -> new ArrayList<>()); + list.add(containerIndex); + + } catch(Exception ignored) { + List list = theirTradeMap.computeIfAbsent(-1, k -> new ArrayList<>()); + list.add(containerIndex); + } + } else { + List list = theirTradeMap.computeIfAbsent(-1, k -> new ArrayList<>()); + list.add(containerIndex); + } + } else { + JsonObject info = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalname); + int price = -1; + if(info != null && info.has("price") && info.has("count")) { + int auctionPricePer = (int)(info.get("price").getAsFloat() / info.get("count").getAsFloat()); + + price = auctionPricePer * stack.stackSize; + } else { + JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalname); + if(bazaarInfo != null && bazaarInfo.has("avg_buy")) { + price = (int)bazaarInfo.get("avg_buy").getAsFloat() * stack.stackSize; + } + } + + price += getBackpackValue(stack); + + List list = theirTradeMap.computeIfAbsent(price, k -> new ArrayList<>()); + list.add(containerIndex); + } + } + int ourTradeIndex = 0; + for(Map.Entry> entry : ourTradeMap.descendingMap().entrySet()) { + for(Integer index : entry.getValue()) { + ourTradeIndexes[ourTradeIndex++] = index; + } + } + + //Their slots + int maxMissing = 16-theirTradeCurrent.size(); + int j=0; + for(int i=0; i<16; i++) { + while(j <= 15 && (j-i= 0) j++; + j = Math.min(15, j); + + String oldUUID = theirTradeOld[i]; + if(oldUUID != null && !theirTradeCurrent.contains(oldUUID)) { + theirTradeChangesMillis[j] = System.currentTimeMillis(); + } + j++; + } + + for(int i=0; i<16; i++) { + theirTradeOld[i] = null; + } + int theirTradeIndex = 0; + displayCountMap.clear(); + j=0; + for(Map.Entry> entry : theirTradeMap.descendingMap().entrySet()) { + for(Integer index : entry.getValue()) { + while(j <= 15 && (j-theirTradeIndex= 0) j++; + j = Math.min(15, j); + + theirTradeIndexes[j] = index; + + ItemStack stack = chest.inventorySlots.getInventory().get(index); + if(stack == null) continue; + + NBTTagCompound tag = stack.getTagCompound(); + String uuid = null; + if(tag != null && tag.hasKey("ExtraAttributes", 10)) { + NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); + + if (ea.hasKey("uuid", 8)) { + uuid = ea.getString("uuid"); + } else { + int displayCount = displayCountMap.computeIfAbsent(stack.getDisplayName(), k->0); + uuid = stack.getDisplayName() + ":" + displayCount; + displayCountMap.put(stack.getDisplayName(), displayCount+1); + } + } else { + int displayCount = displayCountMap.computeIfAbsent(stack.getDisplayName(), k->0); + uuid = stack.getDisplayName() + ":" + displayCount; + displayCountMap.put(stack.getDisplayName(), displayCount+1); + } + //System.out.println(uuid); + theirTradeOld[theirTradeIndex] = uuid; + + j++; + theirTradeIndex++; + } + } + + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(location); + Utils.drawTexturedRect(guiLeft, guiTop, xSize, ySize, 0, 176/256f, 0, 204/256f, GL11.GL_NEAREST); + + Utils.drawStringF(new ChatComponentTranslation("container.inventory").getUnformattedText(), + Minecraft.getMinecraft().fontRendererObj, guiLeft+8, guiTop+111, false, 4210752); + Utils.drawStringF("You", Minecraft.getMinecraft().fontRendererObj, guiLeft+8, + guiTop+5, false, 4210752); + String[] split = containerName.split(" "); + if(split.length >= 1) { + Utils.drawStringF(split[split.length-1], Minecraft.getMinecraft().fontRendererObj, + guiLeft+167-Minecraft.getMinecraft().fontRendererObj.getStringWidth(split[split.length-1]), + guiTop+5, false, 4210752); + } + + int index=0; + for(ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { + int x = 8+18*(index % 9); + int y = 104+18*(index / 9); + if(index < 9) y = 180; + + Utils.drawItemStack(stack, guiLeft+x, guiTop+y); + + if(mouseX > guiLeft+x-1 && mouseX < guiLeft+x+18) { + if(mouseY > guiTop+y-1 && mouseY < guiTop+y+18) { + if(stack != null) stackToRender = stack; + + GlStateManager.disableLighting(); + GlStateManager.disableDepth(); + GlStateManager.colorMask(true, true, true, false); + Utils.drawGradientRect(guiLeft+x, guiTop+y, + guiLeft+x + 16, guiTop+y + 16, -2130706433, -2130706433); + GlStateManager.colorMask(true, true, true, true); + GlStateManager.enableLighting(); + GlStateManager.enableDepth(); + } + } + + index++; + } + + for(int i=0; i<16; i++) { + int x = i % 4; + int y = i / 4; + + int containerIndex = ourTradeIndexes[i]; + + ItemStack stack = null; + if(containerIndex >= 0) { + stack = chest.inventorySlots.getInventory().get(containerIndex); + Utils.drawItemStack(stack, guiLeft+10+x*18, guiTop+15+y*18); + } + + if(mouseX > guiLeft+10+x*18-1 && mouseX < guiLeft+10+x*18+18) { + if(mouseY > guiTop+15+y*18-1 && mouseY < guiTop+15+y*18+18) { + if(stack != null) stackToRender = stack; + + GlStateManager.disableLighting(); + GlStateManager.disableDepth(); + GlStateManager.colorMask(true, true, true, false); + Utils.drawGradientRect(guiLeft+10+x*18, guiTop+15+y*18, + guiLeft+10+x*18 + 16, guiTop+15+y*18 + 16, -2130706433, -2130706433); + GlStateManager.colorMask(true, true, true, true); + GlStateManager.enableLighting(); + GlStateManager.enableDepth(); + } + } + } + + ItemStack bidStack = chest.inventorySlots.getInventory().get(36); + if(bidStack != null) { + Utils.drawItemStack(bidStack, guiLeft+10, guiTop+90); + if(mouseX > guiLeft+10-1 && mouseX < guiLeft+10+18) { + if(mouseY > guiTop+90-1 && mouseY < guiTop+90+18) { + tooltipToDisplay = bidStack.getTooltip(Minecraft.getMinecraft().thePlayer, + Minecraft.getMinecraft().gameSettings.advancedItemTooltips); + } + } + } + + ItemStack confirmStack = chest.inventorySlots.getInventory().get(39); + if(confirmStack != null) { + String confirmDisplay = confirmStack.getDisplayName(); + if(!confirmDisplay.equals(EnumChatFormatting.GREEN+"Trading!")) { + if(mouseX > guiLeft+81-51 && mouseX < guiLeft+81) { + if (mouseY > guiTop+91 && mouseY < guiTop+91+14) { + tooltipToDisplay = confirmStack.getTooltip(Minecraft.getMinecraft().thePlayer, + Minecraft.getMinecraft().gameSettings.advancedItemTooltips); + } + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(location); + Utils.drawTexturedRect(guiLeft+81-51, guiTop+91, 51, 14, + 0, 51/256f, ySize/256f, (ySize+14)/256f, GL11.GL_NEAREST); + + Pattern pattern = Pattern.compile(EnumChatFormatting.GRAY+"\\("+EnumChatFormatting.YELLOW+"([0-9]+)"+EnumChatFormatting.GRAY+"\\)"); + Matcher matcher = pattern.matcher(confirmDisplay); + + if(!confirmDisplay.equals(EnumChatFormatting.YELLOW+"Warning!") && + !confirmDisplay.equals(EnumChatFormatting.YELLOW+"Deal!")) { + lastTradeMillis = -1; + } + + if(matcher.find()) { + String numS = matcher.group(1); + int num = Integer.parseInt(numS); + + Utils.drawStringCentered(EnumChatFormatting.DARK_RED + "Check " + EnumChatFormatting.BOLD + (char) (9311 + num), Minecraft.getMinecraft().fontRendererObj, guiLeft + 56, guiTop + 99, + false, 4210752); + } else if(confirmDisplay.equals(EnumChatFormatting.AQUA+"Gift!")) { + Utils.drawStringCentered(EnumChatFormatting.GREEN+"Accept", Minecraft.getMinecraft().fontRendererObj, guiLeft+56, guiTop+99, + true, 4210752); + } else if(confirmDisplay.equals(EnumChatFormatting.GREEN+"Deal accepted!")) { + Utils.drawStringCentered(EnumChatFormatting.GREEN+"Accepted", Minecraft.getMinecraft().fontRendererObj, + guiLeft+56, guiTop+99, true, 4210752); + } else if(lastTradeMillis > 0) { + long delta = System.currentTimeMillis() - lastTradeMillis; + if(delta > 2000) { + Utils.drawStringCentered(EnumChatFormatting.GREEN+"Accept", Minecraft.getMinecraft().fontRendererObj, guiLeft+56, guiTop+99, + true, 4210752); + } else { + Utils.drawStringCentered(EnumChatFormatting.YELLOW+"Trade "+EnumChatFormatting.BOLD+(char)(9312+(2000-delta)/1000), + Minecraft.getMinecraft().fontRendererObj, guiLeft+56, guiTop+99, + true, 4210752); + } + } else { + Utils.drawStringCentered(EnumChatFormatting.YELLOW+"Trade "+EnumChatFormatting.BOLD+(char)(9314), Minecraft.getMinecraft().fontRendererObj, guiLeft+56, guiTop+99, + true, 4210752); + } + } + } + + ItemStack theirConfirmStack = chest.inventorySlots.getInventory().get(41); + if(theirConfirmStack != null) { + String confirmDisplay = theirConfirmStack.getDisplayName(); + if(mouseX > guiLeft+95 && mouseX < guiLeft+95+51) { + if (mouseY > guiTop+91 && mouseY < guiTop+91+14) { + tooltipToDisplay = theirConfirmStack.getTooltip(Minecraft.getMinecraft().thePlayer, + Minecraft.getMinecraft().gameSettings.advancedItemTooltips); + } + } + + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(location); + Utils.drawTexturedRect(guiLeft+95, guiTop+91, 51, 14, + 0, 51/256f, ySize/256f, (ySize+14)/256f, GL11.GL_NEAREST); + + if(confirmDisplay.equals(EnumChatFormatting.YELLOW+"Pending their confirm")) { + Utils.drawStringCentered(EnumChatFormatting.YELLOW+"Pending", Minecraft.getMinecraft().fontRendererObj, guiLeft+120, guiTop+99, + true, 4210752); + } else if(confirmDisplay.equals(EnumChatFormatting.YELLOW+"Deal timer...")) { + Utils.drawStringCentered(EnumChatFormatting.YELLOW+"Pending", Minecraft.getMinecraft().fontRendererObj, guiLeft+120, guiTop+99, + true, 4210752); + } else if(confirmDisplay.equals(EnumChatFormatting.GREEN+"Other player confirmed!")) { + Utils.drawStringCentered(EnumChatFormatting.GREEN+"Accepted", Minecraft.getMinecraft().fontRendererObj, guiLeft+120, guiTop+99, + true, 4210752); + } + } + + for(int i=0; i<16; i++) { + int x = i % 4; + int y = i / 4; + + int containerIndex = theirTradeIndexes[i]; + + ItemStack stack = null; + if(containerIndex >= 0) { + stack = chest.inventorySlots.getInventory().get(containerIndex); + Utils.drawItemStack(stack, guiLeft+96+x*18, guiTop+15+y*18); + } + + if(currentTime % 400 > 200 && theirTradeChangesMillis[i] != null && theirTradeChangesMillis[i] > 0) { + GlStateManager.translate(0, 0, 200); + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(location); + Utils.drawTexturedRect(guiLeft+96+x*18, guiTop+15+y*18, 16, 16, + 51/256f, 67/256f, 204/256f, 220/256f, GL11.GL_NEAREST); + GlStateManager.translate(0, 0, -200); + } + + if(mouseX > guiLeft+96+x*18-1 && mouseX < guiLeft+96+x*18+18) { + if(mouseY > guiTop+15+y*18-1 && mouseY < guiTop+15+y*18+18) { + if(stack != null) stackToRender = stack; + + GlStateManager.disableLighting(); + GlStateManager.disableDepth(); + GlStateManager.colorMask(true, true, true, false); + Utils.drawGradientRect(guiLeft+96+x*18, guiTop+15+y*18, + guiLeft+96+x*18 + 16, guiTop+15+y*18 + 16, -2130706433, -2130706433); + GlStateManager.colorMask(true, true, true, true); + GlStateManager.enableLighting(); + GlStateManager.enableDepth(); + } + } + } + + if(NotEnoughUpdates.INSTANCE.config.tradeMenu.customTradePrices) { + TreeMap> ourTopItems = new TreeMap<>(); + TreeMap ourTopItemsStack = new TreeMap<>(); + TreeMap ourTopItemsCount = new TreeMap<>(); + int ourPrice = 0; + for(int i=0; i<16; i++) { + int x = i % 4; + int y = i / 4; + int containerIndex = y*9+x; + + ItemStack stack = chest.inventorySlots.getInventory().get(containerIndex); + if(stack == null) continue; + + ourPrice += processTopItems(stack, ourTopItems, ourTopItemsStack, ourTopItemsCount); + } + TreeMap> theirTopItems = new TreeMap<>(); + TreeMap theirTopItemsStack = new TreeMap<>(); + TreeMap theirTopItemsCount = new TreeMap<>(); + int theirPrice = 0; + for(int i=0; i<16; i++) { + int x = i % 4; + int y = i / 4; + int containerIndex = y*9+x+5; + + ItemStack stack = chest.inventorySlots.getInventory().get(containerIndex); + if(stack == null) continue; + + theirPrice += processTopItems(stack, theirTopItems, theirTopItemsStack, theirTopItemsCount); + } + + NumberFormat format = NumberFormat.getInstance(Locale.US); + + GlStateManager.disableLighting(); + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(location); + Utils.drawTexturedRect(guiLeft-80-3, guiTop, 80, 106, + 176/256f, 1, 0, 106/256f, GL11.GL_NEAREST); + drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+"Total Value", + guiLeft-40-3, guiTop+11, 72); + drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+format.format(ourPrice), + guiLeft-40-3, guiTop+21, 72); + + int ourTopIndex = Math.max(0, 3-ourTopItemsStack.size()); + out: + for(Map.Entry> entry : ourTopItems.descendingMap().entrySet()) { + for(String ourTopItemInternal : entry.getValue()) { + ItemStack stack = ourTopItemsStack.get(ourTopItemInternal); + if(stack == null) continue; + + if(NotEnoughUpdates.INSTANCE.config.tradeMenu.customTradePriceStyle) { + String countS = ""; + if(ourTopItemsCount.containsKey(ourTopItemInternal)) { + int count = ourTopItemsCount.get(ourTopItemInternal); + if(count > 999999) { + countS = Math.floor(count/10000f)/100f+"m"; + } else if(count > 999) { + countS = Math.floor(count/10f)/100f+"k"; + } else { + countS = ""+count; + } + } + + Utils.drawItemStackWithText(stack, guiLeft-75-3, guiTop+49+18*ourTopIndex, countS); + + GlStateManager.disableLighting(); + GlStateManager.disableBlend(); + GlStateManager.color(1, 1, 1, 1); + drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+format.format(entry.getKey()), + guiLeft-29-3, guiTop+57+18*ourTopIndex, 52); + GlStateManager.enableBlend(); + } else { + drawStringShadow(stack.getDisplayName() + EnumChatFormatting.GRAY+"x"+ourTopItemsCount.get(ourTopItemInternal), + guiLeft-40-3, guiTop+46+20*ourTopIndex, 72); + drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+format.format(entry.getKey()), + guiLeft-40-3, guiTop+56+20*ourTopIndex, 72); + } + + if(++ourTopIndex >= 3) break out; + } + } + + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(location); + Utils.drawTexturedRect(guiLeft+xSize+3, guiTop, 80, 106, + 176/256f, 1, 0, 106/256f, GL11.GL_NEAREST); + drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+"Total Value", + guiLeft+xSize+3+40, guiTop+11, 72); + drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+format.format(theirPrice), + guiLeft+xSize+3+40, guiTop+21, 72); + + int theirTopIndex = Math.max(0, 3-theirTopItemsStack.size()); + out: + for(Map.Entry> entry : theirTopItems.descendingMap().entrySet()) { + for(String theirTopItemInternal : entry.getValue()) { + ItemStack stack = theirTopItemsStack.get(theirTopItemInternal); + if(stack == null) continue; + + if(NotEnoughUpdates.INSTANCE.config.tradeMenu.customTradePriceStyle) { + String countS = ""; + if(theirTopItemsCount.containsKey(theirTopItemInternal)) { + int count = theirTopItemsCount.get(theirTopItemInternal); + if(count > 999999) { + countS = Math.floor(count/10000f)/100f+"m"; + } else if(count > 999) { + countS = Math.floor(count/10f)/100f+"k"; + } else { + countS = ""+count; + } + } + + Utils.drawItemStackWithText(stack, guiLeft+xSize+25+3-16, guiTop+49+18*theirTopIndex, countS); + + GlStateManager.disableLighting(); + GlStateManager.disableBlend(); + GlStateManager.color(1, 1, 1, 1); + drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+format.format(entry.getKey()), + guiLeft+xSize+3+51, guiTop+57+18*theirTopIndex, 52); + GlStateManager.enableBlend(); + } else { + drawStringShadow(stack.getDisplayName(), + guiLeft+xSize+3+40, guiTop+46+20*theirTopIndex, 72); + drawStringShadow(EnumChatFormatting.GOLD.toString()+EnumChatFormatting.BOLD+format.format(entry.getKey()), + guiLeft+xSize+3+40, guiTop+56+20*theirTopIndex, 72); + } + + if(++theirTopIndex >= 3) break out; + } + } + } + + + boolean button1 = NotEnoughUpdates.INSTANCE.config.tradeMenu.customTradePriceStyle; + boolean button2 = NotEnoughUpdates.INSTANCE.config.tradeMenu.customTradePrices; + boolean button3 = NotEnoughUpdates.INSTANCE.config.tradeMenu.enableCustomTrade; + + GlStateManager.color(1, 1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(location); + Utils.drawTexturedRect(guiLeft+xSize+3, guiTop+ySize-19, 17, 17, + (button3?17:0)/256f, (button3?34:17)/256f, 218/256f, 235/256f, GL11.GL_NEAREST); + Utils.drawTexturedRect(guiLeft+xSize+3, guiTop+ySize-38, 17, 17, + (button2?17:0)/256f, (button2?34:17)/256f, 218/256f, 235/256f, GL11.GL_NEAREST); + Utils.drawTexturedRect(guiLeft+xSize+3, guiTop+ySize-57, 17, 17, + (button1?17:0)/256f, (button1?34:17)/256f, 218/256f, 235/256f, GL11.GL_NEAREST); + + if(mouseX >= guiLeft+xSize+3 && mouseX <= guiLeft+xSize+3+17) { + if(mouseY >= guiTop+ySize-19 && mouseY <= guiTop+ySize-19+17) { + tooltipToDisplay = new ArrayList<>(); + tooltipToDisplay.add(EnumChatFormatting.GOLD+"Enable Custom Trade Menu"); + tooltipToDisplay.add(EnumChatFormatting.GRAY+"Use this menu instead of the default trade window"); + tooltipLen = 200; + } else if(mouseY >= guiTop+ySize-38 && mouseY <= guiTop+ySize-38+17) { + tooltipToDisplay = new ArrayList<>(); + tooltipToDisplay.add(EnumChatFormatting.GOLD+"Price Information"); + tooltipToDisplay.add(EnumChatFormatting.GRAY+"Show the price of items on both sides"); + tooltipLen = 200; + } else if(mouseY >= guiTop+ySize-57 && mouseY <= guiTop+ySize-57+17) { + tooltipToDisplay = new ArrayList<>(); + tooltipToDisplay.add(EnumChatFormatting.GOLD+"Trade Prices Style"); + tooltipToDisplay.add(EnumChatFormatting.GRAY+"Changes the style of the top item prices"); + tooltipLen = 200; + } + } + + if(stackToRender == null && !SBAIntegration.isFreezeBackpack()) lastBackpack = null; + if(SBAIntegration.isFreezeBackpack()) { + if(lastBackpack != null) { + SBAIntegration.setActiveBackpack(lastBackpack, lastBackpackX, lastBackpackY); + GlStateManager.translate(0, 0, 100); + SBAIntegration.renderActiveBackpack(mouseX, mouseY, Minecraft.getMinecraft().fontRendererObj); + GlStateManager.translate(0, 0, -100); + } + } else { + if(stackToRender != null) { + String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stackToRender); + boolean renderedBackpack; + if(internalname != null && (internalname.endsWith("BACKPACK") || internalname.equals("NEW_YEAR_CAKE_BAG"))) { + lastBackpack = stackToRender; + lastBackpackX = mouseX; + lastBackpackY = mouseY; + renderedBackpack = SBAIntegration.setActiveBackpack(lastBackpack, lastBackpackX, lastBackpackY); + if(renderedBackpack) { + GlStateManager.translate(0, 0, 100); + renderedBackpack = SBAIntegration.renderActiveBackpack(mouseX, mouseY, Minecraft.getMinecraft().fontRendererObj); + GlStateManager.translate(0, 0, -100); + } + } else { + renderedBackpack = false; + } + if(!renderedBackpack) { + lastBackpack = null; + tooltipToDisplay = stackToRender.getTooltip(Minecraft.getMinecraft().thePlayer, + Minecraft.getMinecraft().gameSettings.advancedItemTooltips); + } + } + } + + if(tooltipToDisplay != null) { + Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, scaledResolution.getScaledWidth(), scaledResolution.getScaledHeight(), + tooltipLen, Minecraft.getMinecraft().fontRendererObj); + } + } + + public static void handleMouseInput() { + if(!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return; + + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + + int mouseX = Mouse.getEventX() * width / Minecraft.getMinecraft().displayWidth; + int mouseY = height - Mouse.getEventY() * height / Minecraft.getMinecraft().displayHeight - 1; + + GuiContainer chest = ((GuiContainer)Minecraft.getMinecraft().currentScreen); + + if(Mouse.getEventButtonState() && Mouse.isButtonDown(0)) { + int index=0; + for(ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { + if(stack == null) { + index++; + continue; + } + + int x = 8+18*(index % 9); + int y = 104+18*(index / 9); + if(index < 9) y = 180; + + if(mouseX > guiLeft+x && mouseX < guiLeft+x+16) { + if(mouseY > guiTop+y && mouseY < guiTop+y+16) { + Slot slot = chest.inventorySlots.getSlotFromInventory(Minecraft.getMinecraft().thePlayer.inventory, index); + Minecraft.getMinecraft().playerController.windowClick( + chest.inventorySlots.windowId, + slot.slotNumber, 2, 3, Minecraft.getMinecraft().thePlayer); + return; + } + } + + index++; + } + + for(int i=0; i<16; i++) { + int x = i % 4; + int y = i / 4; + + int containerIndex = ourTradeIndexes[i]; + if(containerIndex < 0) continue; + + if(mouseX > guiLeft+10+x*18-1 && mouseX < guiLeft+10+x*18+18) { + if(mouseY > guiTop+15+y*18-1 && mouseY < guiTop+15+y*18+18) { + Minecraft.getMinecraft().playerController.windowClick( + chest.inventorySlots.windowId, + containerIndex, 2, 3, Minecraft.getMinecraft().thePlayer); + return; + } + } + } + + if(mouseX > guiLeft+10-1 && mouseX < guiLeft+10+18) { + if(mouseY > guiTop+90-1 && mouseY < guiTop+90+18) { + Minecraft.getMinecraft().playerController.windowClick( + chest.inventorySlots.windowId, + 36, 2, 3, Minecraft.getMinecraft().thePlayer); + return; + } + } + + ItemStack confirmStack = chest.inventorySlots.getInventory().get(39); + if(confirmStack != null) { + String confirmDisplay = confirmStack.getDisplayName(); + if(!confirmDisplay.equals(EnumChatFormatting.GREEN+"Trading!")) { + if(mouseX > guiLeft+42 && mouseX < guiLeft+42+40) { + if (mouseY > guiTop+92 && mouseY < guiTop+92+14) { + if((confirmDisplay.equals(EnumChatFormatting.YELLOW+"Warning!") || + confirmDisplay.equals(EnumChatFormatting.YELLOW+"Deal!")) && lastTradeMillis < 0) { + lastTradeMillis = System.currentTimeMillis(); + } else if(lastTradeMillis < 0 || System.currentTimeMillis() - lastTradeMillis > 2000) { + Minecraft.getMinecraft().playerController.windowClick( + chest.inventorySlots.windowId, + 39, 2, 3, Minecraft.getMinecraft().thePlayer); + return; + } + } + } + + } + } + + if(mouseX >= guiLeft+xSize+3 && mouseX <= guiLeft+xSize+3+17) { + if(mouseY >= guiTop+ySize-19 && mouseY <= guiTop+ySize-19+17) { + NotEnoughUpdates.INSTANCE.config.tradeMenu.enableCustomTrade = + !NotEnoughUpdates.INSTANCE.config.tradeMenu.enableCustomTrade; + return; + } else if(mouseY >= guiTop+ySize-38 && mouseY <= guiTop+ySize-38+17) { + NotEnoughUpdates.INSTANCE.config.tradeMenu.customTradePrices = + !NotEnoughUpdates.INSTANCE.config.tradeMenu.customTradePrices; + return; + } else if(mouseY >= guiTop+ySize-57 && mouseY <= guiTop+ySize-57+17) { + NotEnoughUpdates.INSTANCE.config.tradeMenu.customTradePriceStyle = + !NotEnoughUpdates.INSTANCE.config.tradeMenu.customTradePriceStyle; + return; + } + } + } + } + + public static boolean keyboardInput() { + return Keyboard.getEventKey() != Keyboard.KEY_ESCAPE; + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinContainer.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinContainer.java new file mode 100644 index 00000000..d3c96896 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinContainer.java @@ -0,0 +1,19 @@ +package io.github.moulberry.notenoughupdates.mixins; + +import io.github.moulberry.notenoughupdates.miscfeatures.EnchantingSolvers; +import net.minecraft.inventory.Container; +import net.minecraft.item.ItemStack; +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(Container.class) +public class MixinContainer { + + @Inject(method = "putStacksInSlots", at=@At("RETURN")) + public void putStacksInSlots(ItemStack[] stacks, CallbackInfo ci) { + EnchantingSolvers.processInventoryContents(); + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinEntityRenderer.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinEntityRenderer.java index b9820033..6ca5a308 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinEntityRenderer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinEntityRenderer.java @@ -1,20 +1,11 @@ package io.github.moulberry.notenoughupdates.mixins; -import io.github.moulberry.notenoughupdates.BetterContainers; -import io.github.moulberry.notenoughupdates.CustomItemEffects; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import net.minecraft.client.gui.FontRenderer; +import io.github.moulberry.notenoughupdates.miscfeatures.CustomItemEffects; import net.minecraft.client.renderer.EntityRenderer; -import net.minecraft.client.renderer.RenderGlobal; -import net.minecraft.entity.Entity; -import net.minecraft.util.EnumWorldBlockLayer; import org.lwjgl.util.vector.Vector3f; 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.ModifyVariable; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(EntityRenderer.class) public class MixinEntityRenderer { 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 bd74b44c..da704ce3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiChest.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiChest.java @@ -1,24 +1,13 @@ 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 io.github.moulberry.notenoughupdates.miscfeatures.BetterContainers; 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; import net.minecraft.client.renderer.texture.TextureManager; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.scoreboard.ScorePlayerTeam; -import net.minecraft.scoreboard.Team; import net.minecraft.util.ResourceLocation; 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.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin({GuiChest.class}) public class MixinGuiChest { 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 e6d0a986..12d1f929 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java @@ -1,20 +1,18 @@ package io.github.moulberry.notenoughupdates.mixins; -import io.github.moulberry.notenoughupdates.BetterContainers; +import io.github.moulberry.notenoughupdates.miscfeatures.BetterContainers; +import io.github.moulberry.notenoughupdates.miscfeatures.EnchantingSolvers; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiChest; import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.renderer.texture.TextureManager; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.client.renderer.RenderHelper; import net.minecraft.inventory.Container; import net.minecraft.inventory.ContainerChest; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -23,7 +21,7 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(GuiContainer.class) -public abstract class MixinGuiContainer { +public abstract class MixinGuiContainer extends GuiScreen { @Inject(method="drawSlot", at=@At("HEAD"), cancellable = true) public void drawSlot(Slot slot, CallbackInfo ci) { @@ -32,6 +30,15 @@ public abstract class MixinGuiContainer { GuiContainer $this = (GuiContainer)(Object)this; ItemStack stack = slot.getStack(); + if(stack != null) { + if(EnchantingSolvers.onStackRender(stack, slot.inventory, slot.getSlotIndex(), slot.xDisplayPosition, slot.yDisplayPosition)) { + ci.cancel(); + return; + } + } + + RenderHelper.enableGUIStandardItemLighting(); + if(stack == null && System.currentTimeMillis() - BetterContainers.lastRenderMillis < 300 && $this instanceof GuiChest) { Container container = ((GuiChest)$this).inventorySlots; if(container instanceof ContainerChest) { @@ -58,12 +65,33 @@ public abstract class MixinGuiContainer { } } + @Shadow + private Slot theSlot; + private static final String TARGET_GETSTACK = "Lnet/minecraft/inventory/Slot;getStack()Lnet/minecraft/item/ItemStack;"; + @Redirect(method="drawScreen", at=@At(value="INVOKE", target=TARGET_GETSTACK)) + public ItemStack drawScreen_getStack(Slot slot) { + if(theSlot != null && theSlot == slot && theSlot.getStack() != null) { + ItemStack newStack = EnchantingSolvers.overrideStack(theSlot.inventory, theSlot.getSlotIndex(), theSlot.getStack()); + if(newStack != null) { + return newStack; + } + } + return slot.getStack(); + } + @Redirect(method="drawSlot", at=@At(value="INVOKE", target=TARGET_GETSTACK)) public ItemStack drawSlot_getStack(Slot slot) { GuiContainer $this = (GuiContainer)(Object)this; ItemStack stack = slot.getStack(); + if(stack != null) { + ItemStack newStack = EnchantingSolvers.overrideStack(slot.inventory, slot.getSlotIndex(), stack); + if(newStack != null) { + stack = newStack; + } + } + if($this instanceof GuiChest) { Container container = ((GuiChest)$this).inventorySlots; if(container instanceof ContainerChest) { @@ -91,7 +119,7 @@ public abstract class MixinGuiContainer { private static final String TARGET_CANBEHOVERED = "Lnet/minecraft/inventory/Slot;canBeHovered()Z"; @Redirect(method="drawScreen", at=@At(value="INVOKE", target=TARGET_CANBEHOVERED)) public boolean drawScreen_canBeHovered(Slot slot) { - if(NotEnoughUpdates.INSTANCE.manager.config.hideEmptyPanes.value && + if(NotEnoughUpdates.INSTANCE.config.improvedSBMenu.hideEmptyPanes && BetterContainers.isOverriding() && BetterContainers.isBlankStack(slot.getStack())) { return false; } @@ -100,12 +128,18 @@ public abstract class MixinGuiContainer { @Inject(method="handleMouseClick", at=@At(value="HEAD"), cancellable = true) public void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType, CallbackInfo ci) { + GuiContainer $this = (GuiContainer)(Object)this; + if(slotIn != null && slotIn.getStack() != null) { + if(EnchantingSolvers.onStackClick(slotIn.getStack(), $this.inventorySlots.windowId, + slotId, clickedButton, clickType)) { + ci.cancel(); + } + } if(slotIn != null && BetterContainers.isOverriding() && (BetterContainers.isBlankStack(slotIn.getStack()) || BetterContainers.isButtonStack(slotIn.getStack()))) { BetterContainers.clickSlot(slotIn.getSlotIndex()); if(BetterContainers.isBlankStack(slotIn.getStack())) { - GuiContainer $this = (GuiContainer)(Object)this; $this.mc.playerController.windowClick($this.inventorySlots.windowId, slotId, 2, clickType, $this.mc.thePlayer); ci.cancel(); } else { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiIngame.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiIngame.java index 60361306..4ec15bea 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiIngame.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiIngame.java @@ -1,7 +1,7 @@ package io.github.moulberry.notenoughupdates.mixins; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.StreamerMode; +import io.github.moulberry.notenoughupdates.miscfeatures.StreamerMode; import net.minecraft.client.gui.GuiIngame; import net.minecraft.scoreboard.ScorePlayerTeam; import net.minecraft.scoreboard.Team; @@ -16,7 +16,7 @@ public class MixinGuiIngame { "formatPlayerName(Lnet/minecraft/scoreboard/Team;Ljava/lang/String;)Ljava/lang/String;"; @Redirect(method="renderScoreboard", at=@At(value="INVOKE", target=TARGET)) public String renderScoreboard_formatPlayerName(Team team, String name) { - if(NotEnoughUpdates.INSTANCE.isOnSkyblock() && NotEnoughUpdates.INSTANCE.manager.config.streamerMode.value) { + if(NotEnoughUpdates.INSTANCE.isOnSkyblock() && NotEnoughUpdates.INSTANCE.config.misc.streamerMode) { return StreamerMode.filterScoreboard(ScorePlayerTeam.formatPlayerName(team, name)); } return ScorePlayerTeam.formatPlayerName(team, name); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinInventoryEffectRenderer.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinInventoryEffectRenderer.java index 00fdc873..390896f2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinInventoryEffectRenderer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinInventoryEffectRenderer.java @@ -13,7 +13,7 @@ public class MixinInventoryEffectRenderer { @ModifyVariable(method="updateActivePotionEffects", at=@At(value="STORE")) public boolean hasVisibleEffect_updateActivePotionEffects(boolean hasVisibleEffect) { - if(NotEnoughUpdates.INSTANCE.manager.config.hidePotionEffect.value && + if(NotEnoughUpdates.INSTANCE.config.misc.hidePotionEffect && NotEnoughUpdates.INSTANCE.isOnSkyblock()) { return false; } else { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinNetHandlerPlayClient.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinNetHandlerPlayClient.java index 0bb84f44..19bcdacf 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinNetHandlerPlayClient.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinNetHandlerPlayClient.java @@ -1,16 +1,16 @@ package io.github.moulberry.notenoughupdates.mixins; -import io.github.moulberry.notenoughupdates.CustomItemEffects; +import io.github.moulberry.notenoughupdates.miscfeatures.CustomItemEffects; +import io.github.moulberry.notenoughupdates.miscfeatures.EnchantingSolvers; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.StreamerMode; import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.scoreboard.ScorePlayerTeam; -import net.minecraft.scoreboard.Team; -import org.lwjgl.util.vector.Vector3f; +import net.minecraft.network.play.server.S2FPacketSetSlot; 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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(NetHandlerPlayClient.class) public class MixinNetHandlerPlayClient { @@ -21,9 +21,16 @@ public class MixinNetHandlerPlayClient { public void handlePlayerPosLook_setPositionAndRotation(EntityPlayer player, double x, double y, double z, float yaw, float pitch) { if(CustomItemEffects.INSTANCE.aoteTeleportationCurr != null) { CustomItemEffects.INSTANCE.aoteTeleportationMillis += - Math.max(0, Math.min(300, NotEnoughUpdates.INSTANCE.manager.config.smoothAoteMillis.value)); + Math.max(0, Math.min(300, NotEnoughUpdates.INSTANCE.config.smoothAOTE.smoothTpMillis)); } player.setPositionAndRotation(x, y, z, yaw, pitch); } + @Inject(method="handleSetSlot", at=@At("HEAD")) + public void handleSetSlot(S2FPacketSetSlot packetIn, CallbackInfo ci) { + EnchantingSolvers.processInventoryContents(); + } + + + } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRender.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRender.java index 2c92a0b1..106f9f94 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRender.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRender.java @@ -20,7 +20,7 @@ public class MixinRender { public void bindEntityTexture(Entity entity, CallbackInfoReturnable cir) { if(entity instanceof EntityBat && DungeonBlocks.isOverriding()) { if(DungeonBlocks.bindModifiedTexture(new ResourceLocation("textures/entity/bat.png"), - SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.manager.config.dungChestColour.value))) { + SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.dungeonBlock.dungBatColour))) { cir.setReturnValue(true); 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/MixinRenderFish.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderFish.java index fc536267..12888dcb 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderFish.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderFish.java @@ -34,7 +34,7 @@ public abstract class MixinRenderFish extends Render { @Inject(method = "doRender(Lnet/minecraft/entity/projectile/EntityFishHook;DDDFF)V", at=@At(value = "HEAD"), cancellable = true) public void render(EntityFishHook entity, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci) { - if(!NotEnoughUpdates.INSTANCE.manager.config.rodColours.value || entity == null) return; + if(!NotEnoughUpdates.INSTANCE.config.rodColours.enableRodColours || entity == null) return; String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(entity.angler.getHeldItem()); if (NotEnoughUpdates.INSTANCE.isOnSkyblock() && internalname != null && entity.angler != null && @@ -103,9 +103,9 @@ public abstract class MixinRenderFish extends Render { String specialColour; if (entity.angler.getUniqueID().equals(Minecraft.getMinecraft().thePlayer.getUniqueID())) { - specialColour = NotEnoughUpdates.INSTANCE.manager.config.selfRodLineColour.value; + specialColour = NotEnoughUpdates.INSTANCE.config.rodColours.ownRodColour; } else { - specialColour = NotEnoughUpdates.INSTANCE.manager.config.otherRodLineColour.value; + specialColour = NotEnoughUpdates.INSTANCE.config.rodColours.otherRodColour; } int colourI = SpecialColour.specialToChromaRGB(specialColour); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderGlobal.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderGlobal.java index 2bb5503b..1b2b99ec 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderGlobal.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderGlobal.java @@ -1,11 +1,16 @@ package io.github.moulberry.notenoughupdates.mixins; -import io.github.moulberry.notenoughupdates.CustomItemEffects; +import io.github.moulberry.notenoughupdates.miscfeatures.CustomItemEffects; +import io.github.moulberry.notenoughupdates.cosmetics.CapeManager; import net.minecraft.client.renderer.RenderGlobal; +import net.minecraft.entity.Entity; +import net.minecraft.util.EnumWorldBlockLayer; import org.lwjgl.util.vector.Vector3f; 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.ModifyVariable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(RenderGlobal.class) public class MixinRenderGlobal { @@ -66,4 +71,12 @@ public class MixinRenderGlobal { return d5; } + @Inject(method="renderBlockLayer", at=@At("RETURN")) + public void renderBlockLayer(EnumWorldBlockLayer blockLayerIn, double partialTicks, int pass, + Entity entityIn, CallbackInfoReturnable cir) { + if(blockLayerIn == EnumWorldBlockLayer.CUTOUT) { + CapeManager.getInstance().postRenderBlocks(); + } + } + } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java index 67f0f7dc..6e552e3c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java @@ -1,42 +1,13 @@ package io.github.moulberry.notenoughupdates.mixins; -import io.github.moulberry.notenoughupdates.ItemRarityHalo; -import io.github.moulberry.notenoughupdates.NEUResourceManager; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -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 io.github.moulberry.notenoughupdates.miscfeatures.ItemRarityHalo; import net.minecraft.client.renderer.entity.RenderItem; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.client.resources.model.IBakedModel; -import net.minecraft.client.shader.Framebuffer; -import net.minecraft.client.shader.Shader; import net.minecraft.item.ItemStack; -import net.minecraft.util.Matrix4f; -import org.lwjgl.BufferUtils; import org.lwjgl.input.Keyboard; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL14; -import org.lwjgl.opengl.GL30; -import org.lwjgl.util.vector.Vector4f; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; 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 javax.vecmath.Vector3f; -import java.awt.*; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.nio.FloatBuffer; -import java.nio.IntBuffer; -import java.util.HashMap; @Mixin({RenderItem.class}) public abstract class MixinRenderItem { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinTileEntitySpecialRenderer.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinTileEntitySpecialRenderer.java index d53f62c9..f7c2435a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinTileEntitySpecialRenderer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinTileEntitySpecialRenderer.java @@ -21,8 +21,8 @@ public abstract class MixinTileEntitySpecialRenderer { location.getResourcePath().equals("textures/entity/chest/normal_double.png") || location.getResourcePath().equals("textures/entity/chest/trapped.png") || location.getResourcePath().equals("textures/entity/chest/trapped_double.png")) { - String colour = location.getResourcePath().contains("trapped") ? NotEnoughUpdates.INSTANCE.manager.config.dungTrappedChestColour.value : - NotEnoughUpdates.INSTANCE.manager.config.dungChestColour.value; + String colour = location.getResourcePath().contains("trapped") ? NotEnoughUpdates.INSTANCE.config.dungeonBlock.dungTrappedChestColour : + NotEnoughUpdates.INSTANCE.config.dungeonBlock.dungChestColour; if(DungeonBlocks.bindModifiedTexture(location, SpecialColour.specialToChromaRGB(colour))) { info.cancel(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinWorld.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinWorld.java new file mode 100644 index 00000000..bedfafc9 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinWorld.java @@ -0,0 +1,25 @@ +package io.github.moulberry.notenoughupdates.mixins; + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.miscfeatures.CustomItemEffects; +import net.minecraft.world.World; +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(World.class) +public class MixinWorld { + + @Inject(method="spawnParticle(IZDDDDDD[I)V", at=@At("HEAD"), cancellable = true) + public void spawnParticle(int particleID, boolean p_175720_2_, double xCood, double yCoord, double zCoord, + double xOffset, double yOffset, double zOffset, int[] p_175720_15_, CallbackInfo ci) { + if(NotEnoughUpdates.INSTANCE.config.smoothAOTE.disableHyperionParticles && + System.currentTimeMillis() - CustomItemEffects.INSTANCE.lastUsedHyperion < 500) { + if(particleID == 1) { + ci.cancel(); + } + } + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java new file mode 100644 index 00000000..3aa7d122 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -0,0 +1,1234 @@ +package io.github.moulberry.notenoughupdates.options; + +import com.google.common.collect.Lists; +import com.google.gson.annotations.Expose; +import io.github.moulberry.notenoughupdates.core.config.Config; +import io.github.moulberry.notenoughupdates.core.config.annotations.*; + +import java.util.ArrayList; + +public class NEUConfig extends Config { + + @Expose + @Category( + name = "Misc", + desc = "Miscellaneous options which don't fit into any other category" + ) + public Misc misc = new Misc(); + + @Expose + @Category( + name = "Notifications", + desc = "Notifications" + ) + public Notifications notifications = new Notifications(); + + @Expose + @Category( + name = "Item List", + desc = "Modify the item list which shows when opening an inventory" + ) + public Itemlist itemlist = new Itemlist(); + + @Expose + @Category( + name = "Toolbar", + desc = "Toolbar" + ) + public Toolbar toolbar = new Toolbar(); + + @Expose + @Category( + name = "Tooltip Tweaks", + desc = "Tooltip Tweaks" + ) + public TooltipTweaks tooltipTweaks = new TooltipTweaks(); + + @Expose + @Category( + name = "Price Info (Auction)", + desc = "Price Info (Auction)" + ) + public PriceInfoAuc priceInfoAuc = new PriceInfoAuc(); + + @Expose + @Category( + name = "Price Info (Bazaar)", + desc = "Price Info (Bazaar)" + ) + public PriceInfoBaz priceInfoBaz = new PriceInfoBaz(); + + @Expose + @Category( + name = "Dungeon Profit", + desc = "Dungeon Profit" + ) + public DungeonProfit dungeonProfit = new DungeonProfit(); + + + @Expose + @Category( + name = "Dungeon Solvers", + desc = "Dungeon Solvers" + ) + public DungeonSolvers dungeonSolvers = new DungeonSolvers(); + + + @Expose + @Category( + name = "Enchanting Solvers", + desc = "Enchanting Solvers" + ) + public EnchSolvers enchantingSolvers = new EnchSolvers(); + + @Expose + @Category( + name = "NEU Auction House", + desc = "NEU Auction House" + ) + public NeuAuctionHouse neuAuctionHouse = new NeuAuctionHouse(); + + @Expose + @Category( + name = "Improved SB Menus", + desc = "Improved SB Menus" + ) + public ImprovedSBMenu improvedSBMenu = new ImprovedSBMenu(); + + @Expose + @Category( + name = "Calendar", + desc = "Calendar" + ) + public Calendar calendar = new Calendar(); + + @Expose + @Category( + name = "Trade Menu", + desc = "Trade Menu" + ) + public TradeMenu tradeMenu = new TradeMenu(); + + @Expose + @Category( + name = "Treecap Overlay", + desc = "Treecap Overlay" + ) + public TreecapOverlay treecapOverlay = new TreecapOverlay(); + + @Expose + @Category( + name = "Builders Wand Overlay", + desc = "Builders Wand Overlay" + ) + public BuilderWand builderWand = new BuilderWand(); + + @Expose + @Category( + name = "Dungeon Block Overlay", + desc = "Dungeon Block Overlay" + ) + public DungeonBlock dungeonBlock = new DungeonBlock(); + + @Expose + @Category( + name = "Accessory Bag Overlay", + desc = "Accessory Bag Overlay" + ) + public AccessoryBag accessoryBag = new AccessoryBag(); + + @Expose + @Category( + name = "Smooth AOTE", + desc = "Smooth AOTE" + ) + public SmoothAOTE smoothAOTE = new SmoothAOTE(); + + @Expose + @Category( + name = "Custom Rod Colours", + desc = "Custom Rod Colours" + ) + public RodColours rodColours = new RodColours(); + + @Expose + @Category( + name = "Dungeon Win Overlay", + desc = "Dungeon Win Overlay" + ) + public DungeonWin dungeonWin = new DungeonWin(); + + @Expose + @Category( + name = "Api Key", + desc = "Api Key" + ) + public ApiKey apiKey = new ApiKey(); + + @Expose + public Hidden hidden = new Hidden(); + + @Expose + public DungeonMap dungeonMap = new DungeonMap(); + + public static class Misc { + @Expose + @ConfigOption( + name = "Only Show on Skyblock", + desc = "The item list and some other GUI elements will only show on skyblock" + ) + @ConfigEditorBoolean + public boolean onlyShowOnSkyblock = true; + + @Expose + @ConfigOption( + name = "Hide Potion Effects", + desc = "Hides the potion effects inside your inventory while on skyblock" + ) + @ConfigEditorBoolean + public boolean hidePotionEffect = true; + + @Expose + @ConfigOption( + name = "Streamer Mode", + desc = "Randomizes lobby names in the scoreboard and chat messages to help prevent stream sniping" + ) + @ConfigEditorBoolean + public boolean streamerMode = false; + + @Expose + @ConfigOption( + name = "Gui Click Sounds", + desc = "Plays click sounds in various NEU-related GUIs when pressing buttons" + ) + @ConfigEditorBoolean + public boolean guiButtonClicks = true; + } + + public static class Notifications { + @Expose + @ConfigOption( + name = "Update Messages", + desc = "Give a notification in chat whenever a new version of NEU is released" + ) + @ConfigEditorBoolean + public boolean showUpdateMsg = true; + } + + public static class Itemlist { + @Expose + @ConfigOption( + name = "Show Vanilla Items", + desc = "Vanilla items are included in the item list" + ) + @ConfigEditorBoolean + public boolean showVanillaItems = true; + + @Expose + @ConfigOption( + name = "Open Itemlist Arrow", + desc = "Creates an arrow on the right-side to open the item list when hovered" + ) + @ConfigEditorBoolean + public boolean tabOpen = true; + + @Expose + @ConfigOption( + name = "Keep Open", + desc = "Keeps the Itemlist open after the inventory is closed" + ) + @ConfigEditorBoolean + public boolean keepopen = false; + + @Expose + @ConfigOption( + name = "Item Style", + desc = "Sets the style of the background behind items" + ) + @ConfigEditorDropdown( + values = {"Round", "Square"} + ) + public int itemStyle = 0; + + @Expose + @ConfigOption( + name = "Pane Gui Scale", + desc = "Change the gui scale of the Itemlist" + ) + @ConfigEditorDropdown( + values = {"Default", "Small", "Medium", "Large", "Auto"} + ) + public int paneGuiScale = 0; + + @Expose + @ConfigOption( + name = "Background Blur", + desc = "Change the blur amount behind the Itemlist. 0 = off" + ) + @ConfigEditorSlider( + minValue = 0, + maxValue = 20, + minStep = 1 + ) + public int bgBlurFactor = 5; + + @Expose + @ConfigOption( + name = "Pane Width Multiplier", + desc = "Change the width of the Itemlist" + ) + @ConfigEditorSlider( + minValue = 0.5f, + maxValue = 1.5f, + minStep = 0.1f + ) + public float paneWidthMult = 1.0f; + + @Expose + @ConfigOption( + name = "Pane Padding", + desc = "Change the padding around the Itemlist" + ) + @ConfigEditorSlider( + minValue = 0f, + maxValue = 20f, + minStep = 1f + ) + public int panePadding = 10; + + @Expose + @ConfigOption( + name = "Foreground Colour", + desc = "Change the colour of foreground elements in the Itemlist" + ) + @ConfigEditorColour + public String foregroundColour = "00:255:100:100:100"; + + @Expose + @ConfigOption( + name = "Favourite Colour", + desc = "Change the colour of favourited elements in the Itemlist" + ) + @ConfigEditorColour + public String favouriteColour = "00:255:200:150:50"; + + @Expose + @ConfigOption( + name = "Pane Background Colour", + desc = "Change the colour of the Itemlist background" + ) + @ConfigEditorColour + public String backgroundColour = "15:6:0:0:255"; + } + + public static class Toolbar { + @Expose + @ConfigOption( + name = "Show Quick Commands", + desc = "Show QuickCommands\u2122 in the NEU toolbar" + ) + @ConfigEditorBoolean + public boolean quickCommands = true; + + @Expose + @ConfigOption( + name = "Show Search Bar", + desc = "Show Itemlist search bar in the NEU toolbar" + ) + @ConfigEditorBoolean + public boolean searchBar = true; + + @Expose + @ConfigOption( + name = "Search Bar Width", + desc = "Change the width of the search bar" + ) + @ConfigEditorSlider( + minValue = 50f, + maxValue = 300f, + minStep = 10f + ) + public int searchBarWidth = 200; + + @Expose + @ConfigOption( + name = "Search Bar Height", + desc = "Change the height of the search bar" + ) + @ConfigEditorSlider( + minValue = 15f, + maxValue = 50f, + minStep = 1f + ) + public int searchBarHeight = 40; + + @Expose + @ConfigOption( + name = "Quick Commands Click Type", + desc = "Change the click type needed to trigger quick commands" + ) + @ConfigEditorDropdown( + values = {"Mouse Up", "Mouse Down"} + ) + public int quickCommandsClickType = 0; + } + + public static class TooltipTweaks { + @Expose + @ConfigOption( + name = "Price Info (Inv)", + desc = "Show price information for items in your inventory" + ) + @ConfigEditorBoolean + public boolean showPriceInfoInvItem = true; + + @Expose + @ConfigOption( + name = "Price Info (AH)", + desc = "Show price information for auctioned items" + ) + @ConfigEditorBoolean + public boolean showPriceInfoAucItem = true; + + @Expose + @ConfigOption( + name = "Missing Enchant List", + desc = "Show which enchants are missing on an item when pressing LSHIFT" + ) + @ConfigEditorBoolean + public boolean missingEnchantList = true; + + @Expose + @ConfigOption( + name = "Tooltip Border Colours", + desc = "Make the borders of tooltips match the rarity of the item (NEU Tooltips Only)" + ) + @ConfigEditorBoolean + public boolean tooltipBorderColours = true; + + @Expose + @ConfigOption( + name = "Tooltip Border Opacity", + desc = "Change the opacity of the rarity highlight (NEU Tooltips Only)" + ) + @ConfigEditorSlider( + minValue = 0f, + maxValue = 255f, + minStep = 1f + ) + public int tooltipBorderOpacity = 200; + } + + public static class PriceInfoAuc { + @Expose + @ConfigOption( + name = "Line 1", + desc = "Set the price information displayed on Line #1" + ) + @ConfigEditorDropdown( + values = {"", "Lowest BIN", "AH Price", "AH Sales", "Raw Craft Cost", "AVG Lowest BIN"} + ) + public int line1 = 1; + + @Expose + @ConfigOption( + name = "Line 2", + desc = "Set the price information displayed on Line #2" + ) + @ConfigEditorDropdown( + values = {"", "Lowest BIN", "AH Price", "AH Sales", "Raw Craft Cost", "AVG Lowest BIN"} + ) + public int line2 = 2; + + @Expose + @ConfigOption( + name = "Line 3", + desc = "Set the price information displayed on Line #3" + ) + @ConfigEditorDropdown( + values = {"", "Lowest BIN", "AH Price", "AH Sales", "Raw Craft Cost", "AVG Lowest BIN"} + ) + public int line3 = 3; + + @Expose + @ConfigOption( + name = "Line 4", + desc = "Set the price information displayed on Line #4" + ) + @ConfigEditorDropdown( + values = {"", "Lowest BIN", "AH Price", "AH Sales", "Raw Craft Cost", "AVG Lowest BIN"} + ) + public int line4 = 4; + + @Expose + @ConfigOption( + name = "Line 5", + desc = "Set the price information displayed on Line #5" + ) + @ConfigEditorDropdown( + values = {"", "Lowest BIN", "AH Price", "AH Sales", "Raw Craft Cost", "AVG Lowest BIN"} + ) + public int line5 = 0; + + @Expose + @ConfigOption( + name = "Line 6", + desc = "Set the price information displayed on Line #6" + ) + @ConfigEditorDropdown( + values = {"", "Lowest BIN", "AH Price", "AH Sales", "Raw Craft Cost", "AVG Lowest BIN"} + ) + public int line6 = 0; + } + + public static class PriceInfoBaz { + @Expose + @ConfigOption( + name = "Line 1", + desc = "Set the price information displayed on Line #1" + ) + @ConfigEditorDropdown( + values = {"", "Buy", "Sell", "Buy (Insta)", "Sell (Insta)", "Raw Craft Cost"} + ) + public int line1 = 1; + + @Expose + @ConfigOption( + name = "Line 2", + desc = "Set the price information displayed on Line #2" + ) + @ConfigEditorDropdown( + values = {"", "Buy", "Sell", "Buy (Insta)", "Sell (Insta)", "Raw Craft Cost"} + ) + public int line2 = 2; + + @Expose + @ConfigOption( + name = "Line 3", + desc = "Set the price information displayed on Line #3" + ) + @ConfigEditorDropdown( + values = {"", "Buy", "Sell", "Buy (Insta)", "Sell (Insta)", "Raw Craft Cost"} + ) + public int line3 = 3; + + @Expose + @ConfigOption( + name = "Line 4", + desc = "Set the price information displayed on Line #4" + ) + @ConfigEditorDropdown( + values = {"", "Buy", "Sell", "Buy (Insta)", "Sell (Insta)", "Raw Craft Cost"} + ) + public int line4 = 4; + + @Expose + @ConfigOption( + name = "Line 5", + desc = "Set the price information displayed on Line #5" + ) + @ConfigEditorDropdown( + values = {"", "Buy", "Sell", "Buy (Insta)", "Sell (Insta)", "Raw Craft Cost"} + ) + public int line5 = 5; + + @Expose + @ConfigOption( + name = "Line 6", + desc = "Set the price information displayed on Line #6" + ) + @ConfigEditorDropdown( + values = {"", "Buy", "Sell", "Buy (Insta)", "Sell (Insta)", "Raw Craft Cost"} + ) + public int line6 = 0; + } + + public static class DungeonProfit { + @Expose + @ConfigOption( + name = "Profit Type", + desc = "Set the price dataset used for calculating profit" + ) + @ConfigEditorDropdown( + values = {"Lowest BIN", "24 AVG Lowest Bin", "Auction AVG"} + ) + public int profitType = 0; + + @Expose + @ConfigOption( + name = "Profit Display Location", + desc = "Set where the profit information is displayed\n" + + "Overlay = Overlay on right side of inventory\n" + + "GUI Title = Text displayed next to the inventory title\n" + + "Lore = Inside the \"Open Reward Chest\" item" + ) + @ConfigEditorDropdown( + values = {"Overlay", "GUI Title", "Lore"} + ) + public int profitDisplayLoc = 0; + } + public static class DungeonSolvers { + + } + + public static class EnchSolvers { + @Expose + @ConfigOption( + name = "Enable Solvers", + desc = "Turn on solvers for the experimentation table" + ) + @ConfigEditorBoolean + public boolean enableEnchantingSolvers = true; + + @Expose + @ConfigOption( + name = "Prevent Misclicks", + desc = "Prevent accidentally failing the Chronomatron and Ultrasequencer experiments" + ) + @ConfigEditorBoolean + public boolean preventMisclicks = true; + + @Expose + @ConfigOption( + name = "Hide Tooltips", + desc = "Hide the tooltip of items in the Chronomatron and Ultrasequencer experiments" + ) + @ConfigEditorBoolean + public boolean hideTooltips = true; + + @Expose + @ConfigOption( + name = "Ultrasequencer Numbers", + desc = "Replace the items in the supersequencer with only numbers" + ) + @ConfigEditorBoolean + public boolean seqNumbers = false; + + @Expose + @ConfigOption( + name = "Ultrasequencer Next", + desc = "Set the colour of the glass pane shown behind the element in the ultrasequencer which is next" + ) + @ConfigEditorDropdown( + values = {"None", "White", "Orange", "Light Purple", "Light Blue", "Yellow", "Light Green", "Pink", + "Gray", "Light Gray", "Cyan", "Dark Purple", "Dark Blue", "Brown", "Dark Green", "Red", "Black"} + ) + public int seqNext = 6; + + @Expose + @ConfigOption( + name = "Ultrasequencer Upcoming", + desc = "Set the colour of the glass pane shown behind the element in the ultrasequencer which is coming after \"next\"" + ) + @ConfigEditorDropdown( + values = {"None", "White", "Orange", "Light Purple", "Light Blue", "Yellow", "Light Green", "Pink", + "Gray", "Light Gray", "Cyan", "Dark Purple", "Dark Blue", "Brown", "Dark Green", "Red", "Black"} + ) + public int seqUpcoming = 5; + + @Expose + @ConfigOption( + name = "Superpairs Matched", + desc = "Set the colour of the glass pane shown behind successfully matched pairs" + ) + @ConfigEditorDropdown( + values = {"None", "White", "Orange", "Light Purple", "Light Blue", "Yellow", "Light Green", "Pink", + "Gray", "Light Gray", "Cyan", "Dark Purple", "Dark Blue", "Brown", "Dark Green", "Red", "Black"} + ) + public int supMatched = 6; + + @Expose + @ConfigOption( + name = "Superpairs Possible", + desc = "Set the colour of the glass pane shown behind pairs which can be matched, but have not yet" + ) + @ConfigEditorDropdown( + values = {"None", "White", "Orange", "Light Purple", "Light Blue", "Yellow", "Light Green", "Pink", + "Gray", "Light Gray", "Cyan", "Dark Purple", "Dark Blue", "Brown", "Dark Green", "Red", "Black"} + ) + public int supPossible = 2; + + @Expose + @ConfigOption( + name = "Superpairs Unmatched", + desc = "Set the colour of the glass pane shown behind pairs which have been previously uncovered" + ) + @ConfigEditorDropdown( + values = {"None", "White", "Orange", "Light Purple", "Light Blue", "Yellow", "Light Green", "Pink", + "Gray", "Light Gray", "Cyan", "Dark Purple", "Dark Blue", "Brown", "Dark Green", "Red", "Black"} + ) + public int supUnmatched = 5; + + @Expose + @ConfigOption( + name = "Superpairs Powerups", + desc = "Set the colour of the glass pane shown behind powerups" + ) + @ConfigEditorDropdown( + values = {"None", "White", "Orange", "Light Purple", "Light Blue", "Yellow", "Light Green", "Pink", + "Gray", "Light Gray", "Cyan", "Dark Purple", "Dark Blue", "Brown", "Dark Green", "Red", "Black"} + ) + public int supPower = 11; + } + + public static class NeuAuctionHouse { + @Expose + @ConfigOption( + name = "Enable NeuAH", + desc = "Turn on the NEU Auction House. \u00A7cWARNING: May negatively impact performance on low-end machines" + ) + @ConfigEditorBoolean + public boolean enableNeuAuctionHouse = false; + + @Expose + @ConfigOption( + name = "Disable AH Scroll", + desc = "Disable scrolling using the scroll wheel inside NeuAH.\n" + + "This should be used if you want to be able to scroll through tooltips" + ) + @ConfigEditorBoolean + public boolean disableAhScroll = false; + + @Expose + @ConfigOption( + name = "AH Notification (Mins)", + desc = "Change the amount of time (in minutes) before the \"Ending Soon\" notification for an auction you have bid on" + ) + @ConfigEditorSlider( + minValue = 1f, + maxValue = 10f, + minStep = 1f + ) + public int ahNotification = 5; + } + + public static class ImprovedSBMenu { + @Expose + @ConfigOption( + name = "Enable Improved SB Menus", + desc = "Change the way that skyblock menus (eg. /sbmenu) look" + ) + @ConfigEditorBoolean + public boolean enableSbMenus = true; + + @Expose + @ConfigOption( + name = "Menu Background Style", + desc = "Change the style of the background of skyblock menus" + ) + @ConfigEditorDropdown( + values = {"Dark 1", "Dark 2", "Transparent", "Light 1", "Light 2", "Light 3", + "Unused 1", "Unused 2", "Unused 3", "Unused 4"} + ) + public int backgroundStyle = 0; + + @Expose + @ConfigOption( + name = "Button Background Style", + desc = "Change the style of the foreground elements in skyblock menus" + ) + @ConfigEditorDropdown( + values = {"Dark 1", "Dark 2", "Transparent", "Light 1", "Light 2", "Light 3", + "Unused 1", "Unused 2", "Unused 3", "Unused 4"} + ) + public int buttonStyle = 0; + + @Expose + @ConfigOption( + name = "Hide Empty Tooltips", + desc = "Hide the tooltips of glass panes with no text" + ) + @ConfigEditorBoolean + public boolean hideEmptyPanes = true; + } + + public static class Calendar { + @Expose + @ConfigOption( + name = "Event Notifications", + desc = "Display notifications for skyblock calendar events" + ) + @ConfigEditorBoolean + public boolean eventNotifications = true; + + @Expose + @ConfigOption( + name = "Starting Soon Time", + desc = "Display a notification before events start, time in seconds.\n" + + "0 = No prior notification" + ) + @ConfigEditorSlider( + minValue = 0f, + maxValue = 600f, + minStep = 30f + ) + public int startingSoonTime = 300; + + @Expose + @ConfigOption( + name = "Timer In Inventory", + desc = "Displays the time until the next event at the top of your screen when in inventories" + ) + @ConfigEditorBoolean + public boolean showEventTimerInInventory = true; + + @Expose + @ConfigOption( + name = "Notification Sounds", + desc = "Play a sound whenever events start" + ) + @ConfigEditorBoolean + public boolean eventNotificationSounds = true; + + @Expose + @ConfigOption( + name = "Spooky Night Notification", + desc = "Send a notification during spooky event when the time reaches 7pm" + ) + @ConfigEditorBoolean + public boolean spookyNightNotification = true; + } + + public static class TradeMenu { + @Expose + @ConfigOption( + name = "Enable Custom Trade Menu", + desc = "When trading with other players in skyblock, display a special GUI designed to prevent scamming" + ) + @ConfigEditorBoolean + public boolean enableCustomTrade = true; + + + @Expose + @ConfigOption( + name = "Price Information", + desc = "Show the price of items in the trade window on both sides" + ) + @ConfigEditorBoolean + public boolean customTradePrices = true; + + @Expose + public boolean customTradePriceStyle = true; + } + + public static class TreecapOverlay { + @Expose + @ConfigOption( + name = "Enable Treecap Overlay", + desc = "Show which blocks will be broken when using a Jungle Axe or Treecapitator" + ) + @ConfigEditorBoolean + public boolean enableTreecapOverlay = true; + + @Expose + @ConfigOption( + name = "Overlay Colour", + desc = "Change the colour of the overlay" + ) + @ConfigEditorColour + public String treecapOverlayColour = "00:50:64:224:208"; + } + + public static class BuilderWand { + @Expose + @ConfigOption( + name = "Enable Wand Overlay", + desc = "Show which blocks will be placed when using the Builder's Wand" + ) + @ConfigEditorBoolean + public boolean enableWandOverlay = true; + + @Expose + @ConfigOption( + name = "Wand Block Count", + desc = "Shows the total count of a block in your inventory" + ) + @ConfigEditorBoolean + public boolean wandBlockCount = true; + + @Expose + @ConfigOption( + name = "Overlay Colour", + desc = "Change the colour of the ghost block outline" + ) + @ConfigEditorColour + public String wandOverlayColour = "00:50:64:224:208"; + } + + public static class DungeonBlock { + @Expose + @ConfigOption( + name = "Enable Block Overlay", + desc = "Change the colour of certain blocks / entities while inside dungeons, but keeps the normal texture outside of dungeons" + ) + @ConfigEditorBoolean + public boolean enableDungBlockOverlay = true; + + @Expose + @ConfigOption( + name = "Show Overlay Everywhere", + desc = "Show the dungeon block overlay even when not inside dungeons. Should only be used for testing." + ) + @ConfigEditorBoolean + public boolean dungeonBlocksEverywhere = false; + + @Expose + @ConfigOption( + name = "Slow Update", + desc = "Updates the colour every second instead of every tick.\n" + + "\u00A7cWARNING: This will cause all texture animations (eg. flowing water) to update slowly.\n" + + "This should only be used on low-end machines" + ) + @ConfigEditorBoolean + public boolean slowDungeonBlocks = false; + + @Expose + @ConfigOption( + name = "Cracked Bricks", + desc = "Change the colour of: Cracked Bricks" + ) + @ConfigEditorColour + public String dungCrackedColour = "0:255:7:255:217"; + + @Expose + @ConfigOption( + name = "Dispensers", + desc = "Change the colour of: Dispensers" + ) + @ConfigEditorColour + public String dungDispenserColour = "0:255:255:76:0"; + + @Expose + @ConfigOption( + name = "Levers", + desc = "Change the colour of: Levers" + ) + @ConfigEditorColour + public String dungLeverColour = "0:252:24:249:255"; + + @Expose + @ConfigOption( + name = "Tripwire String", + desc = "Change the colour of: Tripwire String" + ) + @ConfigEditorColour + public String dungTripWireColour = "0:255:255:0:0"; + + @Expose + @ConfigOption( + name = "Normal Chests", + desc = "Change the colour of: Normal Chests" + ) + @ConfigEditorColour + public String dungChestColour = "0:255:0:163:36"; + + @Expose + @ConfigOption( + name = "Trapped Chests", + desc = "Change the colour of: Trapped Chests" + ) + @ConfigEditorColour + public String dungTrappedChestColour = "0:255:0:163:36"; + + @Expose + @ConfigOption( + name = "Bats", + desc = "Change the colour of: Bats" + ) + @ConfigEditorColour + public String dungBatColour = "0:255:12:255:0"; + } + + public static class AccessoryBag { + @Expose + @ConfigOption( + name = "Enable Accessory Bag Overlay", + desc = "Show an overlay on the accessory bag screen which gives useful information about your accessories" + ) + @ConfigEditorBoolean + public boolean enableOverlay = true; + } + + public static class SmoothAOTE { + @Expose + @ConfigOption( + name = "Enable Smooth AOTE", + desc = "Teleport smoothly to your destination when using AOTE" + ) + @ConfigEditorBoolean + public boolean enableSmoothAOTE = true; + + @Expose + @ConfigOption( + name = "Enable Smooth Hyperion", + desc = "Teleport smoothly to your destination when using Hyperion" + ) + @ConfigEditorBoolean + public boolean enableSmoothHyperion = true; + + @Expose + @ConfigOption( + name = "Smooth TP Time", + desc = "Change the amount of time (milliseconds) taken to teleport" + ) + @ConfigEditorSlider( + minValue = 0, + maxValue = 500, + minStep = 25 + ) + public int smoothTpMillis = 175; + + + @Expose + @ConfigOption( + name = "Disable Hyperion Particles", + desc = "Remove the explosion effect when using a hyperion" + ) + @ConfigEditorBoolean + public boolean disableHyperionParticles = true; + } + + public static class RodColours { + @Expose + @ConfigOption( + name = "Enable Rod Colours", + desc = "Change the colour of your and other players' rod lines\n" + + "Also fixes the position of the rod line" + ) + @ConfigEditorBoolean + public boolean enableRodColours = true; + + @Expose + @ConfigOption( + name = "Own Rod Colour", + desc = "Change the colour of your own rod lines" + ) + @ConfigEditorColour + public String ownRodColour = "0:255:0:0:0"; + + + @Expose + @ConfigOption( + name = "Other Rod Colour", + desc = "Change the colour of other players' rod lines" + ) + @ConfigEditorColour + public String otherRodColour = "0:255:0:0:0"; + } + + public static class DungeonWin { + @Expose + @ConfigOption( + name = "Enable Dungeon Win", + desc = "Show a fancy win screen and stats when completing a dungeon" + ) + @ConfigEditorBoolean + public boolean enableDungeonWin = true; + + @Expose + @ConfigOption( + name = "Dungeon Win Time", + desc = "Change the amount of time (milliseconds) that the win screen shows for" + ) + @ConfigEditorSlider( + minValue = 0, + maxValue = 20000, + minStep = 500 + ) + public int dungeonWinMillis = 8000; + } + + public static class ApiKey { + @Expose + @ConfigOption( + name = "Api Key", + desc = "Hypixel api key" + ) + @ConfigEditorText + public String apiKey = ""; + } + + private static ArrayList createDefaultQuickCommands() { + ArrayList arr = new ArrayList<>(); + arr.add("/warp home:Warp Home:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzljODg4MWU0MjkxNWE5ZDI5YmI2MWExNmZiMjZkMDU5OTEzMjA0ZDI2NWRmNWI0MzliM2Q3OTJhY2Q1NiJ9fX0="); + arr.add("/warp hub:Warp Hub:eyJ0aW1lc3RhbXAiOjE1NTkyMTU0MTY5MDksInByb2ZpbGVJZCI6IjQxZDNhYmMyZDc0OTQwMGM5MDkwZDU0MzRkMDM4MzFiIiwicHJvZmlsZU5hbWUiOiJNZWdha2xvb24iLCJzaWduYXR1cmVSZXF1aXJlZCI6dHJ1ZSwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2Q3Y2M2Njg3NDIzZDA1NzBkNTU2YWM1M2UwNjc2Y2I1NjNiYmRkOTcxN2NkODI2OWJkZWJlZDZmNmQ0ZTdiZjgifX19"); + arr.add("/warp dungeon_hub:Dungeon Hub:eyJ0aW1lc3RhbXAiOjE1Nzg0MDk0MTMxNjksInByb2ZpbGVJZCI6IjQxZDNhYmMyZDc0OTQwMGM5MDkwZDU0MzRkMDM4MzFiIiwicHJvZmlsZU5hbWUiOiJNZWdha2xvb24iLCJzaWduYXR1cmVSZXF1aXJlZCI6dHJ1ZSwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzliNTY4OTViOTY1OTg5NmFkNjQ3ZjU4NTk5MjM4YWY1MzJkNDZkYjljMWIwMzg5YjhiYmViNzA5OTlkYWIzM2QiLCJtZXRhZGF0YSI6eyJtb2RlbCI6InNsaW0ifX19fQ=="); + arr.add("/craft:Crafting Table:CRAFTING_TABLE"); + arr.add("/enderchest:Ender Chest:ENDER_CHEST"); + arr.add("/wardrobe:Wardrobe:LEATHER_CHESTPLATE"); + arr.add("/pets:Pets:BONE"); + arr.add("/ah:Auction House:GOLD_BLOCK"); + arr.add("/bz:Bazaar:GOLD_BARDING"); + return arr; + } + + public static class Hidden { + @Expose public boolean enableItemEditing = false; + @Expose public boolean cacheRenderedItempane = true; + @Expose public boolean autoupdate = true; + @Expose public String overlaySearchBar = ""; + @Expose public String overlayQuickCommand = ""; + @Expose public boolean dev = false; + @Expose public boolean loadedModBefore = false; + @Expose public boolean doRamNotif = true; + @Expose public String selectedCape = null; + @Expose public int compareMode = 0; + @Expose public int sortMode = 0; + @Expose public ArrayList compareAscending = Lists.newArrayList(true, true, true); + @Expose public ArrayList favourites = new ArrayList<>(); + @Expose public ArrayList eventFavourites = new ArrayList<>(); + @Expose public ArrayList quickCommands = createDefaultQuickCommands(); + @Expose public ArrayList enchantColours = Lists.newArrayList( + "[a-zA-Z\\- ]+:\u003e:9:6", + "[a-zA-Z\\- ]+:\u003e:6:c", + "[a-zA-Z\\- ]+:\u003e:5:5", + "Experience:\u003e:3:5", + "Life Steal:\u003e:3:5", + "Scavenger:\u003e:3:5", + "Looting:\u003e:3:5"); + } + + public static class DungeonMap { + @Expose + @ConfigOption( + name = "Border Size", + desc = "Changes the size of the map border, without changing the size of the contents" + ) + @ConfigEditorSlider( + minValue = 0, + maxValue = 5, + minStep = 1 + ) + public int dmBorderSize = 1; + + @Expose + @ConfigOption( + name = "Room Size", + desc = "Changes the size of rooms. Useful for higher dungeons with larger maps" + ) + @ConfigEditorSlider( + minValue = 0, + maxValue = 5, + minStep = 1 + ) + public int dmRoomSize = 1; + + @Expose + @ConfigOption( + name = "Icon Size", + desc = "Changes the scale of room indicators and player icons" + ) + @ConfigEditorSlider( + minValue = 0.5f, + maxValue = 3f, + minStep = 0.25f + ) + public float dmIconScale = 1.0f; + + @Expose + @ConfigOption( + name = "Border Style", + desc = "Various custom borders from various talented artists.\nUse 'custom' if your texture pack has a custom border" + ) + public int dmBorderStyle = 0; + + @Expose + @ConfigOption( + name = "Show Dungeon Map", + desc = "Show/hide the NEU dungeon map" + ) + public boolean dmEnable = true; + + @Expose + @ConfigOption( + name = "Map Center", + desc = "Center on rooms, or center on your player" + ) + public boolean dmCenterPlayer = true; + + @Expose + @ConfigOption( + name = "Rotate with Player", + desc = "Rotate the map to face the same direction as your player" + ) + public boolean dmRotatePlayer = true; + + @Expose + @ConfigOption( + name = "Orient Checkmarks", + desc = "Checkmarks will always show vertically, regardless of rotation" + ) + public boolean dmOrientCheck = true; + + @Expose + @ConfigOption( + name = "Center Checkmarks", + desc = "Checkmarks will show closer to the center of rooms" + ) + public boolean dmCenterCheck = false; + + @Expose + @ConfigOption( + name = "Player Icon Style", + desc = "Various player icon styles" + ) + public int dmPlayerHeads = 0; + + @Expose + @ConfigOption( + name = "Interpolate Far Players", + desc = "Will make players far away move smoothly" + ) + public boolean dmPlayerInterp = true; + + @Expose + @ConfigOption( + name = "OpenGL Compatibility", + desc = "Compatiblity options for people with bad computers. ONLY use this if you know what you are doing, otherwise the map will look worse" + ) + public int dmCompat = 0; + + @Expose + @ConfigOption( + name = "Background Colour", + desc = "Colour of the map background. Supports opacity & chroma" + ) + public String dmBackgroundColour = "00:170:75:75:75"; + + @Expose + @ConfigOption( + name = "Border Colour", + desc = "Colour of the map border. Supports opacity & chroma. Turn off custom borders to see" + ) + public String dmBorderColour = "00:0:0:0:0"; + + @Expose + @ConfigOption( + name = "Chroma Border Mode", + desc = "Applies a hue offset around the map border" + ) + public boolean dmChromaBorder = false; + + @Expose + @ConfigOption( + name = "Background Blur Factor", + desc = "Changes the blur factor behind the map. Set to 0 to disable blur" + ) + public int dmBackgroundBlur = 3; + + @Expose + @ConfigOption( + name = "Center X (%)", + desc = "The horizontal position of the map" + ) + public double dmCenterX = 8.5; + + @Expose + @ConfigOption( + name = "Center Y (%)", + desc = "The vertical position of the map" + ) + public double dmCenterY = 15.0; + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfigEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfigEditor.java new file mode 100644 index 00000000..3d006383 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfigEditor.java @@ -0,0 +1,390 @@ +package io.github.moulberry.notenoughupdates.options; + +import com.google.common.collect.Lists; +import io.github.moulberry.notenoughupdates.core.GlScissorStack; +import io.github.moulberry.notenoughupdates.core.GuiElement; +import io.github.moulberry.notenoughupdates.core.config.Config; +import io.github.moulberry.notenoughupdates.core.config.gui.GuiOptionEditor; +import io.github.moulberry.notenoughupdates.core.config.struct.ConfigProcessor; +import io.github.moulberry.notenoughupdates.core.util.lerp.LerpUtils; +import io.github.moulberry.notenoughupdates.core.util.lerp.LerpingInteger; +import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; +import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils; +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.util.EnumChatFormatting; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; +import static io.github.moulberry.notenoughupdates.util.GuiTextures.*; + +import java.awt.*; +import java.net.URI; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class NEUConfigEditor extends GuiElement { + + private static final ResourceLocation[] socialsIco = new ResourceLocation[] { + DISCORD, + GITHUB, + TWITTER, + YOUTUBE, + PATREON + }; + private static final String[] socialsLink = new String[] { + "https://discord.gg/moulberry", + "https://github.com/Moulberry/Hychat", + "https://twitter.com/moulberry/", + "https://www.youtube.com/channel/UCPh-OKmRSS3IQi9p6YppLcw", + "https://patreon.com/moulberry" + }; + + private final long openedMillis; + + private String selectedCategory = null; + + private LerpingInteger optionsScroll = new LerpingInteger(0, 150); + + private LinkedHashMap processedConfig; + + public NEUConfigEditor(Config config) { + this.openedMillis = System.currentTimeMillis(); + this.processedConfig = ConfigProcessor.create(config); + } + + private LinkedHashMap getCurrentConfigEditing() { + return processedConfig; + } + + private String getSelectedCategory() { + return selectedCategory; + } + + private void setSelectedCategory(String category) { + selectedCategory = category; + optionsScroll.setValue(0); + } + + public void render() { + optionsScroll.tick(); + + List tooltipToDisplay = null; + + long currentTime = System.currentTimeMillis(); + long delta = currentTime - openedMillis; + + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; + int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; + + float opacityFactor = LerpUtils.sigmoidZeroOne(delta/500f); + RenderUtils.drawGradientRect(0, 0, 0, width, height, + (int)(0x80*opacityFactor) << 24 | 0x101010, + (int)(0x90*opacityFactor) << 24 | 0x101010); + + int xSize = Math.min(scaledResolution.getScaledWidth()-100/scaledResolution.getScaleFactor(), 500); + int ySize = Math.min(scaledResolution.getScaledHeight()-100/scaledResolution.getScaleFactor(), 400); + + int x = (scaledResolution.getScaledWidth() - xSize)/2; + int y = (scaledResolution.getScaledHeight() - ySize)/2; + + int adjScaleFactor = Math.max(2, scaledResolution.getScaleFactor()); + + int openingXSize = xSize; + int openingYSize = ySize; + if(delta < 150) { + openingXSize = (int)(delta*xSize/150); + openingYSize = 5; + } else if(delta < 300) { + openingYSize = 5 + (int)(delta-150)*(ySize-5)/150; + } + RenderUtils.drawFloatingRectDark( + (scaledResolution.getScaledWidth() - openingXSize)/2, + (scaledResolution.getScaledHeight() - openingYSize)/2, + openingXSize, openingYSize); + GlScissorStack.clear(); + GlScissorStack.push((scaledResolution.getScaledWidth() - openingXSize)/2, + (scaledResolution.getScaledHeight() - openingYSize)/2, + (scaledResolution.getScaledWidth() + openingXSize)/2, + (scaledResolution.getScaledHeight() + openingYSize)/2, scaledResolution); + + RenderUtils.drawFloatingRectDark(x+5, y+5, xSize-10, 20, false); + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + TextRenderUtils.drawStringCenteredScaledMaxWidth("NotEnoughUpdates by "+EnumChatFormatting.DARK_PURPLE+"Moulberry", + fr, x+xSize/2, y+15, false, 200, 0xa0a0a0); + + RenderUtils.drawFloatingRectDark(x+4, y+49-20, + 140, ySize-54+20, false); + + int innerPadding = 20/adjScaleFactor; + int innerLeft = x+4+innerPadding; + int innerRight = x+144-innerPadding; + int innerTop = y+49+innerPadding; + int innerBottom = y+ySize-5-innerPadding; + Gui.drawRect(innerLeft, innerTop, innerLeft+1, innerBottom, 0xff08080E); //Left + Gui.drawRect(innerLeft+1, innerTop, innerRight, innerTop+1, 0xff08080E); //Top + Gui.drawRect(innerRight-1, innerTop+1, innerRight, innerBottom, 0xff28282E); //Right + Gui.drawRect(innerLeft+1, innerBottom-1, innerRight-1, innerBottom, 0xff28282E); //Bottom + Gui.drawRect(innerLeft+1, innerTop+1, innerRight-1, innerBottom-1, 0x6008080E); //Middle + + GlScissorStack.push(0, innerTop+1, scaledResolution.getScaledWidth(), + innerBottom-1, scaledResolution); + + int categoryIndex = 0; + for(Map.Entry entry : getCurrentConfigEditing().entrySet()) { + if(getSelectedCategory() == null) { + setSelectedCategory(entry.getKey()); + } + String catName = entry.getValue().name; + if(entry.getKey().equals(getSelectedCategory())) { + catName = EnumChatFormatting.DARK_AQUA.toString() + EnumChatFormatting.UNDERLINE + catName; + } else { + catName = EnumChatFormatting.GRAY + catName; + } + TextRenderUtils.drawStringCenteredScaledMaxWidth(catName, + fr, x+75, y+70+categoryIndex*15, false, 140, -1); + categoryIndex++; + } + + GlScissorStack.pop(scaledResolution); + + TextRenderUtils.drawStringCenteredScaledMaxWidth("Categories", + fr, x+75, y+44, false, 120, 0xa368ef); + + RenderUtils.drawFloatingRectDark(x+149, y+29, + xSize-154, ySize-34, false); + + if(getSelectedCategory() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { + ConfigProcessor.ProcessedCategory cat = getCurrentConfigEditing().get(getSelectedCategory()); + + TextRenderUtils.drawStringCenteredScaledMaxWidth(cat.desc, + fr, x+xSize/2+72, y+44, true, xSize-154-innerPadding*2, 0xb0b0b0); + } + + innerLeft = x+149+innerPadding; + innerRight =x+xSize-5-innerPadding; + //innerTop = y+29+innerPadding; + innerBottom = y+ySize-5-innerPadding; + Gui.drawRect(innerLeft, innerTop, innerLeft+1, innerBottom, 0xff08080E); //Left + Gui.drawRect(innerLeft+1, innerTop, innerRight, innerTop+1, 0xff08080E); //Top + Gui.drawRect(innerRight-1, innerTop+1, innerRight, innerBottom, 0xff303036); //Right + Gui.drawRect(innerLeft+1, innerBottom-1, innerRight-1, innerBottom, 0xff303036); //Bottom + Gui.drawRect(innerLeft+1, innerTop+1, innerRight-1, innerBottom-1, 0x6008080E); //Middle + + GlScissorStack.push(innerLeft+1, innerTop+1, innerRight-1, innerBottom-1, scaledResolution); + + float barSize = 1; + int optionY = -optionsScroll.getValue(); + if(getSelectedCategory() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { + ConfigProcessor.ProcessedCategory cat = getCurrentConfigEditing().get(getSelectedCategory()); + int optionWidth = innerRight-innerLeft-20; + GlStateManager.enableDepth(); + for(ConfigProcessor.ProcessedOption option : cat.options.values()) { + GuiOptionEditor editor = option.editor; + if(editor == null) { + continue; + } + int optionHeight = editor.getHeight(); + if(innerTop+5+optionY+optionHeight > innerTop+1 && innerTop+5+optionY < innerBottom-1) { + editor.render(innerLeft+5, innerTop+5+optionY, optionWidth); + } + optionY += optionHeight + 5; + } + GlStateManager.disableDepth(); + if(optionY > 0) { + barSize = LerpUtils.clampZeroOne((float)(innerBottom-innerTop-2)/(optionY+5+optionsScroll.getValue())); + } + } + + GlScissorStack.pop(scaledResolution); + + float barStart = optionsScroll.getValue() / (float)(optionY + optionsScroll.getValue()); + float barEnd = barStart+barSize; + if(barEnd > 1) { + barEnd = 1; + if(optionsScroll.getTarget()/(float)(optionY + optionsScroll.getValue())+barSize < 1) { + int target = optionsScroll.getTarget(); + optionsScroll.setValue((int)Math.ceil((optionY+5+optionsScroll.getValue())-barSize*(optionY+5+optionsScroll.getValue()))); + optionsScroll.setTarget(target); + } else { + optionsScroll.setValue((int)Math.ceil((optionY+5+optionsScroll.getValue())-barSize*(optionY+5+optionsScroll.getValue()))); + } + } + int dist = innerBottom-innerTop-12; + Gui.drawRect(innerRight-10, innerTop+5, innerRight-5, innerBottom-5, 0xff101010); + Gui.drawRect(innerRight-9, innerTop+6+(int)(dist*barStart), innerRight-6, innerTop+6+(int)(dist*barEnd), 0xff303030); + + for(int socialIndex=0; socialIndex= socialLeft && mouseX <= socialLeft+16 && + mouseY >= y+6 && mouseY <= y+23) { + tooltipToDisplay = Lists.newArrayList(EnumChatFormatting.YELLOW+"Go to: "+EnumChatFormatting.RESET+socialsLink[socialIndex]); + } + } + + GlScissorStack.clear(); + + if(tooltipToDisplay != null) { + TextRenderUtils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, fr); + } + + GlStateManager.translate(0, 0, -2); + } + + public boolean mouseInput(int mouseX, int mouseY) { + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + int width = scaledResolution.getScaledWidth(); + int height = scaledResolution.getScaledHeight(); + + int xSize = Math.min(width-100/scaledResolution.getScaleFactor(), 500); + int ySize = Math.min(height-100/scaledResolution.getScaleFactor(), 400); + + int x = (scaledResolution.getScaledWidth() - xSize)/2; + int y = (scaledResolution.getScaledHeight() - ySize)/2; + + int adjScaleFactor = Math.max(2, scaledResolution.getScaleFactor()); + + int innerPadding = 20/adjScaleFactor; + int innerTop = y+49+innerPadding; + int innerBottom = y+ySize-5-innerPadding; + int innerLeft = x+149+innerPadding; + int innerRight = x+xSize-5-innerPadding; + + int dWheel = Mouse.getDWheel(); + if(mouseY > innerTop && mouseY < innerBottom && dWheel != 0) { + if(dWheel < 0) { + dWheel = -1; + } + if(dWheel > 0) { + dWheel = 1; + } + boolean resetTimer = true; + int newTarget = optionsScroll.getTarget() - dWheel*30; + if(newTarget < 0) { + newTarget = 0; + resetTimer = false; + } + + float barSize = 1; + int optionY = -newTarget; + if(getSelectedCategory() != null && getCurrentConfigEditing() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { + ConfigProcessor.ProcessedCategory cat = getCurrentConfigEditing().get(getSelectedCategory()); + for(ConfigProcessor.ProcessedOption option : cat.options.values()) { + GuiOptionEditor editor = option.editor; + if(editor == null) { + continue; + } + optionY += editor.getHeight() + 5; + + if(optionY > 0) { + barSize = LerpUtils.clampZeroOne((float)(innerBottom-innerTop-2)/(optionY+5 + newTarget)); + } + } + } + + int barMax = (int)Math.floor((optionY+5+newTarget)-barSize*(optionY+5+newTarget)); + if(newTarget > barMax) { + newTarget = barMax; + resetTimer = false; + } + if(resetTimer && optionsScroll.getTarget() != newTarget) { + optionsScroll.resetTimer(); + } + optionsScroll.setTarget(newTarget); + } else if(Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { + if(getCurrentConfigEditing() != null) { + int categoryIndex = 0; + for(Map.Entry entry : getCurrentConfigEditing().entrySet()) { + if(getSelectedCategory() == null) { + setSelectedCategory(entry.getKey()); + } + if(mouseX >= x+5 && mouseX <= x+145 && + mouseY >= y+70+categoryIndex*15-7 && mouseY <= y+70+categoryIndex*15+7) { + setSelectedCategory(entry.getKey()); + return true; + } + categoryIndex++; + } + } + + for(int socialIndex=0; socialIndex= socialLeft && mouseX <= socialLeft+16 && + mouseY >= y+6 && mouseY <= y+23) { + try { + Desktop.getDesktop().browse(new URI(socialsLink[socialIndex])); + } catch(Exception ignored) {} + return true; + } + } + } + + int optionY = -optionsScroll.getValue(); + if(getSelectedCategory() != null && getCurrentConfigEditing() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { + int optionWidth = innerRight-innerLeft-20; + ConfigProcessor.ProcessedCategory cat = getCurrentConfigEditing().get(getSelectedCategory()); + for(ConfigProcessor.ProcessedOption option : cat.options.values()) { + GuiOptionEditor editor = option.editor; + if(editor == null) { + continue; + } + if(editor.mouseInputGlobal(innerLeft+5, innerTop+5+optionY, optionWidth, mouseX, mouseY)) { + return true; + } + optionY += editor.getHeight() + 5; + } + } + + if(mouseX > innerLeft && mouseX < innerRight && + mouseY > innerTop && mouseY < innerBottom) { + optionY = -optionsScroll.getValue(); + if(getSelectedCategory() != null && getCurrentConfigEditing() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { + int optionWidth = innerRight-innerLeft-20; + ConfigProcessor.ProcessedCategory cat = getCurrentConfigEditing().get(getSelectedCategory()); + for(ConfigProcessor.ProcessedOption option : cat.options.values()) { + GuiOptionEditor editor = option.editor; + if(editor == null) { + continue; + } + if(editor.mouseInput(innerLeft+5, innerTop+5+optionY, optionWidth, mouseX, mouseY)) { + return true; + } + optionY += editor.getHeight() + 5; + } + } + } + + return true; + } + + public boolean keyboardInput() { + if(getSelectedCategory() != null && getCurrentConfigEditing() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { + ConfigProcessor.ProcessedCategory cat = getCurrentConfigEditing().get(getSelectedCategory()); + for(ConfigProcessor.ProcessedOption option : cat.options.values()) { + GuiOptionEditor editor = option.editor; + if(editor == null) { + continue; + } + if(editor.keyboardInput()) { + return true; + } + } + } + + return true; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/Options.java b/src/main/java/io/github/moulberry/notenoughupdates/options/Options.java deleted file mode 100644 index a5566ce6..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/Options.java +++ /dev/null @@ -1,819 +0,0 @@ -package io.github.moulberry.notenoughupdates.options; - -import com.google.gson.*; -import io.github.moulberry.notenoughupdates.dungeons.GuiDungeonMapEditor; -import io.github.moulberry.notenoughupdates.GuiEnchantColour; -import io.github.moulberry.notenoughupdates.NEUOverlayPlacements; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; - -import java.awt.*; -import java.io.*; -import java.lang.reflect.Field; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class Options { - - /** - * Ok, I'll be honest. I wrote this class without looking too much in to how to make proper serializable - * variables with defaults values/etc. It works. I'm happy. - */ - - public static final transient int FLAG_COLOUR = 0b1; - public static final transient int FLAG_INT = 0b10; - - public static final int CAT_ALL = 0; - public static final int CAT_MISC = 1; - public static final int CAT_FEATURES = 2; - public static final int CAT_SLIDERS = 3; - public static final int CAT_COLOURS = 4; - - public Option enableItemEditing = new Option( - false, - "Enable Item Editing", - true, - "Dev Feature.", CAT_ALL); - public Option onlyShowOnSkyblock = new Option( - true, - "Only Show On Skyblock", - false, - "NEU Overlay only appears when you are playing Skyblock.", CAT_MISC); - public Option showVanillaItems = new Option( - true, - "Show Vanilla Items", - false, - "Shows vanilla items in the itemlist.", CAT_MISC); - public Option hidePotionEffect = new Option( - true, - "Hide Potion Effects", - false, - "Potion effects are hidden in the inventory GUI. Contrib: All the gamers that play on GUI AUTO", CAT_MISC); - public Option showQuickCommands = new Option( - true, - "Quick Commands", - false, - "Shows QuickCommands\u2122 above search bar.", CAT_FEATURES); - public Option showUpdateMsg = new Option( - true, - "Show Update Notifs", - false, - "Shows update messages if NEU is out-of-date.", CAT_MISC); - public Option tooltipBorderColours = new Option( - true, - "Coloured Tooltip Borders", - false, - "Makes the border of tooltips coloured. (Only NEU Tooltips)", CAT_MISC); - public Option disableAhScroll = new Option( - false, - "No NeuAH Scroll", - false, - "Disables Scrolling in NeuAH", CAT_MISC); - public Option advancedPriceInfo = new Option( - false, - "Adv. Item Price Info", - false, - "Shows some extra information about item prices.", CAT_MISC); - public Option cacheRenderedItempane = new Option( - true, - "Cache Itempane", - false, - "Caches the drawn itempane, drastically improving performance. Animated textures will not work.", CAT_MISC); - public Option streamerMode = new Option( - false, - "Streamer Mode", - false, - "Hides or randomises some stuff on your screen to prevent sniping", CAT_MISC); - public Option disableTreecapOverlay = new Option( - false, - "Disable Treecap Overlay", - false, - "Disables the treecapitator overlay effect", CAT_FEATURES); - public Option disableWandOverlay = new Option( - false, - "Disable Builder's Wand Overlay", - false, - "Disables the builder's wand overlay effect", CAT_FEATURES); - public Option wandBlockCount = new Option( - true, - "Builder's Wand Block Count", - false, - "If true, will show how many blocks you have remaining when holding a builder's wand.", CAT_MISC); - public Option hideApiKey = new Option( - false, - "Hide Apikey Setting", - false, - "Hides the Apikey setting (please try not to leak Apikey if you're recording)", CAT_MISC); - public Option bgBlurFactor = new Option( - 5.0, - "Background Blur", - false, - "Changes the strength of pane background blur. 0-50.", 0, 50, CAT_SLIDERS); - public Option apiKey = new Option( - "", - "Api Key", - false, - "Type /api new to receive key and put it here.", CAT_MISC); - public Option autoupdate = new Option( - true, - "Automatically Update Items", - false, - "If true, updated items will automatically download from the remote repository when you start the game. \nHIGHLY RECOMMENDED.", CAT_MISC); - public Option quickcommandMousePress = new Option( - false, - "QuickCommand on Mouse Press", - false, - "If true, quickcommands will trigger on mouse down instead of mouse up.", CAT_MISC); - public Option disableItemTabOpen = new Option( - false, - "No Tab Open", - false, - "If True, moving your mouse to the item tab on the right side won't open the itempane.", CAT_MISC); - public Option keepopen = new Option( - false, - "Keep Itempane Open", - false, - "If true, the itempane will stay open after the gui is closed.", CAT_MISC); - public Option itemStyle = new Option( - true, - "Circular Item Style", - false, - "Uses the circular item background style instead of the square style. Contrib: Calyps0", CAT_MISC); - public Option hideEmptyPanes = new Option( - true, - "Hide GUI Filler Tooltips", - false, - "Hides the tooltip of glass panes in skyblock GUIs. Contrib: ThatGravyBoat", CAT_MISC); - public Option guiButtonClicks = new Option( - true, - "Button Click Sounds", - false, - "Plays a click sound whenever various NEU GUIs are interacted with", CAT_MISC); - public Option dungeonProfitLore = new Option( - false, - "Dungeon Profit in Lore", - false, - "If true, will show the dungeon profit on the tooltip of the 'reward chest' instead of as a GUI.", CAT_MISC); - public Option auctionPriceInfo = new Option( - true, - "Price Info in Auction Lore", - false, - "If true, will show price information about an item inside the auction house item tooltip.", CAT_MISC); - public Option useCustomTrade = new Option( - true, - "Custom Trade", - false, - "If true, uses the custom trade window for skyblock trades.", CAT_FEATURES); - public Option invBazaarPrice = new Option( - false, - "Show Bazaar Price In Inventory", - false, - "If true, shows the bazaar price for the item you hover in your inventory.", CAT_MISC); - public Option invAuctionPrice = new Option( - false, - "Show Auction Price In Inventory", - false, - "If true, shows the auction price for the item you hover in your inventory.", CAT_MISC); - public Option 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.", CAT_MISC); - public Option disableDungeonBlocks = new Option( - true, - "Disable the dungeon blocks feature", - false, - "If true, the dungeon block overlay will be disabled. WARNING: May cause memory/fps issues on some machines", CAT_FEATURES); - public Option slowDungeonBlocks = new Option( - false, - "Slowly Update Dungeon Block Textures", - false, - "If true, dungeon blocks will only update once every second.\n" + - "Use this option if you are having performance\n" + - "issues relating to the dungeon blocks.", CAT_MISC); - public Option missingEnchantList = new Option( - true, - "Missing Enchant List", - false, - "If true, will show enchants that are missing on an enchanted item when LSHIFT is pressed.", CAT_FEATURES); - public Option neuAuctionHouse = new Option( - false, - "NEU Auction House", - false, - "Enables the auction house which can be found using /neuah.\n" + - "Don't enable this option unless you use /neuah\n" + - "You *may* need to restart after enabling this for the auctions to download properly", CAT_FEATURES); - public Option eventNotifications = new Option( - true, - "Skyblock Event Notifications", - false, - "Notifies you 5m (default) before and when favourited events (/neucalendar) start.", CAT_FEATURES); - public Option showEventTimerInInventory = new Option( - true, - "Event Timer In Inventory", - false, - "Will show how long until the next event starts at the top of your inventory", CAT_FEATURES); - public Option eventNotificationSounds = new Option( - true, - "Skyblock Event Notification Sounds", - false, - "Will play a sounds whenever a favourited event starts.", CAT_MISC); - public Option spookyMorningNotification = new Option( - true, - "Spooky Festival Morning Notification", - false, - "During a spooky festival, will notify the player whenever it hits 7am", CAT_MISC); - - public Option accessoryBagOverlay = new Option( - true, - "Accessory Bag Overlay", - false, - "If true, will an overlay with useful information in your accessory bag.", CAT_FEATURES); - public Option rodColours = new Option( - true, - "Custom Rod Line Colours", - false, - "If true, will use custom colours for fishing line rods in skyblock.", CAT_FEATURES); - public Option paneGuiScale = new Option( - 0.0, - "Pane GUI Scale", - false, - "Changes the GUI scale of the item pane. 0 = use game default. 1-4 = scale", FLAG_INT, 0, 4, CAT_SLIDERS); - public Option paneWidthMult = new Option( - 1.0, - "Pane Width", - false, - "Changes how wide the item and info panes are. Value between 0.5-1.5.", 0.5, 1.5, CAT_SLIDERS); - public Option smoothAoteMillis = new Option( - 175.0, - "Smooth AOTE Milliseconds", - false, - "How long teleporting with the AOTE takes. 0 = disable.", 0, 300, CAT_SLIDERS); - public Option itemHighlightOpacity = new Option( - 178.0, - "Item Highlight Opacity", - false, - "Changes the opacity of item highlights. Value between 0-255.", 0, 255, CAT_SLIDERS); - public Option panePadding = new Option( - 10.0, - "Pane Padding", - false, - "Changes the padding of the panes. Value between 0-20.", 0, 20, CAT_SLIDERS); - public Option ahNotification = new Option( - 2.0, - "AH Notification (Mins, 0 = off)", - false, - "Minutes before AH ends to notify. 0-10.", 0, 10, CAT_SLIDERS); - public Option tooltipBorderOpacity = new Option( - 200.0, - "Coloured Tooltip Border Opacity", - false, - "Coloured tooltips only apply to tooltips in my GUIs. Value between 0-255.", 0, 255, CAT_SLIDERS); - public Option dynamicMenuBackgroundStyle = new Option( - 1.0, - "SBMenu Background Style", - false, - "Style of the background used for the skyblock menu.", 0, 10, CAT_FEATURES); - public Option dynamicMenuButtonStyle = new Option( - 1.0, - "SBMenu Button Style", - false, - "Style of the buttons used for the skyblock menu.", 0, 10, CAT_FEATURES); - public Option dungeonWinMillis = new Option( - 5000.0, - "Dungeon Victory Screen Millis", - false, - "Changes how long the victory screen at the end of dungeons appears for. 0 = off", FLAG_INT, 0, 15000, CAT_SLIDERS); - public Option eventNotificationBeforeSeconds = new Option( - 300.0, - "Event Notification Before Seconds", - false, - "Changes how long before skyblock events will the 'starting in' notification show. 0 = off", FLAG_INT, 0, 1800, CAT_SLIDERS); - - public Option itemBackgroundColour = new Option( - "00:255:100:100:100", - "Item BG Colour", - false, - "Item BG Colour", - FLAG_COLOUR, CAT_COLOURS); - public Option itemFavouriteColour = new Option( - "00:255:200:150:50", - "Item BG Favourite Colour", - false, - "Item BG Favourite Colour", - FLAG_COLOUR, CAT_COLOURS); - public Option paneBackgroundColour = new Option( - "15:6:0:0:255", - "Pane Background Colour", - false, - "Pane Background Colour", - FLAG_COLOUR, CAT_COLOURS); - public Option treecapOverlayColour = new Option( - "00:50:64:224:208", - "Treecapitator Overlay Colour", - false, - "Treecapitator Overlay Colour", - FLAG_COLOUR, CAT_COLOURS); - public Option wandOverlayColour = new Option( - "00:50:64:224:208", - "Builder's Wand Overlay Colour", - false, - "Builder's Wand Overlay Colour", - FLAG_COLOUR, CAT_COLOURS); - - public Option dungCrackedColour = new Option( - "0:252:7:255:217", - "Dungeon Cracked Brick Colour", - false, - "Dungeon Cracked Brick Colour", - FLAG_COLOUR, CAT_COLOURS); - public Option dungDispenserColour = new Option( - "0:255:255:76:0", - "Dungeon Dispenser Colour", - false, - "Dungeon Dispenser Colour", - FLAG_COLOUR, CAT_COLOURS); - public Option dungLeverColour = new Option( - "0:252:24:249:255", - "Dungeon Lever Colour", - false, - "Dungeon Lever Colour", - FLAG_COLOUR, CAT_COLOURS); - public Option dungTripWireColour = new Option( - "0:255:255:0:0", - "Dungeon Trip Wire Colour", - false, - "Dungeon Trip Wire Colour", - FLAG_COLOUR, CAT_COLOURS); - public Option dungChestColour = new Option( - "0:255:0:163:36", - "Dungeon Chest Colour", - false, - "Dungeon Chest Colour", - FLAG_COLOUR, CAT_COLOURS); - public Option dungTrappedChestColour = new Option( - "0:255:0:163:36", - "Dungeon Trapped Chest Colour", - false, - "Dungeon Trapped Chest Colour", - FLAG_COLOUR, CAT_COLOURS); - public Option dungBatColour = new Option( - "0:255:12:255:0", - "Dungeon Bat Colour", - false, - "Dungeon Bat Colour", - FLAG_COLOUR, CAT_COLOURS); - public Option selfRodLineColour = new Option( - "0:255:0:0:0", - "Your Rod Line Colour", - false, - "Changes the colour of your rod's fishing line.\nContrib: ThatGravyBoat", - FLAG_COLOUR, CAT_COLOURS); - public Option otherRodLineColour = new Option( - "0:255:0:0:0", - "Other Rod Line Colour", - false, - "Changes the colour of other players' rod's fishing line.\nContrib: ThatGravyBoat", - FLAG_COLOUR, CAT_COLOURS); - - /** - * OPTIONS THAT DON'T SHOW IN GUI - */ - public Option dev = new Option( - false, - "Show Dev Options", - true, - "Dev Feature. Please don't use.", CAT_ALL); - public Option loadedModBefore = new Option( - false, - "loadedModBefore", - true, - "loadedModBefore", CAT_ALL); - public Option doRamNotif = new Option( - true, - "doRamNotif", - false, - "doRamNotif", CAT_ALL); - public Option customTradePrices = new Option( - true, - "Trade Item Values", - true, - "If true, shows a window with the total item value of either side", CAT_ALL); - public Option customTradePriceStyle = new Option( - true, - "Trade Prices Style", - true, - "Changes the style of the top item prices", CAT_ALL); - public Option selectedCape = new Option( - "", - "Selected Cape", - true, - "Selected Cape", CAT_ALL); - public Option compareMode = new Option( - 0.0, - "Compare Mode", - false, - "Compare Mode", CAT_ALL); - public Option sortMode = new Option( - 0.0, - "Sort Mode", - false, - "Sort Mode", CAT_ALL); - public Option> compareAscending = new Option( - Utils.createList(true, true, true), - "Compare Ascending", - false, - "Compare Ascending", CAT_ALL); - public Option> favourites = new Option( - new ArrayList(), - "Favourites", - false, - "Favourites", CAT_ALL); - public Option> eventFavourites = new Option( - new ArrayList(), - "Event Favourites", - false, - "Event Favourites", CAT_ALL); - public Option>> collectionLog = new Option( - new HashMap>(), - "CollectionLog", - false, - "CollectionLog", CAT_ALL); - public Option> quickCommands = new Option( - createDefaultQuickCommands(), - "Quick Commands", - false, - "Quick Commands", CAT_ALL); - public Option overlaySearchBar = new Option( - "", - "OverlaySearchBar", - false, - "OverlaySearchBar", CAT_ALL); - public Option overlayQuickCommand = new Option( - "", - "OverlaySearchBar", - false, - "OverlaySearchBar", CAT_ALL); - public Option> enchantColours = new Option( - Utils.createList("[a-zA-Z\\- ]+:\u003e:9:6", - "[a-zA-Z\\- ]+:\u003e:6:c", - "[a-zA-Z\\- ]+:\u003e:5:5", - "Experience:\u003e:3:5", - "Life Steal:\u003e:3:5", - "Scavenger:\u003e:3:5", - "Looting:\u003e:3:5"), - "enchantColours", - false, - "enchantColours", CAT_ALL); - - //Dungeon Map Options - public Option dmBorderSize = new Option( - 1.0, - "Border Size", - false, - "Changes the size of the map border, without changing the size of the contents", 0, 5, CAT_ALL); - public Option dmRoomSize = new Option( - 1.0, - "Room Size", - false, - "Changes the size of rooms. Useful for higher dungeons with larger maps", 0, 5, CAT_ALL); - public Option dmIconScale = new Option( - 1.0, - "Icon Size", - false, - "Changes the scale of room indicators and player icons", 0.5, 3, CAT_ALL); - public Option dmBorderStyle = new Option( - 0.0, - "Border Style", - false, - "Various custom borders from various talented artists.\nUse 'custom' if your texture pack has a custom border", CAT_ALL); - public Option dmEnable = new Option( - true, - "Show Dungeon Map", - false, - "Show/hide the NEU dungeon map", CAT_ALL); - public Option dmCenterPlayer = new Option( - false, - "Map Center", - false, - "Center on rooms, or center on your player", CAT_ALL); - public Option dmRotatePlayer = new Option( - true, - "Rotate with Player", - false, - "Rotate the map to face the same direction as your player", CAT_ALL); - public Option dmOrientCheck = new Option( - true, - "Orient Checkmarks", - false, - "Checkmarks will always show vertically, regardless of rotation", CAT_ALL); - public Option dmCenterCheck = new Option( - false, - "Center Checkmarks", - false, - "Checkmarks will show closer to the center of rooms", CAT_ALL); - public Option dmPlayerHeads = new Option( - 0.0, - "Player Icon Style", - false, - "Various player icon styles", CAT_ALL); - public Option dmPlayerInterp = new Option( - true, - "Interpolate Far Players", - false, - "Will make players far away move smoothly", CAT_ALL); - public Option dmCompat = new Option( - 0.0, - "OpenGL Compatibility", - false, - "Compatiblity options for people with bad computers. ONLY use this if you know what you are doing, otherwise the map will look worse", CAT_ALL); - public Option dmBackgroundColour = new Option( - "00:170:75:75:75", - "Background Colour", - false, - "Colour of the map background. Supports opacity & chroma", FLAG_COLOUR, CAT_ALL); - public Option dmBorderColour = new Option( - "00:0:0:0:0", - "Border Colour", - false, - "Colour of the map border. Supports opacity & chroma. Turn off custom borders to see", FLAG_COLOUR, CAT_ALL); - public Option dmChromaBorder = new Option( - false, - "Chroma Border Mode", - false, - "Applies a hue offset around the map border", CAT_ALL); - public Option dmBackgroundBlur = new Option( - 3.0, - "Background Blur Factor", - false, - "Changes the blur factor behind the map. Set to 0 to disable blur", CAT_ALL); - public Option dmCenterX = new Option( - 8.5, - "Center X (%)", - false, - "The horizontal position of the map", CAT_ALL); - public Option dmCenterY = new Option( - 15.0, - "Center Y (%)", - false, - "The vertical position of the map", CAT_ALL); - - private ArrayList createDefaultQuickCommands() { - ArrayList arr = new ArrayList<>(); - arr.add("/warp home:Warp Home:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzljODg4MWU0MjkxNWE5ZDI5YmI2MWExNmZiMjZkMDU5OTEzMjA0ZDI2NWRmNWI0MzliM2Q3OTJhY2Q1NiJ9fX0="); - arr.add("/warp hub:Warp Hub:eyJ0aW1lc3RhbXAiOjE1NTkyMTU0MTY5MDksInByb2ZpbGVJZCI6IjQxZDNhYmMyZDc0OTQwMGM5MDkwZDU0MzRkMDM4MzFiIiwicHJvZmlsZU5hbWUiOiJNZWdha2xvb24iLCJzaWduYXR1cmVSZXF1aXJlZCI6dHJ1ZSwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2Q3Y2M2Njg3NDIzZDA1NzBkNTU2YWM1M2UwNjc2Y2I1NjNiYmRkOTcxN2NkODI2OWJkZWJlZDZmNmQ0ZTdiZjgifX19"); - arr.add("/craft:Crafting Table:CRAFTING_TABLE"); - arr.add("/enderchest:Ender Chest:ENDER_CHEST"); - arr.add("/wardrobe:Wardrobe:LEATHER_CHESTPLATE"); - arr.add("/pets:Pets:BONE"); - arr.add("neucl:Collection Log:MAP"); - arr.add("neuah:NEU Auction House:GOLD_BLOCK"); - return arr; - } - - public class Button { - public String displayName; - public String desc; - public Runnable click; - - public Button(String displayName, String desc, Runnable click) { - this.displayName = displayName; - this.desc = desc; - this.click = click; - } - } - - private transient List