Skip to content

Radar Overlays

RealDarkStudios edited this page Sep 8, 2025 · 7 revisions

Radar Overlays are used to render things on the radar. In this example, you will be creating an overlay like this that displays a gray dot at the location of storms.

You can view this example class here

To create a Radar Overlay, you first must create a class that implements IRadarOverlay In this example, I have created the ExampleOverlay class.

public class ExampleOverlay implements IRadarOverlay {
    @Override
    public static void render(RenderData renderData, BufferBuilder bufferBuilder, Object... args) {
        // Render code goes here
    }

    @Override
    public String getModID() {
        // Replace with your mod id
        return PMWeatherAPI.MODID + "_test";
    }
}

Next, we will write the actual code inside the render method:

@Override
public static void render(RenderData renderData, BufferBuilder bufferBuilder, Object... args) {
    BlockEntity blockEntity = renderData.blockEntity();
    BlockPos pos = blockEntity.getBlockPos();
    Storms.client().forStormNearBlock(pos, 2048,
        s -> renderStormMarker(bufferBuilder, s.position.add(-pos.getX(), -pos.getY(), -pos.getZ())));
}

If you plan on displaying information from Nearby Storms or Nearby Radars, use their #client() method

In this case, I am deferring the render call to a renderStormMarker method (and normalizing the position to be relative to the radar):

private static void renderStormMarker(BufferBuilder bufferBuilder, Vec3 relative) {
    float resolution = ClientConfig.radarResolution;
    Vector3f radarPos = relative.add(0.5, 0.5, 0.5).toVector3f().mul(3 / (2 * resolution)).div(2048, 0, 2048).div(1.0F / resolution, 0.0F, 1.0F / resolution);
    Vector3f topLeft = (new Vector3f(-1.0F, 0.0F, -1.0F)).mul(0.015F).add(radarPos.x, 0.005F, radarPos.z);
    Vector3f bottomLeft = (new Vector3f(-1.0F, 0.0F, 1.0F)).mul(0.015F).add(radarPos.x, 0.005F, radarPos.z);
    Vector3f bottomRight = (new Vector3f(1.0F, 0.0F, 1.0F)).mul(0.015F).add(radarPos.x, 0.005F, radarPos.z);
    Vector3f topRight = (new Vector3f(1.0F, 0.0F, -1.0F)).mul(0.015F).add(radarPos.x, 0.005F, radarPos.z);
    int color = 0xFF777777;
        
    bufferBuilder.addVertex(topLeft).setColor(color).addVertex(bottomLeft).setColor(color).addVertex(bottomRight).setColor(color).addVertex(topRight).setColor(color);
}

The actual rendering code for the dots mimics how PMWeather draws the red dot at the center of the radar.

There are also some utility methods available to use, such as #getRadarMode, #renderText, and #renderTexture.

Before your overlay renders onto the radar, you must create an IRadarOverlay instance:

// in ExampleOverlay.java
public static final ExampleOverlay INSTANCE = new ExampleOverlay();

And you must register it to RadarOverlays as such:

// preferably in a client initializer
RadarOverlays.registerOverlay(() -> ExampleOverlay.INSTANCE);

If you need to pass additional arguments to your overlay, you can add another argument with a Supplier<Object[]>:

RadarOverlays.registerOverlay(() -> ExampleOverlay.INSTANCE, () -> new Object[] {true, 1, 500.0f});

Your arguments will then be passed to your #render method

Viola! You have just created an overlay that will update on the radar!

Clone this wiki locally