From 718740e85f48b57bf712a62f811cd4d34dd98450 Mon Sep 17 00:00:00 2001 From: ThatGravyBoat Date: Thu, 15 Jul 2021 01:36:50 -0230 Subject: Updated important locations Updated Config System (Thanks Moulberry) Added Trackers Back with kill trackers --- .../com/thatgravyboat/skyblockhud/GuiTextures.java | 1 - .../com/thatgravyboat/skyblockhud/SkyblockHud.java | 16 +- .../java/com/thatgravyboat/skyblockhud/Utils.java | 10 + .../skyblockhud/api/KillTracking.java | 5 +- .../api/events/SkyBlockEntityKilled.java | 4 +- .../api/sbentities/EntityTypeHelper.java | 18 + .../api/sbentities/EntityTypeRegistry.java | 4 +- .../skyblockhud/config/SBHConfig.java | 27 +- .../skyblockhud/config/SBHConfigEditor.java | 83 +++-- .../skyblockhud/core/BackgroundBlur.java | 118 ++++--- .../skyblockhud/core/ChromaColour.java | 26 +- .../skyblockhud/core/GlScissorStack.java | 23 +- .../thatgravyboat/skyblockhud/core/GuiElement.java | 6 +- .../skyblockhud/core/GuiElementBoolean.java | 44 +-- .../skyblockhud/core/GuiElementColour.java | 283 +++++++++------ .../skyblockhud/core/GuiElementTextField.java | 383 +++++++++++++-------- .../skyblockhud/core/config/Config.java | 4 +- .../skyblockhud/core/config/KeybindHelper.java | 50 +++ .../config/annotations/ConfigEditorKeybind.java | 14 + .../core/config/gui/GuiOptionEditor.java | 22 +- .../core/config/gui/GuiOptionEditorAccordion.java | 20 +- .../core/config/gui/GuiOptionEditorBoolean.java | 11 +- .../core/config/gui/GuiOptionEditorButton.java | 22 +- .../core/config/gui/GuiOptionEditorColour.java | 43 ++- .../config/gui/GuiOptionEditorDraggableList.java | 151 ++++---- .../core/config/gui/GuiOptionEditorDropdown.java | 81 ++--- .../core/config/gui/GuiOptionEditorKeybind.java | 93 +++++ .../core/config/gui/GuiOptionEditorSlider.java | 98 +++--- .../core/config/gui/GuiOptionEditorText.java | 36 +- .../core/config/gui/GuiPositionEditor.java | 58 ++-- .../core/config/struct/ConfigProcessor.java | 90 +++-- .../skyblockhud/core/util/GuiElementSlider.java | 58 ++-- .../skyblockhud/core/util/MiscUtils.java | 103 ------ .../skyblockhud/core/util/Splitters.java | 8 - .../skyblockhud/core/util/StringUtils.java | 28 -- .../skyblockhud/core/util/lerp/LerpUtils.java | 11 +- .../skyblockhud/core/util/lerp/LerpingFloat.java | 16 +- .../skyblockhud/core/util/lerp/LerpingInteger.java | 16 +- .../core/util/render/TextRenderUtils.java | 74 +--- .../skyblockhud/handlers/CrystalWaypoints.java | 2 +- .../skyblockhud/handlers/SlayerHandler.java | 15 + .../skyblockhud/location/MinesHandler.java | 2 +- .../mixins/MixinNetHandlerPlayClient.java | 20 +- .../skyblockhud/overlay/GenericOverlays.java | 22 +- .../skyblockhud/tracker/TrackerFileLoader.java | 167 ++++----- .../skyblockhud/tracker/TrackerHandler.java | 99 +++--- .../skyblockhud/tracker/TrackerObject.java | 94 +++++ 47 files changed, 1462 insertions(+), 1117 deletions(-) create mode 100644 src/main/java/com/thatgravyboat/skyblockhud/core/config/KeybindHelper.java create mode 100644 src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorKeybind.java create mode 100644 src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorKeybind.java delete mode 100644 src/main/java/com/thatgravyboat/skyblockhud/core/util/MiscUtils.java delete mode 100644 src/main/java/com/thatgravyboat/skyblockhud/core/util/Splitters.java create mode 100644 src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerObject.java (limited to 'src/main/java/com') diff --git a/src/main/java/com/thatgravyboat/skyblockhud/GuiTextures.java b/src/main/java/com/thatgravyboat/skyblockhud/GuiTextures.java index cd8c25f..280a18d 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/GuiTextures.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/GuiTextures.java @@ -31,7 +31,6 @@ public class GuiTextures { public static final ResourceLocation overlay = new ResourceLocation("skyblockhud", "stats.png"); public static final ResourceLocation dungeon = new ResourceLocation("skyblockhud", "dungeon.png"); public static final ResourceLocation playerStat = new ResourceLocation("skyblockhud", "playerstats.png"); - public static final ResourceLocation bars = new ResourceLocation("skyblockhud", "bars.png"); public static final ResourceLocation mapOverlay = new ResourceLocation("skyblockhud", "maps/map_overlay.png"); public static final ResourceLocation mining = new ResourceLocation("skyblockhud", "mines.png"); } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java b/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java index 539a42f..1cb00bb 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java @@ -3,6 +3,7 @@ package com.thatgravyboat.skyblockhud; import com.google.common.collect.Sets; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.thatgravyboat.skyblockhud.api.KillTracking; import com.thatgravyboat.skyblockhud.api.LeaderboardGetter; import com.thatgravyboat.skyblockhud.api.events.ProfileSwitchedEvent; import com.thatgravyboat.skyblockhud.commands.Commands; @@ -17,6 +18,8 @@ import com.thatgravyboat.skyblockhud.overlay.OverlayHud; import com.thatgravyboat.skyblockhud.overlay.RPGHud; import com.thatgravyboat.skyblockhud.playerstats.ActionBarParsing; import com.thatgravyboat.skyblockhud.seasons.SeasonDateHandler; +import com.thatgravyboat.skyblockhud.tracker.TrackerFileLoader; +import com.thatgravyboat.skyblockhud.tracker.TrackerHandler; import java.awt.*; import java.awt.datatransfer.StringSelection; import java.io.*; @@ -32,11 +35,13 @@ import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; +import net.minecraftforge.fml.common.event.FMLLoadCompleteEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; +import net.minecraftforge.fml.common.network.FMLNetworkEvent; import org.lwjgl.input.Keyboard; @Mod(modid = SkyblockHud.MODID, version = SkyblockHud.VERSION) @@ -69,10 +74,9 @@ public class SkyblockHud { MinecraftForge.EVENT_BUS.register(new MinesHandler()); MinecraftForge.EVENT_BUS.register(new FarmingIslandHandler()); - /* DISABLE UNTIL NEW SYSTEM MinecraftForge.EVENT_BUS.register(new TrackerHandler()); - MinecraftForge.EVENT_BUS.register(new KillTrackerHandler()); - */ + MinecraftForge.EVENT_BUS.register(new KillTracking()); + MinecraftForge.EVENT_BUS.register(new HeldItemHandler()); ClientRegistry.registerKeyBinding(KeyBindings.map); @@ -99,7 +103,7 @@ public class SkyblockHud { configDirectory = event.getModConfigurationDirectory(); Runtime.getRuntime().addShutdownHook(new Thread(this::saveConfig)); - //Runtime.getRuntime().addShutdownHook(new Thread(() -> TrackerFileLoader.saveTrackerStatsFile(event.getModConfigurationDirectory()))); + Runtime.getRuntime().addShutdownHook(new Thread(() -> TrackerFileLoader.saveTrackerStatsFile(event.getModConfigurationDirectory()))); } public void saveConfig() { @@ -122,7 +126,7 @@ public class SkyblockHud { MinecraftForge.EVENT_BUS.register(new MiningHud()); } - /* DISABLE UNTIL NEW SYSTEM + // DISABLE UNTIL NEW SYSTEM @EventHandler public void loadComplete(FMLLoadCompleteEvent event){ @@ -138,7 +142,7 @@ public class SkyblockHud { TrackerFileLoader.saveTrackerStatsFile(configDirectory); } - */ + public static boolean hasSkyblockScoreboard() { Minecraft mc = Minecraft.getMinecraft(); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/Utils.java b/src/main/java/com/thatgravyboat/skyblockhud/Utils.java index b80d5ae..157077b 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/Utils.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/Utils.java @@ -1,9 +1,13 @@ package com.thatgravyboat.skyblockhud; +import java.math.RoundingMode; import java.nio.FloatBuffer; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; +import java.util.Locale; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.FontRenderer; @@ -353,4 +357,10 @@ public class Utils { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); GlStateManager.popMatrix(); } + + public static String formattedNumber(int number, int numberToFormatAt) { + DecimalFormat formatter = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.CANADA)); + formatter.setRoundingMode(RoundingMode.FLOOR); + return number > numberToFormatAt-1 ? formatter.format((double) number / 1000) + "k" : String.valueOf(number); + } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/api/KillTracking.java b/src/main/java/com/thatgravyboat/skyblockhud/api/KillTracking.java index 32feb1b..c13a7b8 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/api/KillTracking.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/api/KillTracking.java @@ -7,6 +7,7 @@ import java.util.HashSet; import java.util.Set; import java.util.UUID; import net.minecraft.client.Minecraft; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.DamageSource; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.EntityJoinWorldEvent; @@ -32,7 +33,9 @@ public class KillTracking { System.out.println("----------------------------------------------------------------------------------------------------------------"); System.out.println("Name : " + event.entity.getName()); System.out.println("UUID : " + event.entity.getUniqueID()); - System.out.println("Tag : " + event.entity.serializeNBT()); + NBTTagCompound compound = new NBTTagCompound(); + event.entity.writeToNBT(compound); + System.out.println("Tag : " + compound); System.out.println("Damage : " + getDamageSourceString(event.source)); System.out.println("SBH Entity ID: " + EntityTypeRegistry.getEntityId(event.entity)); System.out.println("----------------------------------------------------------------------------------------------------------------"); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/api/events/SkyBlockEntityKilled.java b/src/main/java/com/thatgravyboat/skyblockhud/api/events/SkyBlockEntityKilled.java index 325781c..15fb01a 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/api/events/SkyBlockEntityKilled.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/api/events/SkyBlockEntityKilled.java @@ -1,14 +1,16 @@ package com.thatgravyboat.skyblockhud.api.events; +import javax.annotation.Nullable; import net.minecraft.entity.Entity; import net.minecraftforge.fml.common.eventhandler.Event; public class SkyBlockEntityKilled extends Event { public String id; + @Nullable public Entity entity; - public SkyBlockEntityKilled(String id, Entity entity) { + public SkyBlockEntityKilled(String id, @Nullable Entity entity) { this.id = id; this.entity = entity; } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/api/sbentities/EntityTypeHelper.java b/src/main/java/com/thatgravyboat/skyblockhud/api/sbentities/EntityTypeHelper.java index d1ad8d2..8dc63c8 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/api/sbentities/EntityTypeHelper.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/api/sbentities/EntityTypeHelper.java @@ -4,7 +4,9 @@ import com.thatgravyboat.skyblockhud.location.LocationHandler; import com.thatgravyboat.skyblockhud.location.Locations; import net.minecraft.entity.Entity; import net.minecraft.entity.monster.EntityEnderman; +import net.minecraft.entity.monster.EntityZombie; import net.minecraft.init.Blocks; +import net.minecraft.init.Items; public class EntityTypeHelper { @@ -18,4 +20,20 @@ public class EntityTypeHelper { } return false; } + + public static boolean isCrypt(Entity entity){ + if (entity instanceof EntityZombie) { + EntityZombie zombie = ((EntityZombie) entity); + double maxHealthBase = zombie.getAttributeMap().getAttributeInstanceByName("generic.maxHealth").getBaseValue(); + if (maxHealthBase != 2000d) return false; + if (zombie.getEquipmentInSlot(0) == null || !zombie.getEquipmentInSlot(0).getItem().equals(Items.iron_sword)) + return false; + if (zombie.getEquipmentInSlot(1) == null || !zombie.getEquipmentInSlot(1).getItem().equals(Items.chainmail_boots)) + return false; + if (zombie.getEquipmentInSlot(2) == null || !zombie.getEquipmentInSlot(2).getItem().equals(Items.chainmail_leggings)) + return false; + return zombie.getEquipmentInSlot(3) != null && zombie.getEquipmentInSlot(3).getItem().equals(Items.chainmail_chestplate); + } + return false; + } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/api/sbentities/EntityTypeRegistry.java b/src/main/java/com/thatgravyboat/skyblockhud/api/sbentities/EntityTypeRegistry.java index 952aaa7..6ff88fa 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/api/sbentities/EntityTypeRegistry.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/api/sbentities/EntityTypeRegistry.java @@ -6,13 +6,15 @@ import java.util.List; import java.util.Map; import net.minecraft.entity.Entity; import net.minecraft.entity.monster.EntityEnderman; +import net.minecraft.entity.monster.EntityZombie; public class EntityTypeRegistry { private static final Map, List> entities = Maps.newHashMap(); static { - entities.put(EntityEnderman.class, ImmutableList.of(SkyBlockEntity.of("zealot", EntityTypeHelper::isZealot))); + entities.put(EntityEnderman.class, ImmutableList.of(SkyBlockEntity.of("ZEALOT", EntityTypeHelper::isZealot))); + entities.put(EntityZombie.class, ImmutableList.of(SkyBlockEntity.of("CRYPT_GHOUL", EntityTypeHelper::isCrypt))); } public static String getEntityId(Entity entity) { diff --git a/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfig.java b/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfig.java index 8d84833..9b42192 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfig.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfig.java @@ -50,9 +50,9 @@ public class SBHConfig extends Config { case "map": editOverlay(activeConfigCategory, 72, 72, map.miniMapPosition); return; - // case "tracker": - // editOverlay(activeConfigCategory, 120, 70, trackers.trackerPosition); - // return; + case "tracker": + editOverlay(activeConfigCategory, 130, 70, trackers.trackerPosition); + return; } } @@ -84,17 +84,26 @@ public class SBHConfig extends Config { @Category(name = "Mining", desc = "All Options for the Mining Stuff.") public Mining mining = new Mining(); - //TODO ENABLED WHEN TRACKER GETS ADDED BACK - // @Expose - // @Category(name = "Tracker", desc = "All Options for the Trackers.") - // public Trackers trackers = new Trackers(); + @Expose + @Category(name = "Tracker", desc = "All Options for the Trackers.") + public Trackers trackers = new Trackers(); public static class Misc { @Expose - @ConfigOption(name = "Hide Scoreboard", desc = "Hides the scoreboard when in skyblock.") + @ConfigOption(name = "Hide Scoreboard", desc = "Hides the scoreboard when in Skyblock.") @ConfigEditorBoolean public boolean hideScoreboard = false; + + @Expose + @ConfigOption( + name = "Bar Textures", + desc = "Change the style of bars. Dont change this unless the pack ur using tells you can." + ) + @ConfigEditorDropdown( + values = {"Style 1", "Style 2"} + ) + public int barTexture = 0; } public static class MainHud { @@ -342,6 +351,6 @@ public class SBHConfig extends Config { @Expose @ConfigOption(name = "Hide Tracker", desc = "It will still track the data just in case.") @ConfigEditorBoolean - public boolean hideTracker = false; + public boolean hideTracker = true; } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfigEditor.java b/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfigEditor.java index 8bbeaa7..90325f8 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfigEditor.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfigEditor.java @@ -1,8 +1,5 @@ package com.thatgravyboat.skyblockhud.config; -import static com.thatgravyboat.skyblockhud.GuiTextures.DISCORD; -import static com.thatgravyboat.skyblockhud.GuiTextures.TWITTER; - import com.google.common.collect.Lists; import com.thatgravyboat.skyblockhud.core.GlScissorStack; import com.thatgravyboat.skyblockhud.core.GuiElement; @@ -16,8 +13,8 @@ import com.thatgravyboat.skyblockhud.core.util.render.RenderUtils; import com.thatgravyboat.skyblockhud.core.util.render.TextRenderUtils; import java.awt.*; import java.net.URI; -import java.util.*; import java.util.List; +import java.util.*; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; @@ -28,6 +25,9 @@ import net.minecraft.util.ResourceLocation; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; +import static com.thatgravyboat.skyblockhud.GuiTextures.DISCORD; +import static com.thatgravyboat.skyblockhud.GuiTextures.TWITTER; + public class SBHConfigEditor extends GuiElement { private static final ResourceLocation[] socialsIco = new ResourceLocation[] { DISCORD, TWITTER }; @@ -41,6 +41,7 @@ public class SBHConfigEditor extends GuiElement { private final LerpingInteger categoryScroll = new LerpingInteger(0, 150); private LinkedHashMap processedConfig; + private TreeMap> searchOptionMap = new TreeMap<>(); private HashMap categoryForOption = new HashMap<>(); public SBHConfigEditor(Config config) { @@ -232,14 +233,15 @@ public class SBHConfigEditor extends GuiElement { ConfigProcessor.ProcessedCategory cat = currentConfigEditing.get(getSelectedCategory()); int optionWidthDefault = innerRight - innerLeft - 20; GlStateManager.enableDepth(); - Set activeAccordions = new HashSet<>(); + HashMap activeAccordions = new HashMap<>(); for (ConfigProcessor.ProcessedOption option : getOptionsInCategory(cat).values()) { int optionWidth = optionWidthDefault; if (option.accordionId >= 0) { - if (!activeAccordions.contains(option.accordionId)) { + if(!activeAccordions.containsKey(option.accordionId)) { continue; } - optionWidth = optionWidthDefault - 2 * innerPadding; + int accordionDepth = activeAccordions.get(option.accordionId); + optionWidth = optionWidthDefault - (2 * innerPadding)*(accordionDepth + 1); } GuiOptionEditor editor = option.editor; @@ -249,7 +251,11 @@ public class SBHConfigEditor extends GuiElement { if (editor instanceof GuiOptionEditorAccordion) { GuiOptionEditorAccordion accordion = (GuiOptionEditorAccordion) editor; if (accordion.getToggled()) { - activeAccordions.add(accordion.getAccordionId()); + int accordionDepth = 0; + if (option.accordionId >= 0) { + accordionDepth = activeAccordions.get(option.accordionId)+1; + } + activeAccordions.put(accordion.getAccordionId(), accordionDepth); } } int optionHeight = editor.getHeight(); @@ -274,14 +280,15 @@ public class SBHConfigEditor extends GuiElement { GlStateManager.translate(0, 0, 10); GlStateManager.enableDepth(); - Set activeAccordions = new HashSet<>(); + HashMap activeAccordions = new HashMap<>(); for (ConfigProcessor.ProcessedOption option : getOptionsInCategory(cat).values()) { int optionWidth = optionWidthDefault; if (option.accordionId >= 0) { - if (!activeAccordions.contains(option.accordionId)) { + if (!activeAccordions.containsKey(option.accordionId)) { continue; } - optionWidth = optionWidthDefault - 2 * innerPadding; + int accordionDepth = activeAccordions.get(option.accordionId); + optionWidth = optionWidthDefault - (2 * innerPadding) * (accordionDepth + 1); } GuiOptionEditor editor = option.editor; @@ -291,7 +298,11 @@ public class SBHConfigEditor extends GuiElement { if (editor instanceof GuiOptionEditorAccordion) { GuiOptionEditorAccordion accordion = (GuiOptionEditorAccordion) editor; if (accordion.getToggled()) { - activeAccordions.add(accordion.getAccordionId()); + int accordionDepth = 0; + if (option.accordionId >= 0) { + accordionDepth = activeAccordions.get(option.accordionId)+1; + } + activeAccordions.put(accordion.getAccordionId(), accordionDepth); } } int optionHeight = editor.getHeight(); @@ -403,10 +414,10 @@ public class SBHConfigEditor extends GuiElement { int optionY = -newTarget; if (getSelectedCategory() != null && getCurrentConfigEditing() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { ConfigProcessor.ProcessedCategory cat = getCurrentConfigEditing().get(getSelectedCategory()); - Set activeAccordions = new HashSet<>(); + HashMap activeAccordions = new HashMap<>(); for (ConfigProcessor.ProcessedOption option : getOptionsInCategory(cat).values()) { if (option.accordionId >= 0) { - if (!activeAccordions.contains(option.accordionId)) { + if (!activeAccordions.containsKey(option.accordionId)) { continue; } } @@ -418,7 +429,11 @@ public class SBHConfigEditor extends GuiElement { if (editor instanceof GuiOptionEditorAccordion) { GuiOptionEditorAccordion accordion = (GuiOptionEditorAccordion) editor; if (accordion.getToggled()) { - activeAccordions.add(accordion.getAccordionId()); + int accordionDepth = 0; + if (option.accordionId >= 0) { + accordionDepth = activeAccordions.get(option.accordionId)+1; + } + activeAccordions.put(accordion.getAccordionId(), accordionDepth); } } optionY += editor.getHeight() + 5; @@ -468,14 +483,15 @@ public class SBHConfigEditor extends GuiElement { if (getSelectedCategory() != null && getCurrentConfigEditing() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { int optionWidthDefault = innerRight - innerLeft - 20; ConfigProcessor.ProcessedCategory cat = getCurrentConfigEditing().get(getSelectedCategory()); - Set activeAccordions = new HashSet<>(); + HashMap activeAccordions = new HashMap<>(); for (ConfigProcessor.ProcessedOption option : getOptionsInCategory(cat).values()) { int optionWidth = optionWidthDefault; if (option.accordionId >= 0) { - if (!activeAccordions.contains(option.accordionId)) { + if (!activeAccordions.containsKey(option.accordionId)) { continue; } - optionWidth = optionWidthDefault - 2 * innerPadding; + int accordionDepth = activeAccordions.get(option.accordionId); + optionWidth = optionWidthDefault - (2*innerPadding)*(accordionDepth+1); } GuiOptionEditor editor = option.editor; @@ -485,7 +501,11 @@ public class SBHConfigEditor extends GuiElement { if (editor instanceof GuiOptionEditorAccordion) { GuiOptionEditorAccordion accordion = (GuiOptionEditorAccordion) editor; if (accordion.getToggled()) { - activeAccordions.add(accordion.getAccordionId()); + int accordionDepth = 0; + if (option.accordionId >= 0) { + accordionDepth = activeAccordions.get(option.accordionId)+1; + } + activeAccordions.put(accordion.getAccordionId(), accordionDepth); } } if (editor.mouseInputOverlay((innerLeft + innerRight - optionWidth) / 2 - 5, innerTop + 5 + optionY, optionWidth, mouseX, mouseY)) { @@ -500,14 +520,15 @@ public class SBHConfigEditor extends GuiElement { if (getSelectedCategory() != null && getCurrentConfigEditing() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { int optionWidthDefault = innerRight - innerLeft - 20; ConfigProcessor.ProcessedCategory cat = getCurrentConfigEditing().get(getSelectedCategory()); - Set activeAccordions = new HashSet<>(); + HashMap activeAccordions = new HashMap<>(); for (ConfigProcessor.ProcessedOption option : getOptionsInCategory(cat).values()) { int optionWidth = optionWidthDefault; if (option.accordionId >= 0) { - if (!activeAccordions.contains(option.accordionId)) { + if (!activeAccordions.containsKey(option.accordionId)) { continue; } - optionWidth = optionWidthDefault - 2 * innerPadding; + int accordionDepth = activeAccordions.get(option.accordionId); + optionWidth = optionWidthDefault - (2*innerPadding)*(accordionDepth+1); } GuiOptionEditor editor = option.editor; @@ -517,7 +538,11 @@ public class SBHConfigEditor extends GuiElement { if (editor instanceof GuiOptionEditorAccordion) { GuiOptionEditorAccordion accordion = (GuiOptionEditorAccordion) editor; if (accordion.getToggled()) { - activeAccordions.add(accordion.getAccordionId()); + int accordionDepth = 0; + if (option.accordionId >= 0) { + accordionDepth = activeAccordions.get(option.accordionId)+1; + } + activeAccordions.put(accordion.getAccordionId(), accordionDepth); } } if (editor.mouseInput((innerLeft + innerRight - optionWidth) / 2 - 5, innerTop + 5 + optionY, optionWidth, mouseX, mouseY)) { @@ -544,10 +569,10 @@ public class SBHConfigEditor extends GuiElement { if (getSelectedCategory() != null && getCurrentConfigEditing() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { ConfigProcessor.ProcessedCategory cat = getCurrentConfigEditing().get(getSelectedCategory()); - Set activeAccordions = new HashSet<>(); + HashMap activeAccordions = new HashMap<>(); for (ConfigProcessor.ProcessedOption option : getOptionsInCategory(cat).values()) { if (option.accordionId >= 0) { - if (!activeAccordions.contains(option.accordionId)) { + if (!activeAccordions.containsKey(option.accordionId)) { continue; } } @@ -559,7 +584,11 @@ public class SBHConfigEditor extends GuiElement { if (editor instanceof GuiOptionEditorAccordion) { GuiOptionEditorAccordion accordion = (GuiOptionEditorAccordion) editor; if (accordion.getToggled()) { - activeAccordions.add(accordion.getAccordionId()); + int accordionDepth = 0; + if (option.accordionId >= 0) { + accordionDepth = activeAccordions.get(option.accordionId)+1; + } + activeAccordions.put(accordion.getAccordionId(), accordionDepth); } } if (editor.keyboardInput()) { @@ -570,4 +599,4 @@ public class SBHConfigEditor extends GuiElement { return true; } -} +} \ No newline at end of file diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/BackgroundBlur.java b/src/main/java/com/thatgravyboat/skyblockhud/core/BackgroundBlur.java index a9d9d5d..f143b97 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/BackgroundBlur.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/BackgroundBlur.java @@ -18,19 +18,31 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL30; public class BackgroundBlur { - private static HashMap blurOutput = new HashMap<>(); - private static HashMap lastBlurUse = new HashMap<>(); + private static class OutputStuff { + public Framebuffer framebuffer; + public Shader blurShaderHorz = null; + public Shader blurShaderVert = null; + + public OutputStuff(Framebuffer framebuffer, Shader blurShaderHorz, Shader blurShaderVert) { + this.framebuffer = framebuffer; + this.blurShaderHorz = blurShaderHorz; + this.blurShaderVert = blurShaderVert; + } + } + + private static final HashMap blurOutput = new HashMap<>(); + private static final HashMap lastBlurUse = new HashMap<>(); private static long lastBlur = 0; - private static HashSet requestedBlurs = new HashSet<>(); + private static final HashSet requestedBlurs = new HashSet<>(); private static int fogColour = 0; private static boolean registered = false; - public static void registerListener() { - if (!registered) { + if(!registered) { registered = true; MinecraftForge.EVENT_BUS.register(new BackgroundBlur()); } @@ -57,17 +69,21 @@ public class BackgroundBlur { int width = Minecraft.getMinecraft().displayWidth; int height = Minecraft.getMinecraft().displayHeight; - Framebuffer output = blurOutput.computeIfAbsent( - blur, - k -> { - Framebuffer fb = new Framebuffer(width, height, false); - fb.setFramebufferFilter(GL11.GL_NEAREST); - return fb; - } - ); + OutputStuff output = blurOutput.computeIfAbsent(blur, k -> { + Framebuffer fb = new Framebuffer(width, height, false); + fb.setFramebufferFilter(GL11.GL_NEAREST); + return new OutputStuff(fb, null, null); + }); - output.framebufferWidth = output.framebufferTextureWidth = width; - output.framebufferHeight = output.framebufferTextureHeight = height; + if(output.framebuffer.framebufferWidth != width || output.framebuffer.framebufferHeight != height) { + output.framebuffer.createBindFramebuffer(width, height); + if(output.blurShaderHorz != null) { + output.blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); + } + if(output.blurShaderVert != null) { + output.blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height)); + } + } blurBackground(output, blur); } @@ -89,7 +105,7 @@ public class BackgroundBlur { @SubscribeEvent(priority = EventPriority.HIGHEST) public void onScreenRender(RenderGameOverlayEvent.Pre event) { - if (event.type == RenderGameOverlayEvent.ElementType.ALL) { + if(event.type == RenderGameOverlayEvent.ElementType.ALL) { processBlurs(); } } @@ -102,8 +118,6 @@ public class BackgroundBlur { fogColour |= (int) (event.blue * 255) & 0xFF; } - private static Shader blurShaderHorz = null; - private static Shader blurShaderVert = null; private static Framebuffer blurOutputHorz = null; /** @@ -126,8 +140,8 @@ public class BackgroundBlur { return projMatrix; } - private static void blurBackground(Framebuffer output, float blurFactor) { - if (!OpenGlHelper.isFramebufferEnabled() || !OpenGlHelper.areShadersSupported()) return; + private static void blurBackground(OutputStuff output, float blurFactor) { + if(!OpenGlHelper.isFramebufferEnabled() || !OpenGlHelper.areShadersSupported()) return; int width = Minecraft.getMinecraft().displayWidth; int height = Minecraft.getMinecraft().displayHeight; @@ -139,47 +153,52 @@ public class BackgroundBlur { GlStateManager.loadIdentity(); GlStateManager.translate(0.0F, 0.0F, -2000.0F); - if (blurOutputHorz == null) { + if(blurOutputHorz == null) { blurOutputHorz = new Framebuffer(width, height, false); blurOutputHorz.setFramebufferFilter(GL11.GL_NEAREST); } - if (blurOutputHorz == null || output == null) { + if(blurOutputHorz == null || output == null) { return; } - if (blurOutputHorz.framebufferWidth != width || blurOutputHorz.framebufferHeight != height) { + if(blurOutputHorz.framebufferWidth != width || blurOutputHorz.framebufferHeight != height) { blurOutputHorz.createBindFramebuffer(width, height); - blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); } - 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 ignored) {} - try { - blurShaderVert = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", blurOutputHorz, output); - blurShaderVert.getShaderManager().getShaderUniform("BlurDir").set(0, 1); - blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height)); - } catch (Exception ignored) {} - if (blurShaderHorz != null && blurShaderVert != null) { - if (blurShaderHorz.getShaderManager().getShaderUniform("Radius") == null) { + if(output.blurShaderHorz == null) { + try { + output.blurShaderHorz = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", + output.framebuffer, blurOutputHorz); + output.blurShaderHorz.getShaderManager().getShaderUniform("BlurDir").set(1, 0); + output.blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); + } catch(Exception ignored) { } + } + if(output.blurShaderVert == null) { + try { + output.blurShaderVert = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", + blurOutputHorz, output.framebuffer); + output.blurShaderVert.getShaderManager().getShaderUniform("BlurDir").set(0, 1); + output.blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height)); + } catch(Exception ignored) { } + } + if(output.blurShaderHorz != null && output.blurShaderVert != null) { + if(output.blurShaderHorz.getShaderManager().getShaderUniform("Radius") == null) { //Corrupted shader? return; } - blurShaderHorz.getShaderManager().getShaderUniform("Radius").set(blurFactor); - blurShaderVert.getShaderManager().getShaderUniform("Radius").set(blurFactor); + output.blurShaderHorz.getShaderManager().getShaderUniform("Radius").set(blurFactor); + output.blurShaderVert.getShaderManager().getShaderUniform("Radius").set(blurFactor); GL11.glPushMatrix(); - /*GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, Minecraft.getMinecraft().getFramebuffer().framebufferObject); - GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, output.framebufferObject); + GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, Minecraft.getMinecraft().getFramebuffer().framebufferObject); + GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, output.framebuffer.framebufferObject); GL30.glBlitFramebuffer(0, 0, width, height, - 0, 0, output.framebufferWidth, output.framebufferHeight, - GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST);*/ + 0, 0, output.framebuffer.framebufferWidth, output.framebuffer.framebufferHeight, + GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST); - blurShaderHorz.loadShader(0); - blurShaderVert.loadShader(0); + output.blurShaderHorz.loadShader(0); + output.blurShaderVert.loadShader(0); GlStateManager.enableDepth(); GL11.glPopMatrix(); @@ -208,9 +227,9 @@ public class BackgroundBlur { if (blurOutput.isEmpty()) return; - Framebuffer fb = blurOutput.get(blurStrength); - if (fb == null) { - fb = blurOutput.values().iterator().next(); + OutputStuff out = blurOutput.get(blurStrength); + if(out == null) { + out = blurOutput.values().iterator().next(); } float uMin = x / (float) screenWidth; @@ -220,10 +239,11 @@ public class BackgroundBlur { GlStateManager.depthMask(false); Gui.drawRect(x, y, x + blurWidth, y + blurHeight, fogColour); - fb.bindFramebufferTexture(); + out.framebuffer.bindFramebufferTexture(); GlStateManager.color(1f, 1f, 1f, 1f); RenderUtils.drawTexturedRect(x, y, blurWidth, blurHeight, uMin, uMax, vMin, vMax); - fb.unbindFramebufferTexture(); + out.framebuffer.unbindFramebufferTexture(); GlStateManager.depthMask(true); } + } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/ChromaColour.java b/src/main/java/com/thatgravyboat/skyblockhud/core/ChromaColour.java index 3137153..b9f4e79 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/ChromaColour.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/ChromaColour.java @@ -25,8 +25,9 @@ public class ChromaColour { int[] arr = new int[split.length]; - for (int i = 0; i < split.length; i++) { - arr[i] = Integer.parseInt(split[split.length - 1 - i], RADIX); + + for(int i=0; i 0) { + if(chr > 0) { float seconds = getSecondsForSpeed(chr); - hsv[0] += (System.currentTimeMillis() - startTime) / 1000f / seconds; + hsv[0] += (System.currentTimeMillis()-startTime)/1000f/seconds; hsv[0] %= 1; - if (hsv[0] < 0) hsv[0] += 1; + if(hsv[0] < 0) hsv[0] += 1; } - return ((a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF)); + return (a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF); } public static int rotateHue(int argb, int degrees) { @@ -85,9 +85,11 @@ public class ChromaColour { float[] hsv = Color.RGBtoHSB(r, g, b, null); - hsv[0] += degrees / 360f; + hsv[0] += degrees/360f; hsv[0] %= 1; - return ((a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF)); + return (a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF); } + + } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/GlScissorStack.java b/src/main/java/com/thatgravyboat/skyblockhud/core/GlScissorStack.java index 0e1694e..6f21e9a 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/GlScissorStack.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/GlScissorStack.java @@ -1,14 +1,14 @@ package com.thatgravyboat.skyblockhud.core; -import java.util.LinkedList; 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; @@ -27,10 +27,10 @@ public class GlScissorStack { right = Math.min(right, this.right); bottom = Math.min(bottom, this.bottom); - if (top > bottom) { + if(top > bottom) { top = bottom; } - if (left > right) { + if(left > right) { left = right; } @@ -40,39 +40,39 @@ public class GlScissorStack { 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); + GL11.glScissor(left*scale, height-bottom*scale, (right-left)*scale, (bottom-top)*scale); } } private static final LinkedList boundsStack = new LinkedList<>(); public static void push(int left, int top, int right, int bottom, ScaledResolution scaledResolution) { - if (right < left) { + if(right < left) { int temp = right; right = left; left = temp; } - if (bottom < top) { + if(bottom < top) { int temp = bottom; bottom = top; top = temp; } - if (boundsStack.isEmpty()) { + if(boundsStack.isEmpty()) { boundsStack.push(new Bounds(left, top, right, bottom)); } else { boundsStack.push(boundsStack.peek().createSubBound(left, top, right, bottom)); } - if (!boundsStack.isEmpty()) { + if(!boundsStack.isEmpty()) { boundsStack.peek().set(scaledResolution); } GL11.glEnable(GL11.GL_SCISSOR_TEST); } public static void pop(ScaledResolution scaledResolution) { - if (!boundsStack.isEmpty()) { + if(!boundsStack.isEmpty()) { boundsStack.pop(); } - if (boundsStack.isEmpty()) { + if(boundsStack.isEmpty()) { GL11.glDisable(GL11.GL_SCISSOR_TEST); } else { boundsStack.peek().set(scaledResolution); @@ -83,4 +83,5 @@ public class GlScissorStack { boundsStack.clear(); GL11.glDisable(GL11.GL_SCISSOR_TEST); } + } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElement.java b/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElement.java index cb9b15a..ff817cf 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElement.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElement.java @@ -1,10 +1,10 @@ package com.thatgravyboat.skyblockhud.core; -public abstract class GuiElement { +import net.minecraft.client.gui.Gui; - public abstract void render(); +public abstract class GuiElement extends Gui { + public abstract void render(); public abstract boolean mouseInput(int mouseX, int mouseY); - public abstract boolean keyboardInput(); } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementBoolean.java b/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementBoolean.java index 8daf4b1..7c401ed 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementBoolean.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementBoolean.java @@ -37,7 +37,7 @@ public class GuiElementBoolean extends GuiElement { this.toggleCallback = toggleCallback; this.lastMillis = System.currentTimeMillis(); - if (value) animation = 36; + if(value) animation = 36; } @Override @@ -51,56 +51,58 @@ public class GuiElementBoolean extends GuiElement { long deltaMillis = currentMillis - lastMillis; lastMillis = currentMillis; boolean passedLimit = false; - if (previewValue != value) { - if ((previewValue && animation > 12) || (!previewValue && animation < 24)) { + if(previewValue != value) { + if((previewValue && animation > 12) || + (!previewValue && animation < 24)) { passedLimit = true; } } - if (previewValue != passedLimit) { - animation += deltaMillis / 10; + if(previewValue != passedLimit) { + animation += deltaMillis/10; } else { - animation -= deltaMillis / 10; + animation -= deltaMillis/10; } - lastMillis -= deltaMillis % 10; + lastMillis -= deltaMillis%10; - if (previewValue == value) { + if(previewValue == value) { animation = Math.max(0, Math.min(36, animation)); - } else if (!passedLimit) { - if (previewValue) { + } 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) { + 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) { + int animation = (int)(LerpUtils.sigmoidZeroOne(this.animation/36f)*36); + if(animation < 3) { buttonLoc = GuiTextures.OFF; - } else if (animation < 13) { + } else if(animation < 13) { buttonLoc = GuiTextures.ONE; - } else if (animation < 23) { + } else if(animation < 23) { buttonLoc = GuiTextures.TWO; - } else if (animation < 33) { + } else if(animation < 33) { buttonLoc = GuiTextures.THREE; } Minecraft.getMinecraft().getTextureManager().bindTexture(buttonLoc); - RenderUtils.drawTexturedRect(x + animation, y, 12, 14); + 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()) { + 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 if (previewValue == !value) { + } else if(previewValue == !value) { value = !value; toggleCallback.accept(value); } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementColour.java b/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementColour.java index 2092b31..e2d3e0a 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementColour.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementColour.java @@ -18,10 +18,10 @@ import org.lwjgl.opengl.GL11; public class GuiElementColour extends GuiElement { - public static final ResourceLocation colour_selector_dot = new ResourceLocation("skyblockhud:core/colour_selector_dot.png"); - public static final ResourceLocation colour_selector_bar = new ResourceLocation("skyblockhud:core/colour_selector_bar.png"); - public static final ResourceLocation colour_selector_bar_alpha = new ResourceLocation("skyblockhud:core/colour_selector_bar_alpha.png"); - public static final ResourceLocation colour_selector_chroma = new ResourceLocation("skyblockhud:core/colour_selector_chroma.png"); + 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"); @@ -30,8 +30,8 @@ public class GuiElementColour extends GuiElement { private int x; private int y; - private final int xSize = 119; - private final int ySize = 89; + private int xSize = 119; + private int ySize = 89; private float wheelAngle = 0; private float wheelRadius = 0; @@ -42,11 +42,20 @@ public class GuiElementColour extends GuiElement { private Runnable closeCallback; private String colour; - public GuiElementColour(int x, int y, String initialColour, Consumer colourChangedCallback, Runnable closeCallback) { + private final boolean opacitySlider; + private final boolean valueSlider; + + public GuiElementColour(int x, int y, String initialColour, Consumer colourChangedCallback, + Runnable closeCallback) { + this(x, y, initialColour, colourChangedCallback, closeCallback, true, true); + } + + public GuiElementColour(int x, int y, String initialColour, Consumer colourChangedCallback, + Runnable closeCallback, boolean opacitySlider, boolean valueSlider) { 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.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; @@ -56,11 +65,17 @@ public class GuiElementColour extends GuiElement { Color c = new Color(colour); float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); updateAngleAndRadius(hsv); + + this.opacitySlider = opacitySlider; + this.valueSlider = valueSlider; + + if(!valueSlider) xSize -= 15; + if(!opacitySlider) xSize -= 15; } public void updateAngleAndRadius(float[] hsv) { this.wheelRadius = hsv[1]; - this.wheelAngle = hsv[0] * 360; + this.wheelAngle = hsv[0]*360; } public void render() { @@ -72,178 +87,219 @@ public class GuiElementColour extends GuiElement { 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); + 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); + 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; + 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(); + 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; + 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); + 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); + 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); + int valueOffset = 0; + if(valueSlider) { + valueOffset = 15; - 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(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 opacityOffset = 0; + if(opacitySlider) { + opacityOffset = 15; + + Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_bar_alpha); + GlStateManager.color(1, 1, 1, 1); + RenderUtils.drawTexturedRect(x+5+64+5+valueOffset, 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+valueOffset, 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)); + if(chromaSpeed > 0) { + Gui.drawRect(x+5+64+valueOffset+opacityOffset+5+1, y+5+1, + x+5+64+valueOffset+opacityOffset+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)); + Gui.drawRect(x+5+64+valueOffset+opacityOffset+5+1, y+5+27+1, + x+5+64+valueOffset+opacityOffset+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(valueSlider) RenderUtils.drawTexturedRect(x+5+64+5, y+5, 10, 64, GL11.GL_NEAREST); + if(opacitySlider) RenderUtils.drawTexturedRect(x+5+64+5+valueOffset, 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); + if(chromaSpeed > 0) { + RenderUtils.drawTexturedRect(x+5+64+valueOffset+opacityO