From 7c44258b9bf832b66ff2c212b58cd19507964910 Mon Sep 17 00:00:00 2001 From: froslanz Date: Thu, 22 Oct 2026 09:51:12 -0400 Subject: [PATCH] add VisualRange enter/exit notifications to Notifications uses the radar hud's Range setting so notifications match exactly what the radar shows --- .../modules/client/NotificationsModule.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/main/java/cc/fros/features/modules/client/NotificationsModule.java b/src/main/java/cc/fros/features/modules/client/NotificationsModule.java index 502759d..410ed95 100644 --- a/src/main/java/cc/fros/features/modules/client/NotificationsModule.java +++ b/src/main/java/cc/fros/features/modules/client/NotificationsModule.java @@ -1,11 +1,19 @@ package cc.fros.features.modules.client; +import cc.fros.Fros; import cc.fros.event.impl.ClientEvent; import cc.fros.event.system.Subscribe; import cc.fros.features.modules.Module; +import cc.fros.features.modules.hud.RadarHudModule; import cc.fros.features.settings.Setting; import cc.fros.util.TextUtil; import cc.fros.util.chat.ChatUtil; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.world.entity.player.Player; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; import static cc.fros.util.chat.SimpleSignature.from; @@ -13,6 +21,12 @@ public class NotificationsModule extends Module { private static final String MODULE_FORMAT = "{gray} %s %s%s"; public final Setting moduleToggle = bool("ModuleToggle", true); + public final Setting visualRange = bool("VisualRange", true); + + private final Map inRange = new HashMap<>(); + private ClientLevel lastLevel; + private RadarHudModule radar; + private boolean tracked; public NotificationsModule() { super("Notifications", "Displays notifications for various client events", Category.CLIENT); @@ -36,4 +50,57 @@ public class NotificationsModule extends Module { moduleState ? "{green}" : "{red}", moduleState ? "on" : "off"), from(event.getFeature().getName())); } + + @Override + public void onTick() { + if (!visualRange.getValue() || mc.player == null || mc.level == null) { + inRange.clear(); + tracked = false; + return; + } + + if (mc.level != lastLevel) { + // world change: re-baseline silently instead of notifying everyone present + lastLevel = mc.level; + tracked = false; + inRange.clear(); + } + + double range = getRadarRange(); + Map now = new HashMap<>(); + for (Player player : mc.level.players()) { + if (player == mc.player) continue; + if (mc.player.distanceTo(player) <= range) { + now.put(player.getUUID(), player.getScoreboardName()); + } + } + + if (tracked) { + for (Map.Entry entry : now.entrySet()) { + if (inRange.containsKey(entry.getKey())) continue; + notify(entry.getValue(), "{green}", "entered your visual range"); + } + for (Map.Entry entry : inRange.entrySet()) { + if (now.containsKey(entry.getKey())) continue; + notify(entry.getValue(), "{red}", "left your visual range"); + } + } + + inRange.clear(); + inRange.putAll(now); + tracked = true; + } + + private void notify(String name, String color, String message) { + ChatUtil.sendMessage(TextUtil.text(MODULE_FORMAT, + name, + color, + message), from(getName() + ":" + name)); + } + + private double getRadarRange() { + // stay in sync with what the radar hud actually shows + if (radar == null) radar = Fros.moduleManager.getModuleByClass(RadarHudModule.class); + return radar != null ? radar.range.getValue() : 64.0; + } }