| 1 | package nicotine.mod.mods.combat;
|
| 2 |
|
| 3 | import net.minecraft.ChatFormatting;
|
| 4 | import net.minecraft.client.player.AbstractClientPlayer;
|
| 5 | import net.minecraft.network.chat.Component;
|
| 6 | import net.minecraft.sounds.SoundEvents;
|
| 7 | import net.minecraft.sounds.SoundSource;
|
| 8 | import nicotine.events.ClientLevelTickEvent;
|
| 9 | import nicotine.events.ConnectEvent;
|
| 10 | import nicotine.events.TotemPopEvent;
|
| 11 | import nicotine.mod.Mod;
|
| 12 | import nicotine.mod.ModCategory;
|
| 13 | import nicotine.mod.ModManager;
|
| 14 | import nicotine.mod.option.ToggleOption;
|
| 15 | import nicotine.util.CombatToast;
|
| 16 | import nicotine.util.EventBus;
|
| 17 | import nicotine.util.Message;
|
| 18 |
|
| 19 | import java.util.ArrayList;
|
| 20 | import java.util.Arrays;
|
| 21 | import java.util.List;
|
| 22 |
|
| 23 | import static nicotine.util.Common.mc;
|
| 24 | import static nicotine.util.Common.totemPopCounter;
|
| 25 |
|
| 26 | public class CombatNotif extends Mod {
|
| 27 |
|
| 28 | private List<AbstractClientPlayer> prevPlayers = new ArrayList<>();
|
| 29 |
|
| 30 | private final ToggleOption poppedTotems = new ToggleOption("PoppedTotems");
|
| 31 | private final ToggleOption enterDistance = new ToggleOption("EnterDistance");
|
| 32 | private final ToggleOption toastNotif = new ToggleOption("ToastNotif");
|
| 33 | private final ToggleOption playSound = new ToggleOption("PlaySound");
|
| 34 |
|
| 35 | public CombatNotif() {
|
| 36 | super(ModCategory.Combat, "CombatNotif");
|
| 37 | this.addOptions(Arrays.asList(poppedTotems, enterDistance, toastNotif, playSound));
|
| 38 | }
|
| 39 |
|
| 40 | @Override
|
| 41 | protected void init() {
|
| 42 | EventBus.register(TotemPopEvent.class, event -> {
|
| 43 | int totemCount = totemPopCounter.getOrDefault(event.player, 0) + 1;
|
| 44 | totemPopCounter.put(event.player, totemCount);
|
| 45 |
|
| 46 | if (!this.enabled || !poppedTotems.enabled)
|
| 47 | return true;
|
| 48 |
|
| 49 |
|
| 50 | if (event.player == mc.player) {
|
| 51 | Message.sendWarning(String.format("Popped a totem [%d]", totemCount));
|
| 52 | } else {
|
| 53 | Message.sendInfo(String.format("%s popped a totem [%d]", event.player.getName().getString(), totemCount));
|
| 54 | }
|
| 55 |
|
| 56 | if (toastNotif.enabled) {
|
| 57 | mc.gui.toastManager().clear();
|
| 58 | mc.gui.toastManager().addToast(new CombatToast(Component.literal(String.format("Popped a totem [%s%d%s]", ChatFormatting.DARK_PURPLE, totemCount, ChatFormatting.RESET)), event.player));
|
| 59 | }
|
| 60 |
|
| 61 | return true;
|
| 62 | });
|
| 63 |
|
| 64 | EventBus.register(ClientLevelTickEvent.class, event -> {
|
| 65 | if (this.enabled && enterDistance.enabled) {
|
| 66 | for (AbstractClientPlayer player : mc.level.players()) {
|
| 67 | if (mc.player == player)
|
| 68 | continue;
|
| 69 |
|
| 70 | if (!prevPlayers.contains(player)) {
|
| 71 | Message.sendInfo(String.format("%s entered your render distance", player.getName().getString()));
|
| 72 |
|
| 73 | if (toastNotif.enabled) {
|
| 74 | mc.gui.toastManager().addToast(new CombatToast(Component.literal("In render distance"), player));
|
| 75 | }
|
| 76 |
|
| 77 | if (playSound.enabled)
|
| 78 | mc.level.playLocalSound(mc.player.blockPosition(), SoundEvents.PLAYER_LEVELUP, SoundSource.PLAYERS, 1.0f, 1.0f, false);
|
| 79 | }
|
| 80 | }
|
| 81 |
|
| 82 | prevPlayers.clear();
|
| 83 | prevPlayers.addAll(mc.level.players());
|
| 84 | }
|
| 85 |
|
| 86 | if (!totemPopCounter.isEmpty()) {
|
| 87 | for (AbstractClientPlayer player : totemPopCounter.keySet().stream().toList()) {
|
| 88 | if (!mc.level.players().contains(player) || player.isDeadOrDying()) {
|
| 89 | if (totemPopCounter.containsKey(player)) {
|
| 90 | totemPopCounter.remove(player);
|
| 91 | }
|
| 92 | }
|
| 93 | }
|
| 94 | }
|
| 95 |
|
| 96 | if (mc.player.isDeadOrDying()) {
|
| 97 | if (totemPopCounter.containsKey(mc.player)) {
|
| 98 | totemPopCounter.remove(mc.player);
|
| 99 | }
|
| 100 | }
|
| 101 |
|
| 102 |
|
| 103 | return true;
|
| 104 | });
|
| 105 |
|
| 106 | EventBus.register(ConnectEvent.class, event -> {
|
| 107 | totemPopCounter.clear();
|
| 108 | return true;
|
| 109 | });
|
| 110 | }
|
| 111 | }
|
| 112 |
|