From 57cdd2df3bd1125867fd407055286dd98d959c3d Mon Sep 17 00:00:00 2001 From: MisterCheezeCake <75341435+MisterCheezeCake@users.noreply.github.com> Date: Wed, 6 Nov 2024 22:25:59 -0500 Subject: [PATCH] Multiversion and too much other stuff --- .github/workflows/build.yml | 4 +- build.gradle.kts | 8 +- gradle.properties | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 7 +- gradlew.bat | 4 +- settings.gradle.kts | 4 +- .../java/wtf/cheeze/sbt/SkyblockTweaks.java | 17 ++- .../wtf/cheeze/sbt/command/SBTCommand.java | 2 +- .../wtf/cheeze/sbt/config/ConfigImpl.java | 2 +- .../java/wtf/cheeze/sbt/config/SBTConfig.java | 16 +- .../sbt/config/SkyblockTweaksScreenMain.java | 8 +- .../cheeze/sbt/config/VersionedObject.java | 5 + .../migration/BarColorTransformation.java | 56 +++++++ .../sbt/config/migration/ConfigMigration.java | 23 +++ .../migration/ConfigTransformation.java | 13 ++ .../config/migration/MigrationManager.java | 79 ++++++++++ .../sbt/features/BrewingStandOverlay.java | 7 +- .../sbt/features/chat/ChatProtections.java | 6 +- .../sbt/features/chat/PartyFeatures.java | 6 +- .../sbt/features/huds/CoordinatesHUD.java | 24 +-- .../sbt/features/huds/DamageReductionHUD.java | 24 +-- .../cheeze/sbt/features/huds/DefenseHUD.java | 24 +-- .../sbt/features/huds/DrillFuelBar.java | 10 +- .../sbt/features/huds/DrillFuelHUD.java | 24 +-- .../wtf/cheeze/sbt/features/huds/EhpHUD.java | 25 ++-- .../wtf/cheeze/sbt/features/huds/FpsHUD.java | 25 ++-- .../cheeze/sbt/features/huds/HealthBar.java | 13 +- .../cheeze/sbt/features/huds/HealthHUD.java | 20 +-- .../wtf/cheeze/sbt/features/huds/ManaBar.java | 11 +- .../wtf/cheeze/sbt/features/huds/ManaHUD.java | 25 ++-- .../sbt/features/huds/OverflowManaHUD.java | 25 ++-- .../cheeze/sbt/features/huds/RealTimeHUD.java | 24 +-- .../sbt/features/huds/SkillHUDManager.java | 28 ++-- .../cheeze/sbt/features/huds/SpeedHUD.java | 23 +-- .../cheeze/sbt/features/huds/TickerHUD.java | 7 +- .../wtf/cheeze/sbt/{utils => }/hud/HUD.java | 35 +++-- .../cheeze/sbt/{utils => }/hud/HudIcon.java | 16 +- .../cheeze/sbt/{utils => }/hud/HudScreen.java | 37 ++--- .../hud => hud/bases}/AbstractTickerHUD.java | 13 +- .../sbt/{utils/hud => hud/bases}/BarHUD.java | 28 +++- .../sbt/hud/bases/MultilineTextHUD.java | 105 +++++++++++++ .../sbt/{utils/hud => hud/bases}/TextHUD.java | 11 +- .../sbt/{utils/hud => hud/bounds}/Bounds.java | 2 +- .../hud => hud/bounds}/BoundsRelative.java | 2 +- .../sbt/hud/components/FlexibleHudLine.java | 138 ++++++++++++++++++ .../sbt/hud/components/HudComponent.java | 27 ++++ .../sbt/hud/components/SingleHudLine.java | 103 +++++++++++++ .../utils/AnchorPoint.java} | 13 +- .../wtf/cheeze/sbt/hud/utils/DrawMode.java | 32 ++++ .../hud => hud/utils}/HudInformation.java | 33 ++++- .../mixin/AbstractInventoryScreenMixin.java | 25 +++- .../cheeze/sbt/mixin/DrawContextMixin.java | 21 ++- .../wtf/cheeze/sbt/mixin/InGameHudMixin.java | 4 +- .../sbt/mixin/InventoryScreenMixin.java | 22 ++- .../java/wtf/cheeze/sbt/utils/DataUtils.java | 32 ++++ .../java/wtf/cheeze/sbt/utils/HTTPUtils.java | 14 +- .../wtf/cheeze/sbt/utils/NumberUtils.java | 21 ++- .../java/wtf/cheeze/sbt/utils/TextUtils.java | 4 - .../wtf/cheeze/sbt/utils/UpdateChecker.java | 54 +++---- .../java/wtf/cheeze/sbt/utils/Version.java | 18 +-- .../utils/actionbar/ActionBarTransformer.java | 42 +++--- .../wtf/cheeze/sbt/utils/hud/HudLine.java | 84 ----------- .../wtf/cheeze/sbt/utils/render/Color3f.java | 2 +- .../wtf/cheeze/sbt/utils/render/Colors.java | 21 +++ .../cheeze/sbt/utils/render/RenderUtils.java | 66 +++++++-- .../sbt/utils/render/SBTDrawContext.java | 33 +++++ .../cheeze/sbt/utils/render/ScreenBounds.java | 2 + .../cheeze/sbt/utils/skyblock/IconDict.java | 4 +- .../sbt/utils/skyblock/ProfileManager.java | 13 +- .../sbt/utils/skyblock/SkyblockConstants.java | 2 +- stonecutter.gradle.kts | 9 +- versions/1.21.2/gradle.properties | 6 - versions/1.21.3/gradle.properties | 8 + 74 files changed, 1242 insertions(+), 463 deletions(-) create mode 100644 src/main/java/wtf/cheeze/sbt/config/VersionedObject.java create mode 100644 src/main/java/wtf/cheeze/sbt/config/migration/BarColorTransformation.java create mode 100644 src/main/java/wtf/cheeze/sbt/config/migration/ConfigMigration.java create mode 100644 src/main/java/wtf/cheeze/sbt/config/migration/ConfigTransformation.java create mode 100644 src/main/java/wtf/cheeze/sbt/config/migration/MigrationManager.java rename src/main/java/wtf/cheeze/sbt/{utils => }/hud/HUD.java (83%) rename src/main/java/wtf/cheeze/sbt/{utils => }/hud/HudIcon.java (54%) rename src/main/java/wtf/cheeze/sbt/{utils => }/hud/HudScreen.java (95%) rename src/main/java/wtf/cheeze/sbt/{utils/hud => hud/bases}/AbstractTickerHUD.java (90%) rename src/main/java/wtf/cheeze/sbt/{utils/hud => hud/bases}/BarHUD.java (78%) create mode 100644 src/main/java/wtf/cheeze/sbt/hud/bases/MultilineTextHUD.java rename src/main/java/wtf/cheeze/sbt/{utils/hud => hud/bases}/TextHUD.java (91%) rename src/main/java/wtf/cheeze/sbt/{utils/hud => hud/bounds}/Bounds.java (96%) rename src/main/java/wtf/cheeze/sbt/{utils/hud => hud/bounds}/BoundsRelative.java (97%) create mode 100644 src/main/java/wtf/cheeze/sbt/hud/components/FlexibleHudLine.java create mode 100644 src/main/java/wtf/cheeze/sbt/hud/components/HudComponent.java create mode 100644 src/main/java/wtf/cheeze/sbt/hud/components/SingleHudLine.java rename src/main/java/wtf/cheeze/sbt/{utils/ModifiedDrawContext.java => hud/utils/AnchorPoint.java} (76%) create mode 100644 src/main/java/wtf/cheeze/sbt/hud/utils/DrawMode.java rename src/main/java/wtf/cheeze/sbt/{utils/hud => hud/utils}/HudInformation.java (59%) create mode 100644 src/main/java/wtf/cheeze/sbt/utils/DataUtils.java delete mode 100644 src/main/java/wtf/cheeze/sbt/utils/hud/HudLine.java create mode 100644 src/main/java/wtf/cheeze/sbt/utils/render/Colors.java create mode 100644 src/main/java/wtf/cheeze/sbt/utils/render/SBTDrawContext.java delete mode 100644 versions/1.21.2/gradle.properties create mode 100644 versions/1.21.3/gradle.properties diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b01da52..e74bc27 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,10 +28,10 @@ jobs: - name: make gradle wrapper executable run: chmod +x ./gradlew - name: build - run: ./gradlew build + run: ./gradlew chiseledBuild - name: capture build artifacts if: ${{ matrix.java == '21' }} # Only upload artifacts built from latest java uses: actions/upload-artifact@v4 with: name: Artifacts - path: build/libs/ \ No newline at end of file + path: versions/**/build/libs/*.jar \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index ac07e82..c28300f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,9 +1,9 @@ plugins { - id("fabric-loom") version "1.7-SNAPSHOT" + id("fabric-loom") version "1.8-SNAPSHOT" id("maven-publish") } -version = property("mod_version")!! +version = property("mod_version")!! as String + "+mc" + property("minecraft_version")!! group = property("maven_group")!! base { @@ -24,6 +24,7 @@ repositories { includeGroup("net.azureaaron") } } + maven("https://pkgs.dev.azure.com/djtheredstoner/DevAuth/_packaging/public/maven/v1") } dependencies { @@ -34,6 +35,8 @@ dependencies { modImplementation ("dev.isxander:yet-another-config-lib:${property("yacl_version")}") modImplementation ("com.terraformersmc:modmenu:${property("modmenu_version")}") include(modImplementation("net.azureaaron:hm-api:${property("hmapi_version")}") as Any) + modRuntimeOnly("me.djtheredstoner:DevAuth-fabric:1.2.1") + } tasks.processResources { @@ -55,6 +58,7 @@ java { } tasks.named("jar") { + from("LICENSE") { rename { "${it}_${project.base.archivesName.get()}" } } diff --git a/gradle.properties b/gradle.properties index 34ee9a1..14c02e1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ archives_base_name=SkyblockTweaks loader_version=0.16.7 # Mod Properties -mod_version=0.1.0-Alpha.7 +mod_version=0.1.0-Alpha.8 # mod_version = Unstable diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a441313..df97d72 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index b740cf1..b26d411 100755 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -84,7 +86,8 @@ done # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -246,4 +249,4 @@ eval "set -- $( tr '\n' ' ' )" '"$@"' -exec "$JAVACMD" "$@" +exec "$JAVACMD" "$@" \ No newline at end of file diff --git a/gradlew.bat b/gradlew.bat index 25da30d..f46bb52 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## @@ -89,4 +91,4 @@ exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal -:omega +:omega \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 2e99be7..f317bda 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -19,7 +19,7 @@ stonecutter { centralScript = "build.gradle.kts" create(rootProject) { - versions("1.21.1", "1.21.2") - vcsVersion = "1.21.2" + versions("1.21.1", "1.21.3") + vcsVersion = "1.21.3" } } diff --git a/src/main/java/wtf/cheeze/sbt/SkyblockTweaks.java b/src/main/java/wtf/cheeze/sbt/SkyblockTweaks.java index 9f05909..2ede05b 100644 --- a/src/main/java/wtf/cheeze/sbt/SkyblockTweaks.java +++ b/src/main/java/wtf/cheeze/sbt/SkyblockTweaks.java @@ -19,6 +19,7 @@ package wtf.cheeze.sbt; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; @@ -32,13 +33,15 @@ import wtf.cheeze.sbt.command.SBTCommand; import wtf.cheeze.sbt.config.SBTConfig; +import wtf.cheeze.sbt.config.migration.BarColorTransformation; +import wtf.cheeze.sbt.config.migration.MigrationManager; import wtf.cheeze.sbt.config.persistent.PersistentData; import wtf.cheeze.sbt.features.chat.ChatProtections; import wtf.cheeze.sbt.features.chat.PartyFeatures; import wtf.cheeze.sbt.features.huds.*; import wtf.cheeze.sbt.utils.*; import wtf.cheeze.sbt.utils.actionbar.ActionBarTransformer; -import wtf.cheeze.sbt.utils.hud.HUD; +import wtf.cheeze.sbt.hud.HUD; import wtf.cheeze.sbt.utils.skyblock.ModAPIUtils; import wtf.cheeze.sbt.utils.skyblock.ProfileManager; import wtf.cheeze.sbt.utils.skyblock.SkyblockData; @@ -46,19 +49,26 @@ import java.util.ArrayList; public class SkyblockTweaks implements ModInitializer { - public static final Gson GSON = new Gson(); + public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); public static final Logger LOGGER = LoggerFactory.getLogger("SkyblockTweaks"); public static final SkyblockData DATA = new SkyblockData(); public static final PersistentData PD = PersistentData.load(); public static final ArrayList HUDS = new ArrayList(); - public static final Version VERSION = new Version(Version.VersionType.ALPHA, 0, 1, 0, 7); + public static final Version VERSION = new Version(Version.VersionType.ALPHA, 0, 1, 0, 8); public static final MinecraftClient mc = MinecraftClient.getInstance(); @Override public void onInitialize() { + MigrationManager.handleMigrations(); + + SBTConfig.HANDLER.load(); + + MigrationManager.runTransformation(BarColorTransformation.INSTANCE); + + HUDS.add(SkillHUDManager.INSTANCE.SKILL_HUD); HUDS.add(SkillHUDManager.INSTANCE.SKILL_BAR); @@ -81,7 +91,6 @@ public void onInitialize() { HUDS.add(new TickerHUD()); - HudRenderCallback.EVENT.register((context, tickCounter) -> { HUDS.forEach(hud -> hud.render(context, false)); }); diff --git a/src/main/java/wtf/cheeze/sbt/command/SBTCommand.java b/src/main/java/wtf/cheeze/sbt/command/SBTCommand.java index ec95244..34da1b9 100644 --- a/src/main/java/wtf/cheeze/sbt/command/SBTCommand.java +++ b/src/main/java/wtf/cheeze/sbt/command/SBTCommand.java @@ -35,7 +35,7 @@ import wtf.cheeze.sbt.utils.NumberUtils; import wtf.cheeze.sbt.utils.skyblock.SkyblockConstants; import wtf.cheeze.sbt.utils.skyblock.SkyblockUtils; -import wtf.cheeze.sbt.utils.hud.HudScreen; +import wtf.cheeze.sbt.hud.HudScreen; import java.util.Arrays; diff --git a/src/main/java/wtf/cheeze/sbt/config/ConfigImpl.java b/src/main/java/wtf/cheeze/sbt/config/ConfigImpl.java index d65162c..37182be 100644 --- a/src/main/java/wtf/cheeze/sbt/config/ConfigImpl.java +++ b/src/main/java/wtf/cheeze/sbt/config/ConfigImpl.java @@ -28,7 +28,7 @@ import wtf.cheeze.sbt.utils.Version; import wtf.cheeze.sbt.utils.actionbar.ActionBarTransformer; -public class ConfigImpl { +public class ConfigImpl extends VersionedObject { @SerialEntry // This defines the spec version of the config, so that in the future, migration code can be written if necessary public int configVersion = 1; diff --git a/src/main/java/wtf/cheeze/sbt/config/SBTConfig.java b/src/main/java/wtf/cheeze/sbt/config/SBTConfig.java index 7c4efe5..909e67b 100644 --- a/src/main/java/wtf/cheeze/sbt/config/SBTConfig.java +++ b/src/main/java/wtf/cheeze/sbt/config/SBTConfig.java @@ -29,15 +29,19 @@ import net.minecraft.text.Text; import net.minecraft.util.Identifier; import wtf.cheeze.sbt.config.categories.*; -import wtf.cheeze.sbt.utils.hud.HudLine; +import wtf.cheeze.sbt.hud.utils.DrawMode; + +import java.nio.file.Path; public class SBTConfig { + public static final Path PATH = FabricLoader.getInstance().getConfigDir().resolve("skyblocktweaks-config.json"); + public static final ConfigClassHandler HANDLER = ConfigClassHandler.createBuilder(ConfigImpl.class) .id(Identifier.of("skyblocktweaks", "config")) .serializer(config -> GsonConfigSerializerBuilder.create(config).appendGsonBuilder(builder -> builder.setFieldNamingPolicy(FieldNamingPolicy.IDENTITY)) - .setPath(FabricLoader.getInstance().getConfigDir().resolve("skyblocktweaks-config.json")) + .setPath(PATH) .build()) .build(); public static Screen getScreen(Screen parent) { @@ -78,6 +82,10 @@ public static Huds huds() { return get().huds; } + public static void override(ConfigImpl config) { + + } + public static ControllerBuilder generateBooleanController(Option opt) { @@ -89,8 +97,8 @@ public static FloatSliderControllerBuilder generateScaleController(Option .step(0.1f); } - public static EnumControllerBuilder generateDrawModeController(Option opt) { - return EnumControllerBuilder.create(opt).enumClass(HudLine.DrawMode.class); + public static EnumControllerBuilder generateDrawModeController(Option opt) { + return EnumControllerBuilder.create(opt).enumClass(DrawMode.class); } } diff --git a/src/main/java/wtf/cheeze/sbt/config/SkyblockTweaksScreenMain.java b/src/main/java/wtf/cheeze/sbt/config/SkyblockTweaksScreenMain.java index 55c5c9b..909937e 100644 --- a/src/main/java/wtf/cheeze/sbt/config/SkyblockTweaksScreenMain.java +++ b/src/main/java/wtf/cheeze/sbt/config/SkyblockTweaksScreenMain.java @@ -27,7 +27,7 @@ import net.minecraft.util.Identifier; import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.utils.render.RenderUtils; -import wtf.cheeze.sbt.utils.hud.HudScreen; +import wtf.cheeze.sbt.hud.HudScreen; public class SkyblockTweaksScreenMain extends Screen { public static final Identifier ICON = Identifier.of("skyblocktweaks", "icon.png"); @@ -94,8 +94,8 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { MinecraftClient mc = MinecraftClient.getInstance(); var centerX = mc.getWindow().getScaledWidth() / 2; super.render(context, mouseX, mouseY, delta); - RenderUtils.drawCenteredString(context, Text.literal("SkyblockTweaks"), centerX, 3, 3658595, true, 2.5f); - RenderUtils.drawCenteredString(context, Text.literal("v" + SkyblockTweaks.VERSION.getVersionString()), centerX, 25, 0xFFFFFF, true); - RenderUtils.drawCenteredString(context, Text.literal("By MisterCheezeCake"), centerX, 36, 16733525, true); + RenderUtils.drawCenteredText(context, Text.literal("SkyblockTweaks"), centerX, 3, 3658595, true, 2.5f); + RenderUtils.drawCenteredText(context, Text.literal("v" + SkyblockTweaks.VERSION.getVersionString()), centerX, 25, 0xFFFFFF, true); + RenderUtils.drawCenteredText(context, Text.literal("By MisterCheezeCake"), centerX, 36, 16733525, true); } } diff --git a/src/main/java/wtf/cheeze/sbt/config/VersionedObject.java b/src/main/java/wtf/cheeze/sbt/config/VersionedObject.java new file mode 100644 index 0000000..17a0100 --- /dev/null +++ b/src/main/java/wtf/cheeze/sbt/config/VersionedObject.java @@ -0,0 +1,5 @@ +package wtf.cheeze.sbt.config; + +public class VersionedObject { + public int configVersion; +} diff --git a/src/main/java/wtf/cheeze/sbt/config/migration/BarColorTransformation.java b/src/main/java/wtf/cheeze/sbt/config/migration/BarColorTransformation.java new file mode 100644 index 0000000..4821fe5 --- /dev/null +++ b/src/main/java/wtf/cheeze/sbt/config/migration/BarColorTransformation.java @@ -0,0 +1,56 @@ +package wtf.cheeze.sbt.config.migration; + +import net.minecraft.util.Identifier; +import wtf.cheeze.sbt.config.ConfigImpl; +import wtf.cheeze.sbt.utils.render.Colors; + +import java.util.function.Function; + + +/** + * In mod versions prior to 0.1.0-Alpha.8, bar colors (all colors actually), defaulted to RGB ints. + * This was fine pre 1.21.2 since the shader system was used, which was fine with RGB ints + * However, in 1.21.2, the shader system was tweaked, and we moved to the color parameter in {@link net.minecraft.client.gui.DrawContext#drawTexture(Function, Identifier, int, int, float, float, int, int, int, int, int)} + * This method interprets ints as ARGB, not RGB, which resulted in the bars not rendering with default settings due to the alpha value being 0 + * YACL always treated the color as ARGB, so this issue only affects users who never modified the settings + * This transformation checks for the old defaults and updates them to the new defaults + */ +public class BarColorTransformation implements ConfigTransformation { + + private static final int OLD_HEALTH = 16733525; + private static final int OLD_HEALTH_ABSORB = 16755200; + private static final int OLD_MANA = 5592575; + private static final int OLD_SKILL = 43690; + private static final int OLD_DRILL = 43520; + + private BarColorTransformation() {} + + public static final BarColorTransformation INSTANCE = new BarColorTransformation(); + + @Override + public ConfigImpl tranform(ConfigImpl config) { + if (config.huds.healthBar.color == OLD_HEALTH) config.huds.healthBar.color = Colors.RED; + if (config.huds.healthBar.colorAbsorption == OLD_HEALTH_ABSORB) config.huds.healthBar.colorAbsorption = Colors.ORANGE; + if (config.huds.manaBar.color == OLD_MANA) config.huds.manaBar.color = Colors.BLUE; + if (config.huds.skillBar.color == OLD_SKILL) config.huds.skillBar.color = Colors.CYAN; + if (config.huds.drillFuelBar.color == OLD_DRILL) config.huds.drillFuelBar.color = Colors.GREEN; + + return config; + } + + @Override + public boolean isApplicable(ConfigImpl config) { + return config.huds.healthBar.color == OLD_HEALTH + || config.huds.healthBar.colorAbsorption == OLD_HEALTH_ABSORB + || config.huds.manaBar.color == OLD_MANA + || config.huds.skillBar.color == OLD_SKILL + || config.huds.drillFuelBar.color == OLD_DRILL; + } + + @Override + public boolean isApplicable(int configVersion) { + return configVersion == 1; + } + + +} diff --git a/src/main/java/wtf/cheeze/sbt/config/migration/ConfigMigration.java b/src/main/java/wtf/cheeze/sbt/config/migration/ConfigMigration.java new file mode 100644 index 0000000..8c5f953 --- /dev/null +++ b/src/main/java/wtf/cheeze/sbt/config/migration/ConfigMigration.java @@ -0,0 +1,23 @@ +package wtf.cheeze.sbt.config.migration; + + +/** + * A ConfigMigration migrates a config object from one version to another. + * These should be used instead of Transformations when the actual structure + * of the config changes, as opposed to simply needing to modify certain values. + * A ConfigMigration will always be accompanied by an increase in the config version + */ +public interface ConfigMigration { + + + Source migrate(Target config); + + boolean isApplicable(int aVersion); + + int getTargetVersion(); + int getSourceVersion(); + + Class getSourceClass(); + Class getTargetClass(); + +} diff --git a/src/main/java/wtf/cheeze/sbt/config/migration/ConfigTransformation.java b/src/main/java/wtf/cheeze/sbt/config/migration/ConfigTransformation.java new file mode 100644 index 0000000..76a03df --- /dev/null +++ b/src/main/java/wtf/cheeze/sbt/config/migration/ConfigTransformation.java @@ -0,0 +1,13 @@ +package wtf.cheeze.sbt.config.migration; + +/** + * A ConfigTransformation transforms a single version of a config, rather than migrating from one version to another. + */ +public interface ConfigTransformation{ + + T tranform(T config); + + boolean isApplicable(T config); + + boolean isApplicable(int configVersion); +} diff --git a/src/main/java/wtf/cheeze/sbt/config/migration/MigrationManager.java b/src/main/java/wtf/cheeze/sbt/config/migration/MigrationManager.java new file mode 100644 index 0000000..4e8d008 --- /dev/null +++ b/src/main/java/wtf/cheeze/sbt/config/migration/MigrationManager.java @@ -0,0 +1,79 @@ +package wtf.cheeze.sbt.config.migration; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import wtf.cheeze.sbt.SkyblockTweaks; +import wtf.cheeze.sbt.config.ConfigImpl; +import wtf.cheeze.sbt.config.SBTConfig; +import wtf.cheeze.sbt.config.VersionedObject; + +import java.io.File; +import java.io.FileWriter; +import java.nio.file.Files; +import java.util.ArrayList; + + +/** + * Manages config migrations and transformations + */ +public class MigrationManager { + + private static final ArrayList migrations = new ArrayList<>(); + + public static void registerMigration(ConfigMigration migration) { + migrations.add(migration); + } + + + + /** + * Checks all registered migrations and runs any needed ones. + * This MUST be called BEFORE config is initialized + */ + public static void handleMigrations() { + var file = new File(String.valueOf(SBTConfig.PATH)); + try { + if (!file.exists()) return; + + //SkyblockTweaks.LOGGER.info("Checking for migrations"); + var content = Files.readString(SBTConfig.PATH); + var currentVersion = SkyblockTweaks.GSON.fromJson(content, VersionedObject.class).configVersion; + for (var migration: migrations) { + if (migration.isApplicable(currentVersion)) { + SkyblockTweaks.LOGGER.info("Running config migration: " + migration.getClass().getSimpleName() + " from version " + currentVersion + " to version " + migration.getTargetVersion()); + var source = SkyblockTweaks.GSON.fromJson(content, migration.getSourceClass()); + var target = migration.migrate(source); + var writer = new FileWriter(file); + writer.write(SkyblockTweaks.GSON.toJson(target)); + writer.close(); + } + } + + } catch (Exception e) { + e.printStackTrace(); + } + + } + + /** + * Checks if a given transformation needs to be run, then runs it if applicable + * This MUST be called AFTER the config is loaded + */ + @SuppressWarnings("unchecked") + public static void runTransformation(ConfigTransformation transformation) { + SkyblockTweaks.LOGGER.info("Checking config transformation: " + transformation.getClass().getSimpleName()); + T currentConfig = (T) SBTConfig.get(); + SkyblockTweaks.LOGGER.info("Current config version: " + currentConfig.configVersion); + if (!transformation.isApplicable(currentConfig.configVersion)) { + SkyblockTweaks.LOGGER.info("Transformation not applicable for version"); + return; + } + if (!transformation.isApplicable(currentConfig)) { + SkyblockTweaks.LOGGER.info("Transformation not applicable for config"); + return; + } + SkyblockTweaks.LOGGER.info("Running config transformation: " + transformation.getClass().getSimpleName()); + transformation.tranform(currentConfig); + } +} + diff --git a/src/main/java/wtf/cheeze/sbt/features/BrewingStandOverlay.java b/src/main/java/wtf/cheeze/sbt/features/BrewingStandOverlay.java index d1b9d31..2bd5e1b 100644 --- a/src/main/java/wtf/cheeze/sbt/features/BrewingStandOverlay.java +++ b/src/main/java/wtf/cheeze/sbt/features/BrewingStandOverlay.java @@ -19,14 +19,11 @@ package wtf.cheeze.sbt.features; import dev.isxander.yacl3.api.Option; -import dev.isxander.yacl3.api.OptionDescription; import dev.isxander.yacl3.api.OptionGroup; import dev.isxander.yacl3.config.v2.api.SerialEntry; import net.minecraft.client.gui.DrawContext; import net.minecraft.screen.slot.Slot; -import net.minecraft.text.Text; import net.minecraft.util.collection.DefaultedList; -import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.ConfigImpl; import wtf.cheeze.sbt.config.SBTConfig; import wtf.cheeze.sbt.config.categories.General; @@ -70,13 +67,15 @@ private static void drawName(Slot slot, DrawContext context) { } else { rcolor = color.getRgb(); } - RenderUtils.drawString(context, name, slot.x + DRAW_OFFSET_X, slot.y + DRAW_OFFSET_Y, rcolor, false); + RenderUtils.drawText(context, name, slot.x + DRAW_OFFSET_X, slot.y + DRAW_OFFSET_Y, rcolor, false); } public static class Config { @SerialEntry public boolean enabled = true; + + public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { var enabled = Option.createBuilder() .name(General.key("brewingStandOverlay.enabled")) diff --git a/src/main/java/wtf/cheeze/sbt/features/chat/ChatProtections.java b/src/main/java/wtf/cheeze/sbt/features/chat/ChatProtections.java index 8bb8513..d8db4c4 100644 --- a/src/main/java/wtf/cheeze/sbt/features/chat/ChatProtections.java +++ b/src/main/java/wtf/cheeze/sbt/features/chat/ChatProtections.java @@ -48,7 +48,7 @@ public static void registerEvents() { return true; } lastMessageCoop = TimedValue.of(message, 5000); - SkyblockTweaks.mc.player.sendMessage(Text.literal(String.format(BASE_COOP_MESSAGE, message.split(" ")[1]))); + SkyblockTweaks.mc.player.sendMessage(Text.literal(String.format(BASE_COOP_MESSAGE, message.split(" ")[1])), false); return false; } else if (SBTConfig.get().chatProtections.ip) { var i = checkIp(message); @@ -80,9 +80,9 @@ private static boolean handleIpMessage(String message, boolean address) { } lastMessageIp = TimedValue.of(message, 5000); if (address) { - SkyblockTweaks.mc.player.sendMessage(Text.literal("§7[§aSkyblockTweaks§f§7] §cAre you sure you want to send a message with an ip address? Hypixel may ban you for this! Send the message again to confirm.")); + SkyblockTweaks.mc.player.sendMessage(Text.literal("§7[§aSkyblockTweaks§f§7] §cAre you sure you want to send a message with an ip address? Hypixel may ban you for this! Send the message again to confirm."), false); } else { - SkyblockTweaks.mc.player.sendMessage(Text.literal("§7[§aSkyblockTweaks§f§7] §cAre you sure you want to send a message with the word \"ip\" in it? Hypixel has been known to auto mute/ban messages containing \"ip\"! Send the message again to confirm.")); + SkyblockTweaks.mc.player.sendMessage(Text.literal("§7[§aSkyblockTweaks§f§7] §cAre you sure you want to send a message with the word \"ip\" in it? Hypixel has been known to auto mute/ban messages containing \"ip\"! Send the message again to confirm."), false); } return false; diff --git a/src/main/java/wtf/cheeze/sbt/features/chat/PartyFeatures.java b/src/main/java/wtf/cheeze/sbt/features/chat/PartyFeatures.java index 096bf8b..beb7ea0 100644 --- a/src/main/java/wtf/cheeze/sbt/features/chat/PartyFeatures.java +++ b/src/main/java/wtf/cheeze/sbt/features/chat/PartyFeatures.java @@ -40,9 +40,9 @@ public class PartyFeatures { - public static Pattern PARTY_PATTERN = Pattern.compile("Party > ([^:]+): !(.+)"); - public static Pattern BACKUP_UPDATE_PATTERN = Pattern.compile("The party was transferred to (.+) by .+"); - public static Pattern BOOP_PATTERN = Pattern.compile("From (.*): Boop!"); + public static final Pattern PARTY_PATTERN = Pattern.compile("Party > ([^:]+): !(.+)"); + public static final Pattern BACKUP_UPDATE_PATTERN = Pattern.compile("The party was transferred to (.+) by .+"); + public static final Pattern BOOP_PATTERN = Pattern.compile("From (.*): Boop!"); public static boolean verboseDebug = false; public static long lastPartyCommand = 0; diff --git a/src/main/java/wtf/cheeze/sbt/features/huds/CoordinatesHUD.java b/src/main/java/wtf/cheeze/sbt/features/huds/CoordinatesHUD.java index 89dfaad..d232ba7 100644 --- a/src/main/java/wtf/cheeze/sbt/features/huds/CoordinatesHUD.java +++ b/src/main/java/wtf/cheeze/sbt/features/huds/CoordinatesHUD.java @@ -19,7 +19,6 @@ package wtf.cheeze.sbt.features.huds; import dev.isxander.yacl3.api.Option; -import dev.isxander.yacl3.api.OptionDescription; import dev.isxander.yacl3.api.OptionGroup; import dev.isxander.yacl3.api.controller.ColorControllerBuilder; import dev.isxander.yacl3.api.controller.IntegerSliderControllerBuilder; @@ -28,10 +27,13 @@ import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.ConfigImpl; import wtf.cheeze.sbt.config.SBTConfig; +import wtf.cheeze.sbt.hud.utils.AnchorPoint; import wtf.cheeze.sbt.utils.NumberUtils; -import wtf.cheeze.sbt.utils.hud.HudLine; -import wtf.cheeze.sbt.utils.hud.HudInformation; -import wtf.cheeze.sbt.utils.hud.TextHUD; +import wtf.cheeze.sbt.hud.utils.DrawMode; +import wtf.cheeze.sbt.hud.components.SingleHudLine; +import wtf.cheeze.sbt.hud.utils.HudInformation; +import wtf.cheeze.sbt.hud.bases.TextHUD; +import wtf.cheeze.sbt.utils.render.Colors; import java.awt.Color; @@ -48,7 +50,7 @@ public CoordinatesHUD() { scale -> SBTConfig.huds().coordinates.scale = (float) scale, anchor -> SBTConfig.huds().coordinates.anchor = anchor ); - line = new HudLine( + line = new SingleHudLine( () -> SBTConfig.huds().coordinates.color, () -> SBTConfig.huds().coordinates.outlineColor, () -> SBTConfig.huds().coordinates.mode, @@ -78,13 +80,13 @@ public static class Config { public int decimalPlaces = 0; @SerialEntry - public HudLine.DrawMode mode = HudLine.DrawMode.SHADOW; + public DrawMode mode = DrawMode.SHADOW; @SerialEntry - public int color = 0xFFFFFF; + public int color = Colors.WHITE; @SerialEntry - public int outlineColor = 0x000000; + public int outlineColor = Colors.BLACK; @SerialEntry // Not handled by YACL Gui public float x = 0; @@ -151,7 +153,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { .name(key("coordinates.outlineColor")) .description(keyD("coordinates.outlineColor")) .controller(ColorControllerBuilder::create) - .available(config.huds.coordinates.mode == HudLine.DrawMode.OUTLINE) + .available(config.huds.coordinates.mode == DrawMode.OUTLINE) .binding( new Color(defaults.huds.coordinates.outlineColor), () -> new Color(config.huds.coordinates.outlineColor), @@ -159,7 +161,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { ) .build(); - var mode = Option.createBuilder() + var mode = Option.createBuilder() .name(key("coordinates.mode")) .description(keyD("coordinates.mode")) .controller(SBTConfig::generateDrawModeController) @@ -168,7 +170,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { () -> config.huds.coordinates.mode, value -> { config.huds.coordinates.mode = value; - if (value == HudLine.DrawMode.OUTLINE) outline.setAvailable(true); + if (value == DrawMode.OUTLINE) outline.setAvailable(true); else outline.setAvailable(false); } ) diff --git a/src/main/java/wtf/cheeze/sbt/features/huds/DamageReductionHUD.java b/src/main/java/wtf/cheeze/sbt/features/huds/DamageReductionHUD.java index 82b387a..15b5315 100644 --- a/src/main/java/wtf/cheeze/sbt/features/huds/DamageReductionHUD.java +++ b/src/main/java/wtf/cheeze/sbt/features/huds/DamageReductionHUD.java @@ -19,7 +19,6 @@ package wtf.cheeze.sbt.features.huds; import dev.isxander.yacl3.api.Option; -import dev.isxander.yacl3.api.OptionDescription; import dev.isxander.yacl3.api.OptionGroup; import dev.isxander.yacl3.api.controller.ColorControllerBuilder; import dev.isxander.yacl3.config.v2.api.SerialEntry; @@ -27,11 +26,14 @@ import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.ConfigImpl; import wtf.cheeze.sbt.config.SBTConfig; -import wtf.cheeze.sbt.utils.hud.HudLine; +import wtf.cheeze.sbt.hud.utils.AnchorPoint; +import wtf.cheeze.sbt.hud.utils.DrawMode; +import wtf.cheeze.sbt.hud.components.SingleHudLine; import wtf.cheeze.sbt.utils.NumberUtils; import wtf.cheeze.sbt.utils.TextUtils; -import wtf.cheeze.sbt.utils.hud.HudInformation; -import wtf.cheeze.sbt.utils.hud.TextHUD; +import wtf.cheeze.sbt.hud.utils.HudInformation; +import wtf.cheeze.sbt.hud.bases.TextHUD; +import wtf.cheeze.sbt.utils.render.Colors; import java.awt.Color; @@ -48,7 +50,7 @@ public DamageReductionHUD() { scale -> SBTConfig.huds().dr.scale = (float) scale, anchor -> SBTConfig.huds().dr.anchor = anchor ); - line = new HudLine( + line = new SingleHudLine( () -> SBTConfig.huds().dr.color, () -> SBTConfig.huds().dr.outlineColor, () -> SBTConfig.huds().dr.mode, @@ -74,13 +76,13 @@ public static class Config { public boolean enabled = false; @SerialEntry - public HudLine.DrawMode mode = HudLine.DrawMode.SHADOW; + public DrawMode mode = DrawMode.SHADOW; @SerialEntry - public int color = 5635925; + public int color = Colors.LIME; @SerialEntry - public int outlineColor = 0x000000; + public int outlineColor = Colors.BLACK; @SerialEntry // Not handled by YACL Gui public float x = 0; @@ -122,7 +124,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { .name(key("dr.outlineColor")) .description(keyD("dr.outlineColor")) .controller(ColorControllerBuilder::create) - .available(config.huds.dr.mode == HudLine.DrawMode.OUTLINE) + .available(config.huds.dr.mode == DrawMode.OUTLINE) .binding( new Color(defaults.huds.dr.outlineColor), () -> new Color(config.huds.dr.outlineColor), @@ -130,7 +132,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { ) .build(); - var mode = Option.createBuilder() + var mode = Option.createBuilder() .name(key("dr.mode")) .description(keyD("dr.mode")) .controller(SBTConfig::generateDrawModeController) @@ -139,7 +141,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { () -> config.huds.dr.mode, value -> { config.huds.dr.mode = value; - if (value == HudLine.DrawMode.OUTLINE) outline.setAvailable(true); + if (value == DrawMode.OUTLINE) outline.setAvailable(true); else outline.setAvailable(false); } ) diff --git a/src/main/java/wtf/cheeze/sbt/features/huds/DefenseHUD.java b/src/main/java/wtf/cheeze/sbt/features/huds/DefenseHUD.java index 0426f4e..849fe61 100644 --- a/src/main/java/wtf/cheeze/sbt/features/huds/DefenseHUD.java +++ b/src/main/java/wtf/cheeze/sbt/features/huds/DefenseHUD.java @@ -19,7 +19,6 @@ package wtf.cheeze.sbt.features.huds; import dev.isxander.yacl3.api.Option; -import dev.isxander.yacl3.api.OptionDescription; import dev.isxander.yacl3.api.OptionGroup; import dev.isxander.yacl3.api.controller.ColorControllerBuilder; import dev.isxander.yacl3.api.controller.StringControllerBuilder; @@ -28,11 +27,14 @@ import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.ConfigImpl; import wtf.cheeze.sbt.config.SBTConfig; +import wtf.cheeze.sbt.hud.utils.AnchorPoint; import wtf.cheeze.sbt.utils.NumberUtils; import wtf.cheeze.sbt.utils.TextUtils; -import wtf.cheeze.sbt.utils.hud.HudInformation; -import wtf.cheeze.sbt.utils.hud.TextHUD; -import wtf.cheeze.sbt.utils.hud.HudLine; +import wtf.cheeze.sbt.hud.utils.DrawMode; +import wtf.cheeze.sbt.hud.utils.HudInformation; +import wtf.cheeze.sbt.hud.bases.TextHUD; +import wtf.cheeze.sbt.hud.components.SingleHudLine; +import wtf.cheeze.sbt.utils.render.Colors; import java.awt.Color; @@ -50,7 +52,7 @@ public DefenseHUD() { anchor -> SBTConfig.huds().defense.anchor = anchor ); - line = new HudLine( + line = new SingleHudLine( () -> SBTConfig.huds().defense.color, () -> SBTConfig.huds().defense.outlineColor, () -> SBTConfig.huds().defense.mode, @@ -76,13 +78,13 @@ public static class Config { public boolean enabled = false; @SerialEntry - public HudLine.DrawMode mode = HudLine.DrawMode.SHADOW; + public DrawMode mode = DrawMode.SHADOW; @SerialEntry - public int color = 5635925; + public int color = Colors.LIME; @SerialEntry - public int outlineColor = 0x000000; + public int outlineColor = Colors.BLACK; @SerialEntry // Not handled by YACL Gui public float x = 0; @@ -128,7 +130,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { .name(key("defense.outlineColor")) .description(keyD("defense.outlineColor")) .controller(ColorControllerBuilder::create) - .available(config.huds.defense.mode == HudLine.DrawMode.OUTLINE) + .available(config.huds.defense.mode == DrawMode.OUTLINE) .binding( new Color(defaults.huds.defense.outlineColor), () -> new Color(config.huds.defense.outlineColor), @@ -136,7 +138,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { ) .build(); - var mode = Option.createBuilder() + var mode = Option.createBuilder() .name(key("defense.mode")) .description(keyD("defense.mode")) .controller(SBTConfig::generateDrawModeController) @@ -145,7 +147,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { () -> config.huds.defense.mode, value -> { config.huds.defense.mode = value; - if (value == HudLine.DrawMode.OUTLINE) outline.setAvailable(true); + if (value == DrawMode.OUTLINE) outline.setAvailable(true); else outline.setAvailable(false); } ) diff --git a/src/main/java/wtf/cheeze/sbt/features/huds/DrillFuelBar.java b/src/main/java/wtf/cheeze/sbt/features/huds/DrillFuelBar.java index 9dd5f40..ac09431 100644 --- a/src/main/java/wtf/cheeze/sbt/features/huds/DrillFuelBar.java +++ b/src/main/java/wtf/cheeze/sbt/features/huds/DrillFuelBar.java @@ -19,17 +19,17 @@ package wtf.cheeze.sbt.features.huds; import dev.isxander.yacl3.api.Option; -import dev.isxander.yacl3.api.OptionDescription; import dev.isxander.yacl3.api.OptionGroup; import dev.isxander.yacl3.api.controller.ColorControllerBuilder; import dev.isxander.yacl3.config.v2.api.SerialEntry; -import net.minecraft.text.Text; import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.ConfigImpl; import wtf.cheeze.sbt.config.SBTConfig; +import wtf.cheeze.sbt.hud.utils.AnchorPoint; import wtf.cheeze.sbt.utils.TextUtils; -import wtf.cheeze.sbt.utils.hud.BarHUD; -import wtf.cheeze.sbt.utils.hud.HudInformation; +import wtf.cheeze.sbt.hud.bases.BarHUD; +import wtf.cheeze.sbt.hud.utils.HudInformation; +import wtf.cheeze.sbt.utils.render.Colors; import java.awt.Color; @@ -80,7 +80,7 @@ public static class Config { public AnchorPoint anchor = AnchorPoint.LEFT; @SerialEntry - public int color = 43520; + public int color = Colors.GREEN; public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { var enabled = Option.createBuilder() diff --git a/src/main/java/wtf/cheeze/sbt/features/huds/DrillFuelHUD.java b/src/main/java/wtf/cheeze/sbt/features/huds/DrillFuelHUD.java index 700b92a..d39ad32 100644 --- a/src/main/java/wtf/cheeze/sbt/features/huds/DrillFuelHUD.java +++ b/src/main/java/wtf/cheeze/sbt/features/huds/DrillFuelHUD.java @@ -19,7 +19,6 @@ package wtf.cheeze.sbt.features.huds; import dev.isxander.yacl3.api.Option; -import dev.isxander.yacl3.api.OptionDescription; import dev.isxander.yacl3.api.OptionGroup; import dev.isxander.yacl3.api.controller.ColorControllerBuilder; import dev.isxander.yacl3.api.controller.StringControllerBuilder; @@ -28,11 +27,14 @@ import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.ConfigImpl; import wtf.cheeze.sbt.config.SBTConfig; +import wtf.cheeze.sbt.hud.utils.AnchorPoint; import wtf.cheeze.sbt.utils.NumberUtils; import wtf.cheeze.sbt.utils.TextUtils; -import wtf.cheeze.sbt.utils.hud.HudInformation; -import wtf.cheeze.sbt.utils.hud.TextHUD; -import wtf.cheeze.sbt.utils.hud.HudLine; +import wtf.cheeze.sbt.hud.utils.DrawMode; +import wtf.cheeze.sbt.hud.utils.HudInformation; +import wtf.cheeze.sbt.hud.bases.TextHUD; +import wtf.cheeze.sbt.hud.components.SingleHudLine; +import wtf.cheeze.sbt.utils.render.Colors; import java.awt.Color; @@ -49,7 +51,7 @@ public DrillFuelHUD() { scale -> SBTConfig.huds().drillFuel.scale = (float) scale, anchor -> SBTConfig.huds().drillFuel.anchor = anchor ); - line = new HudLine( + line = new SingleHudLine( () -> SBTConfig.huds().drillFuel.color, () -> SBTConfig.huds().drillFuel.outlineColor, () -> SBTConfig.huds().drillFuel.mode, @@ -80,13 +82,13 @@ public static class Config { public boolean abridgeSecondNumber = false; @SerialEntry - public HudLine.DrawMode mode = HudLine.DrawMode.SHADOW; + public DrawMode mode = DrawMode.SHADOW; @SerialEntry - public int color = 43520; + public int color = Colors.GREEN; @SerialEntry - public int outlineColor = 0x000000; + public int outlineColor = Colors.BLACK; @SerialEntry // Not handled by YACL Gui public float x = 0; @@ -139,14 +141,14 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { .name(key("drillFuel.outlineColor")) .description(keyD("drillFuel.outlineColor")) .controller(ColorControllerBuilder::create) - .available(config.huds.drillFuel.mode == HudLine.DrawMode.OUTLINE) + .available(config.huds.drillFuel.mode == DrawMode.OUTLINE) .binding( new Color(defaults.huds.drillFuel.outlineColor), () -> new Color(config.huds.drillFuel.outlineColor), value -> config.huds.drillFuel.outlineColor = value.getRGB() ) .build(); - var mode = Option.createBuilder() + var mode = Option.createBuilder() .name(key("drillFuel.mode")) .description(keyD("drillFuel.mode")) .controller(SBTConfig::generateDrawModeController) @@ -155,7 +157,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { () -> config.huds.drillFuel.mode, value -> { config.huds.drillFuel.mode = value; - if (value == HudLine.DrawMode.OUTLINE) outline.setAvailable(true); + if (value == DrawMode.OUTLINE) outline.setAvailable(true); else outline.setAvailable(false); } ) diff --git a/src/main/java/wtf/cheeze/sbt/features/huds/EhpHUD.java b/src/main/java/wtf/cheeze/sbt/features/huds/EhpHUD.java index bb09844..5c92940 100644 --- a/src/main/java/wtf/cheeze/sbt/features/huds/EhpHUD.java +++ b/src/main/java/wtf/cheeze/sbt/features/huds/EhpHUD.java @@ -19,21 +19,22 @@ package wtf.cheeze.sbt.features.huds; import dev.isxander.yacl3.api.Option; -import dev.isxander.yacl3.api.OptionDescription; import dev.isxander.yacl3.api.OptionGroup; import dev.isxander.yacl3.api.controller.ColorControllerBuilder; import dev.isxander.yacl3.api.controller.StringControllerBuilder; import dev.isxander.yacl3.config.v2.api.SerialEntry; -import net.minecraft.client.resource.language.I18n; import net.minecraft.text.Text; import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.ConfigImpl; import wtf.cheeze.sbt.config.SBTConfig; +import wtf.cheeze.sbt.hud.utils.AnchorPoint; import wtf.cheeze.sbt.utils.NumberUtils; -import wtf.cheeze.sbt.utils.hud.HudLine; +import wtf.cheeze.sbt.hud.utils.DrawMode; +import wtf.cheeze.sbt.hud.components.SingleHudLine; import wtf.cheeze.sbt.utils.TextUtils; -import wtf.cheeze.sbt.utils.hud.HudInformation; -import wtf.cheeze.sbt.utils.hud.TextHUD; +import wtf.cheeze.sbt.hud.utils.HudInformation; +import wtf.cheeze.sbt.hud.bases.TextHUD; +import wtf.cheeze.sbt.utils.render.Colors; import java.awt.Color; @@ -50,7 +51,7 @@ public EhpHUD() { scale -> SBTConfig.huds().ehp.scale = (float) scale, anchor -> SBTConfig.huds().ehp.anchor = anchor ); - line = new HudLine( + line = new SingleHudLine( () -> SBTConfig.huds().ehp.color, () -> SBTConfig.huds().ehp.outlineColor, () -> SBTConfig.huds().ehp.mode, @@ -75,7 +76,7 @@ public static class Config { public boolean enabled = false; @SerialEntry - public HudLine.DrawMode mode = HudLine.DrawMode.SHADOW; + public DrawMode mode = DrawMode.SHADOW; @SerialEntry // Not handled by YACL Gui public float x = 0; @@ -87,10 +88,10 @@ public static class Config { public float scale = 1.0f; @SerialEntry - public int color = 43520; + public int color = Colors.GREEN; @SerialEntry - public int outlineColor = 0x000000; + public int outlineColor = Colors.BLACK; @SerialEntry public boolean icon = true; @@ -116,7 +117,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { .name(key("ehp.outlineColor")) .description(keyD("ehp.outlineColor")) .controller(ColorControllerBuilder::create) - .available(config.huds.ehp.mode == HudLine.DrawMode.OUTLINE) + .available(config.huds.ehp.mode == DrawMode.OUTLINE) .binding( new Color(defaults.huds.ehp.outlineColor), () -> new Color(config.huds.ehp.outlineColor), @@ -126,7 +127,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { ) .build(); - var mode = Option.createBuilder() + var mode = Option.createBuilder() .name(key("ehp.mode")) .description(keyD("ehp.mode")) .controller(SBTConfig::generateDrawModeController) @@ -135,7 +136,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { () -> config.huds.ehp.mode, value -> { config.huds.ehp.mode = value; - if (value == HudLine.DrawMode.OUTLINE) outline.setAvailable(true); + if (value == DrawMode.OUTLINE) outline.setAvailable(true); else outline.setAvailable(false); } ) diff --git a/src/main/java/wtf/cheeze/sbt/features/huds/FpsHUD.java b/src/main/java/wtf/cheeze/sbt/features/huds/FpsHUD.java index ea30eb8..fc5f0a6 100644 --- a/src/main/java/wtf/cheeze/sbt/features/huds/FpsHUD.java +++ b/src/main/java/wtf/cheeze/sbt/features/huds/FpsHUD.java @@ -19,18 +19,19 @@ package wtf.cheeze.sbt.features.huds; import dev.isxander.yacl3.api.Option; -import dev.isxander.yacl3.api.OptionDescription; import dev.isxander.yacl3.api.OptionGroup; import dev.isxander.yacl3.api.controller.ColorControllerBuilder; import dev.isxander.yacl3.config.v2.api.SerialEntry; -import net.minecraft.client.resource.language.I18n; import net.minecraft.text.Text; import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.ConfigImpl; import wtf.cheeze.sbt.config.SBTConfig; -import wtf.cheeze.sbt.utils.hud.HudLine; -import wtf.cheeze.sbt.utils.hud.HudInformation; -import wtf.cheeze.sbt.utils.hud.TextHUD; +import wtf.cheeze.sbt.hud.utils.AnchorPoint; +import wtf.cheeze.sbt.hud.utils.DrawMode; +import wtf.cheeze.sbt.hud.components.SingleHudLine; +import wtf.cheeze.sbt.hud.utils.HudInformation; +import wtf.cheeze.sbt.hud.bases.TextHUD; +import wtf.cheeze.sbt.utils.render.Colors; import java.awt.Color; @@ -47,7 +48,7 @@ public FpsHUD() { scale -> SBTConfig.huds().fps.scale = (float) scale, anchor -> SBTConfig.huds().fps.anchor = anchor ); - line = new HudLine( + line = new SingleHudLine( () -> SBTConfig.huds().fps.color, () -> SBTConfig.huds().fps.outlineColor, () -> SBTConfig.huds().fps.mode, @@ -78,13 +79,13 @@ public static class Config { public boolean reverse = false; @SerialEntry - public HudLine.DrawMode mode = HudLine.DrawMode.SHADOW; + public DrawMode mode = DrawMode.SHADOW; @SerialEntry - public int color = 0xFFFFFF; + public int color = Colors.WHITE; @SerialEntry - public int outlineColor = 0x000000; + public int outlineColor = Colors.BLACK; @SerialEntry // Not handled by YACL Gui public float x = 0; @@ -146,7 +147,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { .name(key("fps.outlineColor")) .description(keyD("fps.outlineColor")) .controller(ColorControllerBuilder::create) - .available(config.huds.fps.mode == HudLine.DrawMode.OUTLINE) + .available(config.huds.fps.mode == DrawMode.OUTLINE) .binding( new Color(defaults.huds.fps.outlineColor), () -> new Color(config.huds.fps.outlineColor), @@ -154,7 +155,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { ) .build(); - var mode = Option.createBuilder() + var mode = Option.createBuilder() .name(key("fps.mode")) .description(keyD("fps.mode")) .controller(SBTConfig::generateDrawModeController) @@ -163,7 +164,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { () -> config.huds.fps.mode, value -> { config.huds.fps.mode = value; - if (value == HudLine.DrawMode.OUTLINE) outline.setAvailable(true); + if (value == DrawMode.OUTLINE) outline.setAvailable(true); else outline.setAvailable(false); } ) diff --git a/src/main/java/wtf/cheeze/sbt/features/huds/HealthBar.java b/src/main/java/wtf/cheeze/sbt/features/huds/HealthBar.java index 0ddc663..bba4483 100644 --- a/src/main/java/wtf/cheeze/sbt/features/huds/HealthBar.java +++ b/src/main/java/wtf/cheeze/sbt/features/huds/HealthBar.java @@ -19,18 +19,17 @@ package wtf.cheeze.sbt.features.huds; import dev.isxander.yacl3.api.Option; -import dev.isxander.yacl3.api.OptionDescription; import dev.isxander.yacl3.api.OptionGroup; import dev.isxander.yacl3.api.controller.ColorControllerBuilder; import dev.isxander.yacl3.config.v2.api.SerialEntry; -import net.minecraft.client.resource.language.I18n; -import net.minecraft.text.Text; import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.ConfigImpl; import wtf.cheeze.sbt.config.SBTConfig; +import wtf.cheeze.sbt.hud.utils.AnchorPoint; import wtf.cheeze.sbt.utils.TextUtils; -import wtf.cheeze.sbt.utils.hud.BarHUD; -import wtf.cheeze.sbt.utils.hud.HudInformation; +import wtf.cheeze.sbt.hud.bases.BarHUD; +import wtf.cheeze.sbt.hud.utils.HudInformation; +import wtf.cheeze.sbt.utils.render.Colors; import java.awt.Color; @@ -77,10 +76,10 @@ public static class Config { public float scale = 1.0f; @SerialEntry - public int color = 16733525; + public int color = Colors.RED; @SerialEntry - public int colorAbsorption = 16755200; + public int colorAbsorption = Colors.ORANGE; @SerialEntry public AnchorPoint anchor = AnchorPoint.LEFT; diff --git a/src/main/java/wtf/cheeze/sbt/features/huds/HealthHUD.java b/src/main/java/wtf/cheeze/sbt/features/huds/HealthHUD.java index 857d5f6..a7d68be 100644 --- a/src/main/java/wtf/cheeze/sbt/features/huds/HealthHUD.java +++ b/src/main/java/wtf/cheeze/sbt/features/huds/HealthHUD.java @@ -19,21 +19,21 @@ package wtf.cheeze.sbt.features.huds; import dev.isxander.yacl3.api.Option; -import dev.isxander.yacl3.api.OptionDescription; import dev.isxander.yacl3.api.OptionGroup; import dev.isxander.yacl3.api.controller.ColorControllerBuilder; import dev.isxander.yacl3.api.controller.StringControllerBuilder; import dev.isxander.yacl3.config.v2.api.SerialEntry; -import net.minecraft.client.resource.language.I18n; import net.minecraft.text.Text; import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.ConfigImpl; import wtf.cheeze.sbt.config.SBTConfig; +import wtf.cheeze.sbt.hud.utils.AnchorPoint; import wtf.cheeze.sbt.utils.NumberUtils; -import wtf.cheeze.sbt.utils.hud.HudLine; +import wtf.cheeze.sbt.hud.utils.DrawMode; +import wtf.cheeze.sbt.hud.components.SingleHudLine; import wtf.cheeze.sbt.utils.TextUtils; -import wtf.cheeze.sbt.utils.hud.HudInformation; -import wtf.cheeze.sbt.utils.hud.TextHUD; +import wtf.cheeze.sbt.hud.utils.HudInformation; +import wtf.cheeze.sbt.hud.bases.TextHUD; import java.awt.Color; @@ -50,7 +50,7 @@ public HealthHUD() { scale -> SBTConfig.huds().health.scale = (float) scale, anchor -> SBTConfig.huds().health.anchor = anchor ); - line = new HudLine( + line = new SingleHudLine( () -> SkyblockTweaks.DATA.health > SkyblockTweaks.DATA.maxHealth ? SBTConfig.huds().health.colorAbsorption : SBTConfig.huds().health.color, () -> SBTConfig.huds().health.outlineColor, () -> SBTConfig.huds().health.mode, @@ -74,7 +74,7 @@ public static class Config { public boolean enabled = false; @SerialEntry - public HudLine.DrawMode mode = HudLine.DrawMode.SHADOW; + public DrawMode mode = DrawMode.SHADOW; @SerialEntry // Not handled by YACL Gui public float x = 0; @@ -140,7 +140,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { .name(key("health.outlineColor")) .description(keyD("health.outlineColor")) .controller(ColorControllerBuilder::create) - .available(config.huds.health.mode == HudLine.DrawMode.OUTLINE) + .available(config.huds.health.mode == DrawMode.OUTLINE) .binding( new Color(defaults.huds.health.outlineColor), () -> new Color(config.huds.health.outlineColor), @@ -148,7 +148,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { ) .build(); - var mode = Option.createBuilder() + var mode = Option.createBuilder() .name(key("health.mode")) .description(keyD("health.mode")) .controller(SBTConfig::generateDrawModeController) @@ -157,7 +157,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { () -> config.huds.health.mode, value -> { config.huds.health.mode = value; - if (value == HudLine.DrawMode.OUTLINE) outline.setAvailable(true); + if (value == DrawMode.OUTLINE) outline.setAvailable(true); else outline.setAvailable(false); } ) diff --git a/src/main/java/wtf/cheeze/sbt/features/huds/ManaBar.java b/src/main/java/wtf/cheeze/sbt/features/huds/ManaBar.java index 05b6da4..65485b2 100644 --- a/src/main/java/wtf/cheeze/sbt/features/huds/ManaBar.java +++ b/src/main/java/wtf/cheeze/sbt/features/huds/ManaBar.java @@ -19,18 +19,17 @@ package wtf.cheeze.sbt.features.huds; import dev.isxander.yacl3.api.Option; -import dev.isxander.yacl3.api.OptionDescription; import dev.isxander.yacl3.api.OptionGroup; import dev.isxander.yacl3.api.controller.ColorControllerBuilder; import dev.isxander.yacl3.config.v2.api.SerialEntry; -import net.minecraft.client.resource.language.I18n; -import net.minecraft.text.Text; import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.ConfigImpl; import wtf.cheeze.sbt.config.SBTConfig; +import wtf.cheeze.sbt.hud.utils.AnchorPoint; import wtf.cheeze.sbt.utils.TextUtils; -import wtf.cheeze.sbt.utils.hud.BarHUD; -import wtf.cheeze.sbt.utils.hud.HudInformation; +import wtf.cheeze.sbt.hud.bases.BarHUD; +import wtf.cheeze.sbt.hud.utils.HudInformation; +import wtf.cheeze.sbt.utils.render.Colors; import java.awt.Color; @@ -77,7 +76,7 @@ public static class Config { public float scale = 1.0f; @SerialEntry - public int color = 5592575; + public int color = Colors.BLUE; @SerialEntry public AnchorPoint anchor = AnchorPoint.LEFT; diff --git a/src/main/java/wtf/cheeze/sbt/features/huds/ManaHUD.java b/src/main/java/wtf/cheeze/sbt/features/huds/ManaHUD.java index 19ccb36..4b78f17 100644 --- a/src/main/java/wtf/cheeze/sbt/features/huds/ManaHUD.java +++ b/src/main/java/wtf/cheeze/sbt/features/huds/ManaHUD.java @@ -19,21 +19,22 @@ package wtf.cheeze.sbt.features.huds; import dev.isxander.yacl3.api.Option; -import dev.isxander.yacl3.api.OptionDescription; import dev.isxander.yacl3.api.OptionGroup; import dev.isxander.yacl3.api.controller.ColorControllerBuilder; import dev.isxander.yacl3.api.controller.StringControllerBuilder; import dev.isxander.yacl3.config.v2.api.SerialEntry; -import net.minecraft.client.resource.language.I18n; import net.minecraft.text.Text; import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.ConfigImpl; import wtf.cheeze.sbt.config.SBTConfig; +import wtf.cheeze.sbt.hud.utils.AnchorPoint; import wtf.cheeze.sbt.utils.NumberUtils; import wtf.cheeze.sbt.utils.TextUtils; -import wtf.cheeze.sbt.utils.hud.HudInformation; -import wtf.cheeze.sbt.utils.hud.TextHUD; -import wtf.cheeze.sbt.utils.hud.HudLine; +import wtf.cheeze.sbt.hud.utils.DrawMode; +import wtf.cheeze.sbt.hud.utils.HudInformation; +import wtf.cheeze.sbt.hud.bases.TextHUD; +import wtf.cheeze.sbt.hud.components.SingleHudLine; +import wtf.cheeze.sbt.utils.render.Colors; import java.awt.*; @@ -51,7 +52,7 @@ public ManaHUD() { scale -> SBTConfig.huds().mana.scale = (float) scale, anchor -> SBTConfig.huds().mana.anchor = anchor ); - line = new HudLine( + line = new SingleHudLine( () -> SBTConfig.huds().mana.color, () -> SBTConfig.huds().mana.outlineColor, () -> SBTConfig.huds().mana.mode, @@ -83,7 +84,7 @@ public static class Config { // public boolean shadow = true; @SerialEntry - public HudLine.DrawMode mode = HudLine.DrawMode.SHADOW; + public DrawMode mode = DrawMode.SHADOW; @SerialEntry // Not handled by YACL Gui public float x = 0; @@ -95,10 +96,10 @@ public static class Config { public float scale = 1.0f; @SerialEntry - public int color = 5592575; + public int color = Colors.BLUE; @SerialEntry - public int outlineColor = 0x000000; + public int outlineColor = Colors.BLACK; @SerialEntry public boolean icon = true; @@ -135,7 +136,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { .name(key("mana.outlineColor")) .description(keyD("mana.outlineColor")) .controller(ColorControllerBuilder::create) - .available(config.huds.mana.mode == HudLine.DrawMode.OUTLINE) + .available(config.huds.mana.mode == DrawMode.OUTLINE) .binding( new Color(defaults.huds.mana.outlineColor), () -> new Color(config.huds.mana.outlineColor), @@ -143,7 +144,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { ) .build(); - var mode = Option.createBuilder() + var mode = Option.createBuilder() .name(key("mana.mode")) .description(keyD("mana.mode")) .controller(SBTConfig::generateDrawModeController) @@ -152,7 +153,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { () -> config.huds.mana.mode, value -> { config.huds.mana.mode = value; - if (value == HudLine.DrawMode.OUTLINE) outline.setAvailable(true); + if (value == DrawMode.OUTLINE) outline.setAvailable(true); else outline.setAvailable(false); } ) diff --git a/src/main/java/wtf/cheeze/sbt/features/huds/OverflowManaHUD.java b/src/main/java/wtf/cheeze/sbt/features/huds/OverflowManaHUD.java index 97db91d..b51a12f 100644 --- a/src/main/java/wtf/cheeze/sbt/features/huds/OverflowManaHUD.java +++ b/src/main/java/wtf/cheeze/sbt/features/huds/OverflowManaHUD.java @@ -19,21 +19,22 @@ package wtf.cheeze.sbt.features.huds; import dev.isxander.yacl3.api.Option; -import dev.isxander.yacl3.api.OptionDescription; import dev.isxander.yacl3.api.OptionGroup; import dev.isxander.yacl3.api.controller.ColorControllerBuilder; import dev.isxander.yacl3.api.controller.StringControllerBuilder; import dev.isxander.yacl3.config.v2.api.SerialEntry; -import net.minecraft.client.resource.language.I18n; import net.minecraft.text.Text; import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.ConfigImpl; import wtf.cheeze.sbt.config.SBTConfig; +import wtf.cheeze.sbt.hud.utils.AnchorPoint; import wtf.cheeze.sbt.utils.NumberUtils; -import wtf.cheeze.sbt.utils.hud.HudLine; +import wtf.cheeze.sbt.hud.utils.DrawMode; +import wtf.cheeze.sbt.hud.components.SingleHudLine; import wtf.cheeze.sbt.utils.TextUtils; -import wtf.cheeze.sbt.utils.hud.HudInformation; -import wtf.cheeze.sbt.utils.hud.TextHUD; +import wtf.cheeze.sbt.hud.utils.HudInformation; +import wtf.cheeze.sbt.hud.bases.TextHUD; +import wtf.cheeze.sbt.utils.render.Colors; import java.awt.*; @@ -50,7 +51,7 @@ public OverflowManaHUD() { scale -> SBTConfig.huds().overflowMana.scale = (float) scale, anchor -> SBTConfig.huds().overflowMana.anchor = anchor ); - line = new HudLine( + line = new SingleHudLine( () -> SBTConfig.huds().overflowMana.color, () -> SBTConfig.huds().overflowMana.outlineColor, () -> SBTConfig.huds().overflowMana.mode, @@ -79,7 +80,7 @@ public static class Config { public boolean hideWhenZero = true; @SerialEntry - public HudLine.DrawMode mode = HudLine.DrawMode.SHADOW; + public DrawMode mode = DrawMode.SHADOW; @SerialEntry // Not handled by YACL Gui public float x = 0; @@ -91,10 +92,10 @@ public static class Config { public float scale = 1.0f; @SerialEntry - public int color = 43690; + public int color = Colors.CYAN; @SerialEntry - public int outlineColor = 0x000000; + public int outlineColor = Colors.BLACK; @SerialEntry public boolean icon = true; @@ -141,7 +142,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { .name(key("overflowMana.outlineColor")) .description(keyD("overflowMana.outlineColor")) .controller(ColorControllerBuilder::create) - .available(config.huds.overflowMana.mode == HudLine.DrawMode.OUTLINE) + .available(config.huds.overflowMana.mode == DrawMode.OUTLINE) .binding( new Color(defaults.huds.overflowMana.outlineColor), () -> new Color(config.huds.overflowMana.outlineColor), @@ -149,7 +150,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { ) .build(); - var mode = Option.createBuilder() + var mode = Option.createBuilder() .name(key("overflowMana.mode")) .description(keyD("overflowMana.mode")) .controller(SBTConfig::generateDrawModeController) @@ -158,7 +159,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { () -> config.huds.overflowMana.mode, value -> { config.huds.overflowMana.mode = value; - if (value == HudLine.DrawMode.OUTLINE) outline.setAvailable(true); + if (value == DrawMode.OUTLINE) outline.setAvailable(true); else outline.setAvailable(false); } ) diff --git a/src/main/java/wtf/cheeze/sbt/features/huds/RealTimeHUD.java b/src/main/java/wtf/cheeze/sbt/features/huds/RealTimeHUD.java index 0ece3a5..9503746 100644 --- a/src/main/java/wtf/cheeze/sbt/features/huds/RealTimeHUD.java +++ b/src/main/java/wtf/cheeze/sbt/features/huds/RealTimeHUD.java @@ -19,7 +19,6 @@ package wtf.cheeze.sbt.features.huds; import dev.isxander.yacl3.api.Option; -import dev.isxander.yacl3.api.OptionDescription; import dev.isxander.yacl3.api.OptionGroup; import dev.isxander.yacl3.api.controller.ColorControllerBuilder; import dev.isxander.yacl3.config.v2.api.SerialEntry; @@ -27,9 +26,12 @@ import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.ConfigImpl; import wtf.cheeze.sbt.config.SBTConfig; -import wtf.cheeze.sbt.utils.hud.HudLine; -import wtf.cheeze.sbt.utils.hud.HudInformation; -import wtf.cheeze.sbt.utils.hud.TextHUD; +import wtf.cheeze.sbt.hud.utils.AnchorPoint; +import wtf.cheeze.sbt.hud.utils.DrawMode; +import wtf.cheeze.sbt.hud.components.SingleHudLine; +import wtf.cheeze.sbt.hud.utils.HudInformation; +import wtf.cheeze.sbt.hud.bases.TextHUD; +import wtf.cheeze.sbt.utils.render.Colors; import java.awt.Color; import java.time.LocalDateTime; @@ -47,7 +49,7 @@ public RealTimeHUD() { scale -> SBTConfig.huds().time.scale = (float) scale, anchor -> SBTConfig.huds().time.anchor = anchor ); - line = new HudLine( + line = new SingleHudLine( () -> SBTConfig.huds().time.color, () -> SBTConfig.huds().time.outlineColor, () -> SBTConfig.huds().time.mode, @@ -107,13 +109,13 @@ public static class Config { public boolean amPM = true; @SerialEntry - public HudLine.DrawMode mode = HudLine.DrawMode.SHADOW; + public DrawMode mode = DrawMode.SHADOW; @SerialEntry - public int color = 0xFFFFFF; + public int color = Colors.WHITE; @SerialEntry - public int outlineColor = 0x000000; + public int outlineColor = Colors.BLACK; @SerialEntry // Not handled by YACL Gui public float x = 0; @@ -201,7 +203,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { .name(key("time.outlineColor")) .description(keyD("time.outlineColor")) .controller(ColorControllerBuilder::create) - .available(config.huds.time.mode == HudLine.DrawMode.OUTLINE) + .available(config.huds.time.mode == DrawMode.OUTLINE) .binding( new Color(defaults.huds.time.outlineColor), () -> new Color(config.huds.time.outlineColor), @@ -209,7 +211,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { ) .build(); - var mode = Option.createBuilder() + var mode = Option.createBuilder() .name(key("time.mode")) .description(keyD("time.mode")) .controller(SBTConfig::generateDrawModeController) @@ -218,7 +220,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { () -> config.huds.time.mode, value -> { config.huds.time.mode = value; - if (value == HudLine.DrawMode.OUTLINE) outline.setAvailable(true); + if (value == DrawMode.OUTLINE) outline.setAvailable(true); else outline.setAvailable(false); } ) diff --git a/src/main/java/wtf/cheeze/sbt/features/huds/SkillHUDManager.java b/src/main/java/wtf/cheeze/sbt/features/huds/SkillHUDManager.java index f2ffcb8..025488c 100644 --- a/src/main/java/wtf/cheeze/sbt/features/huds/SkillHUDManager.java +++ b/src/main/java/wtf/cheeze/sbt/features/huds/SkillHUDManager.java @@ -20,7 +20,6 @@ import dev.isxander.yacl3.api.NameableEnum; import dev.isxander.yacl3.api.Option; -import dev.isxander.yacl3.api.OptionDescription; import dev.isxander.yacl3.api.OptionGroup; import dev.isxander.yacl3.api.controller.ColorControllerBuilder; import dev.isxander.yacl3.api.controller.EnumControllerBuilder; @@ -30,12 +29,15 @@ import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.ConfigImpl; import wtf.cheeze.sbt.config.SBTConfig; +import wtf.cheeze.sbt.hud.utils.AnchorPoint; import wtf.cheeze.sbt.utils.NumberUtils; import wtf.cheeze.sbt.utils.TextUtils; -import wtf.cheeze.sbt.utils.hud.BarHUD; -import wtf.cheeze.sbt.utils.hud.HudInformation; -import wtf.cheeze.sbt.utils.hud.HudLine; -import wtf.cheeze.sbt.utils.hud.TextHUD; +import wtf.cheeze.sbt.hud.utils.DrawMode; +import wtf.cheeze.sbt.hud.bases.BarHUD; +import wtf.cheeze.sbt.hud.utils.HudInformation; +import wtf.cheeze.sbt.hud.components.SingleHudLine; +import wtf.cheeze.sbt.hud.bases.TextHUD; +import wtf.cheeze.sbt.utils.render.Colors; import wtf.cheeze.sbt.utils.skyblock.IconDict; import wtf.cheeze.sbt.utils.skyblock.SkyblockConstants; import wtf.cheeze.sbt.utils.skyblock.SkyblockUtils; @@ -101,7 +103,7 @@ public SkillHUD() { scale -> SBTConfig.huds().skills.scale = scale, anchor -> SBTConfig.huds().skills.anchor = anchor ); - line = new HudLine( + line = new SingleHudLine( () -> SBTConfig.huds().skills.color, () -> SBTConfig.huds().skills.outlineColor, () -> SBTConfig.huds().skills.mode, @@ -230,7 +232,7 @@ public static class Config { public boolean abridgeDenominator = true; @SerialEntry - public HudLine.DrawMode mode = HudLine.DrawMode.SHADOW; + public DrawMode mode = DrawMode.SHADOW; @SerialEntry // Not handled by YACL Gui public float x = 0; @@ -242,10 +244,10 @@ public static class Config { public float scale = 1.0f; @SerialEntry - public int color = 43690; + public int color = Colors.CYAN; @SerialEntry - public int outlineColor = 0x000000; + public int outlineColor = Colors.BLACK; @SerialEntry public AnchorPoint anchor = AnchorPoint.LEFT; @@ -309,7 +311,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { .name(key("skills.outlineColor")) .description(keyD("skills.outlineColor")) .controller(ColorControllerBuilder::create) - .available(config.huds.skills.mode == HudLine.DrawMode.OUTLINE) + .available(config.huds.skills.mode == DrawMode.OUTLINE) .binding( new Color(defaults.huds.skills.outlineColor), () -> new Color(config.huds.skills.outlineColor), @@ -317,7 +319,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { ) .build(); - var mode = Option.createBuilder() + var mode = Option.createBuilder() .name(key("skills.mode")) .description(keyD("skills.mode")) .controller(SBTConfig::generateDrawModeController) @@ -326,7 +328,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { () -> config.huds.skills.mode, value -> { config.huds.skills.mode = value; - outline.setAvailable(value == HudLine.DrawMode.OUTLINE); + outline.setAvailable(value == DrawMode.OUTLINE); } ) .build(); @@ -410,7 +412,7 @@ public static class Config { public float scale = 1.0f; @SerialEntry - public int color = 43690; + public int color = Colors.CYAN; @SerialEntry public AnchorPoint anchor = AnchorPoint.LEFT; diff --git a/src/main/java/wtf/cheeze/sbt/features/huds/SpeedHUD.java b/src/main/java/wtf/cheeze/sbt/features/huds/SpeedHUD.java index 25023fb..1b44b94 100644 --- a/src/main/java/wtf/cheeze/sbt/features/huds/SpeedHUD.java +++ b/src/main/java/wtf/cheeze/sbt/features/huds/SpeedHUD.java @@ -26,9 +26,12 @@ import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.ConfigImpl; import wtf.cheeze.sbt.config.SBTConfig; -import wtf.cheeze.sbt.utils.hud.HudLine; -import wtf.cheeze.sbt.utils.hud.HudInformation; -import wtf.cheeze.sbt.utils.hud.TextHUD; +import wtf.cheeze.sbt.hud.utils.AnchorPoint; +import wtf.cheeze.sbt.hud.utils.DrawMode; +import wtf.cheeze.sbt.hud.components.SingleHudLine; +import wtf.cheeze.sbt.hud.utils.HudInformation; +import wtf.cheeze.sbt.hud.bases.TextHUD; +import wtf.cheeze.sbt.utils.render.Colors; import java.awt.Color; @@ -45,7 +48,7 @@ public SpeedHUD() { scale -> SBTConfig.huds().speed.scale = (float) scale, anchor -> SBTConfig.huds().speed.anchor = anchor ); - line = new HudLine( + line = new SingleHudLine( () -> SBTConfig.huds().speed.color, () -> SBTConfig.huds().speed.outlineColor, () -> SBTConfig.huds().speed.mode, @@ -69,13 +72,13 @@ public static class Config { public boolean enabled = false; @SerialEntry - public HudLine.DrawMode mode = HudLine.DrawMode.SHADOW; + public DrawMode mode = DrawMode.SHADOW; @SerialEntry - public int color = 0xFFFFFF; + public int color = Colors.WHITE; @SerialEntry - public int outlineColor = 0x000000; + public int outlineColor = Colors.BLACK; @SerialEntry // Not handled by YACL Gui public float x = 0; @@ -116,7 +119,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { .name(key("speed.outlineColor")) .description(keyD("speed.outlineColor")) .controller(ColorControllerBuilder::create) - .available(config.huds.speed.mode == HudLine.DrawMode.OUTLINE) + .available(config.huds.speed.mode == DrawMode.OUTLINE) .binding( new Color(defaults.huds.speed.outlineColor), () -> new Color(config.huds.speed.outlineColor), @@ -124,7 +127,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { ) .build(); - var mode = Option.createBuilder() + var mode = Option.createBuilder() .name(key("speed.mode")) .description(keyD("speed.mode")) .controller(SBTConfig::generateDrawModeController) @@ -133,7 +136,7 @@ public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { () -> config.huds.speed.mode, value -> { config.huds.speed.mode = value; - if (value == HudLine.DrawMode.OUTLINE) outline.setAvailable(true); + if (value == DrawMode.OUTLINE) outline.setAvailable(true); else outline.setAvailable(false); } ) diff --git a/src/main/java/wtf/cheeze/sbt/features/huds/TickerHUD.java b/src/main/java/wtf/cheeze/sbt/features/huds/TickerHUD.java index c92af4d..ff9bc99 100644 --- a/src/main/java/wtf/cheeze/sbt/features/huds/TickerHUD.java +++ b/src/main/java/wtf/cheeze/sbt/features/huds/TickerHUD.java @@ -19,16 +19,15 @@ package wtf.cheeze.sbt.features.huds; import dev.isxander.yacl3.api.Option; -import dev.isxander.yacl3.api.OptionDescription; import dev.isxander.yacl3.api.OptionGroup; import dev.isxander.yacl3.config.v2.api.SerialEntry; -import net.minecraft.text.Text; import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.ConfigImpl; import wtf.cheeze.sbt.config.SBTConfig; +import wtf.cheeze.sbt.hud.utils.AnchorPoint; import wtf.cheeze.sbt.utils.TextUtils; -import wtf.cheeze.sbt.utils.hud.AbstractTickerHUD; -import wtf.cheeze.sbt.utils.hud.HudInformation; +import wtf.cheeze.sbt.hud.bases.AbstractTickerHUD; +import wtf.cheeze.sbt.hud.utils.HudInformation; public class TickerHUD extends AbstractTickerHUD { diff --git a/src/main/java/wtf/cheeze/sbt/utils/hud/HUD.java b/src/main/java/wtf/cheeze/sbt/hud/HUD.java similarity index 83% rename from src/main/java/wtf/cheeze/sbt/utils/hud/HUD.java rename to src/main/java/wtf/cheeze/sbt/hud/HUD.java index e5e3ec2..af5972c 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/hud/HUD.java +++ b/src/main/java/wtf/cheeze/sbt/hud/HUD.java @@ -16,21 +16,32 @@ * You should have received a copy of the GNU Lesser General Public License * along with SkyblockTweaks. If not, see . */ -package wtf.cheeze.sbt.utils.hud; +package wtf.cheeze.sbt.hud; import dev.isxander.yacl3.api.NameableEnum; import dev.isxander.yacl3.api.OptionDescription; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.text.Text; +import wtf.cheeze.sbt.hud.bounds.Bounds; +import wtf.cheeze.sbt.hud.bounds.BoundsRelative; +import wtf.cheeze.sbt.hud.utils.HudInformation; /** - * Represents any sort of HUD that can be drawn to the screen, and handles logic that is that same if the HUD is a text or bar based hud + * Represents any sort of HUD that can be drawn to the screen, and handles logic that is that same no matter how the HUD renders */ public abstract class HUD { public HudInformation INFO; + /**; + * Whether the HUD supports non-left anchors + */ + public boolean supportsNonLeftAnchors = true; + + /** + * @return the name of the HUD that will be shown in the HUD screen + */ public abstract String getName(); @@ -38,6 +49,7 @@ public abstract class HUD { public abstract BoundsRelative getCurrentBoundsRelative(); + public boolean shouldRender(boolean fromHudScreen) { // We let the HUD screen handle rendering when it is open if (!fromHudScreen && MinecraftClient.getInstance().currentScreen instanceof HudScreen) return false; @@ -45,10 +57,21 @@ public boolean shouldRender(boolean fromHudScreen) { else return true; }; + /** + * Calls the render method with hovered set to false + */ public void render(DrawContext context, boolean fromHudScreen) { render(context, fromHudScreen, false); } + /** + * Draws the HUD to the screen + * @param context the DrawContext + * @param fromHudScreen whether the HUD is being drawn in the context of the edit screen + * @param hovered whether the HUD is hovered while being drawn in the context of the edit screen + */ + public abstract void render(DrawContext context, boolean fromHudScreen, boolean hovered); + public void updatePosition(float x, float y) { INFO.setX.accept(x); INFO.setY.accept(y); @@ -106,13 +129,5 @@ public static Text key(String key) { public static OptionDescription keyD(String key) { return OptionDescription.of(Text.translatable(BASE_KEY + key + ".desc")); } - public abstract void render(DrawContext context, boolean fromHudScreen, boolean hovered); - public enum AnchorPoint implements NameableEnum { - LEFT, CENTER, RIGHT; - @Override - public Text getDisplayName() { - return Text.literal(name()); - } - } } diff --git a/src/main/java/wtf/cheeze/sbt/utils/hud/HudIcon.java b/src/main/java/wtf/cheeze/sbt/hud/HudIcon.java similarity index 54% rename from src/main/java/wtf/cheeze/sbt/utils/hud/HudIcon.java rename to src/main/java/wtf/cheeze/sbt/hud/HudIcon.java index 2d91d82..361d39f 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/hud/HudIcon.java +++ b/src/main/java/wtf/cheeze/sbt/hud/HudIcon.java @@ -1,9 +1,10 @@ -package wtf.cheeze.sbt.utils.hud; +package wtf.cheeze.sbt.hud; import net.minecraft.client.gui.DrawContext; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; import org.jetbrains.annotations.Nullable; +import wtf.cheeze.sbt.utils.render.RenderUtils; public class HudIcon { @Nullable private Identifier iconTexture; @@ -20,10 +21,17 @@ public HudIcon(ItemStack iconStack) { this.mode = Mode.ITEM; } - public void render(DrawContext context, int x, int y) { + public void render(DrawContext context, int x, int y, float scale) { switch (mode) { - case TEXTURE -> context.drawTexture(iconTexture, x, y, 0, 0, 8, 8, 8, 8); - case ITEM -> context.drawItem(iconStack, x, y); + case TEXTURE -> { + RenderUtils.drawTexture(context, iconTexture, (int) (x /scale) , (int) (y / scale), 8, 8, 8, 8); + } + case ITEM -> { + context.getMatrices().push(); + context.getMatrices().scale(0.5f, 0.5f, 0.5f); + context.drawItem(iconStack, x, y); + context.getMatrices().pop(); + } } } private static enum Mode { diff --git a/src/main/java/wtf/cheeze/sbt/utils/hud/HudScreen.java b/src/main/java/wtf/cheeze/sbt/hud/HudScreen.java similarity index 95% rename from src/main/java/wtf/cheeze/sbt/utils/hud/HudScreen.java rename to src/main/java/wtf/cheeze/sbt/hud/HudScreen.java index 2fb09b6..5148358 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/hud/HudScreen.java +++ b/src/main/java/wtf/cheeze/sbt/hud/HudScreen.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with SkyblockTweaks. If not, see . */ -package wtf.cheeze.sbt.utils.hud; +package wtf.cheeze.sbt.hud; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; @@ -28,8 +28,8 @@ import net.minecraft.text.Text; import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; -import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.SBTConfig; +import wtf.cheeze.sbt.hud.utils.AnchorPoint; import java.util.ArrayList; import java.util.function.Predicate; @@ -109,15 +109,15 @@ public HudScreen(Text title, ArrayList huds, Screen parent) { anchorButton = ButtonWidget.builder(Text.literal("you should not be seeing this text"), button -> { if (selectedElement != null) { var anchor = selectedElement.INFO.getAnchorPoint.get(); - if (anchor == HUD.AnchorPoint.LEFT) { - selectedElement.INFO.setAnchorPoint.accept(HUD.AnchorPoint.CENTER); - anchorButton.setMessage(Text.literal("Anchor: " + HUD.AnchorPoint.CENTER.name())); - } else if (anchor == HUD.AnchorPoint.CENTER) { - selectedElement.INFO.setAnchorPoint.accept(HUD.AnchorPoint.RIGHT); - anchorButton.setMessage(Text.literal("Anchor: " + HUD.AnchorPoint.RIGHT.name())); - } else if (anchor == HUD.AnchorPoint.RIGHT) { - selectedElement.INFO.setAnchorPoint.accept(HUD.AnchorPoint.LEFT); - anchorButton.setMessage(Text.literal("Anchor: " + HUD.AnchorPoint.LEFT.name())); + if (anchor == AnchorPoint.LEFT) { + selectedElement.INFO.setAnchorPoint.accept(AnchorPoint.CENTER); + anchorButton.setMessage(Text.literal("Anchor: " + AnchorPoint.CENTER.name())); + } else if (anchor == AnchorPoint.CENTER) { + selectedElement.INFO.setAnchorPoint.accept(AnchorPoint.RIGHT); + anchorButton.setMessage(Text.literal("Anchor: " + AnchorPoint.RIGHT.name())); + } else if (anchor == AnchorPoint.RIGHT) { + selectedElement.INFO.setAnchorPoint.accept(AnchorPoint.LEFT); + anchorButton.setMessage(Text.literal("Anchor: " + AnchorPoint.LEFT.name())); } } }).dimensions(centerX, 110, 100, 20).build(); @@ -170,6 +170,7 @@ private void enableTextMode(HUD hud) { widgetX.setText(""+bounds.x); widgetY.setText(""+bounds.y); anchorButton.setMessage(Text.literal("Anchor: " + hud.INFO.getAnchorPoint.get().name())); + anchorButton.active = hud.supportsNonLeftAnchors; } @Override @@ -178,7 +179,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { MinecraftClient mc = MinecraftClient.getInstance(); var centerX = mc.getWindow().getScaledWidth() / 2; - if (!this.hasAltDown() && this.mode == Mode.DRAG) { + if (!hasAltDown() && this.mode == Mode.DRAG) { context.drawCenteredTextWithShadow(mc.textRenderer, "Drag or use the arrow keys to move items" , centerX, 5, 0xFFFFFF); context.drawCenteredTextWithShadow(mc.textRenderer, "Scroll or use the + and - keys to scale items" , centerX, 15, 0xFFFFFF); context.drawCenteredTextWithShadow(mc.textRenderer, "Press shift and hover to see the name of the item" , centerX, 25, 0xFFFFFF); @@ -203,7 +204,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { hud.render(context, true, b); if (b) { hovered = hud; - if (this.hasShiftDown()) { + if (hasShiftDown()) { this.setTooltip(Tooltip.of(Text.literal(hud.getName())), HoveredTooltipPositioner.INSTANCE, false); } } @@ -236,7 +237,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { selectedViaTheKeyboard = null; for (HUD hud : huds) { if (clickInBounds(hud, mouseX, mouseY)) { - if (this.hasControlDown() || this.mode == Mode.TEXT) { + if (hasControlDown() || this.mode == Mode.TEXT) { enableTextMode(hud); return b; } @@ -257,7 +258,7 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) { @Override public boolean keyPressed(int keyCode, int scanCode, int modifiers) { - if (keyCode == GLFW.GLFW_KEY_R && this.hasControlDown()) { + if (keyCode == GLFW.GLFW_KEY_R && hasControlDown()) { setMode(Mode.RESET); } if (this.mode == Mode.DRAG) { @@ -345,11 +346,11 @@ public boolean test(String s) { private void updateOffset(HUD hud, double mouseX, double mouseY) { var bounds = hud.getCurrentBounds(); var anchor = hud.INFO.getAnchorPoint.get(); - if (anchor == HUD.AnchorPoint.LEFT) { + if (anchor == AnchorPoint.LEFT) { offsetX = (float) (mouseX - bounds.x); - } else if (anchor == HUD.AnchorPoint.CENTER) { + } else if (anchor == AnchorPoint.CENTER) { offsetX = (float) (mouseX - bounds.x - bounds.width / 2); - } else if (anchor == HUD.AnchorPoint.RIGHT) { + } else if (anchor == AnchorPoint.RIGHT) { offsetX = (float) (mouseX - bounds.x - bounds.width); } offsetY = (float) (mouseY - bounds.y); diff --git a/src/main/java/wtf/cheeze/sbt/utils/hud/AbstractTickerHUD.java b/src/main/java/wtf/cheeze/sbt/hud/bases/AbstractTickerHUD.java similarity index 90% rename from src/main/java/wtf/cheeze/sbt/utils/hud/AbstractTickerHUD.java rename to src/main/java/wtf/cheeze/sbt/hud/bases/AbstractTickerHUD.java index 50d8bfb..270af3c 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/hud/AbstractTickerHUD.java +++ b/src/main/java/wtf/cheeze/sbt/hud/bases/AbstractTickerHUD.java @@ -16,26 +16,29 @@ * You should have received a copy of the GNU Lesser General Public License * along with SkyblockTweaks. If not, see . */ -package wtf.cheeze.sbt.utils.hud; +package wtf.cheeze.sbt.hud.bases; import net.minecraft.client.gui.DrawContext; import net.minecraft.util.Identifier; import wtf.cheeze.sbt.SkyblockTweaks; +import wtf.cheeze.sbt.hud.bounds.Bounds; +import wtf.cheeze.sbt.hud.bounds.BoundsRelative; +import wtf.cheeze.sbt.hud.HUD; import wtf.cheeze.sbt.utils.render.RenderUtils; /** * The abstract representation of the ticker HUD, for the implementation, see {@link wtf.cheeze.sbt.features.huds.TickerHUD} */ -public abstract class AbstractTickerHUD extends HUD{ +public abstract class AbstractTickerHUD extends HUD { private static final Identifier FULL = Identifier.of("skyblocktweaks", "tickers/full.png"); private static final Identifier BLANK = Identifier.of("skyblocktweaks", "tickers/blank.png"); private static final int DIMENSION = 9; + public abstract int getMax(boolean fromHudScreen); public abstract int getUsable(boolean fromHudScreen); public abstract int getMax(); - @Override public void render(DrawContext context, boolean fromHudScreen, boolean hovered) { if (!shouldRender(fromHudScreen)) return; @@ -54,10 +57,10 @@ public void render(DrawContext context, boolean fromHudScreen, boolean hovered) } - private float drawTickers(DrawContext context, int number, float x, int y, float scale, boolean filled) { + private static float drawTickers(DrawContext context, int number, float x, int y, float scale, boolean filled) { float drawX = x; for (int i = 0; i < number; i++) { - context.drawTexture(filled ? FULL : BLANK, (int) (drawX / scale), (int) (y / scale), 0, 0, DIMENSION, DIMENSION, DIMENSION , DIMENSION); + RenderUtils.drawTexture(context, filled ? FULL : BLANK, (int) (drawX / scale), (int) (y / scale), DIMENSION, DIMENSION, DIMENSION , DIMENSION); drawX = (2 + drawX + (DIMENSION * scale)); } return drawX; diff --git a/src/main/java/wtf/cheeze/sbt/utils/hud/BarHUD.java b/src/main/java/wtf/cheeze/sbt/hud/bases/BarHUD.java similarity index 78% rename from src/main/java/wtf/cheeze/sbt/utils/hud/BarHUD.java rename to src/main/java/wtf/cheeze/sbt/hud/bases/BarHUD.java index b78c25d..ae9d04f 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/hud/BarHUD.java +++ b/src/main/java/wtf/cheeze/sbt/hud/bases/BarHUD.java @@ -16,11 +16,16 @@ * You should have received a copy of the GNU Lesser General Public License * along with SkyblockTweaks. If not, see . */ -package wtf.cheeze.sbt.utils.hud; +package wtf.cheeze.sbt.hud.bases; +import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.render.RenderLayer; import net.minecraft.util.Identifier; import wtf.cheeze.sbt.SkyblockTweaks; +import wtf.cheeze.sbt.hud.bounds.Bounds; +import wtf.cheeze.sbt.hud.bounds.BoundsRelative; +import wtf.cheeze.sbt.hud.HUD; import wtf.cheeze.sbt.utils.render.RenderUtils; /** @@ -39,8 +44,10 @@ public void render(DrawContext context, boolean fromHudScreen, boolean hovered) if (fromHudScreen) { drawBackground(context, hovered ? BACKGROUND_HOVERED : BACKGROUND_NOT_HOVERED); } + + //? if =1.21.1 { var colors = RenderUtils.getColor3f((int) INFO.getColor.get()); - if (bounds.scale == 1.0f) { + /* if (bounds.scale == 1.0f) { context.setShaderColor(colors.red, colors.green, colors.blue, 1.0f); context.drawTexture(UNFILLED, bounds.x, bounds.y, 0, 0, BAR_WIDTH, BAR_HEIGHT, BAR_WIDTH, BAR_HEIGHT); context.drawTexture(FILLED, bounds.x, bounds.y, 0, 0, calculateFill((float) INFO.getFill.get()), BAR_HEIGHT, BAR_WIDTH, BAR_HEIGHT); @@ -53,6 +60,23 @@ public void render(DrawContext context, boolean fromHudScreen, boolean hovered) context.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); RenderUtils.endScale(context); } + *///?} else { + + if (bounds.scale == 1.0f) { + var color = INFO.getColor.get(); + context.drawTexture(RenderLayer::getGuiTextured, UNFILLED, bounds.x, bounds.y, 0, 0, BAR_WIDTH, BAR_HEIGHT, BAR_WIDTH, BAR_HEIGHT, color); + context.drawTexture(RenderLayer::getGuiTextured, FILLED, bounds.x, bounds.y, 0, 0, calculateFill((float) INFO.getFill.get()), BAR_HEIGHT, BAR_WIDTH, BAR_HEIGHT, color); + } else { + var color = INFO.getColor.get(); + RenderUtils.beginScale(context, bounds.scale); + context.drawTexture(RenderLayer::getGuiTextured, UNFILLED, (int)(bounds.x/bounds.scale), (int)(bounds.y/bounds.scale), 0, 0, BAR_WIDTH, BAR_HEIGHT, BAR_WIDTH, BAR_HEIGHT, color); + context.drawTexture(RenderLayer::getGuiTextured, FILLED, (int)(bounds.x/bounds.scale), (int)(bounds.y/bounds.scale), 0, 0, calculateFill((float) INFO.getFill.get()), BAR_HEIGHT, BAR_WIDTH, BAR_HEIGHT, color); + RenderUtils.endScale(context); + } + //?} + + + } @Override public Bounds getCurrentBounds() { diff --git a/src/main/java/wtf/cheeze/sbt/hud/bases/MultilineTextHUD.java b/src/main/java/wtf/cheeze/sbt/hud/bases/MultilineTextHUD.java new file mode 100644 index 0000000..624c7de --- /dev/null +++ b/src/main/java/wtf/cheeze/sbt/hud/bases/MultilineTextHUD.java @@ -0,0 +1,105 @@ +package wtf.cheeze.sbt.hud.bases; + +import net.minecraft.client.gui.DrawContext; +import wtf.cheeze.sbt.SkyblockTweaks; +import wtf.cheeze.sbt.hud.bounds.Bounds; +import wtf.cheeze.sbt.hud.bounds.BoundsRelative; +import wtf.cheeze.sbt.hud.HUD; +import wtf.cheeze.sbt.hud.components.HudComponent; +import wtf.cheeze.sbt.utils.render.RenderUtils; + +public abstract class MultilineTextHUD extends HUD { + + protected MultilineTextHUD() { + this.supportsNonLeftAnchors = false; + } + public HudComponent[] lines; + + public int getLongestLineWidth(boolean relative){ + int longest = 0; + for(var line : lines){ + int width = line.getWidth(); + if (width > longest) longest = width; + } + return longest; + } + public int getLongestLineWidth(){ + return getLongestLineWidth(false); + } + private int getLineNo(){ + int i = 0; + for(var line : lines){ + i+=line.getlines(); + } + return i; + } + + @Override + public Bounds getCurrentBounds() { + var scale = (float) INFO.getScale.get(); + var w = getLongestLineWidth(); + var h = getLineNo(); + return new Bounds(getActualX(INFO.getX.get()), getActualY((float) INFO.getY.get()), w * scale, h * SkyblockTweaks.mc.textRenderer.fontHeight * scale, scale); + } + @Override + public BoundsRelative getCurrentBoundsRelative() { + var scale = (float) INFO.getScale.get(); + var w = getLongestLineWidth(); + var h = getLineNo(); + return new BoundsRelative(INFO.getX.get(), (float) INFO.getY.get(), w * scale, h * SkyblockTweaks.mc.textRenderer.fontHeight * scale, scale); + } + + @Override + public void render(DrawContext context, boolean fromHudScreen, boolean hovered) { + if (!shouldRender(fromHudScreen)) return; + + var bounds = getCurrentBounds(); + var lineHeight = (int) (9 * bounds.scale); + if (fromHudScreen) { + drawBackground(context, hovered ? BACKGROUND_HOVERED : BACKGROUND_NOT_HOVERED); + } + RenderUtils.beginScale(context, bounds.scale); +// for(int i = 0; i < lines.length; i++){ +// var line = lines[i]; +// var y = bounds.y + i * lineHeight; +// line.render(context, getXPosition(line, bounds.x), y, bounds.scale); +// } + int i = 0; + for (var line : lines) { + var y = bounds.y + lineHeight * line.getlines(); +// i+=line.render(context, getXPosition(line, bounds.x), y, bounds.scale); + i+=line.render(context, bounds.x, y, bounds.scale); + } + RenderUtils.endScale(context); + } + + +// private int getXPosition(HudComponent line, int hudX) { +// var anchor = INFO.getAnchorPoint.get(); +// var width = line.getWidth(); +// return switch (anchor) { +// case LEFT -> hudX; +// case RIGHT -> hudX - width; +// case CENTER -> hudX - width / 2; +// +// }; +// } +// private int fixBoundsX(int x, float width){ +// var anchor = INFO.getAnchorPoint.get(); +// return switch (anchor) { +// case LEFT -> x; +// case RIGHT -> (int) (x - width); +// case CENTER -> (int) (x - width / 2); +// +// }; +// } +// private float fixBoundsXRelative(float x, float width){ +// var anchor = INFO.getAnchorPoint.get(); +// return switch (anchor) { +// case LEFT -> x; +// case RIGHT -> x - width; +// case CENTER -> x - width / 2; +// +// }; +// } +} diff --git a/src/main/java/wtf/cheeze/sbt/utils/hud/TextHUD.java b/src/main/java/wtf/cheeze/sbt/hud/bases/TextHUD.java similarity index 91% rename from src/main/java/wtf/cheeze/sbt/utils/hud/TextHUD.java rename to src/main/java/wtf/cheeze/sbt/hud/bases/TextHUD.java index 48f480d..6d75971 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/hud/TextHUD.java +++ b/src/main/java/wtf/cheeze/sbt/hud/bases/TextHUD.java @@ -16,23 +16,28 @@ * You should have received a copy of the GNU Lesser General Public License * along with SkyblockTweaks. If not, see . */ -package wtf.cheeze.sbt.utils.hud; +package wtf.cheeze.sbt.hud.bases; import net.minecraft.client.gui.DrawContext; import wtf.cheeze.sbt.SkyblockTweaks; +import wtf.cheeze.sbt.hud.utils.DrawMode; +import wtf.cheeze.sbt.hud.bounds.Bounds; +import wtf.cheeze.sbt.hud.bounds.BoundsRelative; +import wtf.cheeze.sbt.hud.HUD; +import wtf.cheeze.sbt.hud.components.SingleHudLine; import wtf.cheeze.sbt.utils.render.RenderUtils; public abstract class TextHUD extends HUD { //public abstract String getText(); - public HudLine line; + public SingleHudLine line; @Override public void render(DrawContext context, boolean fromHudScreen, boolean hovered) { if (!shouldRender(fromHudScreen)) return; var bounds = getCurrentBounds(); if (fromHudScreen) { - drawBackground(context, hovered ? BACKGROUND_HOVERED : BACKGROUND_NOT_HOVERED, line.mode.get() == HudLine.DrawMode.OUTLINE); + drawBackground(context, hovered ? BACKGROUND_HOVERED : BACKGROUND_NOT_HOVERED, line.mode.get() == DrawMode.OUTLINE); } RenderUtils.beginScale(context, bounds.scale); line.render(context, bounds.x, bounds.y, bounds.scale); diff --git a/src/main/java/wtf/cheeze/sbt/utils/hud/Bounds.java b/src/main/java/wtf/cheeze/sbt/hud/bounds/Bounds.java similarity index 96% rename from src/main/java/wtf/cheeze/sbt/utils/hud/Bounds.java rename to src/main/java/wtf/cheeze/sbt/hud/bounds/Bounds.java index 2871fcf..256cfc4 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/hud/Bounds.java +++ b/src/main/java/wtf/cheeze/sbt/hud/bounds/Bounds.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with SkyblockTweaks. If not, see . */ -package wtf.cheeze.sbt.utils.hud; +package wtf.cheeze.sbt.hud.bounds; public class Bounds { public int x; diff --git a/src/main/java/wtf/cheeze/sbt/utils/hud/BoundsRelative.java b/src/main/java/wtf/cheeze/sbt/hud/bounds/BoundsRelative.java similarity index 97% rename from src/main/java/wtf/cheeze/sbt/utils/hud/BoundsRelative.java rename to src/main/java/wtf/cheeze/sbt/hud/bounds/BoundsRelative.java index 7ba54e2..4a9b728 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/hud/BoundsRelative.java +++ b/src/main/java/wtf/cheeze/sbt/hud/bounds/BoundsRelative.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with SkyblockTweaks. If not, see . */ -package wtf.cheeze.sbt.utils.hud; +package wtf.cheeze.sbt.hud.bounds; public class BoundsRelative { public float x; diff --git a/src/main/java/wtf/cheeze/sbt/hud/components/FlexibleHudLine.java b/src/main/java/wtf/cheeze/sbt/hud/components/FlexibleHudLine.java new file mode 100644 index 0000000..c3c2bfb --- /dev/null +++ b/src/main/java/wtf/cheeze/sbt/hud/components/FlexibleHudLine.java @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2024 MisterCheezeCake + * + * This file is part of SkyblockTweaks. + * + * SkyblockTweaks is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * SkyblockTweaks is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with SkyblockTweaks. If not, see . + */ +package wtf.cheeze.sbt.hud.components; + +import net.minecraft.client.gui.DrawContext; +import net.minecraft.text.Text; +import org.jetbrains.annotations.Nullable; +import wtf.cheeze.sbt.hud.HudIcon; +import wtf.cheeze.sbt.hud.utils.DrawMode; +import wtf.cheeze.sbt.utils.DataUtils; +import wtf.cheeze.sbt.utils.render.RenderUtils; + +import java.util.function.Supplier; + +public class FlexibleHudLine implements HudComponent { + + + public Supplier parts; + + private int width = 1; + private int lines = 1; + + public FlexibleHudLine(Supplier parts) { + this.parts = parts; + } + + @Override + public int render(DrawContext context, int x, int y, float scale) { + var pts = parts.get(); + var longest = 0; + var lineHeight = (int) (9 * scale); + for (Part part : pts) { + var text = part.text.get(); + var w = RenderUtils.getStringWidth(text); + if (part.useIcon.get()) { + w += 10; + renderLine(context, text, part.icon.get(), x, y, scale, part.mode.get(), part.color.get(), part.outlineColor.get()); + } else { + renderLine(context, text, x, y, scale, part.mode.get(), part.color.get(), part.outlineColor.get()); + } + if (w > longest) { + longest = w; + } + + y += lineHeight; + } + this.width = longest; + this.lines = pts.length; + return lines; + + } + + + + @Override + public int getWidth() { + return width; + } + + @Override + public int getlines() { + return lines; + } + + +// private static void renderLine(DrawContext context, Text text, HudIcon icon, int x, int y, float scale, DrawMode mode, int color) { +// renderLine(context, text, icon, x, y, scale, mode, color, -1); +// } +// private static void renderLine(DrawContext context, Text text, int x, int y, float scale, DrawMode mode, int color) { +// renderLine(context, text, x, y, scale, mode, color, -1); +// } + + private static void renderLine(DrawContext context, Text text, int x, int y, float scale, DrawMode mode, int color, int outlineColor) { + switch (mode) { + case PURE -> RenderUtils.drawText(context, text, x, y, color, false, scale, true); + case SHADOW -> RenderUtils.drawText(context, text, x, y, color, true, scale, true); + case OUTLINE -> RenderUtils.drawTextWithOutline(context, text, x, y, color, outlineColor, scale, true); + } + } + private static void renderLine(DrawContext context, Text text, HudIcon icon, int x, int y, float scale, DrawMode mode, int color, int outlineColor) { + icon.render(context, x, y, scale); + switch (mode) { + case PURE -> { + RenderUtils.drawText(context, text, x + (int) (10 * scale), y, color, false, scale, true); + } + case SHADOW -> { + RenderUtils.drawText(context, text, x + (int) (10 * scale), y, color, true, scale, true); + } + case OUTLINE -> { + RenderUtils.drawTextWithOutline(context, text, x + (int) (10 * scale), y, color, outlineColor, scale, true); + } + } + } + + public static class Part { + public final Supplier text; + public final Supplier useIcon; + @Nullable + public Supplier icon; + public final Supplier mode; + public final Supplier color; + public final Supplier outlineColor; + + public Part(Supplier text, Supplier mode, Supplier color, Supplier outlineColor) { + this.text = text; + this.useIcon = DataUtils.alwaysFalse; + this.mode = mode; + this.color = color; + this.outlineColor = outlineColor; + } + + public Part(Supplier text, Supplier mode, Supplier color, Supplier outlineColor, Supplier icon, Supplier useIcon) { + this.text = text; + this.mode = mode; + this.color = color; + this.outlineColor = outlineColor; + this.icon = icon; + this.useIcon = useIcon; + } + + } +} diff --git a/src/main/java/wtf/cheeze/sbt/hud/components/HudComponent.java b/src/main/java/wtf/cheeze/sbt/hud/components/HudComponent.java new file mode 100644 index 0000000..a515094 --- /dev/null +++ b/src/main/java/wtf/cheeze/sbt/hud/components/HudComponent.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2024 MisterCheezeCake + * + * This file is part of SkyblockTweaks. + * + * SkyblockTweaks is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * SkyblockTweaks is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with SkyblockTweaks. If not, see . + */ +package wtf.cheeze.sbt.hud.components; + +import net.minecraft.client.gui.DrawContext; + +public interface HudComponent { + int render(DrawContext context, int x, int y, float scale); + int getWidth(); + int getlines(); +} diff --git a/src/main/java/wtf/cheeze/sbt/hud/components/SingleHudLine.java b/src/main/java/wtf/cheeze/sbt/hud/components/SingleHudLine.java new file mode 100644 index 0000000..cc4e203 --- /dev/null +++ b/src/main/java/wtf/cheeze/sbt/hud/components/SingleHudLine.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2024 MisterCheezeCake + * + * This file is part of SkyblockTweaks. + * + * SkyblockTweaks is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * SkyblockTweaks is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with SkyblockTweaks. If not, see . + */ +package wtf.cheeze.sbt.hud.components; + +import net.minecraft.client.gui.DrawContext; +import net.minecraft.text.Text; +import org.jetbrains.annotations.Nullable; +import wtf.cheeze.sbt.hud.HudIcon; +import wtf.cheeze.sbt.hud.utils.DrawMode; +import wtf.cheeze.sbt.utils.render.RenderUtils; + +import java.util.function.Supplier; + +public class SingleHudLine implements HudComponent { + + public Supplier color; + public Supplier outlineColor; + public Supplier mode; + public Supplier text; + public Supplier useIcon; + + public int lineCount = 1; + + @Nullable + // Make sure not to create a new instance of HudIcon every time you call this + public Supplier icon; + + public SingleHudLine(Supplier getColor, Supplier getOutlineColor, Supplier getMode, Supplier getText) { + this.color = getColor; + this.outlineColor = getOutlineColor; + this.text = getText; + this.mode = getMode; + this.useIcon = () -> false; + + } + + public SingleHudLine(Supplier getColor, Supplier getOutlineColor, Supplier getMode, Supplier getText, Supplier icon, Supplier useIcon) { + this.color = getColor; + this.outlineColor = getOutlineColor; + this.text = getText; + this.mode = getMode; + this.icon = icon; + this.useIcon = useIcon; + } + + + @Override + public int render(DrawContext context, int x, int y, float scale) { + + switch (mode.get()) { + case PURE: + render(context, x, y, scale, false); + break; + case SHADOW: + render(context, x, y, scale, true); + break; + case OUTLINE: + if (useIcon.get()) { + icon.get().render(context, x, y, scale); + RenderUtils.drawTextWithOutline(context, text.get(), x + (int) (10 * scale), y, color.get(), outlineColor.get(), scale, true); + } else { + RenderUtils.drawTextWithOutline(context, text.get(), x, y, color.get(), outlineColor.get(), scale, true); + } + } + return 1; + } + + private void render(DrawContext context, int x, int y, float scale, boolean shadow) { + + if (useIcon.get()) { + +// context.fill(x - i, y - i, x + RenderUtils.getStringWidth(text.get()) + 10, y + 9, 1694433280); + icon.get().render(context, x, y, scale); + RenderUtils.drawText(context, text.get(), x + (int) (10 * scale), y, color.get(), shadow, scale, true); + } else { + RenderUtils.drawText(context, text.get(), x, y, color.get(), shadow, scale, true); + } + } + + @Override + public int getWidth() { + return RenderUtils.getStringWidth(text.get()) + (useIcon.get() ? 10 : 0); + } + + @Override + public int getlines() { return 1;} +} \ No newline at end of file diff --git a/src/main/java/wtf/cheeze/sbt/utils/ModifiedDrawContext.java b/src/main/java/wtf/cheeze/sbt/hud/utils/AnchorPoint.java similarity index 76% rename from src/main/java/wtf/cheeze/sbt/utils/ModifiedDrawContext.java rename to src/main/java/wtf/cheeze/sbt/hud/utils/AnchorPoint.java index a43b06f..ca89fe5 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/ModifiedDrawContext.java +++ b/src/main/java/wtf/cheeze/sbt/hud/utils/AnchorPoint.java @@ -16,11 +16,16 @@ * You should have received a copy of the GNU Lesser General Public License * along with SkyblockTweaks. If not, see . */ -package wtf.cheeze.sbt.utils; +package wtf.cheeze.sbt.hud.utils; -import net.minecraft.client.font.TextRenderer; +import dev.isxander.yacl3.api.NameableEnum; import net.minecraft.text.Text; -public interface ModifiedDrawContext { - int sbt$drawTextWithBackgroundNoShadow(TextRenderer textRenderer, Text text, int x, int y, int width, int color); +public enum AnchorPoint implements NameableEnum { + LEFT, CENTER, RIGHT; + + @Override + public Text getDisplayName() { + return Text.literal(name()); + } } diff --git a/src/main/java/wtf/cheeze/sbt/hud/utils/DrawMode.java b/src/main/java/wtf/cheeze/sbt/hud/utils/DrawMode.java new file mode 100644 index 0000000..1642c40 --- /dev/null +++ b/src/main/java/wtf/cheeze/sbt/hud/utils/DrawMode.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2024 MisterCheezeCake + * + * This file is part of SkyblockTweaks. + * + * SkyblockTweaks is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * SkyblockTweaks is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with SkyblockTweaks. If not, see . + */ +package wtf.cheeze.sbt.hud.utils; + +import dev.isxander.yacl3.api.NameableEnum; +import net.minecraft.text.Text; +import wtf.cheeze.sbt.utils.TextUtils; + +public enum DrawMode implements NameableEnum { + PURE, SHADOW, OUTLINE; + + @Override + public Text getDisplayName() { + return Text.literal(TextUtils.firstLetterUppercase(name().toLowerCase())); + } +} diff --git a/src/main/java/wtf/cheeze/sbt/utils/hud/HudInformation.java b/src/main/java/wtf/cheeze/sbt/hud/utils/HudInformation.java similarity index 59% rename from src/main/java/wtf/cheeze/sbt/utils/hud/HudInformation.java rename to src/main/java/wtf/cheeze/sbt/hud/utils/HudInformation.java index bc8df39..c34c72f 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/hud/HudInformation.java +++ b/src/main/java/wtf/cheeze/sbt/hud/utils/HudInformation.java @@ -16,9 +16,10 @@ * You should have received a copy of the GNU Lesser General Public License * along with SkyblockTweaks. If not, see . */ -package wtf.cheeze.sbt.utils.hud; +package wtf.cheeze.sbt.hud.utils; import org.jetbrains.annotations.Nullable; +import wtf.cheeze.sbt.utils.DataUtils; import java.util.function.Consumer; import java.util.function.Supplier; @@ -28,7 +29,7 @@ public class HudInformation { public Supplier getX; public Supplier getY; public Supplier getScale; - public Supplier getAnchorPoint; + public Supplier getAnchorPoint; @Nullable public Supplier getFill; @@ -39,9 +40,12 @@ public class HudInformation { public Consumer setX; public Consumer setY; public Consumer setScale; - public Consumer setAnchorPoint; + public Consumer setAnchorPoint; - public HudInformation(Supplier xSupplier, Supplier ySupplier, Supplier scaleSupplier, Supplier anchorPointSupplier, Consumer xConsumer, Consumer yConsumer, Consumer scaleConsumer, Consumer anchorPointConsumer) { + /** + * This constructor is used for Single Line Text HUDs and the Ticker HUD + */ + public HudInformation(Supplier xSupplier, Supplier ySupplier, Supplier scaleSupplier, Supplier anchorPointSupplier, Consumer xConsumer, Consumer yConsumer, Consumer scaleConsumer, Consumer anchorPointConsumer) { this.getX = xSupplier; this.getY = ySupplier; this.getScale = scaleSupplier; @@ -52,7 +56,11 @@ public HudInformation(Supplier xSupplier, Supplier ySupplier, Supp this.setScale = scaleConsumer; this.setAnchorPoint = anchorPointConsumer; } - public HudInformation(Supplier xSupplier, Supplier ySupplier, Supplier scaleSupplier, Supplier anchorPointSupplier, Supplier colorSupplier, Supplier fillSupplier, Consumer xConsumer, Consumer yConsumer, Consumer scaleConsumer, Consumer anchorPointConsumer) { + + /** + * This constructor is used for Bar HUDs + */ + public HudInformation(Supplier xSupplier, Supplier ySupplier, Supplier scaleSupplier, Supplier anchorPointSupplier, Supplier colorSupplier, Supplier fillSupplier, Consumer xConsumer, Consumer yConsumer, Consumer scaleConsumer, Consumer anchorPointConsumer) { this.getX = xSupplier; this.getY = ySupplier; this.getScale = scaleSupplier; @@ -66,4 +74,19 @@ public HudInformation(Supplier xSupplier, Supplier ySupplier, Supp this.setScale = scaleConsumer; this.setAnchorPoint = anchorPointConsumer; } + + /** + * This constructor is used for Multi Line Text HUDs + */ + public HudInformation(Supplier xSupplier, Supplier ySupplier, Supplier scaleSupplier, Consumer xConsumer, Consumer yConsumer, Consumer scaleConsumer) { + this.getX = xSupplier; + this.getY = ySupplier; + this.getScale = scaleSupplier; + this.getAnchorPoint = DataUtils.alwaysLeft; + + this.setX = xConsumer; + this.setY = yConsumer; + this.setScale = scaleConsumer; + this.setAnchorPoint = DataUtils.doNothing; + } } diff --git a/src/main/java/wtf/cheeze/sbt/mixin/AbstractInventoryScreenMixin.java b/src/main/java/wtf/cheeze/sbt/mixin/AbstractInventoryScreenMixin.java index 7aecbf6..dd85c99 100644 --- a/src/main/java/wtf/cheeze/sbt/mixin/AbstractInventoryScreenMixin.java +++ b/src/main/java/wtf/cheeze/sbt/mixin/AbstractInventoryScreenMixin.java @@ -18,22 +18,37 @@ */ package wtf.cheeze.sbt.mixin; +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen; +//? if =1.21.1 +/*import net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen;*/ +//? if >=1.21.3 { +import net.minecraft.client.gui.screen.ingame.InventoryScreen; +import net.minecraft.client.gui.screen.ingame.StatusEffectsDisplay; +//?} import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; +//? if =1.21.1 { +/*import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +*///?} import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.SBTConfig; -@Mixin(AbstractInventoryScreen.class) +@Mixin(/*? if >=1.21.3 {*/InventoryScreen.class /*?} else {*/ /*AbstractInventoryScreen.class *//*?}*/) public abstract class AbstractInventoryScreenMixin { - @Inject(method = "drawStatusEffects", at = @At("HEAD"), cancellable = true) + //? if >=1.21.3 { + @WrapWithCondition(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/StatusEffectsDisplay;drawStatusEffects(Lnet/minecraft/client/gui/DrawContext;IIF)V")) + private boolean sbt$onDrawStatusEffects(StatusEffectsDisplay instance, DrawContext context, int mouseX, int mouseY, float tickDelta){ + return !SBTConfig.get().inventory.noRenderPotionHud || !SkyblockTweaks.DATA.inSB; + } + //?} else { + /*@Inject(method = "drawStatusEffects", at = @At("HEAD"), cancellable = true) private void sbt$onDrawStatusEffects(DrawContext context, int mouseX, int mouseY, CallbackInfo ci){ if (SBTConfig.get().inventory.noRenderPotionHud && SkyblockTweaks.DATA.inSB) { ci.cancel(); } } + *///?} -} +} \ No newline at end of file diff --git a/src/main/java/wtf/cheeze/sbt/mixin/DrawContextMixin.java b/src/main/java/wtf/cheeze/sbt/mixin/DrawContextMixin.java index 7214146..915330a 100644 --- a/src/main/java/wtf/cheeze/sbt/mixin/DrawContextMixin.java +++ b/src/main/java/wtf/cheeze/sbt/mixin/DrawContextMixin.java @@ -21,16 +21,19 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.text.Text; import net.minecraft.util.math.ColorHelper; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import wtf.cheeze.sbt.utils.ModifiedDrawContext; +import org.spongepowered.asm.mixin.Unique; +import wtf.cheeze.sbt.utils.render.SBTDrawContext; import java.util.Objects; @Mixin(DrawContext.class) -public abstract class DrawContextMixin implements ModifiedDrawContext { +public abstract class DrawContextMixin implements SBTDrawContext { @Shadow private MinecraftClient client; @@ -40,13 +43,25 @@ public abstract class DrawContextMixin implements ModifiedDrawContext { @Shadow public abstract int drawText(TextRenderer textRenderer, Text text, int x, int y, int color, boolean shadow); + @Shadow @Final private VertexConsumerProvider.Immediate vertexConsumers; + @Override public int sbt$drawTextWithBackgroundNoShadow(TextRenderer textRenderer, Text text, int x, int y, int width, int color) { int i = this.client.options.getTextBackgroundColor(0.0F); if (i != 0) { Objects.requireNonNull(textRenderer); - this.fill(x -2, y-2 , x + width + 2, y + 9 + 2, ColorHelper.Argb.mixColor(i, color)); + this.fill(x -2, y-2 , x + width + 2, y + 9 + 2, ColorHelper./*? if >=1.21.3 {*/mix/*?} else {*//*Argb.mixColor*//*?}*/(i, color)); } return this.drawText(textRenderer, text, x, y, color, false); } + + /** + * You may ask yourself, "Why is this not an accessor?" The answer is that I really did not want to deal with mixins only existing on one version, and this works fine + */ + //? if >=1.21.3 { + @Override + public VertexConsumerProvider.Immediate sbt$getVertexConsumers() { + return this.vertexConsumers; + } + //?} } diff --git a/src/main/java/wtf/cheeze/sbt/mixin/InGameHudMixin.java b/src/main/java/wtf/cheeze/sbt/mixin/InGameHudMixin.java index 2475dff..4265fca 100644 --- a/src/main/java/wtf/cheeze/sbt/mixin/InGameHudMixin.java +++ b/src/main/java/wtf/cheeze/sbt/mixin/InGameHudMixin.java @@ -30,14 +30,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.SBTConfig; -import wtf.cheeze.sbt.utils.ModifiedDrawContext; +import wtf.cheeze.sbt.utils.render.SBTDrawContext; @Mixin(InGameHud.class) public abstract class InGameHudMixin { @WrapOperation(method = "renderOverlayMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTextWithBackground(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/text/Text;IIII)I")) private int sbt$drawTextWithBackgroundNoShadowWrap(DrawContext instance, TextRenderer textRenderer, Text text, int x, int y, int width, int color, Operation original) { if (SBTConfig.get().hudTweaks.noShadowActionBar) { - return ((ModifiedDrawContext) instance).sbt$drawTextWithBackgroundNoShadow(textRenderer, text, x, y, width, color); + return ((SBTDrawContext) instance).sbt$drawTextWithBackgroundNoShadow(textRenderer, text, x, y, width, color); } else { return original.call(instance, textRenderer, text, x, y, width, color); } diff --git a/src/main/java/wtf/cheeze/sbt/mixin/InventoryScreenMixin.java b/src/main/java/wtf/cheeze/sbt/mixin/InventoryScreenMixin.java index 8395d1c..030f581 100644 --- a/src/main/java/wtf/cheeze/sbt/mixin/InventoryScreenMixin.java +++ b/src/main/java/wtf/cheeze/sbt/mixin/InventoryScreenMixin.java @@ -19,7 +19,9 @@ package wtf.cheeze.sbt.mixin; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.ingame.InventoryScreen; + +import net.minecraft.client.gui.screen.ingame.*; + import net.minecraft.client.gui.widget.ButtonWidget; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -28,17 +30,27 @@ import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.SBTConfig; -@Mixin(InventoryScreen.class) -public abstract class InventoryScreenMixin { + +//? if =1.21.1 { +/*@Mixin(InventoryScreen.class) + *///?} else { +@Mixin(RecipeBookScreen.class) +//?} + +public abstract class InventoryScreenMixin { // This injects into the head of the synthetic method that is triggered when you click the recipe book button - @Inject(method = "method_19891", at = @At("HEAD"), cancellable = true) + //? if =1.21.1 { + /*@Inject(method = "method_19891", at = @At("HEAD"), cancellable = true) + *///?} else { + @Inject(method = "method_64513", at = @At("HEAD"), cancellable = true) + //?} private void sbt$onPressRBook(ButtonWidget button, CallbackInfo ci) { if (SBTConfig.get().inventory.redirectRecipeBook && SkyblockTweaks.DATA.inSB) { ci.cancel(); MinecraftClient.getInstance().getNetworkHandler().sendChatCommand("recipebook"); } } - } + diff --git a/src/main/java/wtf/cheeze/sbt/utils/DataUtils.java b/src/main/java/wtf/cheeze/sbt/utils/DataUtils.java new file mode 100644 index 0000000..6e4d5c2 --- /dev/null +++ b/src/main/java/wtf/cheeze/sbt/utils/DataUtils.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2024 MisterCheezeCake + * + * This file is part of SkyblockTweaks. + * + * SkyblockTweaks is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * SkyblockTweaks is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with SkyblockTweaks. If not, see . + */ +package wtf.cheeze.sbt.utils; + +import wtf.cheeze.sbt.hud.utils.AnchorPoint; + +import java.util.function.Consumer; +import java.util.function.Supplier; + +public class DataUtils { + + public static Supplier alwaysFalse = () -> false; + public static Supplier alwaysZero = () -> 0; + public static Supplier alwaysLeft = () -> AnchorPoint.LEFT; + public static Consumer doNothing = (o) -> {}; +} diff --git a/src/main/java/wtf/cheeze/sbt/utils/HTTPUtils.java b/src/main/java/wtf/cheeze/sbt/utils/HTTPUtils.java index dbd99dd..0d9c55b 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/HTTPUtils.java +++ b/src/main/java/wtf/cheeze/sbt/utils/HTTPUtils.java @@ -18,16 +18,22 @@ */ package wtf.cheeze.sbt.utils; +import wtf.cheeze.sbt.SkyblockTweaks; + import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; public class HTTPUtils { public static String get(String uri){ try { - URL url = new URL(uri); + // URL url = new URL(uri); + URL url = new URI(uri).toURL(); + var connection = url.openConnection(); - connection.setRequestProperty("User-Agent", "Mozilla/5.0 SkyblockTweaks"); + connection.setRequestProperty("User-Agent", "Mozilla/5.0 SkyblockTweaks " + SkyblockTweaks.VERSION.getVersionString()); var reader = new java.io.BufferedReader(new java.io.InputStreamReader(connection.getInputStream())); var response = new StringBuilder(); String line; @@ -36,8 +42,8 @@ public static String get(String uri){ } reader.close(); return response.toString(); - } catch (IOException e) { - e.printStackTrace(); + } catch (Exception e) { + SkyblockTweaks.LOGGER.error("Update Checker Experienced an Error", e); return null; } } diff --git a/src/main/java/wtf/cheeze/sbt/utils/NumberUtils.java b/src/main/java/wtf/cheeze/sbt/utils/NumberUtils.java index 8262774..e1f9880 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/NumberUtils.java +++ b/src/main/java/wtf/cheeze/sbt/utils/NumberUtils.java @@ -46,27 +46,26 @@ public static int parseIntWithKorM(String text) { } } + @SuppressWarnings("DuplicatedCode") public static float parseFloatWithKorM(String text) { text = text.toLowerCase(); text = text.replaceAll(",", ""); - if (text.endsWith("k")) { - var v = Float.parseFloat(text.substring(0, text.length() - 1)); - return v * 1000; - } else if (text.endsWith("m")) { - var v = Float.parseFloat(text.substring(0, text.length() - 1)); - return v * 1000000; - } else { - return Float.parseFloat(text); - } + + return switch (text.charAt(text.length() - 1)) { + case 'k' -> Float.parseFloat(text.substring(0, text.length() - 1)) * 1000; + case 'm' -> Float.parseFloat(text.substring(0, text.length() - 1)) * 1000000; + default -> Float.parseFloat(text); + }; + } - public static String formatNumber(int number, String seperator) { + public static String formatNumber(int number, String separator) { String str = Integer.toString(number); StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { sb.append(str.charAt(i)); if ((str.length() - i - 1) % 3 == 0 && i != str.length() - 1) { - sb.append(seperator); + sb.append(separator); } } return sb.toString(); diff --git a/src/main/java/wtf/cheeze/sbt/utils/TextUtils.java b/src/main/java/wtf/cheeze/sbt/utils/TextUtils.java index d704a9a..8e05619 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/TextUtils.java +++ b/src/main/java/wtf/cheeze/sbt/utils/TextUtils.java @@ -68,10 +68,6 @@ public static String firstLetterUppercase(String text) { return text.substring(0, 1).toUpperCase() + text.substring(1); } - - - - public static Text join(Text... texts) { var result = Text.literal(""); for (var text : texts) { diff --git a/src/main/java/wtf/cheeze/sbt/utils/UpdateChecker.java b/src/main/java/wtf/cheeze/sbt/utils/UpdateChecker.java index e97624a..78ee27a 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/UpdateChecker.java +++ b/src/main/java/wtf/cheeze/sbt/utils/UpdateChecker.java @@ -20,66 +20,58 @@ import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.SBTConfig; +import wtf.cheeze.sbt.utils.Version.NotificationStream; public class UpdateChecker { - public static final String REMOTE_VERSION_FILE = "https://raw.githubusercontent.com/MisterCheezeCake/RemoteData/main/SBT/updateInfo.json"; + public static final String REMOTE_VERSION_FILE = "https://raw.githubusercontent.com/MisterCheezeCake/RemoteData/refs/heads/main/SBT/updateNew.json"; public static void checkForUpdates() { - if (SBTConfig.get().notificationStream != Version.NotificationStream.NONE && SkyblockTweaks.VERSION.STREAM != Version.VersionType.UNSTABLE) { + if (SBTConfig.get().notificationStream != NotificationStream.NONE && SkyblockTweaks.VERSION.STREAM != Version.VersionType.UNSTABLE) { try { SkyblockTweaks.LOGGER.info("Checking for updates"); var result = HTTPUtils.get(REMOTE_VERSION_FILE); - //LOGGER.info(result); Version.RemoteVersionFile remote = SkyblockTweaks.GSON.fromJson(result, Version.RemoteVersionFile.class); if (remote == null) { SkyblockTweaks.LOGGER.error("Failed to parse remote version file"); } else { - if (remote.enabled != false) { + if (remote.enabled) { switch (SBTConfig.get().notificationStream) { - case Version.NotificationStream.ALPHA -> { + case NotificationStream.ALPHA -> { if (remote.latestAlpha == null) { break; } - var version = new Version(remote.latestAlpha.versionString); - var comparison = Version.compareVersions(version, SkyblockTweaks.VERSION); - if (comparison == Version.VersionComparison.GREATER) { - var link = Version.getModrinthLink(remote.latestAlpha.modrinthName); - var message = TextUtils.getTextThatLinksToURL("§7[§aSkyblockTweaks§f§7] §3Update §e" + remote.latestAlpha.modrinthName + " §3is available! §2[Download]", "§3Click to open Modrinth in your browser", link); - NotificationHandler.NOTIFICATION_QUEUE.add(message); - } + internalRun(remote.latestAlpha.get(SkyblockTweaks.mc.getGameVersion())); } - case Version.NotificationStream.BETA -> { + case NotificationStream.BETA -> { if (remote.latestBeta == null) { break; } - var version = new Version(remote.latestBeta.versionString); - var comparison = Version.compareVersions(version, SkyblockTweaks.VERSION); - if (comparison == Version.VersionComparison.GREATER) { - var link = Version.getModrinthLink(remote.latestBeta.modrinthName); - var message = TextUtils.getTextThatLinksToURL("§7[§aSkyblockTweaks§f§7] §3Update §e" + remote.latestBeta.modrinthName + " §3is available! §2[Download]", "§3Click to open Modrinth in your browser", link); - NotificationHandler.NOTIFICATION_QUEUE.add(message); - } - + internalRun(remote.latestBeta.get(SkyblockTweaks.mc.getGameVersion())); } - case Version.NotificationStream.RELEASE -> { + case NotificationStream.RELEASE -> { if (remote.latestRelease == null) { break; } - var version = new Version(remote.latestRelease.versionString); - var comparison = Version.compareVersions(version, SkyblockTweaks.VERSION); - if (comparison == Version.VersionComparison.GREATER) { - var link = Version.getModrinthLink(remote.latestRelease.modrinthName); - var message = TextUtils.getTextThatLinksToURL("§7[§aSkyblockTweaks§f§7] §3Update §e" + remote.latestRelease.modrinthName + " §3is available! §2[Download]", "§3Click to open Modrinth in your browser", link); - NotificationHandler.NOTIFICATION_QUEUE.add(message); - } - + internalRun(remote.latestRelease.get(SkyblockTweaks.mc.getGameVersion())); } } } } } catch (Exception e) { - e.printStackTrace(); + SkyblockTweaks.LOGGER.error("Failed to check for updates", e); } } } + + private static void internalRun(Version.RemoteVersion remoteVersion) { + var version = new Version(remoteVersion.versionString); + var comparison = Version.compareVersions(version, SkyblockTweaks.VERSION); + if (comparison == Version.VersionComparison.GREATER) { + var link = Version.getModrinthLink(remoteVersion.modrinthName); + var message = TextUtils.getTextThatLinksToURL("§7[§aSkyblockTweaks§f§7] §3Update §e" + remoteVersion.versionString + " §3is available! §2[Download]", "§3Click to open Modrinth in your browser", link); + NotificationHandler.NOTIFICATION_QUEUE.add(message); + } + } + + } diff --git a/src/main/java/wtf/cheeze/sbt/utils/Version.java b/src/main/java/wtf/cheeze/sbt/utils/Version.java index 55d514a..deee435 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/Version.java +++ b/src/main/java/wtf/cheeze/sbt/utils/Version.java @@ -20,12 +20,12 @@ import dev.isxander.yacl3.api.NameableEnum; import dev.isxander.yacl3.api.Option; -import dev.isxander.yacl3.api.OptionDescription; import dev.isxander.yacl3.api.controller.EnumControllerBuilder; import net.minecraft.text.Text; import wtf.cheeze.sbt.config.ConfigImpl; import wtf.cheeze.sbt.config.categories.General; +import java.util.Map; import java.util.regex.Pattern; public class Version { @@ -105,25 +105,17 @@ public String getVersionString() { return String.format("%d.%d.%d", MAJOR, MINOR, PATCH); } } + public static class RemoteVersionFile { - // This can be disabled in the remote file in case of a bug public boolean enabled; - // Latest Alpha is not necessarily the latest build with on the alpha stream, it is the latest build that someone with their notifier set on alpha will get notified about, so it could be alpha, beta or release. - public RemoteVersion latestAlpha; - // Like latest alpha, latest beta could be beta or release. - public RemoteVersion latestBeta; - // Latest release is the latest build that is on the release stream. - public RemoteVersion latestRelease; - - + public Map latestAlpha; + public Map latestBeta; + public Map latestRelease; } public static class RemoteVersion { public String versionString; - // The names that the build has on modrinth, used to generate the links to the modrinth page for the builds - // https://modrinth.com/mod/sbt/version/${version} public String modrinthName; - } public static enum VersionComparison { diff --git a/src/main/java/wtf/cheeze/sbt/utils/actionbar/ActionBarTransformer.java b/src/main/java/wtf/cheeze/sbt/utils/actionbar/ActionBarTransformer.java index 9e0e492..ba13490 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/actionbar/ActionBarTransformer.java +++ b/src/main/java/wtf/cheeze/sbt/utils/actionbar/ActionBarTransformer.java @@ -66,13 +66,13 @@ public static ActionBarData extractDataAndRunTransformation(String actionBarText try { ActionBarData data = new ActionBarData(); String[] parts = actionBarText.split(SEPERATOR3); - String newText = ""; + StringBuilder newText = new StringBuilder(); for (String part : parts) { String unpadded = part.trim(); String segment = TextUtils.removeColorCodes(unpadded); if (segment.toLowerCase().contains("race")) { // Races, we do these first because the timer updates an obscene amount - newText += unpadded + SEPERATOR12; + newText.append(unpadded).append(SEPERATOR12); } else if (segment.contains("❤")) { // Health if (segment.contains("+")) { @@ -81,9 +81,9 @@ public static ActionBarData extractDataAndRunTransformation(String actionBarText data.currentHealth = Float.parseFloat(health[0].replace(",", "")); data.maxHealth = Float.parseFloat(health[1].replace(",", "")); if (!SBTConfig.get().actionBarFilters.hideHealth) { - newText += SEPERATOR5 + unpadded; + newText.append(SEPERATOR5).append(unpadded); } else { - newText += SEPERATOR5 + TextUtils.SECTION + "c" + "+" + segment.split("\\+")[1]; + newText.append(SEPERATOR5 + TextUtils.SECTION + "c" + "+").append(segment.split("\\+")[1]); } continue; } @@ -91,7 +91,7 @@ public static ActionBarData extractDataAndRunTransformation(String actionBarText data.currentHealth = Float.parseFloat(health[0].replace(",", "")); data.maxHealth = Float.parseFloat(health[1].replace(",", "")); if (!SBTConfig.get().actionBarFilters.hideHealth) { - newText += SEPERATOR5 + unpadded; + newText.append(SEPERATOR5).append(unpadded); } } else if (segment.contains("✎")) { @@ -109,16 +109,16 @@ public static ActionBarData extractDataAndRunTransformation(String actionBarText data.overflowMana = 0f; } if (!SBTConfig.get().actionBarFilters.hideMana) { - newText += SEPERATOR5 + unpadded; + newText.append(SEPERATOR5).append(unpadded); } } else if (segment.contains("NOT ENOUGH MANA")) { - newText += SEPERATOR5 + unpadded; + newText.append(SEPERATOR5).append(unpadded); } else if (segment.contains("❈")) { // Defense String defense = segment.split("❈")[0].trim(); data.defense = Integer.parseInt(defense.replace(",", "")); if (!SBTConfig.get().actionBarFilters.hideDefense) { - newText += SEPERATOR5 + unpadded; + newText.append(SEPERATOR5).append(unpadded); } } else if (segment.contains("Mana")) { @@ -127,11 +127,11 @@ public static ActionBarData extractDataAndRunTransformation(String actionBarText data.abilityManaCost = Integer.parseInt(matcher.group(1)); data.abilityName = matcher.group(2); if (!SBTConfig.get().actionBarFilters.hideAbilityUse) { - newText += SEPERATOR5 + unpadded; + newText.append(SEPERATOR5).append(unpadded); } continue; } - newText += SEPERATOR5 + unpadded; + newText.append(SEPERATOR5).append(unpadded); } else if (skillLevelPatern.matcher(segment).matches()) { Matcher matcher = skillLevelPatern.matcher(segment); @@ -148,10 +148,10 @@ public static ActionBarData extractDataAndRunTransformation(String actionBarText SkillHUDManager.INSTANCE.update(data.skillType, data.gainedXP, data.skillPercentage); } if (!SBTConfig.get().actionBarFilters.hideSkill) { - newText += SEPERATOR5 + unpadded; + newText.append(SEPERATOR5).append(unpadded); } } else { - newText += SEPERATOR5 + unpadded; + newText.append(SEPERATOR5).append(unpadded); } } else if (segment.contains("Secrets")) { Matcher matcher = secretsPattern.matcher(segment); @@ -160,7 +160,7 @@ public static ActionBarData extractDataAndRunTransformation(String actionBarText data.secretsTotal = Integer.parseInt(matcher.group(2)); } if (!SBTConfig.get().actionBarFilters.hideSecrets) { - newText += SEPERATOR5 + unpadded; + newText.append(SEPERATOR5).append(unpadded); } } else if (segment.contains("Drill Fuel")) { // Drill Fuel @@ -168,11 +168,11 @@ public static ActionBarData extractDataAndRunTransformation(String actionBarText data.drillFuel = Integer.parseInt(drillFuel[0].replace(",", "")); data.maxDrillFuel = NumberUtils.parseIntWithKorM(drillFuel[1]); if (!SBTConfig.get().actionBarFilters.hideDrill) { - newText += SEPERATOR5 + unpadded; + newText.append(SEPERATOR5).append(unpadded); } } else if (segment.contains("second") || segment.contains("DPS")) { // Trial of Fire - newText += SEPERATOR3 + unpadded; + newText.append(SEPERATOR3).append(unpadded); } else if (segment.contains("ⓩ") || segment.contains("Ⓞ")){ // Ornate/Florid: §e§lⓩⓩⓩ§6§lⓄⓄ // Regular: §a§lⓩ§2§lⓄⓄⓄ @@ -191,20 +191,22 @@ else if (unpadded.contains("§7§l")) { } if (!SBTConfig.get().actionBarFilters.hideTickers) { - newText += SEPERATOR4 + unpadded; + newText.append(SEPERATOR4).append(unpadded); } } else { - newText += SEPERATOR5 + unpadded; + newText.append(SEPERATOR5).append(unpadded); } } - newText = newText.trim(); - data.transformedText = newText; + + data.transformedText = newText.toString().trim(); return data; } catch (Exception e) { SkyblockTweaks.LOGGER.error("Error parsing action bar text: {}", actionBarText, e); SkyblockTweaks.LOGGER.warn("Some features may not work correctly. Please report this to MisterCheezeCake immediately."); - return new ActionBarData(); + var data = new ActionBarData(); + // data.transformedText = actionBarText; + return data; } } diff --git a/src/main/java/wtf/cheeze/sbt/utils/hud/HudLine.java b/src/main/java/wtf/cheeze/sbt/utils/hud/HudLine.java deleted file mode 100644 index 0b15bd0..0000000 --- a/src/main/java/wtf/cheeze/sbt/utils/hud/HudLine.java +++ /dev/null @@ -1,84 +0,0 @@ -package wtf.cheeze.sbt.utils.hud; - -import dev.isxander.yacl3.api.NameableEnum; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.text.Text; -import org.jetbrains.annotations.Nullable; -import wtf.cheeze.sbt.utils.render.RenderUtils; - -import java.util.function.Supplier; - -public class HudLine { - - public Supplier color; - public Supplier outlineColor; - public Supplier mode; - public Supplier text; - public Supplier useIcon; - - @Nullable - // Make sure not to create a new instance of HudIcon every time you call this - public Supplier icon; - - public HudLine(Supplier getColor, Supplier getOutlineColor, Supplier getMode, Supplier getText) { - this.color = getColor; - this.outlineColor = getOutlineColor; - this.text = getText; - this.mode = getMode; - this.useIcon = () -> false; - - } - - public HudLine(Supplier getColor, Supplier getOutlineColor, Supplier getMode, Supplier getText, Supplier icon, Supplier useIcon) { - this.color = getColor; - this.outlineColor = getOutlineColor; - this.text = getText; - this.mode = getMode; - this.icon = icon; - this.useIcon = useIcon; - } - - public void render(DrawContext context, int x, int y, float scale) { - - switch (mode.get()) { - case PURE: - render(context, x, y, scale, false); - break; - case SHADOW: - render(context, x, y, scale, true); - break; - case OUTLINE: - if (useIcon.get()) { - icon.get().render(context, (int) (x /scale), (int) (y /scale)); - RenderUtils.drawStringWithOutline(context, text.get(), x + (int) (10 * scale), y, color.get(), outlineColor.get(), scale, true); - } else { - RenderUtils.drawStringWithOutline(context, text.get(), x, y, color.get(), outlineColor.get(), scale, true); - } - } - } - - private void render(DrawContext context, int x, int y, float scale, boolean shadow) { - - if (useIcon.get()) { - int i = (int) (1 * scale); -// context.fill(x - i, y - i, x + RenderUtils.getStringWidth(text.get()) + 10, y + 9, 1694433280); - icon.get().render(context, (int) (x /scale), (int) (y /scale)); - RenderUtils.drawString(context, text.get(), x + (int) (10 * scale), y, color.get(), shadow, scale, true); - } else { - RenderUtils.drawString(context, text.get(), x, y, color.get(), shadow, scale, true); - } - } - - public int getWidth() { - return RenderUtils.getStringWidth(text.get()) + (useIcon.get() ? 10 : 0); - } - - public enum DrawMode implements NameableEnum { - PURE, SHADOW, OUTLINE; - @Override - public Text getDisplayName() { - return Text.literal(name()); - } - } - -} diff --git a/src/main/java/wtf/cheeze/sbt/utils/render/Color3f.java b/src/main/java/wtf/cheeze/sbt/utils/render/Color3f.java index 6ede567..a01e299 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/render/Color3f.java +++ b/src/main/java/wtf/cheeze/sbt/utils/render/Color3f.java @@ -19,7 +19,6 @@ package wtf.cheeze.sbt.utils.render; public class Color3f { - public float red; public float green; public float blue; @@ -29,4 +28,5 @@ public class Color3f { this.green = (float) (color >> 8 & 255) / 255.0F; this.blue = (float) (color & 255) / 255.0F; } + } diff --git a/src/main/java/wtf/cheeze/sbt/utils/render/Colors.java b/src/main/java/wtf/cheeze/sbt/utils/render/Colors.java new file mode 100644 index 0000000..cbf87e4 --- /dev/null +++ b/src/main/java/wtf/cheeze/sbt/utils/render/Colors.java @@ -0,0 +1,21 @@ +package wtf.cheeze.sbt.utils.render; + + +public class Colors { + + public static final int WHITE = 0xFFFFFFFF; + public static final int BLACK = 0xFF000000; + + public static final int BLUE = 0xFF5555FF; + public static final int RED = 0xFFFF5555; + public static final int ORANGE = 0xFFFFAA00; + public static final int GREEN = 0xFF00AA00; + public static final int CYAN = 0xFF00AAAA; + public static final int LIME = 0xFF55FF55; + + + + + + +} diff --git a/src/main/java/wtf/cheeze/sbt/utils/render/RenderUtils.java b/src/main/java/wtf/cheeze/sbt/utils/render/RenderUtils.java index 9933204..9ed26db 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/render/RenderUtils.java +++ b/src/main/java/wtf/cheeze/sbt/utils/render/RenderUtils.java @@ -20,7 +20,10 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.render.RenderLayer; +import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.text.Text; +import net.minecraft.util.Identifier; import wtf.cheeze.sbt.SkyblockTweaks; public class RenderUtils { @@ -33,37 +36,46 @@ public static void endScale(DrawContext context) { context.getMatrices().pop(); } - public static void drawString(DrawContext context, Text text, int x, int y, int color, boolean shadow, float scale) { + public static void drawText(DrawContext context, Text text, int x, int y, int color, boolean shadow, float scale) { beginScale(context, scale); - drawString(context, text, (int) (x/scale), (int) (y/scale), color, shadow); + drawText(context, text, (int) (x/scale), (int) (y/scale), color, shadow); endScale(context); } - public static void drawString(DrawContext context, Text text, int x, int y, int color, boolean shadow, float scale, boolean imHandlingTheScaleMyself) { - drawString(context, text, (int) (x/scale), (int) (y/scale), color, shadow); + public static void drawText(DrawContext context, Text text, int x, int y, int color, boolean shadow, float scale, boolean imHandlingTheScaleMyself) { + drawText(context, text, (int) (x/scale), (int) (y/scale), color, shadow); } - public static void drawString(DrawContext context, Text text, int x, int y, int color, boolean shadow) { + public static void drawText(DrawContext context, Text text, int x, int y, int color, boolean shadow) { context.drawText(SkyblockTweaks.mc.textRenderer, text, x, y, color, shadow); } - public static void drawStringWithOutline (DrawContext context, Text text, int x, int y, int color, int outlineColor) { + public static void drawTextWithOutline(DrawContext context, Text text, int x, int y, int color, int outlineColor) { // TODO: This currently renders weirdly, fix it - SkyblockTweaks.mc.textRenderer.drawWithOutline(text.asOrderedText(), x, y, color, outlineColor, context.getMatrices().peek().getPositionMatrix(), context.getVertexConsumers(), 15728880); - } - public static void drawStringWithOutline (DrawContext context, Text text, int x, int y, int color, int outlineColor, float scale) { + SkyblockTweaks.mc.textRenderer.drawWithOutline( + text.asOrderedText(), + x, y, color, outlineColor, + context.getMatrices().peek().getPositionMatrix(), + //? if =1.21.1 { + /*context.getVertexConsumers(), + *///?} else { + getVertexConsumers(context), + //?} + 15728880); + } + public static void drawTextWithOutline(DrawContext context, Text text, int x, int y, int color, int outlineColor, float scale) { beginScale(context, scale); - drawStringWithOutline(context, text, (int) (x/scale), (int) (y/scale), color, outlineColor); + drawTextWithOutline(context, text, (int) (x/scale), (int) (y/scale), color, outlineColor); endScale(context); } - public static void drawStringWithOutline (DrawContext context, Text text, int x, int y, int color, int outlineColor, float scale, boolean imHandlingTheScaleMyself) { - drawStringWithOutline(context, text, (int) (x/scale), (int) (y/scale), color, outlineColor); + public static void drawTextWithOutline(DrawContext context, Text text, int x, int y, int color, int outlineColor, float scale, boolean imHandlingTheScaleMyself) { + drawTextWithOutline(context, text, (int) (x/scale), (int) (y/scale), color, outlineColor); } - public static void drawCenteredString(DrawContext context, Text text, int x, int y, int color, boolean shadow, float scale) { + public static void drawCenteredText(DrawContext context, Text text, int x, int y, int color, boolean shadow, float scale) { int width = (int) (getStringWidth(text) * scale); - drawString(context, text, x - width / 2, y, color, shadow, scale); + drawText(context, text, x - width / 2, y, color, shadow, scale); } - public static void drawCenteredString(DrawContext context, Text text, int x, int y, int color, boolean shadow) { + public static void drawCenteredText(DrawContext context, Text text, int x, int y, int color, boolean shadow) { int width = getStringWidth(text); - drawString(context, text, x - width / 2, y, color, shadow); + drawText(context, text, x - width / 2, y, color, shadow); } public static int getStringWidth(Text text) { @@ -72,6 +84,7 @@ public static int getStringWidth(Text text) { public static int getStringWidth(String text) { return SkyblockTweaks.mc.textRenderer.getWidth(text); } + public static int getRelativeStringWidth(String text) { return (int) (SkyblockTweaks.mc.textRenderer.getWidth(text) / MinecraftClient.getInstance().getWindow().getScaledWidth()); } @@ -79,6 +92,27 @@ public static int getRelativeStringWidth(Text text) { return (int) (SkyblockTweaks.mc.textRenderer.getWidth(text) / MinecraftClient.getInstance().getWindow().getScaledWidth()); } + public static void drawTexture(DrawContext context, Identifier texture, int x, int y, int width, int height, int textureWidth, int textureHeight) { + //? if =1.21.1 { + /*context.drawTexture(texture, x, y, 0, 0, width, height, textureWidth, textureHeight); + *///?} else { + context.drawTexture(RenderLayer::getGuiTextured, texture, x, y, 0, 0, width, height, textureWidth, textureHeight); + //?} + } +// public static void drawTextureWithColor(DrawContext context, Identifier texture, int x, int y, int width, int height, int textureWidth, int textureHeight, int color) { +// //? if <1.21.1 { +// /*context.drawTexture(texture, x, y, 0, 0, width, height, textureWidth, textureHeight, color); +// *///?} else { +// context.drawTexture(RenderLayer::getGuiTextured, texture, x, y, 0, 0, width, height, textureWidth, textureHeight, color); +// //?} +// } + + //? if >=1.21.3 { + public static VertexConsumerProvider.Immediate getVertexConsumers(DrawContext context) { + return ((SBTDrawContext) context).sbt$getVertexConsumers(); + } + //?} + public static Color3f getColor3f(int color) { return new Color3f(color); } diff --git a/src/main/java/wtf/cheeze/sbt/utils/render/SBTDrawContext.java b/src/main/java/wtf/cheeze/sbt/utils/render/SBTDrawContext.java new file mode 100644 index 0000000..7d913d4 --- /dev/null +++ b/src/main/java/wtf/cheeze/sbt/utils/render/SBTDrawContext.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2024 MisterCheezeCake + * + * This file is part of SkyblockTweaks. + * + * SkyblockTweaks is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * SkyblockTweaks is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with SkyblockTweaks. If not, see . + */ +package wtf.cheeze.sbt.utils.render; + +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.text.Text; + +public interface SBTDrawContext { + int sbt$drawTextWithBackgroundNoShadow(TextRenderer textRenderer, Text text, int x, int y, int width, int color); + + /** + * You may ask yourself, "Why is this not an accessor?" The answer is that I really did not want to deal with mixins only existing on one version, and this works fine + */ + //? if <=1.21.3 + VertexConsumerProvider.Immediate sbt$getVertexConsumers(); +} diff --git a/src/main/java/wtf/cheeze/sbt/utils/render/ScreenBounds.java b/src/main/java/wtf/cheeze/sbt/utils/render/ScreenBounds.java index 842f8b1..9833494 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/render/ScreenBounds.java +++ b/src/main/java/wtf/cheeze/sbt/utils/render/ScreenBounds.java @@ -31,3 +31,5 @@ public class ScreenBounds { this.height = window.getScaledHeight(); } } + + diff --git a/src/main/java/wtf/cheeze/sbt/utils/skyblock/IconDict.java b/src/main/java/wtf/cheeze/sbt/utils/skyblock/IconDict.java index f40776f..ac13b1e 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/skyblock/IconDict.java +++ b/src/main/java/wtf/cheeze/sbt/utils/skyblock/IconDict.java @@ -19,7 +19,7 @@ package wtf.cheeze.sbt.utils.skyblock; import net.minecraft.util.Identifier; -import wtf.cheeze.sbt.utils.hud.HudIcon; +import wtf.cheeze.sbt.hud.HudIcon; import java.util.Map; @@ -48,4 +48,4 @@ private static Identifier ofItem(String name) { private static Identifier ofBlock(String name) { return Identifier.ofVanilla("textures/block/" + name + ".png"); } -} +} \ No newline at end of file diff --git a/src/main/java/wtf/cheeze/sbt/utils/skyblock/ProfileManager.java b/src/main/java/wtf/cheeze/sbt/utils/skyblock/ProfileManager.java index cd76e10..e996541 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/skyblock/ProfileManager.java +++ b/src/main/java/wtf/cheeze/sbt/utils/skyblock/ProfileManager.java @@ -40,21 +40,20 @@ public static void registerEvents() { var messageString = message.getString(); var matcher = ID_MESSAGE_PATTERN.matcher(messageString); if (matcher.find()) { - var id = matcher.group(1); - SkyblockTweaks.DATA.currentProfile = id; + SkyblockTweaks.DATA.currentProfile = matcher.group(1); SkyblockTweaks.PD.profiles.putIfAbsent(SkyblockTweaks.DATA.getCurrentProfileUnique(), new ProfileData()); SkyblockTweaks.PD.save(); return; } - var ss = TextUtils.removeColorCodes(messageString).trim(); - var mm = SKILL_LEVEL_UP_PATTERN.matcher(ss); - if (mm.find()) { - var skill = SkyblockUtils.strictCastStringToSkill(mm.group(1)); + var text = TextUtils.removeColorCodes(messageString).trim(); + var levelUpMatcher = SKILL_LEVEL_UP_PATTERN.matcher(text); + if (levelUpMatcher.find()) { + var skill = SkyblockUtils.strictCastStringToSkill(levelUpMatcher.group(1)); if (skill == null) return; var profile = SkyblockTweaks.PD.profiles.get(SkyblockTweaks.DATA.getCurrentProfileUnique()); if (profile == null) return; - var level = Integer.parseInt(mm.group(2)); + var level = Integer.parseInt(levelUpMatcher.group(2)); profile.skillLevels.put(skill, level); SkyblockTweaks.PD.save(); } diff --git a/src/main/java/wtf/cheeze/sbt/utils/skyblock/SkyblockConstants.java b/src/main/java/wtf/cheeze/sbt/utils/skyblock/SkyblockConstants.java index 4015c91..31bb24c 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/skyblock/SkyblockConstants.java +++ b/src/main/java/wtf/cheeze/sbt/utils/skyblock/SkyblockConstants.java @@ -950,7 +950,7 @@ public class SkyblockConstants { * Crop levels for carrot and potato */ public static final int[] CROP_LEVELS_CP = { - 100, + 100, 150, 250, 500, diff --git a/stonecutter.gradle.kts b/stonecutter.gradle.kts index 42894de..52091f2 100644 --- a/stonecutter.gradle.kts +++ b/stonecutter.gradle.kts @@ -1,9 +1,14 @@ plugins { id("dev.kikugie.stonecutter") } -stonecutter active "1.21.2" /* [SC] DO NOT EDIT */ +stonecutter active "1.21.3" /* [SC] DO NOT EDIT */ stonecutter registerChiseled tasks.register("chiseledBuild", stonecutter.chiseled) { group = "project" ofTask("build") -} \ No newline at end of file +} + +stonecutter registerChiseled tasks.register("chiseledRunClient", stonecutter.chiseled) { + group = "chiseled" + ofTask("runClient") +} diff --git a/versions/1.21.2/gradle.properties b/versions/1.21.2/gradle.properties deleted file mode 100644 index 155210e..0000000 --- a/versions/1.21.2/gradle.properties +++ /dev/null @@ -1,6 +0,0 @@ -minecraft_version=1.21.2 -fabric_version=0.106.1+1.21.2 -modmenu_version=11.0.3 -yacl_version=3.6.1+1.21-fabric -hmapi_version=1.0.1+1.21.1 -yarn_mappings=1.21.2+build.1 \ No newline at end of file diff --git a/versions/1.21.3/gradle.properties b/versions/1.21.3/gradle.properties new file mode 100644 index 0000000..969cc5e --- /dev/null +++ b/versions/1.21.3/gradle.properties @@ -0,0 +1,8 @@ +minecraft_version=1.21.3 +loader_version=0.16.9 +# Fabric API +fabric_version=0.107.0+1.21.3 +modmenu_version=12.0.0-beta.1 +yacl_version=3.6.1+1.21.2-fabric +hmapi_version=1.0.1+1.21.2 +yarn_mappings=1.21.2+build.1 \ No newline at end of file