diff options
author | Aaron <51387595+AzureAaron@users.noreply.github.com> | 2023-07-09 15:36:08 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-09 15:36:08 -0400 |
commit | 00983f7c455b65274e14dfc1611de7281f70a082 (patch) | |
tree | 4619093332d2a18e6faaa59f734d831a08521a24 /src | |
parent | 379cd758fb6895c4e88d7cb8245f79bde1494f34 (diff) | |
parent | 324248b4c44d10d3a2cf5412b4ff4beeaa5f681c (diff) | |
download | Skyblocker-00983f7c455b65274e14dfc1611de7281f70a082.tar.gz Skyblocker-00983f7c455b65274e14dfc1611de7281f70a082.tar.bz2 Skyblocker-00983f7c455b65274e14dfc1611de7281f70a082.zip |
Merge pull request #196 from Futuremappermydud/TitleContainer
Title container
Diffstat (limited to 'src')
16 files changed, 604 insertions, 33 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/SkyblockerMod.java b/src/main/java/me/xmrvizzy/skyblocker/SkyblockerMod.java index a629f851..4688d90f 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/SkyblockerMod.java +++ b/src/main/java/me/xmrvizzy/skyblocker/SkyblockerMod.java @@ -20,6 +20,7 @@ import me.xmrvizzy.skyblocker.skyblock.rift.TheRift; import me.xmrvizzy.skyblocker.skyblock.tabhud.TabHud; import me.xmrvizzy.skyblocker.skyblock.tabhud.util.PlayerListMgr; import me.xmrvizzy.skyblocker.utils.*; +import me.xmrvizzy.skyblocker.utils.title.TitleContainer; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.loader.api.FabricLoader; @@ -84,6 +85,7 @@ public class SkyblockerMod implements ClientModInitializer { TabHud.init(); DungeonMap.init(); TheRift.init(); + TitleContainer.init(); containerSolverManager.init(); scheduler.scheduleCyclic(Utils::update, 20); scheduler.scheduleCyclic(DiscordRPCManager::updateDataAndPresence, 100); diff --git a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java index 26e59b40..7da9979a 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java @@ -1,5 +1,6 @@ package me.xmrvizzy.skyblocker.config; +import com.mojang.brigadier.Command; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import me.shedaniel.autoconfig.AutoConfig; import me.shedaniel.autoconfig.ConfigData; @@ -10,8 +11,6 @@ import me.xmrvizzy.skyblocker.SkyblockerMod; import me.xmrvizzy.skyblocker.chat.ChatFilterResult; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.resource.language.I18n; import java.util.ArrayList; @@ -175,6 +174,11 @@ public class SkyblockerConfig implements ConfigData { @ConfigEntry.Gui.CollapsibleObject() public Hitbox hitbox = new Hitbox(); + @ConfigEntry.Gui.Tooltip() + @ConfigEntry.Category("titleContainer") + @ConfigEntry.Gui.CollapsibleObject() + public TitleContainer titleContainer = new TitleContainer(); + @ConfigEntry.Gui.Excluded public List<Integer> lockedSlots = new ArrayList<>(); } @@ -247,6 +251,45 @@ public class SkyblockerConfig implements ConfigData { public boolean oldLeverHitbox = false; } + public static class TitleContainer { + @ConfigEntry.BoundedDiscrete(min = 30, max = 140) + public float titleContainerScale = 100; + public int x = 540; + public int y = 10; + @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) + public Direction direction = Direction.HORIZONTAL; + @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.DROPDOWN) + public Alignment alignment = Alignment.MIDDLE; + } + + public enum Direction { + HORIZONTAL, + VERTICAL; + + @Override + public String toString() { + return switch (this) { + case HORIZONTAL -> "Horizontal"; + case VERTICAL -> "Vertical"; + }; + } + } + + public enum Alignment { + LEFT, + RIGHT, + MIDDLE; + + @Override + public String toString() { + return switch (this) { + case LEFT -> "Left"; + case RIGHT -> "Right"; + case MIDDLE -> "Middle"; + }; + } + } + public static class RichPresence { public boolean enableRichPresence = false; @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) @@ -399,6 +442,10 @@ public class SkyblockerConfig implements ConfigData { @ConfigEntry.BoundedDiscrete(min = 1, max = 10) @ConfigEntry.Gui.Tooltip() public int steakStakeUpdateFrequency = 5; + public boolean enableManiaIndicator = true; + @ConfigEntry.BoundedDiscrete(min = 1, max = 10) + @ConfigEntry.Gui.Tooltip() + public int maniaUpdateFrequency = 5; } public static class Messages { @@ -452,11 +499,8 @@ public class SkyblockerConfig implements ConfigData { private static LiteralArgumentBuilder<FabricClientCommandSource> optionsLiteral(String name) { return literal(name).executes(context -> { // Don't immediately open the next screen as it will be closed by ChatScreen right after this command is executed - SkyblockerMod.getInstance().scheduler.schedule(() -> { - Screen a = AutoConfig.getConfigScreen(SkyblockerConfig.class, null).get(); - MinecraftClient.getInstance().setScreen(a); - }, 0); - return 1; + SkyblockerMod.getInstance().scheduler.queueOpenScreen(AutoConfig.getConfigScreen(SkyblockerConfig.class, null)); + return Command.SINGLE_SUCCESS; }); } diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FishingHelper.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FishingHelper.java index 822b89d9..8dee3fcb 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FishingHelper.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FishingHelper.java @@ -2,6 +2,7 @@ package me.xmrvizzy.skyblocker.skyblock; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import me.xmrvizzy.skyblocker.utils.RenderHelper; +import me.xmrvizzy.skyblocker.utils.title.Title; import net.fabricmc.fabric.api.event.player.UseItemCallback; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; @@ -15,6 +16,7 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; public class FishingHelper { + private static final Title title = new Title("skyblocker.fishing.reelNow", Formatting.GREEN); private static long startTime; private static Vec3d normalYawVector; @@ -49,7 +51,7 @@ public class FishingHelper { if (player != null && player.fishHook != null) { Vec3d soundToFishHook = player.fishHook.getPos().subtract(packet.getX(), 0, packet.getZ()); if (Math.abs(normalYawVector.x * soundToFishHook.z - normalYawVector.z * soundToFishHook.x) < 0.2D && Math.abs(normalYawVector.dotProduct(soundToFishHook)) < 4D && player.getPos().squaredDistanceTo(packet.getX(), packet.getY(), packet.getZ()) > 1D) { - RenderHelper.displayTitleAndPlaySound(10, 5, "skyblocker.fishing.reelNow", Formatting.GREEN); + RenderHelper.displayInTitleContainerAndPlaySound(title, 10); reset(); } } else { diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/EffigyWaypoints.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/EffigyWaypoints.java index 0d44900a..7376c896 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/EffigyWaypoints.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/EffigyWaypoints.java @@ -32,7 +32,7 @@ public class EffigyWaypoints { ); private static final List<BlockPos> unBrokenEffigies = new ArrayList<>(); - public static void updateEffigies() { + protected static void updateEffigies() { if (!SkyblockerConfig.get().slayer.vampireSlayer.enableEffigyWaypoints || !Utils.isOnSkyblock() || !Utils.isInTheRift() || !Utils.getLocation().contains("Stillgore Château")) return; unBrokenEffigies.clear(); @@ -61,7 +61,7 @@ public class EffigyWaypoints { } } - public static void render(WorldRenderContext context) { + protected static void render(WorldRenderContext context) { if (SkyblockerConfig.get().slayer.vampireSlayer.enableEffigyWaypoints && Utils.getLocation().contains("Stillgore Château")) { for (BlockPos effigy : unBrokenEffigies) { float[] colorComponents = DyeColor.RED.getColorComponents(); diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/HealingMelonIndicator.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/HealingMelonIndicator.java index f98c17e7..fed34796 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/HealingMelonIndicator.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/HealingMelonIndicator.java @@ -3,19 +3,25 @@ package me.xmrvizzy.skyblocker.skyblock.rift; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import me.xmrvizzy.skyblocker.utils.RenderHelper; import me.xmrvizzy.skyblocker.utils.Utils; +import me.xmrvizzy.skyblocker.utils.title.Title; +import me.xmrvizzy.skyblocker.utils.title.TitleContainer; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.util.Formatting; public class HealingMelonIndicator { - private static long lastDisplayTime = 0; + private static final Title title = new Title("skyblocker.rift.healNow", Formatting.DARK_RED); public static void updateHealth(MinecraftClient client) { - if (!SkyblockerConfig.get().slayer.vampireSlayer.enableHealingMelonIndicator || !Utils.isOnSkyblock() || !Utils.isInTheRift() || !Utils.getLocation().contains("Stillgore Château")) return; + if (!SkyblockerConfig.get().slayer.vampireSlayer.enableHealingMelonIndicator || !Utils.isOnSkyblock() || !Utils.isInTheRift() || !Utils.getLocation().contains("Stillgore Château")) { + TitleContainer.removeTitle(title); + return; + } ClientPlayerEntity player = client.player; - if (player != null && player.getHealth() <= SkyblockerConfig.get().slayer.vampireSlayer.healingMelonHealthThreshold * 2F && System.currentTimeMillis() - lastDisplayTime > 2500) { - lastDisplayTime = System.currentTimeMillis(); - RenderHelper.displayTitleAndPlaySound(15, 5, "skyblocker.rift.healNow", Formatting.DARK_RED); + if (player != null && player.getHealth() <= SkyblockerConfig.get().slayer.vampireSlayer.healingMelonHealthThreshold * 2F) { + RenderHelper.displayInTitleContainerAndPlaySound(title); + } else { + TitleContainer.removeTitle(title); } } }
\ No newline at end of file diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/ManiaIndicator.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/ManiaIndicator.java new file mode 100644 index 00000000..38f6b018 --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/ManiaIndicator.java @@ -0,0 +1,42 @@ +package me.xmrvizzy.skyblocker.skyblock.rift; + +import me.xmrvizzy.skyblocker.config.SkyblockerConfig; +import me.xmrvizzy.skyblocker.utils.RenderHelper; +import me.xmrvizzy.skyblocker.utils.SlayerUtils; +import me.xmrvizzy.skyblocker.utils.Utils; +import me.xmrvizzy.skyblocker.utils.title.Title; +import me.xmrvizzy.skyblocker.utils.title.TitleContainer; +import net.minecraft.block.Blocks; +import net.minecraft.client.MinecraftClient; +import net.minecraft.entity.Entity; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import net.minecraft.util.math.BlockPos; + +public class ManiaIndicator { + private static final Title title = new Title("skyblocker.rift.mania", Formatting.RED); + + protected static void updateMania() { + if (!SkyblockerConfig.get().slayer.vampireSlayer.enableManiaIndicator || !Utils.isOnSkyblock() || !Utils.isInTheRift() || !(Utils.getLocation().contains("Stillgore Château")) || !SlayerUtils.isInSlayer()) { + TitleContainer.removeTitle(title); + return; + } + + Entity slayerEntity = SlayerUtils.getSlayerEntity(); + if (slayerEntity == null) return; + + boolean anyMania = false; + for (Entity entity : SlayerUtils.getEntityArmorStands(slayerEntity)) { + if (entity.getDisplayName().toString().contains("MANIA")) { + anyMania = true; + BlockPos pos = MinecraftClient.getInstance().player.getBlockPos().down(); + boolean isGreen = MinecraftClient.getInstance().world.getBlockState(pos).getBlock() == Blocks.GREEN_TERRACOTTA; + title.setText(Text.translatable("skyblocker.rift.mania").formatted(isGreen ? Formatting.GREEN : Formatting.RED)); + RenderHelper.displayInTitleContainerAndPlaySound(title); + } + } + if (!anyMania) { + TitleContainer.removeTitle(title); + } + } +}
\ No newline at end of file diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/MirrorverseWaypoints.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/MirrorverseWaypoints.java index 276ec551..32551179 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/MirrorverseWaypoints.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/MirrorverseWaypoints.java @@ -34,7 +34,7 @@ public class MirrorverseWaypoints { /** * Loads the waypoint locations into memory */ - public static void loadWaypoints() { + private static void loadWaypoints() { try (BufferedReader reader = CLIENT.getResourceManager().openAsReader(WAYPOINTS_JSON)) { JsonObject file = JsonParser.parseReader(reader).getAsJsonObject(); JsonArray sections = file.get("sections").getAsJsonArray(); @@ -69,7 +69,7 @@ public class MirrorverseWaypoints { } } - public static void render(WorldRenderContext wrc) { + protected static void render(WorldRenderContext wrc) { //I would also check for the mirrorverse location but the scoreboard stuff is not performant at all... if (Utils.isInTheRift() && SkyblockerConfig.get().locations.rift.mirrorverseWaypoints) { for (BlockPos pos : LAVA_PATH_WAYPOINTS) { diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/StakeIndicator.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/StakeIndicator.java index d1132be8..90fc436d 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/StakeIndicator.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/StakeIndicator.java @@ -4,18 +4,25 @@ import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import me.xmrvizzy.skyblocker.utils.RenderHelper; import me.xmrvizzy.skyblocker.utils.SlayerUtils; import me.xmrvizzy.skyblocker.utils.Utils; +import me.xmrvizzy.skyblocker.utils.title.Title; +import me.xmrvizzy.skyblocker.utils.title.TitleContainer; import net.minecraft.entity.Entity; +import net.minecraft.text.Text; import net.minecraft.util.Formatting; public class StakeIndicator { - private static long lastDisplayTime = 0; + private static final Title title = new Title("skyblocker.rift.stakeNow",Formatting.RED); - public static void updateStake() { - if (!SkyblockerConfig.get().slayer.vampireSlayer.enableSteakStakeIndicator || !Utils.isOnSkyblock() || !Utils.isInTheRift() || !Utils.getLocation().contains("Stillgore Château") || !SlayerUtils.isInSlayer()) return; + protected static void updateStake() { + if (!SkyblockerConfig.get().slayer.vampireSlayer.enableSteakStakeIndicator || !Utils.isOnSkyblock() || !Utils.isInTheRift() || !Utils.getLocation().contains("Stillgore Château") || !SlayerUtils.isInSlayer()) { + TitleContainer.removeTitle(title); + return; + } Entity slayerEntity = SlayerUtils.getSlayerEntity(); - if (slayerEntity != null && slayerEntity.getDisplayName().toString().contains("҉") && System.currentTimeMillis() - lastDisplayTime > 2500) { - lastDisplayTime = System.currentTimeMillis(); - RenderHelper.displayTitleAndPlaySound(25, 5, "skyblocker.rift.stakeNow", Formatting.RED); + if (slayerEntity != null && slayerEntity.getDisplayName().toString().contains("҉")) { + RenderHelper.displayInTitleContainerAndPlaySound(title); + } else { + TitleContainer.removeTitle(title); } } }
\ No newline at end of file diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/TheRift.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/TheRift.java index 91b727e2..5ca89dcf 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/TheRift.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/TheRift.java @@ -15,6 +15,7 @@ public class TheRift { WorldRenderEvents.AFTER_TRANSLUCENT.register(EffigyWaypoints::render); SkyblockerMod.getInstance().scheduler.scheduleCyclic(EffigyWaypoints::updateEffigies, SkyblockerConfig.get().slayer.vampireSlayer.effigyUpdateFrequency); SkyblockerMod.getInstance().scheduler.scheduleCyclic(TwinClawsIndicator::updateIce, SkyblockerConfig.get().slayer.vampireSlayer.holyIceUpdateFrequency); + SkyblockerMod.getInstance().scheduler.scheduleCyclic(ManiaIndicator::updateMania, SkyblockerConfig.get().slayer.vampireSlayer.maniaUpdateFrequency); SkyblockerMod.getInstance().scheduler.scheduleCyclic(StakeIndicator::updateStake, SkyblockerConfig.get().slayer.vampireSlayer.steakStakeUpdateFrequency); } } diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/TwinClawsIndicator.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/TwinClawsIndicator.java index 7e1d6605..f36b97df 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/TwinClawsIndicator.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/rift/TwinClawsIndicator.java @@ -5,28 +5,40 @@ import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import me.xmrvizzy.skyblocker.utils.RenderHelper; import me.xmrvizzy.skyblocker.utils.SlayerUtils; import me.xmrvizzy.skyblocker.utils.Utils; +import me.xmrvizzy.skyblocker.utils.title.Title; +import me.xmrvizzy.skyblocker.utils.title.TitleContainer; import net.minecraft.entity.Entity; +import net.minecraft.text.Text; import net.minecraft.util.Formatting; public class TwinClawsIndicator { - private static long lastDisplayTime = 0; + private static final Title title = new Title("skyblocker.rift.iceNow",Formatting.AQUA); + private static boolean scheduled = false; - public static void updateIce() { - if (!SkyblockerConfig.get().slayer.vampireSlayer.enableHolyIceIndicator || !Utils.isOnSkyblock() || !Utils.isInTheRift() || !(Utils.getLocation().contains("Stillgore Château")) || !SlayerUtils.isInSlayer()) return; + protected static void updateIce() { + if (!SkyblockerConfig.get().slayer.vampireSlayer.enableHolyIceIndicator || !Utils.isOnSkyblock() || !Utils.isInTheRift() || !(Utils.getLocation().contains("Stillgore Château")) || !SlayerUtils.isInSlayer()) { + TitleContainer.removeTitle(title); + return; + } Entity slayerEntity = SlayerUtils.getSlayerEntity(); if (slayerEntity == null) return; + boolean anyClaws = false; for (Entity entity : SlayerUtils.getEntityArmorStands(slayerEntity)) { if (entity.getDisplayName().toString().contains("TWINCLAWS")) { - SkyblockerMod.getInstance().scheduler.schedule(() -> { - if (System.currentTimeMillis() - lastDisplayTime > 2500) { - lastDisplayTime = System.currentTimeMillis(); - RenderHelper.displayTitleAndPlaySound(40, 5, "skyblocker.rift.iceNow", Formatting.AQUA); - } - }, SkyblockerConfig.get().slayer.vampireSlayer.holyIceIndicatorTickDelay); + anyClaws = true; + if (!TitleContainer.containsTitle(title) && !scheduled) { + scheduled = true; + SkyblockerMod.getInstance().scheduler.schedule(() -> { + RenderHelper.displayInTitleContainerAndPlaySound(title); + scheduled = false; + }, SkyblockerConfig.get().slayer.vampireSlayer.holyIceIndicatorTickDelay); + } } } - + if (!anyClaws) { + TitleContainer.removeTitle(title); + } } }
\ No newline at end of file diff --git a/src/main/java/me/xmrvizzy/skyblocker/utils/RenderHelper.java b/src/main/java/me/xmrvizzy/skyblocker/utils/RenderHelper.java index a7e1fc99..6fa93735 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/utils/RenderHelper.java +++ b/src/main/java/me/xmrvizzy/skyblocker/utils/RenderHelper.java @@ -2,6 +2,8 @@ package me.xmrvizzy.skyblocker.utils; import me.x150.renderer.render.Renderer3d; import me.xmrvizzy.skyblocker.mixin.accessor.BeaconBlockEntityRendererInvoker; +import me.xmrvizzy.skyblocker.utils.title.Title; +import me.xmrvizzy.skyblocker.utils.title.TitleContainer; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.block.entity.BeaconBlockEntityRenderer; @@ -51,6 +53,31 @@ public class RenderHelper { playNotificationSound(); } + /** + * Adds the title to {@link TitleContainer} and {@link #playNotificationSound() plays the notification sound} if the title is not in the {@link TitleContainer} already. + * No checking needs to be done on whether the title is in the {@link TitleContainer} already by the caller. + * + * @param title the title + */ + public static void displayInTitleContainerAndPlaySound(Title title) { + if (TitleContainer.addTitle(title)) { + playNotificationSound(); + } + } + + /** + * Adds the title to {@link TitleContainer} for a set number of ticks and {@link #playNotificationSound() plays the notification sound} if the title is not in the {@link TitleContainer} already. + * No checking needs to be done on whether the title is in the {@link TitleContainer} already by the caller. + * + * @param title the title + * @param ticks the number of ticks the title will remain + */ + public static void displayInTitleContainerAndPlaySound(Title title, int ticks) { + if (TitleContainer.addTitle(title, ticks)) { + playNotificationSound(); + } + } + private static void playNotificationSound() { if (MinecraftClient.getInstance().player != null) { MinecraftClient.getInstance().player.playSound(SoundEvent.of(new Identifier("entity.experience_orb.pickup")), 100f, 0.1f); diff --git a/src/main/java/me/xmrvizzy/skyblocker/utils/Scheduler.java b/src/main/java/me/xmrvizzy/skyblocker/utils/Scheduler.java index 02162140..7b19e284 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/utils/Scheduler.java +++ b/src/main/java/me/xmrvizzy/skyblocker/utils/Scheduler.java @@ -1,10 +1,13 @@ package me.xmrvizzy.skyblocker.utils; import me.xmrvizzy.skyblocker.SkyblockerMod; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.Screen; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.PriorityQueue; +import java.util.function.Supplier; /** * A scheduler for running tasks at a later time. Tasks will be run synchronously on the main client thread. Use the instance stored in {@link SkyblockerMod#scheduler}. Do not instantiate this class. @@ -50,6 +53,24 @@ public class Scheduler { } } + /** + * Schedules a screen to open in the next tick. Used in commands to avoid screen immediately closing after the command is executed. + * + * @param screenSupplier the supplier of the screen to open + */ + public void queueOpenScreen(Supplier<Screen> screenSupplier) { + queueOpenScreen(screenSupplier.get()); + } + + /** + * Schedules a screen to open in the next tick. Used in commands to avoid screen immediately closing after the command is executed. + * + * @param screen the supplier of the screen to open + */ + public void queueOpenScreen(Screen screen) { + MinecraftClient.getInstance().send(() -> MinecraftClient.getInstance().setScreen(screen)); + } + public void tick() { currentTick += 1; ScheduledTask task; diff --git a/src/main/java/me/xmrvizzy/skyblocker/utils/title/Title.java b/src/main/java/me/xmrvizzy/skyblocker/utils/title/Title.java new file mode 100644 index 00000000..0a3bc845 --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/utils/title/Title.java @@ -0,0 +1,53 @@ +package me.xmrvizzy.skyblocker.utils.title; + +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + +/** + * Represents a title used for {@link TitleContainer}. + * + * @see TitleContainer + */ +public class Title { + private MutableText text; + protected float x = -1; + protected float y = -1; + + /** + * Constructs a new title with the given translation key and formatting to be applied. + * + * @param textKey the translation key + * @param formatting the formatting to be applied to the text + */ + public Title(String textKey, Formatting formatting) { + this(Text.translatable(textKey).formatted(formatting)); + } + + /** + * Constructs a new title with the given {@link MutableText}. + * Use {@link Text#literal(String)} or {@link Text#translatable(String)} to create a {@link MutableText} + * + * @param text the mutable text + */ + public Title(MutableText text) { + this.text = text; + } + + public MutableText getText() { + return text; + } + + public void setText(MutableText text) { + this.text = text; + } + + protected boolean isDefaultPos() { + return x == -1 && y == -1; + } + + protected void resetPos() { + this.x = -1; + this.y = -1; + } +} diff --git a/src/main/java/me/xmrvizzy/skyblocker/utils/title/TitleContainer.java b/src/main/java/me/xmrvizzy/skyblocker/utils/title/TitleContainer.java new file mode 100644 index 00000000..a4e445ee --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/utils/title/TitleContainer.java @@ -0,0 +1,179 @@ +package me.xmrvizzy.skyblocker.utils.title; + +import com.mojang.brigadier.Command; +import me.xmrvizzy.skyblocker.SkyblockerMod; +import me.xmrvizzy.skyblocker.config.SkyblockerConfig; +import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; +import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; +import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.text.Text; +import net.minecraft.util.math.MathHelper; + +import java.util.LinkedHashSet; +import java.util.Set; + +public class TitleContainer { + /** + * The set of titles which will be rendered. + * + * @see #containsTitle(Title) + * @see #addTitle(Title) + * @see #addTitle(Title, int) + * @see #removeTitle(Title) + */ + private static final Set<Title> titles = new LinkedHashSet<>(); + + public static void init() { + HudRenderCallback.EVENT.register(TitleContainer::render); + ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal("skyblocker") + .then(ClientCommandManager.literal("hud") + .then(ClientCommandManager.literal("titleContainer") + .executes(context -> { + SkyblockerMod.getInstance().scheduler.queueOpenScreen(new TitleContainerConfigScreen(Text.of("Title Container HUD Config"))); + return Command.SINGLE_SUCCESS; + }))))); + } + + /** + * Returns {@code true} if the title is currently shown. + * + * @param title the title to check + * @return whether the title in currently shown + */ + public static boolean containsTitle(Title title) { + return titles.contains(title); + } + + /** + * Adds a title to be shown + * + * @param title the title to be shown + * @return whether the title is already currently being shown + */ + public static boolean addTitle(Title title) { + if (titles.add(title)) { + title.resetPos(); + return true; + } + return false; + } + + /** + * Adds a title to be shown for a set number of ticks + * + * @param title the title to be shown + * @param ticks the number of ticks to show the title + * @return whether the title is already currently being shown + */ + public static boolean addTitle(Title title, int ticks) { + if (addTitle(title)) { + SkyblockerMod.getInstance().scheduler.schedule(() -> TitleContainer.removeTitle(title), ticks); + return true; + } + return false; + } + + /** + * Stops showing a title + * + * @param title the title to stop showing + */ + public static void removeTitle(Title title) { + titles.remove(title); + } + + private static void render(DrawContext context, float tickDelta) { + render(context, titles, SkyblockerConfig.get().general.titleContainer.x, SkyblockerConfig.get().general.titleContainer.y, tickDelta); + } + + protected static void render(DrawContext context, Set<Title> titles, int xPos, int yPos, float tickDelta) { + var client = MinecraftClient.getInstance(); + TextRenderer textRenderer = client.textRenderer; + + // Calculate Scale to use + float scale = 3F * (SkyblockerConfig.get().general.titleContainer.titleContainerScale / 100F); + + // Grab direction and alignment values + SkyblockerConfig.Direction direction = SkyblockerConfig.get().general.titleContainer.direction; + SkyblockerConfig.Alignment alignment = SkyblockerConfig.get().general.titleContainer.alignment; + // x/y refer to the starting position for the text + // y always starts at yPos + float x = 0; + float y = yPos; + + //Calculate the width of combined text + float width = 0; + for (Title title : titles) { + width += textRenderer.getWidth(title.getText()) * scale + 10; + } + + if (alignment == SkyblockerConfig.Alignment.MIDDLE) { + if (direction == SkyblockerConfig.Direction.HORIZONTAL) { + //If middle aligned horizontally, start the xPosition at half of the width to the left. + x = xPos - (width / 2); + } else { + //If middle aligned vertically, start at xPos, we will shift each text to the left later + x = xPos; + } + } + if (alignment == SkyblockerConfig.Alignment.LEFT || alignment == SkyblockerConfig.Alignment.RIGHT) { + //If left or right aligned, start at xPos, we will shift each text later + x = xPos; + } + + for (Title title : titles) { + + //Calculate which x the text should use + float xToUse; + if (direction == SkyblockerConfig.Direction.HORIZONTAL) { + xToUse = alignment == SkyblockerConfig.Alignment.RIGHT ? + x - (textRenderer.getWidth(title.getText()) * scale) : //if right aligned we need the text position to be aligned on the right side. + x; + } else { + xToUse = alignment == SkyblockerConfig.Alignment.MIDDLE ? + x - (textRenderer.getWidth(title.getText()) * scale) / 2 : //if middle aligned we need the text position to be aligned in the middle. + alignment == SkyblockerConfig.Alignment.RIGHT ? + x - (textRenderer.getWidth(title.getText()) * scale) : //if right aligned we need the text position to be aligned on the right side. + x; + } + + //Start displaying the title at the correct position, not at the default position + if (title.isDefaultPos()) { + title.x = xToUse; + title.y = y; + } + + //Lerp the texts x and y variables + title.x = MathHelper.lerp(tickDelta * 0.5F, title.x, xToUse); + title.y = MathHelper.lerp(tickDelta * 0.5F, title.y, y); + + //Translate the matrix to the texts position and scale + context.getMatrices().push(); + context.getMatrices().translate(title.x, title.y, 200); + context.getMatrices().scale(scale, scale, scale); + + //Draw text + context.drawTextWithShadow(textRenderer, title.getText(), 0, 0, 0xFFFFFF); + context.getMatrices().pop(); + + //Calculate the x and y positions for the next title + if (direction == SkyblockerConfig.Direction.HORIZONTAL) { + if (alignment == SkyblockerConfig.Alignment.MIDDLE || alignment == SkyblockerConfig.Alignment.LEFT) { + //Move to the right if middle or left aligned + x += textRenderer.getWidth(title.getText()) * scale + 10; + } + + if (alignment == SkyblockerConfig.Alignment.RIGHT) { + //Move to the left if right aligned + x -= textRenderer.getWidth(title.getText()) * scale + 10; + } + } else { + //Y always moves by the same amount if vertical + y += textRenderer.fontHeight * scale + 10; + } + } + } +}
\ No newline at end of file diff --git a/src/main/java/me/xmrvizzy/skyblocker/utils/title/TitleContainerConfigScreen.java b/src/main/java/me/xmrvizzy/skyblocker/utils/title/TitleContainerConfigScreen.java new file mode 100644 index 00000000..e729ea15 --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/utils/title/TitleContainerConfigScreen.java @@ -0,0 +1,164 @@ +package me.xmrvizzy.skyblocker.utils.title; + +import me.shedaniel.autoconfig.AutoConfig; +import me.xmrvizzy.skyblocker.config.SkyblockerConfig; +import me.xmrvizzy.skyblocker.utils.RenderUtils; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.util.math.Vector2f; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import net.minecraft.util.Pair; +import org.lwjgl.glfw.GLFW; + +import java.awt.*; +import java.util.Set; + +public class TitleContainerConfigScreen extends Screen { + private final Title example1 = new Title(Text.literal("Test1").formatted(Formatting.RED)); + private final Title example2 = new Title(Text.literal("Test23").formatted(Formatting.AQUA)); + private final Title example3 = new Title(Text.literal("Testing1234").formatted(Formatting.DARK_GREEN)); + private float hudX = SkyblockerConfig.get().general.titleContainer.x; + private float hudY = SkyblockerConfig.get().general.titleContainer.y; + + protected TitleContainerConfigScreen(Text title) { + super(title); + } + + @Override + public void render(DrawContext context, int mouseX, int mouseY, float delta) { + super.render(context, mouseX, mouseY, delta); + renderBackground(context); + TitleContainer.render(context, Set.of(example1, example2, example3), (int) hudX, (int) hudY, delta); + SkyblockerConfig.Direction direction = SkyblockerConfig.get().general.titleContainer.direction; + SkyblockerConfig.Alignment alignment = SkyblockerConfig.get().general.titleContainer.alignment; + context.drawCenteredTextWithShadow(textRenderer, "Press Q/E to change Alignment: " + alignment, width / 2, textRenderer.fontHeight * 2, Color.WHITE.getRGB()); + context.drawCenteredTextWithShadow(textRenderer, "Press R to change Direction: " + direction, width / 2, textRenderer.fontHeight * 3 + 5, Color.WHITE.getRGB()); + context.drawCenteredTextWithShadow(textRenderer, "Press +/- to change Scale", width / 2, textRenderer.fontHeight * 4 + 10, Color.WHITE.getRGB()); + context.drawCenteredTextWithShadow(textRenderer, "Right Click To Reset Position", width / 2, textRenderer.fontHeight * 5 + 15, Color.GRAY.getRGB()); + + Pair<Vector2f, Vector2f> boundingBox = getSelectionBoundingBox(); + int x1 = (int) boundingBox.getLeft().getX(); + int y1 = (int) boundingBox.getLeft().getY(); + int x2 = (int) boundingBox.getRight().getX(); + int y2 = (int) boundingBox.getRight().getY(); + + context.drawHorizontalLine(x1, x2, y1, Color.RED.getRGB()); + context.drawHorizontalLine(x1, x2, y2, Color.RED.getRGB()); + context.drawVerticalLine(x1, y1, y2, Color.RED.getRGB()); + context.drawVerticalLine(x2, y1, y2, Color.RED.getRGB()); + } + + private Pair<Vector2f, Vector2f> getSelectionBoundingBox() { + SkyblockerConfig.Alignment alignment = SkyblockerConfig.get().general.titleContainer.alignment; + + float midWidth = getSelectionWidth() / 2F; + float x1 = 0; + float x2 = 0; + float y1 = hudY; + float y2 = hudY + getSelectionHeight(); + switch (alignment) { + case RIGHT -> { + x1 = hudX - midWidth * 2; + x2 = hudX; + } + case MIDDLE -> { + x1 = hudX - midWidth; + x2 = hudX + midWidth; + } + case LEFT -> { + x1 = hudX; + x2 = hudX + midWidth * 2; + } + } + return new Pair<>(new Vector2f(x1, y1), new Vector2f(x2, y2)); + } + + private float getSelectionHeight() { + float scale = (3F * (SkyblockerConfig.get().general.titleContainer.titleContainerScale / 100F)); + return SkyblockerConfig.get().general.titleContainer.direction == SkyblockerConfig.Direction.HORIZONTAL ? + (textRenderer.fontHeight * scale) : + (textRenderer.fontHeight + 10F) * 3F * scale; + } + + private float getSelectionWidth() { + float scale = (3F * (SkyblockerConfig.get().general.titleContainer.titleContainerScale / 100F)); + return SkyblockerConfig.get().general.titleContainer.direction == SkyblockerConfig.Direction.HORIZONTAL ? + (textRenderer.getWidth("Test1") + 10 + textRenderer.getWidth("Test23") + 10 + textRenderer.getWidth("Testing1234")) * scale : + textRenderer.getWidth("Testing1234") * scale; + } + + @Override + public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { + float midWidth = getSelectionWidth() / 2; + float midHeight = getSelectionHeight() / 2; + var alignment = SkyblockerConfig.get().general.titleContainer.alignment; + + Pair<Vector2f, Vector2f> boundingBox = getSelectionBoundingBox(); + float x1 = boundingBox.getLeft().getX(); + float y1 = boundingBox.getLeft().getY(); + float x2 = boundingBox.getRight().getX(); + float y2 = boundingBox.getRight().getY(); + + if (RenderUtils.pointExistsInArea((int) mouseX, (int) mouseY, (int) x1, (int) y1, (int) x2, (int) y2) && button == 0) { + hudX = switch (alignment) { + case LEFT -> (int) mouseX - midWidth; + case MIDDLE -> (int) mouseX; + case RIGHT -> (int) mouseX + midWidth; + }; + hudY = (int) (mouseY - midHeight); + } + return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (button == 1) { + hudX = (float) this.width / 2; + hudY = this.height * 0.6F; + } + return super.mouseClicked(mouseX, mouseY, button); + } + + @Override + public boolean keyPressed(int keyCode, int scanCode, int modifiers) { + if (keyCode == GLFW.GLFW_KEY_Q) { + SkyblockerConfig.Alignment current = SkyblockerConfig.get().general.titleContainer.alignment; + SkyblockerConfig.get().general.titleContainer.alignment = switch (current) { + case LEFT -> SkyblockerConfig.Alignment.MIDDLE; + case MIDDLE -> SkyblockerConfig.Alignment.RIGHT; + case RIGHT -> SkyblockerConfig.Alignment.LEFT; + }; + } + if (keyCode == GLFW.GLFW_KEY_E) { + SkyblockerConfig.Alignment current = SkyblockerConfig.get().general.titleContainer.alignment; + SkyblockerConfig.get().general.titleContainer.alignment = switch (current) { + case LEFT -> SkyblockerConfig.Alignment.RIGHT; + case MIDDLE -> SkyblockerConfig.Alignment.LEFT; + case RIGHT -> SkyblockerConfig.Alignment.MIDDLE; + }; + } + if (keyCode == GLFW.GLFW_KEY_R) { + SkyblockerConfig.Direction current = SkyblockerConfig.get().general.titleContainer.direction; + SkyblockerConfig.get().general.titleContainer.direction = switch (current) { + case HORIZONTAL -> SkyblockerConfig.Direction.VERTICAL; + case VERTICAL -> SkyblockerConfig.Direction.HORIZONTAL; + }; + } + if (keyCode == GLFW.GLFW_KEY_EQUAL) { + SkyblockerConfig.get().general.titleContainer.titleContainerScale += 10; + } + if (keyCode == GLFW.GLFW_KEY_MINUS) { + SkyblockerConfig.get().general.titleContainer.titleContainerScale -= 10; + } + return super.keyPressed(keyCode, scanCode, modifiers); + } + + @Override + public void close() { + SkyblockerConfig.get().general.titleContainer.x = (int) hudX; + SkyblockerConfig.get().general.titleContainer.y = (int) hudY; + AutoConfig.getConfigHolder(SkyblockerConfig.class).save(); + super.close(); + } +} diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 20c2c27f..dc3a6cf8 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -52,6 +52,13 @@ "text.autoconfig.skyblocker.option.general.hitbox": "Hitboxes", "text.autoconfig.skyblocker.option.general.hitbox.oldFarmlandHitbox": "Enable 1.8 farmland hitbox", "text.autoconfig.skyblocker.option.general.hitbox.oldLeverHitbox": "Enable 1.8 lever hitbox", + "text.autoconfig.skyblocker.option.general.titleContainer": "Title Container", + "text.autoconfig.skyblocker.option.general.titleContainer.@Tooltip": "Used to display multiple titles at once, Example use: Vampire Slayer", + "text.autoconfig.skyblocker.option.general.titleContainer.titleContainerScale": "Title Container Scale", + "text.autoconfig.skyblocker.option.general.titleContainer.x": "Title Container X Position", + "text.autoconfig.skyblocker.option.general.titleContainer.y": "Title Container Y Position", + "text.autoconfig.skyblocker.option.general.titleContainer.direction": "Title Container Orientation", + "text.autoconfig.skyblocker.option.general.titleContainer.alignment": "Title Container Horizontal Alignment", "skyblocker.itemTooltip.nullMessage": "§b[§6Skyblocker§b] §cItem price information on tooltip will renew in max 60 seconds. If not, check latest.log", "skyblocker.itemTooltip.noData": "§cNo Data", @@ -240,6 +247,9 @@ "text.autoconfig.skyblocker.option.slayer.vampireSlayer.enableSteakStakeIndicator": "Enable Steak Stake Indicator", "text.autoconfig.skyblocker.option.slayer.vampireSlayer.steakStakeUpdateFrequency": "Steak Stake Indicator Update Frequency (Ticks)", "text.autoconfig.skyblocker.option.slayer.vampireSlayer.steakStakeUpdateFrequency.@Tooltip": "The lower the value, the more frequent the updates, which may cause lag.", + "text.autoconfig.skyblocker.option.slayer.vampireSlayer.enableManiaIndicator": "Enable Mania Block Indicator", + "text.autoconfig.skyblocker.option.slayer.vampireSlayer.maniaUpdateFrequency": "Mania Indicator Update Frequency (Ticks)", + "text.autoconfig.skyblocker.option.slayer.vampireSlayer.maniaUpdateFrequency.@Tooltip": "The lower the value, the more frequent the updates, which may cause lag.", "skyblocker.update.update_message": "§b[§6Skyblocker§b] §2There is a new version available!", "skyblocker.update.update_link": " §2§nClick here§r", @@ -255,6 +265,7 @@ "skyblocker.fishing.reelNow": "Reel in now!", "skyblocker.rift.healNow": "Heal now!", "skyblocker.rift.iceNow": "Ice now!", + "skyblocker.rift.mania": "Mania!", "skyblocker.rift.stakeNow": "Stake now!", "skyblocker.fairySouls.markAllFound": "Marked all fairy souls in the current island as found", "skyblocker.fairySouls.markAllMissing": "Marked all fairy souls in the current island as missing" |