| 1 | /*
|
| 2 | * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
|
| 3 | * Copyright (c) Meteor Development.
|
| 4 | */
|
| 5 |
|
| 6 | package meteordevelopment.meteorclient.systems.modules.render;
|
| 7 |
|
| 8 | import meteordevelopment.meteorclient.events.render.RenderBossBarEvent;
|
| 9 | import meteordevelopment.meteorclient.settings.BoolSetting;
|
| 10 | import meteordevelopment.meteorclient.settings.DoubleSetting;
|
| 11 | import meteordevelopment.meteorclient.settings.Setting;
|
| 12 | import meteordevelopment.meteorclient.settings.SettingGroup;
|
| 13 | import meteordevelopment.meteorclient.systems.modules.Categories;
|
| 14 | import meteordevelopment.meteorclient.systems.modules.Module;
|
| 15 | import meteordevelopment.orbit.EventHandler;
|
| 16 | import net.minecraft.client.gui.components.LerpingBossEvent;
|
| 17 | import net.minecraft.network.chat.Component;
|
| 18 |
|
| 19 | import java.util.HashMap;
|
| 20 | import java.util.Map;
|
| 21 | import java.util.WeakHashMap;
|
| 22 |
|
| 23 | public class BossStack extends Module {
|
| 24 | private final SettingGroup sgGeneral = settings.getDefaultGroup();
|
| 25 |
|
| 26 | public final Setting<Boolean> stack = sgGeneral.add(new BoolSetting.Builder()
|
| 27 | .name("stack")
|
| 28 | .description("Stacks boss bars and adds a counter to the text.")
|
| 29 | .defaultValue(true)
|
| 30 | .build()
|
| 31 | );
|
| 32 |
|
| 33 | public final Setting<Boolean> hideName = sgGeneral.add(new BoolSetting.Builder()
|
| 34 | .name("hide-name")
|
| 35 | .description("Hides the names of boss bars.")
|
| 36 | .defaultValue(false)
|
| 37 | .build()
|
| 38 | );
|
| 39 |
|
| 40 | private final Setting<Double> spacing = sgGeneral.add(new DoubleSetting.Builder()
|
| 41 | .name("bar-spacing")
|
| 42 | .description("The spacing reduction between each boss bar.")
|
| 43 | .defaultValue(10)
|
| 44 | .min(0)
|
| 45 | .build()
|
| 46 | );
|
| 47 |
|
| 48 | public static final Map<LerpingBossEvent, Integer> barMap = new WeakHashMap<>();
|
| 49 |
|
| 50 | public BossStack() {
|
| 51 | super(Categories.Render, "boss-stack", "Stacks boss bars to make your HUD less cluttered.");
|
| 52 | }
|
| 53 |
|
| 54 | @EventHandler
|
| 55 | private void onFetchText(RenderBossBarEvent.BossText event) {
|
| 56 | if (hideName.get()) {
|
| 57 | event.name = Component.empty();
|
| 58 | return;
|
| 59 | } else if (barMap.isEmpty() || !stack.get()) return;
|
| 60 | LerpingBossEvent bar = event.bossBar;
|
| 61 | Integer integer = barMap.get(bar);
|
| 62 | barMap.remove(bar);
|
| 63 | if (integer != null && !hideName.get()) event.name = event.name.copy().append(" x" + integer);
|
| 64 | }
|
| 65 |
|
| 66 | @EventHandler
|
| 67 | private void onSpaceBars(RenderBossBarEvent.BossSpacing event) {
|
| 68 | event.spacing = spacing.get().intValue();
|
| 69 | }
|
| 70 |
|
| 71 | @EventHandler
|
| 72 | private void onGetBars(RenderBossBarEvent.BossIterator event) {
|
| 73 | if (stack.get()) {
|
| 74 | HashMap<String, LerpingBossEvent> chosenBarMap = new HashMap<>();
|
| 75 | event.iterator.forEachRemaining(bar -> {
|
| 76 | String name = bar.getName().getString();
|
| 77 | if (chosenBarMap.containsKey(name)) {
|
| 78 | barMap.compute(chosenBarMap.get(name), (clientBossBar, integer) -> (integer == null) ? 2 : integer + 1);
|
| 79 | } else {
|
| 80 | chosenBarMap.put(name, bar);
|
| 81 | }
|
| 82 | });
|
| 83 | event.iterator = chosenBarMap.values().iterator();
|
| 84 | }
|
| 85 | }
|
| 86 | }
|
| 87 |
|