minecraft-src/net/minecraft/client/waypoints/ClientWaypointManager.java
2025-09-18 12:27:44 +00:00

42 lines
1.3 KiB
Java

package net.minecraft.client.waypoints;
import com.mojang.datafixers.util.Either;
import java.util.Comparator;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.waypoints.TrackedWaypoint;
import net.minecraft.world.waypoints.TrackedWaypointManager;
@Environment(EnvType.CLIENT)
public class ClientWaypointManager implements TrackedWaypointManager {
private final Map<Either<UUID, String>, TrackedWaypoint> waypoints = new ConcurrentHashMap();
public void trackWaypoint(TrackedWaypoint waypoint) {
this.waypoints.put(waypoint.id(), waypoint);
}
public void updateWaypoint(TrackedWaypoint waypoint) {
((TrackedWaypoint)this.waypoints.get(waypoint.id())).update(waypoint);
}
public void untrackWaypoint(TrackedWaypoint waypoint) {
this.waypoints.remove(waypoint.id());
}
public boolean hasWaypoints() {
return !this.waypoints.isEmpty();
}
public void forEachWaypoint(Entity entity, Consumer<TrackedWaypoint> action) {
this.waypoints
.values()
.stream()
.sorted(Comparator.comparingDouble(trackedWaypoint -> trackedWaypoint.distanceSquared(entity)).reversed())
.forEachOrdered(action);
}
}