Archive incari-client (client, 26.3, clean)

This commit is contained in:
2026-11-28 00:54:38 -06:00
parent 7a6174687f
commit 12838e838c
2383 changed files with 280266 additions and 0 deletions
@@ -0,0 +1,26 @@
# minimap: Minimap
A live map of the loaded world around you, round or square, turning with you or north-up, with waypoints, compass letters and coordinates. In the Nether it shows a slice at your height.
**M** opens the world map: drag, zoom, see waypoints (click to edit, right-click to add). With **Remember explored map** on, land you've seen is kept per world and dimension (`incari/map/`).
[ADR 0051](../../docs/adr/0051-minimap-and-waypoints.md).
| Setting | Kind | Default |
| --- | --- | --- |
| Shape | Round, Square | Round |
| Turn with you | on/off (off: north up, the arrow turns) | on |
| Zoom | 256, 192, 128, 96, 64, 48 or 32 blocks across | 96 |
| Zoom in key, Zoom out key | keybinds | =, - |
| World map key | keybind | M |
| Remember explored map | on/off | on |
| Show waypoints | on/off | on |
| Compass letters | on/off | on |
| Coordinates | on/off | on |
| HUD: Map | position and scale | top right, 1x |
The game's effect icons, also top right, move down below the map (and anything else of Incari's in their place) rather than over it (`ModuleSystem.effectIconsShift`, hooked in `Hud.extractEffects`).
```sh
./gradlew :features:minimap:check
```
@@ -0,0 +1,16 @@
plugins {
`java-library`
}
// Minimap (ADR 0051): the loaded world around the player from above, with the waypoints on it.
// A feature module: it sees the module framework and nothing else.
dependencies {
api(project(":framework"))
testImplementation(testFixtures(project(":framework")))
testImplementation(platform(libs.junit.bom))
testImplementation(libs.junit.jupiter)
testImplementation(libs.assertj)
testImplementation(libs.archunit)
testRuntimeOnly(libs.junit.launcher)
}
@@ -0,0 +1,213 @@
package incari.features.minimap;
import incari.features.minimap.Minimap.MapShape;
import incari.framework.game.PlayerView;
import incari.framework.hud.Anchor;
import incari.framework.hud.HudCanvas;
import incari.framework.hud.HudElement;
import incari.framework.hud.Shape;
import incari.framework.hud.Tone;
import incari.framework.waypoint.Waypoint;
import java.util.List;
import org.jspecify.annotations.Nullable;
/**
* The map on the HUD. Live ({@link #isLive()}): it turns and scrolls with the player every frame,
* which the HUD's few dozen refreshes a second would show as stutter. Nothing allocates while the
* player stays in a block; the coordinates' text is made again only when they move to another.
*/
final class MapElement extends HudElement {
/** The map's size, frame and all, in GUI units at scale 1. */
static final int SIZE = 96;
/** The frame's width around the terrain. */
static final int FRAME = 2;
/** A waypoint's icon on the map. */
static final float MARKER = 8;
/** A waypoint's icon beyond the map's edge, sitting on the edge. */
static final float MARKER_AT_EDGE = 6;
/** The player's arrow. */
static final float ARROW = 10;
/** The compass letters' badges' radius. */
static final float BADGE = 5.5F;
/** The gap between the map and the coordinates below it. */
static final int COORDINATES_GAP = 3;
private static final String[] LETTERS = {"N", "E", "S", "W"};
private final Minimap module;
private int shownX = Integer.MIN_VALUE;
private int shownY;
private int shownZ;
private String coordinates = "";
MapElement(Minimap module) {
super("map", "Map", Anchor.TOP_RIGHT, 4, 4);
this.module = module;
}
@Override
public boolean isLive() {
return true;
}
@Override
public boolean isVisible() {
return module.player() != null;
}
@Override
public int width(HudCanvas canvas) {
return SIZE;
}
@Override
public int height(HudCanvas canvas) {
return module.coordinates.get() ? SIZE + COORDINATES_GAP + canvas.lineHeight() + 3 : SIZE;
}
@Override
public void draw(HudCanvas canvas) {
PlayerView player = module.player();
boolean round = module.shape.get() == MapShape.ROUND;
float center = SIZE / 2.0F;
int inner = SIZE - 2 * FRAME;
float radius = inner / 2.0F;
// The frame, and the backdrop where nothing's loaded.
if (round) {
canvas.disc(center, center, center, Tone.BACKGROUND);
} else {
canvas.fill(0, 0, SIZE, SIZE, Tone.BACKGROUND);
}
float heading = player == null ? 0 : player.heading();
float rotation = module.turn.get() ? heading : 0;
int blocks = module.blocksAcross();
if (player != null) {
canvas.terrain(FRAME, FRAME, inner, round, player.x(), player.z(), blocks, rotation);
}
if (round) {
canvas.ring(center, center, center - 0.5F, 1, Tone.EDGE);
}
double radians = Math.toRadians(rotation);
float cos = (float) Math.cos(radians);
float sin = (float) Math.sin(radians);
if (player != null && module.showWaypoints.get()) {
drawWaypoints(canvas, player, center, radius, round, inner / (float) blocks, cos, sin);
}
canvas.shape(Shape.ARROW, center, center, ARROW, module.turn.get() ? 0 : heading, Tone.TEXT);
if (module.compass.get()) {
drawCompass(canvas, center, radius, round, cos, sin);
}
if (module.coordinates.get()) {
drawCoordinates(canvas, player);
}
}
/**
* Each of the dimension's shown waypoints at its place on the map; one beyond the edge on the
* edge, smaller, the way it lies.
*
* @param scale GUI units a block
*/
private void drawWaypoints(
HudCanvas canvas,
PlayerView player,
float center,
float radius,
boolean round,
float scale,
float cos,
float sin) {
List<Waypoint> all = module.waypoints().all();
float limit = radius - MARKER / 2;
for (int i = 0; i < all.size(); i++) {
Waypoint waypoint = all.get(i);
if (!waypoint.isVisible() || !waypoint.dimension().equals(player.dimension())) {
continue;
}
float dx = (float) (waypoint.x() + 0.5 - player.x());
float dz = (float) (waypoint.z() + 0.5 - player.z());
// East and south in the world, turned so the map's up is the rotation's bearing.
float x = (dx * cos + dz * sin) * scale;
float y = (-dx * sin + dz * cos) * scale;
float reach = round ? (float) Math.sqrt(x * x + y * y) : Math.max(Math.abs(x), Math.abs(y));
float size = MARKER;
if (reach > limit) {
x *= limit / reach;
y *= limit / reach;
size = MARKER_AT_EDGE;
}
canvas.shape(waypoint.icon(), center + x, center + y, size, 0, waypoint.argb());
}
}
/**
* N, E, S and W on badges on the frame, where each lies; north in the accent. Every badge, then
* every letter: drawn in turn, each letter would stack a layer above its badge, and each layer
* costs the GUI a draw call.
*/
private static void drawCompass(HudCanvas canvas, float center, float radius, boolean round, float cos, float sin) {
for (int pass = 0; pass < 2; pass++) {
for (int i = 0; i < LETTERS.length; i++) {
drawCompassPoint(canvas, i, pass == 0, center, radius, round, cos, sin);
}
}
}
/** Letter {@code i}'s badge, or the letter on it. */
private static void drawCompassPoint(
HudCanvas canvas, int i, boolean badge, float center, float radius, boolean round, float cos, float sin) {
// Bearing 0, 90, 180, 270 from north: east (1, 0), south (0, 1) in the world turned onto the map.
float wx = i == 1 ? 1 : i == 3 ? -1 : 0;
float wz = i == 0 ? -1 : i == 2 ? 1 : 0;
float x = wx * cos + wz * sin;
float y = -wx * sin + wz * cos;
float reach = round ? 1 : Math.max(Math.abs(x), Math.abs(y));
float at = radius - 1;
float bx = center + x / reach * at;
float by = center + y / reach * at;
if (badge) {
canvas.disc(bx, by, BADGE, Tone.BACKGROUND);
return;
}
String letter = LETTERS[i];
canvas.push(bx, by, 0.75F);
try {
canvas.text(
letter,
-Math.round(canvas.textWidth(letter) / 2.0F),
-canvas.lineHeight() / 2 + 1,
i == 0 ? Tone.ACCENT : Tone.TEXT);
} finally {
canvas.pop();
}
}
/** "x, y, z" of the player's block on a tag below the map; in the HUD editor without one, a sample. */
private void drawCoordinates(HudCanvas canvas, @Nullable PlayerView player) {
int x = player == null ? 0 : (int) Math.floor(player.x());
int y = player == null ? 64 : (int) Math.floor(player.y());
int z = player == null ? 0 : (int) Math.floor(player.z());
if (x != shownX || y != shownY || z != shownZ) {
shownX = x;
shownY = y;
shownZ = z;
coordinates = x + ", " + y + ", " + z;
}
int width = canvas.textWidth(coordinates) + 10;
int height = canvas.lineHeight() + 3;
int left = (SIZE - width) / 2;
int top = SIZE + COORDINATES_GAP;
canvas.fill(left, top, width, height, Tone.BACKGROUND);
canvas.text(coordinates, left + 5, top + 2, Tone.TEXT);
}
}
@@ -0,0 +1,123 @@
package incari.features.minimap;
import incari.framework.Category;
import incari.framework.Module;
import incari.framework.game.PlayerView;
import incari.framework.setting.BooleanSetting;
import incari.framework.setting.ChoiceSetting;
import incari.framework.setting.IntSetting;
import incari.framework.setting.Key;
import incari.framework.setting.KeySetting;
import incari.framework.waypoint.Waypoints;
import org.jspecify.annotations.Nullable;
/**
* Minimap: the loaded world around the player seen from above, in a round or square frame on the
* HUD, turning with them or with north up. The player is an arrow in the middle, the compass's
* letters ride the frame, and the world's waypoints are marked in their colors and shapes; one
* beyond the map's edge sits on the edge, the way it lies. The coordinates go below. A key opens
* the world map, which shows what the map has seen; with Remember explored map on, that's kept for
* each world, so it shows where the player has been on other days too.
*/
public final class Minimap extends Module {
/** The map's frame. */
public enum MapShape {
ROUND("Round"),
SQUARE("Square");
private final String label;
MapShape(String label) {
this.label = label;
}
/** What the settings screen calls it. */
public String label() {
return label;
}
}
/** How many blocks the map's width shows at each zoom, out to in. */
static final int[] ZOOMS = {256, 192, 128, 96, 64, 48, 32};
/** The zoom a new player starts at: 96 blocks, two thirds of a render distance of 8 in view. */
static final int DEFAULT_ZOOM = 4;
/** The = key, to zoom in. */
private static final int KEY_EQUALS = 46;
/** The - key, to zoom out. */
private static final int KEY_MINUS = 45;
/** M, for the map. */
private static final int KEY_M = 16;
final ChoiceSetting<MapShape> shape =
settings().choice("shape", "Shape", MapShape.values(), MapShape.ROUND, MapShape::label);
final BooleanSetting turn = settings()
.bool("turn", "Turn with you", true)
.describedAs("On: the way you face is up. Off: north is up and your arrow turns.");
final IntSetting zoom = settings()
.integer("zoom", "Zoom", 1, ZOOMS.length, DEFAULT_ZOOM)
.formattedAs(level -> blocksAcross(level) + " blocks across")
.describedAs("How much of the world the map shows.");
final KeySetting zoomIn =
settings().key("zoom-in", "Zoom in key", Key.keyboard(KEY_EQUALS)).onPress(() -> zoomBy(1));
final KeySetting zoomOut =
settings().key("zoom-out", "Zoom out key", Key.keyboard(KEY_MINUS)).onPress(() -> zoomBy(-1));
final KeySetting worldMap = settings()
.key("world-map", "World map key", Key.keyboard(KEY_M))
.describedAs("Opens the world map. Drag to move, scroll to zoom.")
.onPress(() -> system().game().openWorldMap());
final BooleanSetting remember = settings()
.bool("remember", "Remember explored map", true)
.describedAs("Keeps the land the map has seen, for each world, so the world map shows where you've been.");
final BooleanSetting showWaypoints = settings()
.bool("waypoints", "Show waypoints", true)
.describedAs("Marks this world's waypoints on the map.");
final BooleanSetting compass =
settings().bool("compass", "Compass letters", true).describedAs("N, E, S and W around the map's edge.");
final BooleanSetting coordinates =
settings().bool("coordinates", "Coordinates", true).describedAs("Where you stand, below the map.");
/** Minimap, off until the player turns it on. */
public Minimap() {
super("minimap", "Minimap", "A map of the world around you, with your waypoints on it.", Category.HUD);
hud(new MapElement(this));
remember.onChange(() -> {
if (isEnabled()) {
system().game().rememberMap(remember.get());
}
});
}
@Override
protected void onEnable() {
system().game().rememberMap(remember.get());
}
/** The player, or null outside a world. */
@Nullable
PlayerView player() {
return system().game().player();
}
/** The world's waypoints. */
Waypoints waypoints() {
return system().waypoints();
}
/** How many blocks the map's width shows now. */
int blocksAcross() {
return blocksAcross(zoom.get());
}
private static int blocksAcross(int level) {
return ZOOMS[Math.max(1, Math.min(ZOOMS.length, level)) - 1];
}
private void zoomBy(int steps) {
zoom.set(Math.max(1, Math.min(ZOOMS.length, zoom.get() + steps)));
}
}
@@ -0,0 +1,5 @@
/** Minimap (ADR 0051): the loaded world around the player from above, with the waypoints on it. */
@NullMarked
package incari.features.minimap;
import org.jspecify.annotations.NullMarked;
@@ -0,0 +1,20 @@
package incari.features.minimap;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import com.tngtech.archunit.core.importer.ImportOption;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;
/** A feature sees the module framework and the JDK's basics: no game, platform or other feature. */
@AnalyzeClasses(packages = "incari.features.minimap", importOptions = ImportOption.DoNotIncludeTests.class)
class BoundaryTest {
@ArchTest
static final ArchRule onlyTheFramework = classes()
.should()
.onlyDependOnClassesThat()
.resideInAnyPackage(
"java.lang..", "java.util..", "org.jspecify..", "incari.framework..", "incari.features.minimap..");
}
@@ -0,0 +1,157 @@
package incari.features.minimap;
import static org.assertj.core.api.Assertions.assertThat;
import incari.features.minimap.Minimap.MapShape;
import incari.framework.game.PlayerView;
import incari.framework.hud.Anchor;
import incari.framework.hud.HudElement;
import incari.framework.hud.Shape;
import incari.framework.testing.TestGame;
import incari.framework.waypoint.Waypoint;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class MinimapTest {
private final Minimap module = new Minimap();
private final TestGame game = new TestGame(module);
private final HudElement map = module.hudElements().get(0);
@BeforeEach
void atTheTopLeft() {
module.setEnabled(true);
map.anchor().set(Anchor.TOP_LEFT);
map.offsetX().set(0);
map.offsetY().set(0);
}
private List<String> drawn() {
return game.drawLive().drawn;
}
@Test
void liveAndOnlyInAWorld() {
assertThat(map.isLive()).isTrue();
assertThat(drawn()).isEmpty();
game.join();
assertThat(game.drawHud().drawn).isEmpty();
assertThat(drawn()).isNotEmpty();
}
@Test
void theGamesEffectIconsMoveBelowItInTheTopRight() {
map.resetPlacement();
game.join();
game.drawLive();
// At 4, 4 with the coordinates below: 111 tall, so the icons start a gap below 115.
assertThat(game.system().effectIconsShift(320, 240)).isEqualTo(116);
// Elsewhere, or once it's off, they keep their place.
map.anchor().set(Anchor.TOP_LEFT);
game.drawLive();
assertThat(game.system().effectIconsShift(320, 240)).isZero();
map.anchor().set(Anchor.TOP_RIGHT);
game.drawLive();
module.setEnabled(false);
assertThat(game.system().effectIconsShift(320, 240)).isZero();
}
@Test
void theTerrainTurnsWithThePlayer() {
game.join().at(100.5, 70, -30.25).facing(90);
assertThat(drawn())
.contains("terrain round 92 at 2,2 around 101,-30 96 blocks facing 90", "shape ARROW 10 at 48,48 TEXT");
module.turn.set(false);
assertThat(drawn())
.contains(
"terrain round 92 at 2,2 around 101,-30 96 blocks facing 0",
"shape ARROW 10 at 48,48 turned 90 TEXT");
}
@Test
void zoomKeysStepThroughTheZooms() {
game.join();
game.press(module.zoomIn.get());
game.tick();
assertThat(module.blocksAcross()).isEqualTo(64);
for (int i = 0; i < 10; i++) {
game.press(module.zoomOut.get());
game.tick();
}
assertThat(module.blocksAcross()).isEqualTo(256);
assertThat(module.zoom.format(module.zoom.get())).isEqualTo("256 blocks across");
}
@Test
void waypointsSitWhereTheyAreAndOnTheEdgeBeyondIt() {
module.turn.set(false);
module.zoom.set(5); // 64 blocks across 92 units
game.join().at(0.5, 64, 0.5);
Waypoints waypoints = new Waypoints(game);
waypoints.add("East", 16, 0, 0xFF0000, Shape.STAR);
waypoints.add("Far north", 0, -500, 0x00FF00, Shape.HEART);
waypoints.add("Hidden", 5, 5, 0, Shape.CIRCLE).setVisible(false);
List<String> drawn = drawn();
// 16 blocks east at 92/64 units a block: 23 units right of the middle.
assertThat(drawn).contains("shape STAR 8 at 71,48 #ffff0000");
// Beyond the edge: on it, straight up, smaller.
assertThat(drawn).contains("shape HEART 6 at 48,6 #ff00ff00");
assertThat(drawn).noneMatch(line -> line.startsWith("shape CIRCLE"));
module.showWaypoints.set(false);
assertThat(drawn()).noneMatch(line -> line.startsWith("shape STAR"));
}
@Test
void turnedWithThePlayerWhatTheyFaceIsUp() {
game.join().at(0.5, 64, 0.5).facing(90);
new Waypoints(game).add("East", 16, 0, 0xFF0000, Shape.STAR);
// Facing east: east is up.
assertThat(drawn()).anyMatch(line -> line.startsWith("shape STAR 8 at 48,"));
}
@Test
void compassLettersAndCoordinates() {
game.join().at(-12.5, 70.9, 300.1);
List<String> drawn = drawn();
assertThat(drawn).anyMatch(line -> line.startsWith("text \"N\"") && line.endsWith("ACCENT"));
assertThat(drawn).anyMatch(line -> line.startsWith("text \"S\"") && line.endsWith("TEXT"));
assertThat(drawn).anyMatch(line -> line.startsWith("text \"-13, 70, 300\""));
module.compass.set(false);
module.coordinates.set(false);
assertThat(drawn()).noneMatch(line -> line.startsWith("text"));
assertThat(map.height(game.drawLive())).isEqualTo(MapElement.SIZE);
}
@Test
void squareMapsHaveNoRing() {
module.shape.set(MapShape.SQUARE);
game.join();
assertThat(drawn())
.noneMatch(line -> line.startsWith("ring"))
.anyMatch(line -> line.startsWith("terrain square"));
}
/** Waypoints added to the test's world. */
private record Waypoints(TestGame game) {
Waypoint add(String name, int x, int z, int rgb, Shape icon) {
Waypoint waypoint = new Waypoint(name, x, 64, z, PlayerView.OVERWORLD, rgb, icon);
game.system().waypoints().add(waypoint);
return waypoint;
}
}
@Test
void theWorldMapKeyOpensItAndTheMapIsRememberedAsSet() {
game.join();
assertThat(game.rememberMap).isTrue();
game.press(module.worldMap.get());
game.tick();
assertThat(game.screens).containsExactly("worldmap");
module.remember.set(false);
assertThat(game.rememberMap).isFalse();
}
}