diff options
| author | Kevin <92656833+kevinthegreat1@users.noreply.github.com> | 2024-07-26 15:15:12 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-26 15:15:12 +0800 |
| commit | 8288c1b0da604db3242dd848c3a66e0c7f0edc88 (patch) | |
| tree | 0f29c27291685e6974eebf8f683814f7c13af5ba /src/main/java/de/hysky/skyblocker/skyblock/dungeon | |
| parent | f53edcc01a94be3da0e83d2fc0fe4d13f58f13da (diff) | |
| parent | 8f27eb76273fe8424d44c2a1e08e45454e76b77c (diff) | |
| download | Skyblocker-8288c1b0da604db3242dd848c3a66e0c7f0edc88.tar.gz Skyblocker-8288c1b0da604db3242dd848c3a66e0c7f0edc88.tar.bz2 Skyblocker-8288c1b0da604db3242dd848c3a66e0c7f0edc88.zip | |
Merge pull request #812 from LifeIsAParadox/Quicknav-and-livid-fix
emi/rei, Quicknav, livid and nukekubi head (eman boss head) fix
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock/dungeon')
| -rw-r--r-- | src/main/java/de/hysky/skyblocker/skyblock/dungeon/LividColor.java | 95 |
1 files changed, 65 insertions, 30 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/LividColor.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/LividColor.java index 42810b60..b6a035aa 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/LividColor.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/LividColor.java @@ -1,23 +1,24 @@ package de.hysky.skyblocker.skyblock.dungeon; -import de.hysky.skyblocker.config.SkyblockerConfig; import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.config.configs.DungeonsConfig; import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager; import de.hysky.skyblocker.utils.Constants; import de.hysky.skyblocker.utils.Utils; import de.hysky.skyblocker.utils.scheduler.MessageScheduler; -import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.client.MinecraftClient; +import net.minecraft.entity.effect.StatusEffects; import net.minecraft.registry.Registries; import net.minecraft.text.MutableText; import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; import java.util.Map; -import java.util.Set; public class LividColor { private static final Map<Block, Formatting> WOOL_TO_FORMATTING = Map.of( @@ -42,39 +43,55 @@ public class LividColor { "Doctor Livid", Formatting.GRAY, "Vendetta Livid", Formatting.WHITE ); - public static final Set<String> LIVID_NAMES = Set.copyOf(LIVID_TO_FORMATTING.keySet()); public static final DungeonsConfig.Livid CONFIG = SkyblockerConfigManager.get().dungeons.livid; - private static int tenTicks = 0; - private static Formatting color; + private static Formatting color = Formatting.AQUA; + private static Block lastColor = Blocks.AIR; + + private static boolean isInitialized = false; + /** + * The correct livid may change color in M5, so we use the entity id to track the correct original livid. + */ + private static boolean correctLividIdFound = false; + private static int correctLividId = 0; + private static final long OFFSET_DURATION = 2000; + private static long toggleTime = 0; public static void init() { - ClientReceiveMessageEvents.GAME.register((message, overlay) -> { - DungeonsConfig.Livid config = SkyblockerConfigManager.get().dungeons.livid; - if ((config.enableLividColorText || config.enableLividColorTitle || config.enableLividColorGlow) && message.getString().equals("[BOSS] Livid: I respect you for making it to here, but I'll be your undoing.")) { - tenTicks = 8; - } - }); + ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> LividColor.reset()); + WorldRenderEvents.AFTER_ENTITIES.register(LividColor::update); } - public static void update() { + private static void update(WorldRenderContext context) { + DungeonsConfig.Livid config = SkyblockerConfigManager.get().dungeons.livid; + if (!(config.enableLividColorText || config.enableLividColorTitle || config.enableLividColorGlow || config.enableLividColorBoundingBox)) return; + MinecraftClient client = MinecraftClient.getInstance(); - if (tenTicks != 0) { - DungeonsConfig.Livid config = SkyblockerConfigManager.get().dungeons.livid; - if ((config.enableLividColorText || config.enableLividColorTitle || config.enableLividColorGlow) && Utils.isInDungeons() && client.world != null) { - if (tenTicks == 1) { - onLividColorFound(client, Blocks.RED_WOOL); - return; - } - Block color = client.world.getBlockState(new BlockPos(5, 110, 42)).getBlock(); - if (WOOL_TO_FORMATTING.containsKey(color) && !color.equals(Blocks.RED_WOOL)) { - onLividColorFound(client, color); - return; - } - tenTicks--; - } else { - tenTicks = 0; + + if (!(Utils.isInDungeons() && DungeonManager.isInBoss() && client.player != null && client.world != null)) return; + + Block currentColor = client.world.getBlockState(new BlockPos(5, 110, 42)).getBlock(); + if (!(WOOL_TO_FORMATTING.containsKey(currentColor) && !currentColor.equals(lastColor))) return; + + if (!isInitialized && client.player.hasStatusEffect(StatusEffects.BLINDNESS)) { + toggleTime = System.currentTimeMillis(); + isInitialized = true; + } else if (isInitialized && System.currentTimeMillis() - toggleTime >= OFFSET_DURATION) { + onLividColorFound(client, currentColor); + if (!correctLividIdFound) { + String lividName = LIVID_TO_FORMATTING.entrySet().stream() + .filter(entry -> entry.getValue() == color) + .map(Map.Entry::getKey) + .findFirst() + .orElse("unknown"); + client.world.getPlayers().stream() + .filter(entity -> entity.getName().getString().equals(lividName)) + .findFirst() + .ifPresent(entity -> correctLividId = entity.getId()); + correctLividIdFound = true; } + lastColor = currentColor; } + } private static void onLividColorFound(MinecraftClient client, Block color) { @@ -91,7 +108,6 @@ public class LividColor { client.inGameHud.setDefaultTitleFade(); client.inGameHud.setTitle(message); } - tenTicks = 0; } public static boolean allowGlow() { @@ -102,8 +118,27 @@ public class LividColor { return SkyblockerConfigManager.get().dungeons.livid.enableLividColorGlow && color == LIVID_TO_FORMATTING.get(name); } + public static boolean shouldDrawBoundingBox(String name) { + return SkyblockerConfigManager.get().dungeons.livid.enableLividColorBoundingBox && color == LIVID_TO_FORMATTING.get(name); + } + @SuppressWarnings("DataFlowIssue") public static int getGlowColor(String name) { - return LIVID_TO_FORMATTING.containsKey(name) ? LIVID_TO_FORMATTING.get(name).getColorValue() : Formatting.WHITE.getColorValue(); + if (SkyblockerConfigManager.get().dungeons.livid.enableSolidColor) return Formatting.RED.getColorValue(); + if (LIVID_TO_FORMATTING.containsKey(name)) return LIVID_TO_FORMATTING.get(name).getColorValue(); + return Formatting.WHITE.getColorValue(); + } + + public static int getCorrectLividId() { + return correctLividId; + } + + private static void reset() { + lastColor = Blocks.AIR; + toggleTime = 0; + isInitialized = false; + correctLividIdFound = false; + correctLividId = 0; + color = Formatting.AQUA; } } |
