From 7b78e67b434e427b696a43a95b9bb6705da41ad8 Mon Sep 17 00:00:00 2001 From: bowser0000 Date: Tue, 7 Sep 2021 17:14:40 -0400 Subject: Make cooldown display work with mage cooldown reduction --- .../java/me/Danker/features/AbilityCooldowns.java | 73 ++++++++++++++++++---- 1 file changed, 61 insertions(+), 12 deletions(-) (limited to 'src/main/java/me/Danker/features/AbilityCooldowns.java') diff --git a/src/main/java/me/Danker/features/AbilityCooldowns.java b/src/main/java/me/Danker/features/AbilityCooldowns.java index ed6767e..397857a 100644 --- a/src/main/java/me/Danker/features/AbilityCooldowns.java +++ b/src/main/java/me/Danker/features/AbilityCooldowns.java @@ -2,45 +2,63 @@ package me.Danker.features; import me.Danker.commands.MoveCommand; import me.Danker.commands.ScaleCommand; +import me.Danker.commands.ToggleCommand; import me.Danker.events.RenderOverlayEvent; import me.Danker.handlers.TextRenderer; import me.Danker.utils.Utils; import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.gui.inventory.GuiChest; +import net.minecraft.inventory.ContainerChest; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StringUtils; import net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; import java.util.ArrayList; import java.util.List; public class AbilityCooldowns { - List cooldowns = new ArrayList<>(); + static List cooldowns = new ArrayList<>(); + static double mageReduction = 0D; @SubscribeEvent(priority = EventPriority.LOW) public void onChat(ClientChatReceivedEvent event) { - if (!Utils.inSkyblock || event.type != 2) return; + if (!Utils.inSkyblock || !ToggleCommand.abilityCooldowns) return; - String[] actionBarSections = StringUtils.stripControlCodes(event.message.getUnformattedText()).split(" {3,}"); + if (event.type == 2) { + String[] actionBarSections = StringUtils.stripControlCodes(event.message.getUnformattedText()).split(" {3,}"); - for (String section : actionBarSections) { - if (section.charAt(0) == '-' && section.contains("(") && section.charAt(section.length() - 1) == ')') { - String ability = section.substring(section.indexOf("(") + 1, section.length() - 1); + for (String section : actionBarSections) { + if (section.charAt(0) == '-' && section.contains("(") && section.charAt(section.length() - 1) == ')') { + String ability = section.substring(section.indexOf("(") + 1, section.length() - 1); - for (Ability cooldown : cooldowns) { - if (cooldown.ability.equals(ability)) return; + for (Ability cooldown : cooldowns) { + if (cooldown.ability.equals(ability)) return; + } + + cooldowns.add(new Ability(ability, Utils.getCooldownFromAbility(ability) * (1D - mageReduction))); } + } + } else { + String message = StringUtils.stripControlCodes(event.message.getUnformattedText()); - cooldowns.add(new Ability(ability, Utils.getCooldownFromAbility(ability))); + if (Utils.inDungeons && message.startsWith("[Mage] Cooldown Reduction ")) { + mageReduction = Integer.parseInt(message.substring(message.indexOf(">") + 2, message.length() - 1)) / 100D; } } } @SubscribeEvent public void renderPlayerInfo(RenderOverlayEvent event) { - if (Utils.inSkyblock) { + if (ToggleCommand.abilityCooldowns && Utils.inSkyblock) { StringBuilder sb = new StringBuilder(); for (int i = cooldowns.size() - 1; i >= 0; i--) { @@ -58,14 +76,45 @@ public class AbilityCooldowns { } } + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent event) { + if (event.phase != TickEvent.Phase.START) return; + + Minecraft mc = Minecraft.getMinecraft(); + EntityPlayerSP player = mc.thePlayer; + if (mc.currentScreen instanceof GuiChest) { + if (player == null) return; + ContainerChest chest = (ContainerChest) player.openContainer; + List invSlots = ((GuiChest) mc.currentScreen).inventorySlots.inventorySlots; + String chestName = chest.getLowerChestInventory().getDisplayName().getUnformattedText().trim(); + + if (ToggleCommand.abilityCooldowns && Utils.inDungeons && chestName.startsWith("Catacombs - ")) { + ItemStack mage = invSlots.get(30).getStack(); + if (mage == null || mage.getDisplayName() == null) return; + if (mage.isItemEnchanted()) { + String display = mage.getDisplayName(); + mageReduction = Utils.getCooldownReductionFromLevel(Integer.parseInt(display.substring(display.indexOf(" ") + 1, display.indexOf("]")))); + } else { + mageReduction = 0D; + } + } + } + } + + @SubscribeEvent + public void onWorldChange(WorldEvent.Load event) { + cooldowns.clear(); + mageReduction = 0D; + } + public static class Ability { public final String ability; private final long cooldown; - public Ability(String ability, int cooldown) { + public Ability(String ability, double cooldown) { this.ability = ability; - this.cooldown = System.currentTimeMillis() + cooldown * 1000L; + this.cooldown = (long) (System.currentTimeMillis() + cooldown * 1000L); } public String getTimer() { -- cgit