add radar hud module
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package cc.fros.features.modules.hud;
|
||||
|
||||
import cc.fros.Fros;
|
||||
import cc.fros.event.impl.render.Render2DEvent;
|
||||
import cc.fros.features.modules.client.HudModule;
|
||||
import cc.fros.features.settings.Setting;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class RadarHudModule extends HudModule {
|
||||
public final Setting<Double> range = num("Range", 64.0, 8.0, 256.0);
|
||||
public final Setting<Integer> maxPlayers = num("MaxPlayers", 8, 1, 32);
|
||||
public final Setting<Boolean> showDistance = bool("Distance", true);
|
||||
|
||||
private record Entry(String name, double distance, boolean friend) {
|
||||
}
|
||||
|
||||
public RadarHudModule() {
|
||||
super("Radar", "Display players near you", 100, 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void render(Render2DEvent e) {
|
||||
super.render(e);
|
||||
|
||||
if (nullCheck()) return;
|
||||
|
||||
List<Entry> nearby = new ArrayList<>();
|
||||
for (Player player : mc.level.players()) {
|
||||
if (player == mc.player) continue;
|
||||
|
||||
double distance = mc.player.distanceTo(player);
|
||||
if (distance > range.getValue()) continue;
|
||||
|
||||
nearby.add(new Entry(player.getScoreboardName(), distance,
|
||||
Fros.friendManager.isFriend(player)));
|
||||
}
|
||||
|
||||
if (nearby.isEmpty()) return;
|
||||
|
||||
nearby.sort(Comparator.comparingDouble(Entry::distance));
|
||||
int limit = Math.min(nearby.size(), maxPlayers.getValue());
|
||||
nearby = nearby.subList(0, limit);
|
||||
|
||||
float x = getX();
|
||||
float y = getY();
|
||||
int lineHeight = mc.font.lineHeight;
|
||||
int widest = 0;
|
||||
|
||||
for (int i = 0; i < nearby.size(); i++) {
|
||||
Entry entry = nearby.get(i);
|
||||
String text = showDistance.getValue()
|
||||
? entry.name() + " " + (int) Math.round(entry.distance()) + "m"
|
||||
: entry.name();
|
||||
int color = entry.friend() ? 0xFF55FF55 : -1;
|
||||
|
||||
e.getContext().drawString(mc.font, text, (int) x, (int) (y + i * lineHeight), color);
|
||||
widest = Math.max(widest, mc.font.width(text));
|
||||
}
|
||||
|
||||
setWidth(widest);
|
||||
setHeight(lineHeight * nearby.size());
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import cc.fros.features.modules.combat.KeyPearlModule;
|
||||
import cc.fros.features.modules.hud.CoordinatesHudModule;
|
||||
import cc.fros.features.modules.hud.FpsHudModule;
|
||||
import cc.fros.features.modules.hud.PingHudModule;
|
||||
import cc.fros.features.modules.hud.RadarHudModule;
|
||||
import cc.fros.features.modules.hud.TimeHudModule;
|
||||
import cc.fros.features.modules.hud.WelcomerHudModule;
|
||||
import cc.fros.features.modules.hud.WatermarkHudModule;
|
||||
@@ -51,6 +52,7 @@ public class ModuleManager implements Jsonable, Util {
|
||||
register(new CoordinatesHudModule());
|
||||
register(new FpsHudModule());
|
||||
register(new PingHudModule());
|
||||
register(new RadarHudModule());
|
||||
register(new WelcomerHudModule());
|
||||
register(new TimeHudModule());
|
||||
register(new HudEditorModule());
|
||||
|
||||
Reference in New Issue
Block a user