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
+28
View File
@@ -0,0 +1,28 @@
# features
One project per client feature (`features/<name>`, ADR 0046). Each is a `Module` from `:framework`.
- **Depend on `:framework` only.** Never the game, the platform or another feature; each feature has
a `BoundaryTest` saying so. If the framework can't tell or let you do something, add that to the
framework (its `AGENTS.md`), not a way around it.
- **Declare, don't wire.** Settings as fields (`settings().bool(...)`), HUD elements with `hud(...)`
and listeners with `on(...)` in the constructor. Never draw a settings screen: it's generated.
- **Colors by tone.** Draw HUD text and panels in a `Tone`; a fixed color only from a `ColorSetting`
the player chose. The theme decides the rest, so the client's restyle reaches every feature.
- **Hot paths don't allocate**: event listeners and `HudElement.draw`. Make strings once, keep
state in fields.
- **Ids are forever**: the module's, each setting's and each HUD element's are config keys.
- **Names and descriptions** are short and plain: a setting's description is one sentence, shown as
its tooltip.
- **Test with `TestGame`** (`:framework`'s test fixtures): enable the module, fire events, draw the
HUD on its recording canvas.
## Adding a feature
1. `features/<name>/build.gradle.kts` as `togglesprint`'s, and its sources under
`incari.features.<name>`, with a `BoundaryTest` and tests.
2. `include(":features:<name>")` in `settings.gradle.kts`; a `:features:<name> :framework` line in
`gradle/module-boundaries.txt`, and `:features:<name>` added to `:client`'s line there.
3. `implementation(project(":features:<name>"))` in `client/build.gradle.kts`, and the module in
`incari.client.modules.Features`.
4. `./gradlew :features:<name>:check`, then `./gradlew :client:strictCompile`.
+48
View File
@@ -0,0 +1,48 @@
# features
One client module per folder, each a `Module` built on `:framework` (ADR 0046). Every module but
Theme (always on) also has a **toggle key** setting, unbound by default, not repeated in each
README. How to write and add one: [`AGENTS.md`](AGENTS.md). **Rust** says whether the experimental
Rust build has it (ADR 0068, 0069): its settings and HUD are the Rust client's own
([`rust/mods/incari`](../rust/README.md)), its behaviour a mod in `rust/mods`.
| Module | Category | What it does | Rust |
| --- | --- | --- | --- |
| [1.7 Animations](oldanimations/README.md) | Visual | 1.7's block-hit swing and first-person poses | Ported |
| [Armor & Potion View](armorpotionview/README.md) | HUD | Armor durability and active effects | Ported |
| [Block Outline](blockoutline/README.md) | Visual | Your own block outline colour and width | Ported |
| [Clear Chat](clearchat/README.md) | HUD | No dark box behind chat | Ported |
| [Cooldown Indicator](cooldownindicator/README.md) | Combat | Attack cooldown as a bar, ring or percentage | Ported |
| [Coordinates](coordinates/README.md) | HUD | Position, facing, biome, other-dimension spot | Ported |
| [CPS](cps/README.md) | HUD | Clicks per second | Ported |
| [Crosshair Editor](crosshair/README.md) | Visual | A crosshair of your own design | Ported |
| [Custom Scoreboard](customscoreboard/README.md) | HUD | Place and scale the server's sidebar | Ported |
| [Custom Sky](customsky/README.md) | Visual | Resource packs' skies, OptiFine's format | Ported |
| [Enchant Glint](glintcolor/README.md) | Visual | Enchantment shimmer in your colour | Ported |
| [Fast Crystal](fastcrystal/README.md) | Combat | Crystals and anchors gone as you break them, not a ping later | Ported |
| [FPS Display](fpsdisplay/README.md) | HUD | Frames per second | Ported |
| [Freelook](freelook/README.md) | Visual | Look around without turning | Ported |
| [Fullbright](fullbright/README.md) | Visual | Caves and nights as light as day | Ported |
| [Hitboxes](hitboxes/README.md) | Combat | Entities' hitboxes in your color | Ported |
| [Hit & Kill Effects](hiteffects/README.md) | Combat | Particles on hits and kills | Ported |
| [Hit Color](hitcolor/README.md) | Visual | Hurt flash in your colour | Ported |
| [Keystrokes](keystrokes/README.md) | HUD | Keys and mouse buttons, lit while held | Ported |
| [Low Fire](lowfire/README.md) | Visual | Fire overlay drawn lower | Ported |
| [Low Shield](lowshield/README.md) | Visual | Shield drawn lower | Ported |
| [Minimap](minimap/README.md) | HUD | Live map, world map, remembered exploration | Ported |
| [No Hurt Cam](nohurtcam/README.md) | Visual | No camera tilt when hurt | Ported |
| [No Render](norender/README.md) | Visual | Hide items on the ground, XP orbs, particles | Ported |
| [Old Textures](oldtextures/README.md) | Visual | Programmer Art on and off | Ported |
| [Reach Display](reachdisplay/README.md) | Combat | Your last hit's reach | Ported |
| [Saturation](saturation/README.md) | HUD | Saturation shown on the hunger bar | Ported |
| [Schematics](schematics/README.md) | Utility | Ghost blocks of a schematic to build by | Ported |
| [Shield & Totem HUD](shieldtotem/README.md) | HUD | Shield durability and totem count | Ported |
| [Short Items](shortitems/README.md) | Visual | Smaller first-person held items | Ported |
| [Shulker Tooltips](shulkertooltips/README.md) | Utility | Shulker contents as a grid | Ported |
| [Theme Editor](theme/README.md) | Visual | Client colours and font (always on) | Ported |
| [Toggle Sprint](togglesprint/README.md) | Movement | Latch sprint and sneak | Ported |
| [Waypoints](waypoints/README.md) | Utility | Marked places over the world | Ported |
| [Weather Changer](weatherchanger/README.md) | Visual | Your own weather and time of day | Ported |
| [Zoom](zoom/README.md) | Visual | Hold C to zoom in, as OptiFine's | Ported |
Test one module with `./gradlew :features:<name>:check`.
@@ -0,0 +1,21 @@
# armorpotionview: Armor & Potion View
Two HUD elements: your armor and held item with durability (green, amber below half, red below a fifth), and your active effects with level and time left. The HUD editor shows a sample when there's nothing to show. ([ADR 0050](../../docs/adr/0050-first-modules-game-view.md))
| Setting | Kind | Default |
| --- | --- | --- |
| Show armor | on/off | on |
| Show held item | on/off | on |
| Durability | Percent, Uses left, Uses left of max, Bar only | Percent |
| Color by wear | on/off | on |
| Armor layout | Vertical, Horizontal | Vertical |
| Show effects | on/off | on |
| Effect names | on/off (off: icons and times) | on |
| Color by kind | on/off: helpful green, harmful red | off |
| Effect icons on the | Left, Right | Left |
| HUD: Armor | position and scale | bottom right, 1x |
| HUD: Effects | position and scale | top left, below Toggle Sprint's line and the FPS, CPS and reach readouts (y 62), 1x |
```sh
./gradlew :features:armorpotionview:check
```
@@ -0,0 +1,16 @@
plugins {
`java-library`
}
// Armor & Potion View (ADR 0050): armor, its durability and the active effects on the HUD.
// 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,192 @@
package incari.features.armorpotionview;
import incari.features.armorpotionview.ArmorPotionView.Durability;
import incari.features.armorpotionview.ArmorPotionView.Layout;
import incari.framework.game.EquipmentSlot;
import incari.framework.game.ItemView;
import incari.framework.game.PlayerView;
import incari.framework.hud.Anchor;
import incari.framework.hud.HudCanvas;
import incari.framework.hud.HudElement;
import incari.framework.hud.Tone;
import org.jspecify.annotations.Nullable;
/**
* The armor the player wears, helmet first, then what they hold: each item's icon with the game's
* durability bar, and its durability written beside it in the module's format.
*/
final class ArmorElement extends HudElement {
private static final EquipmentSlot[] ARMOR = {
EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET
};
private static final int ICON = 16;
/** Between an icon and its text. */
private static final int TEXT_GAP = 2;
/** Between rows (vertical) or cells (horizontal). */
private static final int ROW_GAP = 1;
private static final int CELL_GAP = 4;
private final ArmorPotionView module;
// This draw's rows, refilled without allocating each time the HUD asks.
private final ItemView[] items = new ItemView[ARMOR.length + 1];
private final @Nullable String[] texts = new String[ARMOR.length + 1];
// Each row's text, made again only when its numbers change.
private final int[] cachedDamage = new int[ARMOR.length + 1];
private final int[] cachedMax = new int[ARMOR.length + 1];
private final @Nullable Durability[] cachedFormat = new Durability[ARMOR.length + 1];
private final @Nullable String[] cachedText = new String[ARMOR.length + 1];
ArmorElement(ArmorPotionView module) {
super("armor", "Armor", Anchor.BOTTOM_RIGHT, 2, 2);
this.module = module;
}
@Override
public boolean isVisible() {
return module.showArmor.get() && collect(false) > 0;
}
@Override
public boolean isPlaceable() {
return module.showArmor.get();
}
@Override
public int width(HudCanvas canvas) {
int count = collect(canvas.editing());
if (module.layout.get() == Layout.HORIZONTAL) {
int width = 0;
for (int i = 0; i < count; i++) {
width += (i > 0 ? CELL_GAP : 0) + cellWidth(canvas, i);
}
return width;
}
int width = 0;
for (int i = 0; i < count; i++) {
width = Math.max(width, cellWidth(canvas, i));
}
return width;
}
@Override
public int height(HudCanvas canvas) {
int count = collect(canvas.editing());
if (count == 0) {
return 0;
}
return module.layout.get() == Layout.HORIZONTAL ? ICON : count * (ICON + ROW_GAP) - ROW_GAP;
}
@Override
public void draw(HudCanvas canvas) {
int count = collect(canvas.editing());
boolean horizontal = module.layout.get() == Layout.HORIZONTAL;
int textY = (ICON - canvas.lineHeight()) / 2 + 1;
int x = 0;
int y = 0;
for (int i = 0; i < count; i++) {
ItemView item = items[i];
canvas.item(item, x, y, true);
String text = texts[i];
if (text != null) {
canvas.text(text, x + ICON + TEXT_GAP, y + textY, tone(item));
}
if (horizontal) {
x += cellWidth(canvas, i) + CELL_GAP;
} else {
y += ICON + ROW_GAP;
}
}
}
private int cellWidth(HudCanvas canvas, int row) {
String text = texts[row];
return text == null ? ICON : ICON + TEXT_GAP + canvas.textWidth(text);
}
private Tone tone(ItemView item) {
if (!module.wearColors.get() || item.maxDamage() <= 0) {
return Tone.TEXT;
}
// Thresholds in whole numbers: remaining / max below a half, below a fifth.
long remaining = item.remaining();
long max = item.maxDamage();
if (remaining * 5 < max) {
return Tone.NEGATIVE;
}
return remaining * 2 < max ? Tone.WARNING : Tone.POSITIVE;
}
/**
* Fills this draw's rows from the player (the sample in the editor when the real player has
* nothing to show) and returns how many.
*/
private int collect(boolean editing) {
PlayerView player = module.player();
int rows = player == null ? 0 : fill(player);
return rows == 0 && editing ? fill(module.samplePlayer()) : rows;
}
private int fill(PlayerView player) {
int count = 0;
for (EquipmentSlot slot : ARMOR) {
ItemView item = player.item(slot);
if (!item.isEmpty()) {
count = add(count, item);
}
}
if (module.showHeld.get()) {
ItemView held = player.item(EquipmentSlot.MAINHAND);
if (!held.isEmpty()) {
count = add(count, held);
}
}
return count;
}
private int add(int row, ItemView item) {
items[row] = item;
// The bar alone: the icon carries it, nothing is written beside it.
texts[row] = item.isDamageable() && module.durability.get() != Durability.BAR ? text(row, item) : null;
return row + 1;
}
/** {@code item}'s durability in the module's format, made again only when it changed. */
private String text(int row, ItemView item) {
int damage = item.damage();
int max = item.maxDamage();
Durability format = module.durability.get();
String cached = cachedText[row];
if (cached != null && cachedDamage[row] == damage && cachedMax[row] == max && cachedFormat[row] == format) {
return cached;
}
String text = format(format, max - damage, max);
cachedDamage[row] = damage;
cachedMax[row] = max;
cachedFormat[row] = format;
cachedText[row] = text;
return text;
}
/** "86%", "312", "312/363", or nothing for the bar alone. */
static String format(Durability format, int remaining, int max) {
return switch (format) {
case PERCENT -> percent(remaining, max) + "%";
case REMAINING -> Integer.toString(remaining);
case REMAINING_OF_MAX -> remaining + "/" + max;
case BAR -> "";
};
}
/** Whole percent left, rounded down, but 1 while anything's left: 0% is broken. */
static int percent(int remaining, int max) {
if (max <= 0 || remaining <= 0) {
return 0;
}
return Math.max(1, (int) ((long) remaining * 100 / max));
}
}
@@ -0,0 +1,132 @@
package incari.features.armorpotionview;
import incari.framework.Category;
import incari.framework.Module;
import incari.framework.game.PlayerView;
import incari.framework.setting.BooleanSetting;
import incari.framework.setting.ChoiceSetting;
import org.jspecify.annotations.Nullable;
/**
* Armor &amp; Potion View: two HUD elements, placed apart. One shows the armor the player wears (and
* what they hold) with how worn each piece is, so a breaking helmet is seen before it breaks; the
* other lists the active effects with their levels and the time left.
*/
public final class ArmorPotionView extends Module {
/** How an item's durability is written beside it. */
public enum Durability {
/** "86%". */
PERCENT("Percent"),
/** "312": uses left. */
REMAINING("Uses left"),
/** "312/363". */
REMAINING_OF_MAX("Uses left of max"),
/** Nothing beside it: the game's bar on the icon only. */
BAR("Bar only");
private final String label;
Durability(String label) {
this.label = label;
}
/** What the settings screen calls it. */
public String label() {
return label;
}
}
/** Which way the armor runs. */
public enum Layout {
/** Helmet at the top, boots at the bottom. */
VERTICAL("Vertical"),
/** Helmet on the left, boots on the right. */
HORIZONTAL("Horizontal");
private final String label;
Layout(String label) {
this.label = label;
}
/** What the settings screen calls it. */
public String label() {
return label;
}
}
/** Which side of the effects' text their icons go. */
public enum Side {
/** Icons on the left, text after. */
LEFT("Left"),
/** Icons on the right, text before: for the screen's right side. */
RIGHT("Right");
private final String label;
Side(String label) {
this.label = label;
}
/** What the settings screen calls it. */
public String label() {
return label;
}
}
final BooleanSetting showArmor = settings()
.bool("show-armor", "Show armor", true)
.describedAs("Shows the armor you wear and its durability.");
final BooleanSetting showHeld = settings()
.bool("show-held", "Show held item", true)
.describedAs("Adds the item in your main hand below the armor.")
.visibleWhen(showArmor::get);
final ChoiceSetting<Durability> durability = settings()
.choice("durability", "Durability", Durability.values(), Durability.PERCENT, Durability::label)
.describedAs("How durability is shown beside each piece.")
.visibleWhen(showArmor::get);
final BooleanSetting wearColors = settings()
.bool("wear-colors", "Color by wear", true)
.describedAs("Durability turns amber below half and red below a fifth.")
.visibleWhen(() -> showArmor.get() && durability.get() != Durability.BAR);
final ChoiceSetting<Layout> layout = settings()
.choice("layout", "Armor layout", Layout.values(), Layout.VERTICAL, Layout::label)
.visibleWhen(showArmor::get);
final BooleanSetting showEffects = settings()
.bool("show-effects", "Show effects", true)
.describedAs("Lists your active effects with the time they have left.");
final BooleanSetting effectNames = settings()
.bool("effect-names", "Effect names", true)
.describedAs("Off: icons and times only.")
.visibleWhen(showEffects::get);
final BooleanSetting kindColors = settings()
.bool("kind-colors", "Color by kind", false)
.describedAs("Helpful effects' names in green, harmful ones' in red.")
.visibleWhen(() -> showEffects.get() && effectNames.get());
final ChoiceSetting<Side> side = settings()
.choice("side", "Effect icons on the", Side.values(), Side.LEFT, Side::label)
.visibleWhen(showEffects::get);
/** Armor &amp; Potion View, off until the player turns it on. */
public ArmorPotionView() {
super(
"armorpotionview",
"Armor & Potion View",
"Shows your armor's durability and your active effects on the HUD.",
Category.HUD);
hud(new ArmorElement(this));
hud(new EffectsElement(this));
}
/** The player, or null outside a world. */
@Nullable
PlayerView player() {
return system().game().player();
}
/** The HUD editor's stand-in player. */
PlayerView samplePlayer() {
return system().game().samplePlayer();
}
}
@@ -0,0 +1,183 @@
package incari.features.armorpotionview;
import incari.features.armorpotionview.ArmorPotionView.Side;
import incari.framework.game.EffectCategory;
import incari.framework.game.EffectView;
import incari.framework.game.PlayerView;
import incari.framework.hud.Anchor;
import incari.framework.hud.HudCanvas;
import incari.framework.hud.HudElement;
import incari.framework.hud.Tone;
import java.util.Arrays;
import org.jspecify.annotations.Nullable;
/**
* The player's active effects, one row each in the game's order: the effect's icon, its name and
* level, and the time it has left (amber in its last ten seconds).
*/
final class EffectsElement extends HudElement {
private static final int ICON = 18;
private static final int TEXT_GAP = 3;
private static final int ROW_GAP = 2;
/** Ticks left from which the time turns amber: ten seconds. */
private static final int ENDING = 200;
/** Rows with their text kept; more effects than this make their text each draw. */
private static final int CACHED = 32;
private static final String[] NUMERALS = {"", " II", " III", " IV", " V", " VI", " VII", " VIII", " IX", " X"};
private final ArmorPotionView module;
// Each row's text, made again only when what it says changes.
private final @Nullable String[] cachedNameOf = new String[CACHED];
private final int[] cachedAmplifier = new int[CACHED];
private final @Nullable String[] cachedName = new String[CACHED];
private final int[] cachedSeconds = new int[CACHED];
private final @Nullable String[] cachedTime = new String[CACHED];
EffectsElement(ArmorPotionView module) {
// Top left, below Toggle Sprint's line and the FPS, CPS and reach readouts, so a long list
// grows away from them.
super("effects", "Effects", Anchor.TOP_LEFT, 2, 62);
this.module = module;
Arrays.fill(cachedSeconds, Integer.MIN_VALUE);
}
@Override
public boolean isVisible() {
PlayerView player = module.player();
return module.showEffects.get() && player != null && player.effectCount() > 0;
}
@Override
public boolean isPlaceable() {
return module.showEffects.get();
}
@Override
public int width(HudCanvas canvas) {
PlayerView player = player(canvas);
int count = player.effectCount();
int text = 0;
boolean names = module.effectNames.get();
for (int i = 0; i < count; i++) {
EffectView effect = player.effect(i);
if (names) {
text = Math.max(text, canvas.textWidth(name(i, effect)));
}
text = Math.max(text, canvas.textWidth(time(i, effect)));
}
return count == 0 ? 0 : ICON + TEXT_GAP + text;
}
@Override
public int height(HudCanvas canvas) {
int count = player(canvas).effectCount();
return count == 0 ? 0 : count * (ICON + ROW_GAP) - ROW_GAP;
}
@Override
public void draw(HudCanvas canvas) {
PlayerView player = player(canvas);
int count = player.effectCount();
boolean right = module.side.get() == Side.RIGHT;
boolean names = module.effectNames.get();
int width = right ? width(canvas) : 0;
int line = canvas.lineHeight();
for (int i = 0; i < count; i++) {
EffectView effect = player.effect(i);
int y = i * (ICON + ROW_GAP);
canvas.effect(effect, right ? width - ICON : 0, y);
String time = time(i, effect);
Tone timeTone = !effect.isInfinite() && effect.duration() < ENDING ? Tone.WARNING : Tone.MUTED;
if (names) {
String name = name(i, effect);
text(canvas, name, right, width, y, nameTone(effect));
text(canvas, time, right, width, y + line, timeTone);
} else {
text(canvas, time, right, width, y + (ICON - line) / 2 + 1, timeTone);
}
}
}
private static void text(HudCanvas canvas, String text, boolean right, int width, int y, Tone tone) {
int x = right ? width - ICON - TEXT_GAP - canvas.textWidth(text) : ICON + TEXT_GAP;
canvas.text(text, x, y, tone);
}
private Tone nameTone(EffectView effect) {
if (!module.kindColors.get()) {
return Tone.TEXT;
}
return effect.category() == EffectCategory.BENEFICIAL
? Tone.POSITIVE
: effect.category() == EffectCategory.HARMFUL ? Tone.NEGATIVE : Tone.TEXT;
}
/** The real player, or in the HUD editor the sample when the real one has no effects. */
private PlayerView player(HudCanvas canvas) {
PlayerView player = module.player();
if (player != null && player.effectCount() > 0) {
return player;
}
return canvas.editing() ? module.samplePlayer() : PlayerView.EMPTY;
}
/** "Speed II", made again only when the effect in this row changes. */
@SuppressWarnings("ReferenceEquality") // The client hands out the same name string each time.
private String name(int row, EffectView effect) {
String name = effect.name();
int amplifier = effect.amplifier();
if (row < CACHED && cachedNameOf[row] == name && cachedAmplifier[row] == amplifier) {
String cached = cachedName[row];
if (cached != null) {
return cached;
}
}
String text = name + level(amplifier);
if (row < CACHED) {
cachedNameOf[row] = name;
cachedAmplifier[row] = amplifier;
cachedName[row] = text;
}
return text;
}
/** "1:23", made again only when the second changes. */
private String time(int row, EffectView effect) {
int seconds = effect.isInfinite() ? -1 : effect.duration() / 20;
if (row < CACHED && cachedSeconds[row] == seconds) {
String cached = cachedTime[row];
if (cached != null) {
return cached;
}
}
String text = seconds < 0 ? "∞" : clock(seconds);
if (row < CACHED) {
cachedSeconds[row] = seconds;
cachedTime[row] = text;
}
return text;
}
/** " II" for amplifier 1; nothing for level I; numbers past X. */
static String level(int amplifier) {
if (amplifier >= 0 && amplifier < NUMERALS.length) {
return NUMERALS[amplifier];
}
return " " + (amplifier + 1);
}
/** "0:08", "1:23", "1:02:03". */
static String clock(int seconds) {
int hours = seconds / 3600;
int minutes = seconds / 60 % 60;
int secs = seconds % 60;
String tail = (secs < 10 ? ":0" : ":") + secs;
if (hours > 0) {
return hours + (minutes < 10 ? ":0" : ":") + minutes + tail;
}
return minutes + tail;
}
}
@@ -0,0 +1,5 @@
/** Armor & Potion View (ADR 0050): armor, its durability and the active effects on the HUD. */
@NullMarked
package incari.features.armorpotionview;
import org.jspecify.annotations.NullMarked;
@@ -0,0 +1,164 @@
package incari.features.armorpotionview;
import static org.assertj.core.api.Assertions.assertThat;
import incari.features.armorpotionview.ArmorPotionView.Durability;
import incari.framework.game.EffectCategory;
import incari.framework.game.EquipmentSlot;
import incari.framework.hud.Anchor;
import incari.framework.hud.HudElement;
import incari.framework.testing.FakePlayer;
import incari.framework.testing.TestGame;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class ArmorPotionViewTest {
private final ArmorPotionView module = new ArmorPotionView();
private final TestGame game = new TestGame(module);
private final HudElement armor = module.hudElements().get(0);
private final HudElement effects = module.hudElements().get(1);
@BeforeEach
void atTheTopLeft() {
module.setEnabled(true);
for (HudElement element : module.hudElements()) {
element.anchor().set(Anchor.TOP_LEFT);
element.offsetX().set(0);
element.offsetY().set(0);
}
}
@Test
void nothingOutsideAWorldOrWithNothingOn() {
assertThat(game.drawHud().drawn).isEmpty();
game.join();
assertThat(game.drawHud().drawn).isEmpty();
}
@Test
void eachPieceWithItsDurabilityColoredByWear() {
game.join()
.wear(EquipmentSlot.HEAD, "helmet", 0, 363)
.wear(EquipmentSlot.CHEST, "chestplate", 300, 528)
.wear(EquipmentSlot.FEET, "boots", 400, 429)
.hold(EquipmentSlot.MAINHAND, "dirt", 64);
effects.anchor().set(Anchor.BOTTOM_RIGHT);
assertThat(game.drawHud().drawn)
.containsExactly(
"item \"helmet\" at 0,0 +decorations",
"text \"100%\" at 18,4 POSITIVE",
"item \"chestplate\" at 0,17 +decorations",
"text \"43%\" at 18,21 WARNING",
"item \"boots\" at 0,34 +decorations",
"text \"6%\" at 18,38 NEGATIVE",
// Held, but nothing to wear out: no text.
"item \"dirt\" at 0,51 +decorations");
}
@Test
void durabilityInEachFormat() {
assertThat(ArmorElement.format(Durability.PERCENT, 312, 363)).isEqualTo("85%");
assertThat(ArmorElement.format(Durability.REMAINING, 312, 363)).isEqualTo("312");
assertThat(ArmorElement.format(Durability.REMAINING_OF_MAX, 312, 363)).isEqualTo("312/363");
assertThat(ArmorElement.percent(1, 1000)).isEqualTo(1);
assertThat(ArmorElement.percent(0, 1000)).isZero();
}
@Test
void theBarAloneWritesNothingAndPlainColorsAreTheText() {
game.join().wear(EquipmentSlot.HEAD, "helmet", 350, 363);
module.durability.set(Durability.BAR);
assertThat(game.drawHud().drawn).containsExactly("item \"helmet\" at 0,0 +decorations");
module.durability.set(Durability.REMAINING);
module.wearColors.set(false);
assertThat(game.drawHud().drawn)
.containsExactly("item \"helmet\" at 0,0 +decorations", "text \"13\" at 18,4 TEXT");
}
@Test
void horizontalArmorRunsAcross() {
game.join().wear(EquipmentSlot.HEAD, "helmet", 0, 100).wear(EquipmentSlot.LEGS, "leggings", 50, 100);
module.showHeld.set(false);
module.layout.set(ArmorPotionView.Layout.HORIZONTAL);
// "100%" is 24 wide: the next cell starts at 16 + 2 + 24 + 4.
assertThat(game.drawHud().drawn)
.containsExactly(
"item \"helmet\" at 0,0 +decorations",
"text \"100%\" at 18,4 POSITIVE",
"item \"leggings\" at 46,0 +decorations",
"text \"50%\" at 64,4 POSITIVE");
}
@Test
void effectsWithLevelsAndTimeLeft() {
game.join()
.effect("Speed", 1, 1660, EffectCategory.BENEFICIAL)
.effect("Poison", 0, 150, EffectCategory.HARMFUL)
.effect("Night Vision", 0, -1, EffectCategory.BENEFICIAL);
assertThat(game.drawHud().drawn)
.containsExactly(
"effect \"Speed\" at 0,0",
"text \"Speed II\" at 21,0 TEXT",
"text \"1:23\" at 21,9 MUTED",
"effect \"Poison\" at 0,20",
"text \"Poison\" at 21,20 TEXT",
// The last ten seconds stand out.
"text \"0:07\" at 21,29 WARNING",
"effect \"Night Vision\" at 0,40",
"text \"Night Vision\" at 21,40 TEXT",
"text \"∞\" at 21,49 MUTED");
}
@Test
void effectsColoredByKindIconsOnTheRightTimesOnly() {
game.join()
.effect("Speed", 0, 400, EffectCategory.BENEFICIAL)
.effect("Weakness", 2, 9000, EffectCategory.HARMFUL);
module.kindColors.set(true);
assertThat(game.drawHud().drawn)
.contains("text \"Speed\" at 21,0 POSITIVE", "text \"Weakness III\" at 21,20 NEGATIVE");
module.side.set(ArmorPotionView.Side.RIGHT);
module.effectNames.set(false);
// Width: 18 + 3 + "7:30" (24) = 45; the times end 3 left of the icons.
assertThat(game.drawHud().drawn)
.containsExactly(
"effect \"Speed\" at 27,0",
"text \"0:20\" at 0,5 MUTED",
"effect \"Weakness\" at 27,20",
"text \"7:30\" at 0,25 MUTED");
}
@Test
void levelsAndClocks() {
assertThat(EffectsElement.level(0)).isEmpty();
assertThat(EffectsElement.level(3)).isEqualTo(" IV");
assertThat(EffectsElement.level(254)).isEqualTo(" 255");
assertThat(EffectsElement.clock(8)).isEqualTo("0:08");
assertThat(EffectsElement.clock(3723)).isEqualTo("1:02:03");
}
@Test
void theHudEditorShowsTheSampleWhenThePlayerHasNothing() {
game.join();
FakePlayer sample = game.sample;
sample.wear(EquipmentSlot.HEAD, "sample helmet", 0, 363).effect("Speed", 0, 600, EffectCategory.BENEFICIAL);
assertThat(game.drawHud(true).drawn)
.contains("item \"sample helmet\" at 0,0 +decorations", "effect \"Speed\" at 0,0");
assertThat(game.drawHud().drawn).isEmpty();
}
@Test
void eachHalfTurnsOffOnItsOwn() {
game.join().wear(EquipmentSlot.HEAD, "helmet", 0, 100).effect("Speed", 0, 400, EffectCategory.BENEFICIAL);
module.showArmor.set(false);
assertThat(armor.isPlaceable()).isFalse();
assertThat(game.drawHud().drawn).noneMatch(line -> line.startsWith("item"));
module.showEffects.set(false);
assertThat(game.drawHud().drawn).isEmpty();
}
}
@@ -0,0 +1,24 @@
package incari.features.armorpotionview;
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.armorpotionview", 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.armorpotionview..");
}
@@ -0,0 +1,16 @@
# blockoutline: Block Outline
Outlines the block you're looking at in your own color and width, with an optional faint fill. Only you see it. ([ADR 0061](../../docs/adr/0061-cosmetics.md))
| Setting | Kind | Default |
| --- | --- | --- |
| Color | color | `#A9DCFF` |
| Opacity | 10-100% | 90% |
| Width | 1-6 pixels | 2.5 |
| Fill | on/off | off |
| Fill color | color (when Fill is on) | `#A9DCFF` |
| Fill opacity | 5-60% (when Fill is on) | 20% |
```sh
./gradlew :features:blockoutline:check
```
@@ -0,0 +1,16 @@
plugins {
`java-library`
}
// Block Outline (ADR 0061): the outline of the block the crosshair is on, in a color and width of the player's, filled if they like.
// 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,65 @@
package incari.features.blockoutline;
import incari.framework.Category;
import incari.framework.Module;
import incari.framework.event.Events;
import incari.framework.setting.BooleanSetting;
import incari.framework.setting.ColorSetting;
import incari.framework.setting.FloatSetting;
import incari.framework.setting.IntSetting;
/**
* Block Outline: the outline round the block the crosshair is on, in the player's color and width,
* its faces filled faintly if they like. The game's thin dark line comes back when it's off.
*/
public final class BlockOutline extends Module {
final ColorSetting color = settings().color("color", "Color", 0xA9DCFF).describedAs("The outline's color.");
final IntSetting opacity = settings()
.integer("opacity", "Opacity", 10, 100, 90)
.formattedAs(value -> value + "%")
.describedAs("How solid the outline is.");
final FloatSetting width =
settings().decimal("width", "Width", 1, 6, 0.5F, 2.5F).describedAs("How thick the outline is, in pixels.");
final BooleanSetting fill = settings().bool("fill", "Fill", false).describedAs("Shades the block's faces too.");
final ColorSetting fillColor = settings()
.color("fill-color", "Fill color", 0xA9DCFF)
.describedAs("The shade's color.")
.visibleWhen(fill::get);
final IntSetting fillOpacity = settings()
.integer("fill-opacity", "Fill opacity", 5, 60, 20)
.formattedAs(value -> value + "%")
.describedAs("How strong the shade is.")
.visibleWhen(fill::get);
/** Block Outline, off until the player turns it on. */
public BlockOutline() {
super(
"blockoutline",
"Block Outline",
"Draws the outline of the block you look at in your own color and width.",
Category.VISUAL);
on(Events.TICK, this::apply);
}
private void apply() {
int fillArgb = fill.get() ? withOpacity(fillColor.get(), fillOpacity.get()) : 0;
system().game().overrideBlockOutline(withOpacity(color.get(), opacity.get()), width.get(), fillArgb);
}
@Override
protected void onEnable() {
apply();
}
@Override
protected void onDisable() {
system().game().overrideBlockOutline(0, 0, 0);
}
/** {@code argb}'s color at {@code percent} opacity, never fully clear (0 means the game's own). */
static int withOpacity(int argb, int percent) {
int alpha = Math.max(1, Math.round(percent * 255 / 100.0F));
return alpha << 24 | (argb & 0xFFFFFF);
}
}
@@ -0,0 +1,5 @@
/** Block Outline (ADR 0061): the outline of the block the crosshair is on, in a color and width of the player's, filled if they like. */
@NullMarked
package incari.features.blockoutline;
import org.jspecify.annotations.NullMarked;
@@ -0,0 +1,35 @@
package incari.features.blockoutline;
import static org.assertj.core.api.Assertions.assertThat;
import incari.framework.testing.TestGame;
import org.junit.jupiter.api.Test;
class BlockOutlineTest {
private final BlockOutline module = new BlockOutline();
private final TestGame game = new TestGame(module);
@Test
void outlinesInThePlayersColorWhileOnAndTheGamesAfter() {
module.setEnabled(true);
assertThat(game.outlineColor).isEqualTo(0xE6A9DCFF);
assertThat(game.outlineWidth).isEqualTo(2.5F);
assertThat(game.outlineFill).isZero();
module.fill.set(true);
module.color.set(0xFF0000);
game.tick();
assertThat(game.outlineColor & 0xFFFFFF).isEqualTo(0xFF0000);
assertThat(game.outlineFill).isEqualTo(0x33A9DCFF);
module.setEnabled(false);
assertThat(game.outlineColor).isZero();
}
@Test
void anOpacityNeverClearsTheColor() {
assertThat(BlockOutline.withOpacity(0xFF123456, 0) >>> 24).isEqualTo(1);
assertThat(BlockOutline.withOpacity(0x123456, 100)).isEqualTo(0xFF123456);
}
}
@@ -0,0 +1,24 @@
package incari.features.blockoutline;
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.blockoutline", 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.blockoutline..");
}
@@ -0,0 +1,9 @@
# clearchat: Clear Chat
Removes the dark box behind chat by holding the game's Text Background Opacity at 0%. Moving that slider yourself turns the module off. ([ADR 0050](../../docs/adr/0050-first-modules-game-view.md))
No settings besides the toggle key.
```sh
./gradlew :features:clearchat:check
```
@@ -0,0 +1,16 @@
plugins {
`java-library`
}
// Clear Chat (ADR 0050): chat without the dark box behind its lines.
// 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,24 @@
package incari.features.clearchat;
import incari.framework.Category;
import incari.framework.Module;
import incari.framework.game.GameOption;
/**
* Clear Chat: no dark box behind the chat's lines. It holds the game's own Text Background Opacity
* (Chat Settings) at 0 while on, so the game's slider shows it; moving that slider hands control
* back to the player and turns the module off. Turning the module off puts the player's opacity
* back.
*/
public final class ClearChat extends Module {
/** Clear Chat, off until the player turns it on. */
public ClearChat() {
super(
"clearchat",
"Clear Chat",
"Removes the dark box behind chat (the game's Text Background Opacity, set to 0%).",
Category.HUD);
holdOption(GameOption.TEXT_BACKGROUND_OPACITY, () -> 0);
}
}
@@ -0,0 +1,5 @@
/** Clear Chat (ADR 0050): chat without the dark box behind its lines. */
@NullMarked
package incari.features.clearchat;
import org.jspecify.annotations.NullMarked;
@@ -0,0 +1,24 @@
package incari.features.clearchat;
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.clearchat", 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.clearchat..");
}
@@ -0,0 +1,60 @@
package incari.features.clearchat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.data.Offset.offset;
import incari.framework.game.GameOption;
import incari.framework.testing.TestGame;
import org.junit.jupiter.api.Test;
class ClearChatTest {
private final ClearChat module = new ClearChat();
private final TestGame game = new TestGame(module);
@Test
void setsTheChatsBackgroundOpacityToZeroWhileOn() {
game.setOption(GameOption.TEXT_BACKGROUND_OPACITY, 0.7);
module.setEnabled(true);
assertThat(game.option(GameOption.TEXT_BACKGROUND_OPACITY)).isZero();
game.ticks(5);
assertThat(module.isEnabled()).isTrue();
module.setEnabled(false);
assertThat(game.option(GameOption.TEXT_BACKGROUND_OPACITY)).isEqualTo(0.7, offset(1e-4));
}
@Test
void raisingTheSliderInChatSettingsTurnsItOffAndKeepsTheNewValue() {
module.setEnabled(true);
game.setOption(GameOption.TEXT_BACKGROUND_OPACITY, 0.3);
game.tick();
assertThat(module.isEnabled()).isFalse();
assertThat(game.option(GameOption.TEXT_BACKGROUND_OPACITY)).isEqualTo(0.3);
}
@Test
void givesThePlayersOpacityBackAfterARestartWithItOn() {
game.setOption(GameOption.TEXT_BACKGROUND_OPACITY, 0.6);
module.setEnabled(true);
game.system().flush();
// A new start: the game's options kept the 0, the profile has the module on.
ClearChat again = new ClearChat();
TestGame restarted = new TestGame(again);
restarted.files.putAll(game.files);
restarted.setOption(GameOption.TEXT_BACKGROUND_OPACITY, 0);
restarted.system().load();
assertThat(again.isEnabled()).isTrue();
again.setEnabled(false);
assertThat(restarted.option(GameOption.TEXT_BACKGROUND_OPACITY)).isEqualTo(0.6, offset(1e-4));
}
@Test
void theHeldValueIsntInTheSettingsScreen() {
assertThat(module.settings().anyShown()).isTrue(); // the toggle key
assertThat(module.settings().get("before-text-background-opacity").isVisible())
.isFalse();
}
}
@@ -0,0 +1,16 @@
# cooldownindicator: Cooldown Indicator
Shows the attack cooldown as a bar, ring or percentage, in place of the game's indicator (which is held Off while this is on). ([ADR 0053](../../docs/adr/0053-visual-and-combat-modules.md))
| Setting | Kind | Default |
| --- | --- | --- |
| Style | Bar, Ring, Percent | Bar |
| Bar width / height | 8-80 / 1-6 | 24 / 2 |
| Ring size | 6-24 | 10 |
| Hide when charged | on/off | on |
| Show charged on target | on/off | on |
| Custom colors | on/off, two colors | off |
```sh
./gradlew :features:cooldownindicator:check
```
@@ -0,0 +1,16 @@
plugins {
`java-library`
}
// Cooldown Indicator (ADR 0053): the attack cooldown as a bar, ring or number, in place of the game's indicator.
// 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,234 @@
package incari.features.cooldownindicator;
import incari.framework.Category;
import incari.framework.Module;
import incari.framework.game.Game;
import incari.framework.game.GameOption;
import incari.framework.hud.Anchor;
import incari.framework.hud.HudCanvas;
import incari.framework.hud.HudElement;
import incari.framework.hud.Tone;
import incari.framework.setting.BooleanSetting;
import incari.framework.setting.ChoiceSetting;
import incari.framework.setting.ColorSetting;
import incari.framework.setting.IntSetting;
/**
* Cooldown Indicator: 1.9's attack cooldown the way the player wants it, in place of the game's
* indicator (whose option it holds at Off while on). A bar, a ring round the crosshair, or the
* charge as a percentage; hidden once charged, or shown full while the crosshair is on a target.
*/
public final class CooldownIndicator extends Module {
/** How the charge is drawn. */
public enum Style {
BAR("Bar"),
RING("Ring"),
NUMBER("Percent");
private final String label;
Style(String label) {
this.label = label;
}
/** What the settings screen calls it. */
public String label() {
return label;
}
}
/** The ring's thickness, in GUI units. */
static final float RING_WIDTH = 1.5F;
/** The charge the HUD editor shows. */
static final float SAMPLE = 0.6F;
final ChoiceSetting<Style> style = settings()
.choice("style", "Style", Style.values(), Style.BAR, Style::label)
.describedAs("A bar, a ring around the crosshair, or a percentage.");
final IntSetting barWidth =
settings().integer("bar-width", "Bar width", 8, 80, 24).visibleWhen(() -> style.get() == Style.BAR);
final IntSetting barHeight =
settings().integer("bar-height", "Bar height", 1, 6, 2).visibleWhen(() -> style.get() == Style.BAR);
final IntSetting ringSize = settings()
.integer("ring-size", "Ring size", 6, 24, 10)
.describedAs("The ring's radius, in GUI units.")
.visibleWhen(() -> style.get() == Style.RING);
final BooleanSetting hideWhenReady = settings()
.bool("hide-when-ready", "Hide when charged", true)
.describedAs("Shows the indicator only while the attack charges.");
final BooleanSetting readyOnTarget = settings()
.bool("ready-on-target", "Show charged on target", true)
.describedAs("Shows it full when the crosshair is on a mob or player in reach.")
.visibleWhen(hideWhenReady::get);
final BooleanSetting customColors = settings()
.bool("custom-colors", "Custom colors", false)
.describedAs("Off: charging in the accent, charged in green.");
final ColorSetting chargingColor =
settings().color("charging-color", "Charging color", 0xA9DCFF).visibleWhen(customColors::get);
final ColorSetting readyColor =
settings().color("ready-color", "Charged color", 0x8FE3B0).visibleWhen(customColors::get);
/** Cooldown Indicator, off until the player turns it on. */
public CooldownIndicator() {
super(
"cooldownindicator",
"Cooldown Indicator",
"Replaces the attack indicator with a bar, ring or percentage.",
Category.COMBAT);
// The game's own indicator is off while this one is on.
holdOption(GameOption.ATTACK_INDICATOR, () -> 0);
hud(new Bar());
hud(new Ring());
}
/** The charge now, or -1 if nothing should show. */
float charge(HudCanvas canvas) {
Game game = system().game();
if (game.player() == null) {
return canvas.editing() ? SAMPLE : -1;
}
float strength = Math.min(1, game.attackStrength());
if (strength >= 1 && hideWhenReady.get() && !(readyOnTarget.get() && game.onTarget())) {
return canvas.editing() ? SAMPLE : -1;
}
return strength;
}
int color(float charge) {
if (customColors.get()) {
return charge >= 1 ? readyColor.get() : chargingColor.get();
}
return 0;
}
Tone tone(float charge) {
return charge >= 1 ? Tone.POSITIVE : Tone.ACCENT;
}
/** "60%". */
static String percent(float charge) {
return Math.round(charge * 100) + "%";
}
/** The bar, or the percentage: below the crosshair by default. */
private final class Bar extends HudElement {
private int cachedPercent = -1;
private String cachedText = "";
Bar() {
super("bar", "Cooldown", Anchor.CENTER, 0, 12);
}
@Override
public boolean isLive() {
return true;
}
@Override
public boolean isPlaceable() {
return style.get() != Style.RING;
}
@Override
public boolean isVisible() {
return style.get() != Style.RING && system().game().player() != null;
}
private String text(float charge) {
int percent = Math.round(charge * 100);
if (percent != cachedPercent) {
cachedPercent = percent;
cachedText = percent(charge);
}
return cachedText;
}
@Override
public int width(HudCanvas canvas) {
return style.get() == Style.NUMBER ? canvas.textWidth("100%") : barWidth.get();
}
@Override
public int height(HudCanvas canvas) {
return style.get() == Style.NUMBER ? canvas.lineHeight() : barHeight.get();
}
@Override
public void draw(HudCanvas canvas) {
float charge = charge(canvas);
if (charge < 0) {
return;
}
if (style.get() == Style.NUMBER) {
String text = text(charge);
int x = (width(canvas) - canvas.textWidth(text)) / 2;
if (customColors.get()) {
canvas.text(text, x, 0, color(charge));
} else {
canvas.text(text, x, 0, tone(charge));
}
return;
}
int w = barWidth.get();
int h = barHeight.get();
canvas.fill(0, 0, w, h, Tone.BACKGROUND);
int filled = Math.round(w * charge);
if (customColors.get()) {
canvas.fill(0, 0, filled, h, color(charge));
} else {
canvas.fill(0, 0, filled, h, tone(charge));
}
}
}
/** The ring round the crosshair. */
private final class Ring extends HudElement {
Ring() {
super("ring", "Cooldown ring", Anchor.CENTER, 0, 0);
}
@Override
public boolean isLive() {
return true;
}
@Override
public boolean isPlaceable() {
return style.get() == Style.RING;
}
@Override
public boolean isVisible() {
return style.get() == Style.RING && system().game().player() != null;
}
@Override
public int width(HudCanvas canvas) {
return ringSize.get() * 2;
}
@Override
public int height(HudCanvas canvas) {
return ringSize.get() * 2;
}
@Override
public void draw(HudCanvas canvas) {
float charge = charge(canvas);
if (charge < 0) {
return;
}
float r = ringSize.get();
canvas.ring(r, r, r, RING_WIDTH, Tone.BACKGROUND);
if (customColors.get()) {
canvas.arc(r, r, r, RING_WIDTH, charge, color(charge));
} else {
canvas.arc(r, r, r, RING_WIDTH, charge, tone(charge));
}
}
}
}
@@ -0,0 +1,5 @@
/** Cooldown Indicator (ADR 0053): 1.9's attack cooldown, drawn as the player likes. */
@NullMarked
package incari.features.cooldownindicator;
import org.jspecify.annotations.NullMarked;
@@ -0,0 +1,24 @@
package incari.features.cooldownindicator;
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.cooldownindicator", 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.cooldownindicator..");
}
@@ -0,0 +1,56 @@
package incari.features.cooldownindicator;
import static org.assertj.core.api.Assertions.assertThat;
import incari.framework.game.GameOption;
import incari.framework.testing.TestGame;
import java.util.List;
import org.junit.jupiter.api.Test;
class CooldownIndicatorTest {
private final CooldownIndicator module = new CooldownIndicator();
private final TestGame game = new TestGame(module);
@Test
void holdsTheGamesIndicatorOffWhileOn() {
game.options.put(GameOption.ATTACK_INDICATOR, 2.0);
module.setEnabled(true);
assertThat(game.option(GameOption.ATTACK_INDICATOR)).isZero();
module.setEnabled(false);
assertThat(game.option(GameOption.ATTACK_INDICATOR)).isEqualTo(2.0);
}
@Test
void drawsTheChargeAsABarBelowTheCrosshair() {
module.setEnabled(true);
game.join();
game.attackStrength = 0.5F;
List<String> drawn = game.drawLive().drawn;
assertThat(drawn).containsExactly("fill 24x2 at 148,131 BACKGROUND", "fill 12x2 at 148,131 ACCENT");
}
@Test
void hidesWhenChargedUnlessOnATarget() {
module.setEnabled(true);
game.join();
assertThat(game.drawLive().drawn).isEmpty();
game.onTarget = true;
assertThat(game.drawLive().drawn).contains("fill 24x2 at 148,131 POSITIVE");
}
@Test
void ringsTheCrosshair() {
module.setEnabled(true);
module.style.set(CooldownIndicator.Style.RING);
game.join();
game.attackStrength = 0.25F;
assertThat(game.drawLive().drawn)
.containsExactly("ring r10 at 160,120 BACKGROUND", "arc r10 25% at 160,120 ACCENT");
}
@Test
void writesThePercentage() {
assertThat(CooldownIndicator.percent(0.604F)).isEqualTo("60%");
}
}
@@ -0,0 +1,18 @@
# coordinates: Coordinates
Your block position, facing, biome, and the matching spot in the other dimension (Nether ↔ Overworld). ([ADR 0052](../../docs/adr/0052-hud-modules.md))
| Setting | Kind | Default |
| --- | --- | --- |
| Layout | Lines, One line | Lines |
| Facing | on/off | on |
| Biome | on/off | on |
| Other dimension | on/off | on |
| Background | on/off | on |
| HUD: Coordinates | position and scale | top left, under the readouts (y 62), above the chat, 1x |
In the Nether, the Overworld spot is worked out from where you stand, not your block: x 100.9 is 807, not 800.
```sh
./gradlew :features:coordinates:check
```
@@ -0,0 +1,16 @@
plugins {
`java-library`
}
// Coordinates (ADR 0052): the player's position, facing, biome and the other dimension's position.
// 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,237 @@
package incari.features.coordinates;
import incari.framework.Category;
import incari.framework.Module;
import incari.framework.game.PlayerView;
import incari.framework.hud.Anchor;
import incari.framework.hud.HudCanvas;
import incari.framework.hud.HudElement;
import incari.framework.hud.TextElement;
import incari.framework.hud.Tone;
import incari.framework.setting.BooleanSetting;
import incari.framework.setting.ChoiceSetting;
import org.jspecify.annotations.Nullable;
/**
* Coordinates: where the player is, block by block, which way they face, the biome they stand in,
* and where the same spot is in the other dimension (a Nether portal's partner).
*/
public final class Coordinates extends Module {
/** How the position is laid out. */
public enum Layout {
/** X, Y and Z on lines of their own. */
VERTICAL("Lines"),
/** "X 12 Y 64 Z -40" on one line. */
LINE("One line");
private final String label;
Layout(String label) {
this.label = label;
}
/** What the settings screen calls it. */
public String label() {
return label;
}
}
final ChoiceSetting<Layout> layout = settings()
.choice("layout", "Layout", Layout.values(), Layout.VERTICAL, Layout::label)
.describedAs("X, Y and Z on lines of their own, or on one.");
final BooleanSetting showFacing = settings()
.bool("show-facing", "Facing", true)
.describedAs("Which way you face, with the axis it runs along.");
final BooleanSetting showBiome =
settings().bool("show-biome", "Biome", true).describedAs("The biome you stand in.");
final BooleanSetting showOther = settings()
.bool("show-other", "Other dimension", true)
.describedAs("In the Nether, where you'd be in the Overworld; in the Overworld, in the Nether.");
final BooleanSetting background =
settings().bool("background", "Background", true).describedAs("Draws a panel behind the text.");
/** Coordinates, off until the player turns it on. */
public Coordinates() {
super("coordinates", "Coordinates", "Shows where you are, which way you face and the biome.", Category.HUD);
hud(new Position());
}
/** The compass point for a bearing (0 north, 90 east), with the axis that way runs along. */
static String facing(float heading) {
int sector = Math.floorMod(Math.round(heading / 45.0F), 8);
return switch (sector) {
case 0 -> "North (-Z)";
case 1 -> "Northeast";
case 2 -> "East (+X)";
case 3 -> "Southeast";
case 4 -> "South (+Z)";
case 5 -> "Southwest";
case 6 -> "West (-X)";
default -> "Northwest";
};
}
/** The block a coordinate is in: rounded down, so -0.5 is block -1. */
static int block(double coordinate) {
return (int) Math.floor(coordinate);
}
/** The lines, label beside value, on the glass. */
private final class Position extends HudElement {
private static final int MAX_ROWS = 6;
private static final int LABEL_GAP = 4;
private final @Nullable String[] labels = new String[MAX_ROWS];
private final String[] values = new String[MAX_ROWS];
private int rows;
// What the rows were made from: made again only when one of these changes.
private int cachedX = Integer.MIN_VALUE;
private int cachedY;
private int cachedZ;
private int cachedOverworldX;
private int cachedOverworldZ;
private int cachedSector = -1;
private @Nullable String cachedBiome;
private @Nullable String cachedDimension;
private long cachedSettings = -1;
Position() {
super("position", "Coordinates", Anchor.TOP_LEFT, 2, 62);
for (int i = 0; i < MAX_ROWS; i++) {
values[i] = "";
}
}
@Override
public boolean isVisible() {
return system().game().player() != null;
}
private void refresh(HudCanvas canvas) {
PlayerView player = system().game().player();
if (player == null) {
player = canvas.editing() ? system().game().samplePlayer() : null;
}
if (player == null) {
rows = 0;
return;
}
int x = block(player.x());
int y = block(player.y());
int z = block(player.z());
int sector = Math.floorMod(Math.round(player.heading() / 45.0F), 8);
String biome = showBiome.get() ? player.biome() : "";
String dimension = player.dimension();
// The Overworld block matching where they stand in the Nether: from the exact position,
// as a Nether block spans 8 Overworld ones (x 100.9 is 807, not 800).
int overworldX = block(player.x() * 8);
int overworldZ = block(player.z() * 8);
long settingsKey = (layout.get() == Layout.LINE ? 1 : 0)
| (showFacing.get() ? 2 : 0)
| (showBiome.get() ? 4 : 0)
| (showOther.get() ? 8 : 0);
if (x == cachedX
&& y == cachedY
&& overworldX == cachedOverworldX
&& overworldZ == cachedOverworldZ
&& z == cachedZ
&& sector == cachedSector
&& biome.equals(cachedBiome)
&& dimension.equals(cachedDimension)
&& settingsKey == cachedSettings) {
return;
}
cachedX = x;
cachedY = y;
cachedOverworldX = overworldX;
cachedOverworldZ = overworldZ;
cachedZ = z;
cachedSector = sector;
cachedBiome = biome;
cachedDimension = dimension;
cachedSettings = settingsKey;
rows = 0;
if (layout.get() == Layout.LINE) {
row(null, "X " + x + " Y " + y + " Z " + z);
} else {
row("X", Integer.toString(x));
row("Y", Integer.toString(y));
row("Z", Integer.toString(z));
}
if (showFacing.get()) {
row(null, facing(player.heading()));
}
if (showBiome.get() && !biome.isEmpty()) {
row(null, biome);
}
if (showOther.get()) {
if (dimension.equals(PlayerView.NETHER)) {
row("Overworld", overworldX + ", " + overworldZ);
} else if (dimension.equals(PlayerView.OVERWORLD)) {
row("Nether", Math.floorDiv(x, 8) + ", " + Math.floorDiv(z, 8));
}
}
}
private void row(@Nullable String label, String value) {
labels[rows] = label;
values[rows] = value;
rows++;
}
private int pad() {
return background.get() ? TextElement.PAD_X : 0;
}
private int padY() {
return background.get() ? TextElement.PAD_Y : 0;
}
/** A row's label and the gap after it; 0 for a row without. */
private int labelWidth(HudCanvas canvas, int row) {
String label = labels[row];
return label == null ? 0 : canvas.textWidth(label) + LABEL_GAP;
}
@Override
public int width(HudCanvas canvas) {
refresh(canvas);
int width = 0;
for (int i = 0; i < rows; i++) {
width = Math.max(width, labelWidth(canvas, i) + canvas.textWidth(values[i]));
}
return rows == 0 ? 0 : width + pad() * 2;
}
@Override
public int height(HudCanvas canvas) {
refresh(canvas);
return rows == 0 ? 0 : rows * canvas.lineHeight() + (background.get() ? padY() * 2 - 1 : -1);
}
@Override
public void draw(HudCanvas canvas) {
refresh(canvas);
if (rows == 0) {
return;
}
if (background.get()) {
canvas.fill(0, 0, width(canvas), height(canvas), Tone.BACKGROUND);
}
int y = padY();
for (int i = 0; i < rows; i++) {
String label = labels[i];
int x = pad();
if (label != null) {
canvas.text(label, x, y, Tone.ACCENT);
x += labelWidth(canvas, i);
}
canvas.text(values[i], x, y, label == null && i >= 1 ? Tone.MUTED : Tone.TEXT);
y += canvas.lineHeight();
}
}
}
}
@@ -0,0 +1,5 @@
/** Coordinates (ADR 0052): where the player is, which way they face, the biome. */
@NullMarked
package incari.features.coordinates;
import org.jspecify.annotations.NullMarked;
@@ -0,0 +1,24 @@
package incari.features.coordinates;
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.coordinates", 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.coordinates..");
}
@@ -0,0 +1,71 @@
package incari.features.coordinates;
import static org.assertj.core.api.Assertions.assertThat;
import incari.framework.game.PlayerView;
import incari.framework.setting.BooleanSetting;
import incari.framework.setting.ChoiceSetting;
import incari.framework.testing.TestGame;
import java.util.List;
import org.junit.jupiter.api.Test;
class CoordinatesTest {
private final Coordinates module = new Coordinates();
private final TestGame game = new TestGame(module);
@Test
void drawsNothingOutsideAWorld() {
module.setEnabled(true);
assertThat(game.drawHud().drawn).isEmpty();
}
@Test
void writesThePositionFacingBiomeAndTheNethersPlace() {
module.setEnabled(true);
game.join().at(100.5, 64, -41.2).facing(91).biome("Desert");
List<String> drawn = game.drawHud().drawn;
assertThat(drawn.get(0)).startsWith("fill").endsWith("BACKGROUND");
assertThat(drawn).anyMatch(line -> line.startsWith("text \"100\""));
assertThat(drawn).anyMatch(line -> line.startsWith("text \"-42\""));
assertThat(drawn).anyMatch(line -> line.startsWith("text \"East (+X)\""));
assertThat(drawn).anyMatch(line -> line.startsWith("text \"Desert\""));
assertThat(drawn).anyMatch(line -> line.startsWith("text \"12, -6\""));
}
@Test
void inTheNetherGivesTheOverworldsPlace() {
module.setEnabled(true);
game.join().at(10, 70, -3).in(PlayerView.NETHER);
assertThat(game.drawHud().drawn).anyMatch(line -> line.startsWith("text \"80, -24\""));
}
@Test
void theOverworldsPlaceIsFromTheExactPosition() {
module.setEnabled(true);
// Block 100 and -1 in the Nether, but 807 and -4 in the Overworld: not 800 and -8.
game.join().at(100.9, 70, -0.5).in(PlayerView.NETHER);
assertThat(game.drawHud().drawn).anyMatch(line -> line.startsWith("text \"807, -4\""));
}
@Test
@SuppressWarnings("unchecked")
void oneLineWhenAsked() {
module.setEnabled(true);
((ChoiceSetting<Coordinates.Layout>) module.settings().get("layout")).set(Coordinates.Layout.LINE);
((BooleanSetting) module.settings().get("show-facing")).set(false);
((BooleanSetting) module.settings().get("show-biome")).set(false);
((BooleanSetting) module.settings().get("show-other")).set(false);
game.join().at(1, 2, 3);
assertThat(game.drawHud().drawn).contains("text \"X 1 Y 2 Z 3\" at 6,65 TEXT");
}
@Test
void facingRoundsToTheNearestPoint() {
assertThat(Coordinates.facing(0)).isEqualTo("North (-Z)");
assertThat(Coordinates.facing(359)).isEqualTo("North (-Z)");
assertThat(Coordinates.facing(200)).isEqualTo("South (+Z)");
assertThat(Coordinates.facing(230)).isEqualTo("Southwest");
assertThat(Coordinates.block(-0.5)).isEqualTo(-1);
}
}
@@ -0,0 +1,12 @@
# cps: CPS
Clicks per second over the last second. ([ADR 0052](../../docs/adr/0052-hud-modules.md))
| Setting | Kind | Default |
| --- | --- | --- |
| Buttons | Left and right, Left, Right | Left and right |
| HUD: CPS | position and scale | top left, under FPS (y 30), 1x |
```sh
./gradlew :features:cps:check
```
@@ -0,0 +1,16 @@
plugins {
`java-library`
}
// CPS (ADR 0052): clicks a second, left and right, on the HUD.
// 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,108 @@
package incari.features.cps;
import incari.framework.Category;
import incari.framework.Module;
import incari.framework.event.ClickCounter;
import incari.framework.event.ClickListener;
import incari.framework.event.Events;
import incari.framework.hud.Anchor;
import incari.framework.hud.HudCanvas;
import incari.framework.hud.TextElement;
import incari.framework.setting.ChoiceSetting;
import org.jspecify.annotations.Nullable;
/** CPS: how many times the player clicked in the last second, left, right or both. */
public final class Cps extends Module {
/** Which buttons are counted. */
public enum Buttons {
/** "12 | 4 CPS". */
BOTH("Left and right"),
/** "12 CPS". */
LEFT("Left"),
/** "4 CPS". */
RIGHT("Right");
private final String label;
Buttons(String label) {
this.label = label;
}
/** What the settings screen calls it. */
public String label() {
return label;
}
}
final ChoiceSetting<Buttons> buttons = settings()
.choice("buttons", "Buttons", Buttons.values(), Buttons.BOTH, Buttons::label)
.describedAs("Which mouse buttons' clicks are counted.");
private final ClickCounter left = new ClickCounter();
private final ClickCounter right = new ClickCounter();
/** CPS, off until the player turns it on. */
public Cps() {
super("cps", "CPS", "Shows how many times a second you click.", Category.HUD);
on(Events.CLICK, this::onClick);
hud(new Counter());
}
private void onClick(int button) {
long now = system().game().millis();
if (button == ClickListener.LEFT) {
left.click(now);
} else if (button == ClickListener.RIGHT) {
right.click(now);
}
}
@Override
protected void onDisable() {
left.clear();
right.clear();
}
/** "12 | 4 CPS" for {@code buttons}. */
static String text(Buttons buttons, int left, int right) {
return switch (buttons) {
case BOTH -> left + " | " + right + " CPS";
case LEFT -> left + " CPS";
case RIGHT -> right + " CPS";
};
}
/** The count, on the glass. */
private final class Counter extends TextElement {
private int cachedLeft = -1;
private int cachedRight = -1;
private @Nullable Buttons cachedButtons;
private String cached = "";
Counter() {
super("cps", "CPS", Anchor.TOP_LEFT, 2, 30);
}
@Override
protected @Nullable String text(HudCanvas canvas) {
long now = system().game().millis();
int l = left.perSecond(now);
int r = right.perSecond(now);
Buttons chosen = buttons.get();
if (l != cachedLeft || r != cachedRight || chosen != cachedButtons) {
cachedLeft = l;
cachedRight = r;
cachedButtons = chosen;
cached = Cps.text(chosen, l, r);
}
return cached;
}
@Override
protected @Nullable String widest() {
return buttons.get() == Buttons.BOTH ? "00 | 00 CPS" : "00 CPS";
}
}
}
@@ -0,0 +1,5 @@
/** CPS (ADR 0052): clicks a second on the HUD. */
@NullMarked
package incari.features.cps;
import org.jspecify.annotations.NullMarked;
@@ -0,0 +1,20 @@
package incari.features.cps;
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.cps", 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.cps..");
}
@@ -0,0 +1,44 @@
package incari.features.cps;
import static org.assertj.core.api.Assertions.assertThat;
import incari.framework.event.ClickListener;
import incari.framework.testing.TestGame;
import org.junit.jupiter.api.Test;
class CpsTest {
private final Cps module = new Cps();
private final TestGame game = new TestGame(module);
@Test
void countsEachButtonsClicksOverTheLastSecond() {
module.setEnabled(true);
for (int i = 0; i < 9; i++) {
game.click(ClickListener.LEFT);
game.millis += 100;
}
game.click(ClickListener.RIGHT);
game.click(ClickListener.MIDDLE);
assertThat(game.drawHud().drawn).anyMatch(line -> line.startsWith("text \"9 | 1 CPS\""));
game.millis += 600;
assertThat(game.drawHud().drawn).anyMatch(line -> line.startsWith("text \"3 | 1 CPS\""));
game.millis += 1000;
assertThat(game.drawHud().drawn).anyMatch(line -> line.startsWith("text \"0 | 0 CPS\""));
}
@Test
void clicksWhileOffArentCounted() {
game.click(ClickListener.LEFT);
module.setEnabled(true);
assertThat(game.drawHud().drawn).anyMatch(line -> line.startsWith("text \"0 | 0 CPS\""));
}
@Test
void writesOneButtonWhenAsked() {
assertThat(Cps.text(Cps.Buttons.LEFT, 12, 4)).isEqualTo("12 CPS");
assertThat(Cps.text(Cps.Buttons.RIGHT, 12, 4)).isEqualTo("4 CPS");
}
}
@@ -0,0 +1,17 @@
# crosshair: Crosshair Editor
Replaces the crosshair with your own: a cross, T, circle or dot from sliders, or a 15×15 pixel grid you draw. ([ADR 0053](../../docs/adr/0053-visual-and-combat-modules.md))
| Setting | Kind | Default |
| --- | --- | --- |
| Preset | Custom, Classic, Competitive, Small, Dot, Circle, T | Classic |
| Style | Cross, T, Circle, Dot, Pixel grid | Cross |
| Pixel grid | grid editor | a plus |
| Length / Gap / Thickness | 1-30 / 0-20 / 1-10 px | 9 / 0 / 2 |
| Center dot / Outline | on/off | off / off |
| Color / Opacity | color / 10-100% | white / 100% |
| Color on target | on/off, a color | off |
```sh
./gradlew :features:crosshair:check
```
@@ -0,0 +1,16 @@
plugins {
`java-library`
}
// Crosshair Editor (ADR 0053): the crosshair drawn from presets, sliders or a 15x15 pixel grid.
// 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,280 @@
package incari.features.crosshair;
import incari.framework.Category;
import incari.framework.Module;
import incari.framework.event.Crosshair;
import incari.framework.event.Events;
import incari.framework.hud.HudCanvas;
import incari.framework.setting.BooleanSetting;
import incari.framework.setting.ChoiceSetting;
import incari.framework.setting.ColorSetting;
import incari.framework.setting.GridSetting;
import incari.framework.setting.IntSetting;
/**
* Crosshair Editor: the crosshair the player designs, in place of the game's. A cross, a T, a
* circle or a dot from sliders measured in screen pixels, with an outline and a center dot; or a
* 15 by 15 grid drawn cell by cell. Presets fill the sliders in. It can change color while the
* crosshair is on a mob or player in reach.
*/
public final class CrosshairEditor extends Module {
/** What's drawn. */
public enum Style {
CROSS("Cross"),
/** A cross without its top arm. */
T("T"),
CIRCLE("Circle"),
/** The center dot alone. */
DOT("Dot"),
/** The pixel grid, cell by cell. */
GRID("Pixel grid");
private final String label;
Style(String label) {
this.label = label;
}
/** What the settings screen calls it. */
public String label() {
return label;
}
}
/** Ready-made crosshairs: each sets the sliders, which the player may then change. */
public enum Preset {
CUSTOM("Custom", Style.CROSS, 0, 0, 0, false, false),
CLASSIC("Classic", Style.CROSS, 9, 0, 2, false, false),
COMPETITIVE("Competitive", Style.CROSS, 6, 3, 2, false, true),
SMALL("Small", Style.CROSS, 4, 2, 1, false, true),
DOT("Dot", Style.DOT, 0, 0, 4, true, true),
CIRCLE("Circle", Style.CIRCLE, 0, 8, 2, true, true),
T_SHAPE("T", Style.T, 7, 3, 2, false, true);
private final String label;
private final Style style;
private final int length;
private final int gap;
private final int thickness;
private final boolean dot;
private final boolean outline;
Preset(String label, Style style, int length, int gap, int thickness, boolean dot, boolean outline) {
this.label = label;
this.style = style;
this.length = length;
this.gap = gap;
this.thickness = thickness;
this.dot = dot;
this.outline = outline;
}
/** What the settings screen calls it. */
public String label() {
return label;
}
}
/** The grid's side: the game's crosshair is 15 GUI units across. */
static final int GRID = 15;
/** A plus five cells a side with a clear middle, as the grid starts. */
static final long[] DEFAULT_GRID = defaultGrid();
final ChoiceSetting<Preset> preset = settings()
.choice("preset", "Preset", Preset.values(), Preset.CLASSIC, Preset::label)
.describedAs("Loads a preset crosshair into the sliders below.");
final ChoiceSetting<Style> style = settings()
.choice("style", "Style", Style.values(), Style.CROSS, Style::label)
.describedAs("A cross, a T, a circle, a dot, or the pixel grid you draw.");
final GridSetting grid = settings()
.grid("grid", "Pixel grid", GRID, DEFAULT_GRID)
.describedAs("Draw your own crosshair, a cell a GUI pixel.")
.visibleWhen(() -> style.get() == Style.GRID);
final IntSetting length = settings()
.integer("length", "Length", 1, 30, 9)
.formattedAs(pixels -> pixels + " px")
.describedAs("How long each arm is, in screen pixels.")
.visibleWhen(() -> style.get() == Style.CROSS || style.get() == Style.T);
final IntSetting gap = settings()
.integer("gap", "Gap", 0, 20, 0)
.formattedAs(pixels -> pixels + " px")
.describedAs("Space between the middle and each arm; a circle's radius.")
.visibleWhen(() -> style.get() != Style.DOT && style.get() != Style.GRID);
final IntSetting thickness = settings()
.integer("thickness", "Thickness", 1, 10, 2)
.formattedAs(pixels -> pixels + " px")
.describedAs("How thick the lines are, and the dot's size.")
.visibleWhen(() -> style.get() != Style.GRID);
final BooleanSetting dot = settings()
.bool("dot", "Center dot", false)
.describedAs("Adds a dot in the middle.")
.visibleWhen(() -> style.get() != Style.DOT && style.get() != Style.GRID);
final BooleanSetting outline = settings()
.bool("outline", "Outline", false)
.describedAs("A dark outline that keeps the crosshair visible on snow and sky.");
final ColorSetting color = settings().color("color", "Color", 0xFFFFFF);
final IntSetting opacity =
settings().integer("opacity", "Opacity", 10, 100, 100).formattedAs(percent -> percent + "%");
final BooleanSetting targetColor = settings()
.bool("target-color", "Color on target", false)
.describedAs("Changes color while the crosshair is on a mob or player in reach.");
final ColorSetting onTargetColor =
settings().color("on-target-color", "Target color", 0xFF5555).visibleWhen(targetColor::get);
/** Whether a preset is filling the sliders in: their changes are its, not the player's. */
private boolean applying;
/** Crosshair Editor, off until the player turns it on. */
public CrosshairEditor() {
super("crosshair", "Crosshair Editor", "Draws a crosshair of your own design.", Category.VISUAL);
preset.onChange(this::applyPreset);
// A slider moved away from the preset makes it Custom, so picking the preset again loads it.
style.onChange(this::followSliders);
length.onChange(this::followSliders);
gap.onChange(this::followSliders);
thickness.onChange(this::followSliders);
dot.onChange(this::followSliders);
outline.onChange(this::followSliders);
on(Events.CROSSHAIR, this::draw);
}
private void applyPreset() {
Preset chosen = preset.get();
if (chosen == Preset.CUSTOM) {
return;
}
applying = true;
try {
style.set(chosen.style);
length.set(Math.max(1, chosen.length));
gap.set(chosen.gap);
thickness.set(chosen.thickness);
dot.set(chosen.dot);
outline.set(chosen.outline);
} finally {
applying = false;
}
}
private void followSliders() {
Preset chosen = preset.get();
if (!applying && chosen != Preset.CUSTOM && !shows(chosen)) {
preset.set(Preset.CUSTOM);
}
}
/** Whether the sliders are as {@code chosen} sets them. */
private boolean shows(Preset chosen) {
return style.get() == chosen.style
&& length.get() == Math.max(1, chosen.length)
&& gap.get() == chosen.gap
&& thickness.get() == chosen.thickness
&& dot.get() == chosen.dot
&& outline.get() == chosen.outline;
}
private static long[] defaultGrid() {
long[] rows = new long[GRID];
int middle = GRID / 2;
for (int i = 2; i <= 6; i++) {
rows[middle] |= 1L << (middle - i) | 1L << (middle + i);
rows[middle - i] |= 1L << middle;
rows[middle + i] |= 1L << middle;
}
return rows;
}
private void draw(Crosshair crosshair) {
HudCanvas canvas = crosshair.canvas();
int alpha = Math.round(opacity.get() * 2.55F) << 24;
int rgb = (targetColor.get() && crosshair.onTarget() ? onTargetColor.get() : color.get()) & 0xFFFFFF;
int argb = alpha | rgb;
int shade = alpha | 0x000000;
if (style.get() == Style.GRID) {
// In GUI units, as the game's own crosshair is drawn.
canvas.push(crosshair.centerX() - GRID / 2.0F, crosshair.centerY() - GRID / 2.0F, 1);
try {
drawGrid(canvas, argb, shade);
} finally {
canvas.pop();
}
return;
}
// In screen pixels, around the middle.
canvas.push(crosshair.centerX(), crosshair.centerY(), crosshair.pixel());
try {
if (outline.get()) {
shapes(canvas, shade, 1);
}
shapes(canvas, argb, 0);
} finally {
canvas.pop();
}
}
/** Every line of the style, grown by {@code grow} pixels each side (the outline). */
private void shapes(HudCanvas canvas, int argb, int grow) {
int t = thickness.get();
int half = t / 2;
int g = gap.get();
int l = length.get();
switch (style.get()) {
case CROSS, T -> {
rect(canvas, -g - l, -half, l, t, grow, argb);
rect(canvas, g + (t - half * 2), -half, l, t, grow, argb);
rect(canvas, -half, g + (t - half * 2), t, l, grow, argb);
if (style.get() == Style.CROSS) {
rect(canvas, -half, -g - l, t, l, grow, argb);
}
}
case CIRCLE -> {
// In pixels too: the canvas is scaled to them.
canvas.ring(0, 0, g + t + grow, t + grow * 2, argb);
}
case DOT, GRID -> {}
}
if (dot.get() || style.get() == Style.DOT) {
rect(canvas, -half, -half, t, t, grow, argb);
}
}
private static void rect(HudCanvas canvas, int x, int y, int w, int h, int grow, int argb) {
canvas.fill(x - grow, y - grow, w + grow * 2, h + grow * 2, argb);
}
private void drawGrid(HudCanvas canvas, int argb, int shade) {
if (outline.get()) {
// Each row's outline: the cells beside, above and below a lit one, a column out on each
// side (bit x + 1 is cell x), drawn as runs like the cells. Drawn every frame: a run is
// one quad where a cell's four sides were four.
for (int y = -1; y <= GRID; y++) {
long around = shifted(y - 1) | shifted(y + 1) | shifted(y) << 1 | shifted(y) >>> 1;
runs(canvas, around, y, -1, shade);
}
}
for (int y = 0; y < GRID; y++) {
runs(canvas, grid.row(y), y, 0, argb);
}
}
/** Row {@code y} of the grid with cell x at bit x + 1; nothing outside it. */
private long shifted(int y) {
return y < 0 || y >= GRID ? 0 : grid.row(y) << 1;
}
/** The set bits of {@code row} as fills, a run of them in one: bit i is cell {@code i + first}. */
private static void runs(HudCanvas canvas, long row, int y, int first, int argb) {
for (int i = 0; i < Long.SIZE; i++) {
if ((row >>> i & 1L) != 0) {
int run = 1;
while (i + run < Long.SIZE && (row >>> (i + run) & 1L) != 0) {
run++;
}
canvas.fill(i + first, y, run, 1, argb);
i += run - 1;
}
}
}
}
@@ -0,0 +1,5 @@
/** Crosshair Editor (ADR 0053): the crosshair from presets, sliders or a pixel grid. */
@NullMarked
package incari.features.crosshair;
import org.jspecify.annotations.NullMarked;
@@ -0,0 +1,24 @@
package incari.features.crosshair;
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.crosshair", 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.crosshair..");
}
@@ -0,0 +1,76 @@
package incari.features.crosshair;
import static org.assertj.core.api.Assertions.assertThat;
import incari.framework.setting.BooleanSetting;
import incari.framework.setting.GridSetting;
import incari.framework.testing.TestGame;
import java.util.List;
import org.junit.jupiter.api.Test;
class CrosshairEditorTest {
private final CrosshairEditor module = new CrosshairEditor();
private final TestGame game = new TestGame(module);
@Test
void leavesTheGamesCrosshairWhileOff() {
assertThat(game.system().events().count(incari.framework.event.Events.CROSSHAIR))
.isZero();
}
@Test
void drawsTheClassicCrossInScreenPixels() {
module.setEnabled(true);
List<String> drawn = game.crosshair().drawn;
// Four arms of 9 by 2 pixels: at half a GUI unit a pixel, 4.5 by 1 units round the middle.
assertThat(drawn).hasSize(4).allMatch(line -> line.endsWith("#ffffffff"));
assertThat(drawn).contains("fill 9x2 at 156,120 #ffffffff");
}
@Test
void presetsSetTheSliders() {
module.setEnabled(true);
module.preset.set(CrosshairEditor.Preset.DOT);
assertThat(module.style.get()).isEqualTo(CrosshairEditor.Style.DOT);
List<String> drawn = game.crosshair().drawn;
// The outline's dark square, then the dot.
assertThat(drawn).containsExactly("fill 6x6 at 159,119 #ff000000", "fill 4x4 at 159,119 #ffffffff");
}
@Test
void aSliderMovedMakesThePresetCustomAndPickingItAgainLoadsIt() {
module.setEnabled(true);
assertThat(module.preset.get()).isEqualTo(CrosshairEditor.Preset.CLASSIC);
module.gap.set(5);
assertThat(module.preset.get()).isEqualTo(CrosshairEditor.Preset.CUSTOM);
assertThat(module.gap.get()).isEqualTo(5);
module.preset.set(CrosshairEditor.Preset.CLASSIC);
assertThat(module.gap.get()).isZero();
assertThat(module.preset.get()).isEqualTo(CrosshairEditor.Preset.CLASSIC);
}
@Test
void changesColorOnATarget() {
module.setEnabled(true);
((BooleanSetting) module.settings().get("target-color")).set(true);
game.onTarget = true;
assertThat(game.crosshair().drawn).allMatch(line -> line.endsWith("#ffff5555"));
}
@Test
void drawsThePixelGridInRuns() {
module.setEnabled(true);
module.style.set(CrosshairEditor.Style.GRID);
GridSetting grid = (GridSetting) module.settings().get("grid");
grid.clear();
grid.set(3, 7, true);
grid.set(4, 7, true);
grid.set(5, 7, true);
grid.set(7, 0, true);
List<String> drawn = game.crosshair().drawn;
assertThat(drawn).containsExactly("fill 1x1 at 160,113 #ffffffff", "fill 3x1 at 156,120 #ffffffff");
}
}
@@ -0,0 +1,11 @@
# customscoreboard: Custom Scoreboard
Lets you place and scale the server's scoreboard sidebar like any HUD element. The editor shows a sample when the server sends none. ([ADR 0050](../../docs/adr/0050-first-modules-game-view.md))
| Setting | Kind | Default |
| --- | --- | --- |
| HUD: Scoreboard | position and scale | right, a unit in, 1x (the game's place) |
```sh
./gradlew :features:customscoreboard:check
```
@@ -0,0 +1,16 @@
plugins {
`java-library`
}
// Custom Scoreboard (ADR 0050): the server's scoreboard sidebar placed and sized by the player.
// 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,27 @@
package incari.features.customscoreboard;
import incari.framework.Category;
import incari.framework.Module;
import incari.framework.game.GamePart;
import incari.framework.hud.Anchor;
import incari.framework.hud.GamePartElement;
/**
* Custom Scoreboard: the scoreboard sidebar a server sends, wherever the player puts it and at the
* size they choose. The game draws the sidebar as it always does (its lines, its numbers, the
* client's look); the module only takes over where ({@link GamePartElement}), so it's placed with
* the HUD editor like any other element. Nothing shows while the server sends no sidebar.
*/
public final class CustomScoreboard extends Module {
/** Custom Scoreboard, off until the player turns it on. */
public CustomScoreboard() {
super(
"customscoreboard",
"Custom Scoreboard",
"Move and resize the scoreboard a server shows, with the HUD editor.",
Category.HUD);
// The game's place: on the right, a unit in, about halfway down.
hud(new GamePartElement(GamePart.SCOREBOARD, "sidebar", Anchor.RIGHT, 1, 0));
}
}
@@ -0,0 +1,5 @@
/** Custom Scoreboard (ADR 0050): the server's scoreboard sidebar placed and sized by the player. */
@NullMarked
package incari.features.customscoreboard;
import org.jspecify.annotations.NullMarked;
@@ -0,0 +1,24 @@
package incari.features.customscoreboard;
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.customscoreboard", 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.customscoreboard..");
}
@@ -0,0 +1,51 @@
package incari.features.customscoreboard;
import static org.assertj.core.api.Assertions.assertThat;
import incari.framework.game.GamePart;
import incari.framework.hud.Anchor;
import incari.framework.hud.HudElement;
import incari.framework.testing.TestGame;
import org.junit.jupiter.api.Test;
class CustomScoreboardTest {
private final CustomScoreboard module = new CustomScoreboard();
private final TestGame game = new TestGame(module);
private final HudElement sidebar = module.hudElements().get(0);
@Test
void takesTheSidebarFromTheGameOnlyWhileOn() {
assertThat(game.system().holds(GamePart.SCOREBOARD)).isFalse();
module.setEnabled(true);
assertThat(game.system().holds(GamePart.SCOREBOARD)).isTrue();
module.setEnabled(false);
assertThat(game.system().holds(GamePart.SCOREBOARD)).isFalse();
}
@Test
void drawsTheSidebarWhereTheGameWouldByDefault() {
module.setEnabled(true);
game.parts.put(GamePart.SCOREBOARD, new int[] {80, 60});
// Right side, a unit in, middle of a 320 by 240 screen.
assertThat(game.drawHud().drawn).containsExactly("part SCOREBOARD 80x60 at 239,90");
}
@Test
void drawsItWhereThePlayerPutItAtTheirScale() {
module.setEnabled(true);
game.parts.put(GamePart.SCOREBOARD, new int[] {80, 60});
sidebar.anchor().set(Anchor.TOP_LEFT);
sidebar.offsetX().set(4);
sidebar.offsetY().set(10);
sidebar.scale().set(0.5F);
assertThat(game.drawHud().drawn).containsExactly("part SCOREBOARD 40x30 at 4,10");
}
@Test
void nothingWithoutASidebarButASampleInTheEditor() {
module.setEnabled(true);
assertThat(game.drawHud().drawn).isEmpty();
assertThat(game.drawHud(true).drawn).containsExactly("part SCOREBOARD 60x40 at 259,100");
}
}
@@ -0,0 +1,23 @@
# customsky: Custom Sky
Draws the skies resource packs bring in OptiFine's format (`optifine/sky/world0/sky<N>.properties`,
or MCPatcher's `mcpatcher/sky/world0`), over the game's own sky, in the overworld. Without it the
game ignores them. A pack without one leaves the sky as it is. ([ADR 0067](../../docs/adr/0067-custom-sky.md))
| Setting | Kind | Default |
| --- | --- | --- |
| Brightness | 10-100% | 100% |
| Pack key | Read |
| --- | --- |
| `source`, `blend`, `rotate`, `speed`, `axis`, `weather` | yes |
| `startFadeIn`, `endFadeIn`, `startFadeOut`, `endFadeOut` | yes (`endFadeOut` defaults as OptiFine's) |
| `biomes`, `heights`, `days`, `daysLoop`, `transition` | not yet: the layer shows everywhere, every day |
| `sun.properties`, `moon_phases.properties`, the Nether and End | not yet |
The module parses the files (`SkyLayer`, no game types); the client's `ModuleSkyLayers` finds them,
loads the textures while the module is on, and draws them after the sunrise, before the sun.
```sh
./gradlew :features:customsky:check
```
@@ -0,0 +1,16 @@
plugins {
`java-library`
}
// Custom Sky: the skies resource packs bring in OptiFine's format, drawn over the game's.
// 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,39 @@
package incari.features.customsky;
import incari.framework.Category;
import incari.framework.Module;
import incari.framework.event.Events;
import incari.framework.setting.IntSetting;
/**
* Custom Sky: the skies resource packs bring in OptiFine's format ({@link SkyLayer}), drawn over
* the game's own in the overworld, on this client only. Most PvP packs have one; without OptiFine
* the game ignores them. A pack without one leaves the game's sky as it is.
*/
public final class CustomSky extends Module {
final IntSetting brightness = settings()
.integer("brightness", "Brightness", 10, 100, 100)
.formattedAs(percent -> percent + "%")
.describedAs("100%: the sky as the pack made it.");
/** Custom Sky, off until the player turns it on. */
public CustomSky() {
super("customsky", "Custom Sky", "Shows the sky your resource packs bring, as OptiFine does.", Category.VISUAL);
on(Events.TICK, this::apply);
}
private void apply() {
system().game().showPackSkies(brightness.get() / 100F);
}
@Override
protected void onEnable() {
apply();
}
@Override
protected void onDisable() {
system().game().showPackSkies(0);
}
}
@@ -0,0 +1,354 @@
package incari.features.customsky;
import java.util.Locale;
import org.jspecify.annotations.Nullable;
/**
* One layer of a resource pack's custom sky, in OptiFine's format: a {@code sky<N>.properties} in
* {@code optifine/sky/world0} (or MCPatcher's {@code mcpatcher/sky/world0}), naming a texture that
* holds a cube's six faces in a 3 by 2 grid. Read here without the game: the client finds the
* files, loads the texture, and draws the cube at {@link #brightness}, turned by {@link #angle}.
*
* <p>Understood: {@code source}, the four fade times, {@code blend}, {@code rotate}, {@code speed},
* {@code axis} and {@code weather}. Not yet: {@code biomes}, {@code heights}, {@code days} and
* {@code transition}; a layer that has them shows everywhere, every day.
*/
public final class SkyLayer {
/** How a layer is mixed with what's behind it, OptiFine's names. */
public enum Blend {
ALPHA,
ADD,
SUBTRACT,
MULTIPLY,
DODGE,
BURN,
SCREEN,
OVERLAY,
REPLACE
}
/** Ticks in a day; 0 is 6:00, as the game counts. */
static final int DAY = 24000;
private final String source;
/** The fades in ticks from dawn; {@code startFadeIn} -1 for a layer always shown. */
private final int startFadeIn;
private final int endFadeIn;
private final int startFadeOut;
private final int endFadeOut;
private final Blend blend;
private final boolean rotate;
private final float speed;
private final float axisX;
private final float axisY;
private final float axisZ;
private final boolean clear;
private final boolean rain;
private final boolean thunder;
private SkyLayer(
String source,
int[] fades,
Blend blend,
boolean rotate,
float speed,
float[] axis,
boolean clear,
boolean rain,
boolean thunder) {
this.source = source;
this.startFadeIn = fades[0];
this.endFadeIn = fades[1];
this.startFadeOut = fades[2];
this.endFadeOut = fades[3];
this.blend = blend;
this.rotate = rotate;
this.speed = speed;
this.axisX = axis[0];
this.axisY = axis[1];
this.axisZ = axis[2];
this.clear = clear;
this.rain = rain;
this.thunder = thunder;
}
/**
* The layer {@code text} describes, or null if it can't be drawn (fade times missing or
* unreadable, a source that isn't a path).
*
* @param file where it was found, {@code optifine/sky/world0/sky1.properties}: a source is
* relative to its folder, and its own name with {@code .png} is the default source
*/
public static @Nullable SkyLayer parse(String text, String file) {
String folder = file.lastIndexOf('/') < 0 ? "" : file.substring(0, file.lastIndexOf('/'));
String base = file.endsWith(".properties") ? file.substring(0, file.length() - ".properties".length()) : file;
String sourceText = null;
String[] fadeText = new String[4];
Blend blend = Blend.ADD;
boolean rotate = true;
float speed = 1;
float[] axis = {0, 0, 1};
boolean clear = true;
boolean rain = false;
boolean thunder = false;
for (String raw : text.split("\r?\n", -1)) {
String line = raw.strip();
if (line.isEmpty() || line.charAt(0) == '#' || line.charAt(0) == '!') {
continue;
}
int split = line.indexOf('=');
if (split < 0) {
split = line.indexOf(':');
}
if (split <= 0) {
continue;
}
String key = line.substring(0, split).strip();
String value = line.substring(split + 1).strip();
switch (key) {
case "source" -> sourceText = value;
case "startFadeIn" -> fadeText[0] = value;
case "endFadeIn" -> fadeText[1] = value;
case "startFadeOut" -> fadeText[2] = value;
case "endFadeOut" -> fadeText[3] = value;
case "blend" -> blend = blend(value);
case "rotate" -> rotate = !value.equalsIgnoreCase("false");
case "speed" -> speed = number(value, 1);
case "axis" -> axis = axis(value);
case "weather" -> {
String weathers = " " + value.toLowerCase(Locale.ROOT) + " ";
clear = weathers.contains(" clear ");
rain = weathers.contains(" rain ");
thunder = weathers.contains(" thunder ");
}
default -> {
// Biomes, heights, days, transition: not yet; the layer shows regardless.
}
}
}
int[] fades = fades(fadeText);
String source = resolve(sourceText == null ? base + ".png" : sourceText, folder);
if (fades == null || source == null) {
return null;
}
return new SkyLayer(source, fades, blend, rotate, speed, axis, clear, rain, thunder);
}
/** The texture, {@code namespace:path}. */
public String source() {
return source;
}
public Blend blend() {
return blend;
}
/** The axis the layer turns on, in the world's frame (x east, y up, z south), of length 1. */
public float axisX() {
return axisX;
}
public float axisY() {
return axisY;
}
public float axisZ() {
return axisZ;
}
/** How far the layer is turned, in radians, with the sun at {@code sunAngle}. */
public float angle(float sunAngle) {
return rotate ? sunAngle * speed : 0;
}
/**
* How strongly it shows, 0 to 1, at {@code timeOfDay} ticks from dawn, with the rain and thunder
* as shown (0 to 1 each).
*/
public float brightness(long timeOfDay, float rainLevel, float thunderLevel) {
float weather = 0;
if (clear) {
weather += 1 - rainLevel;
}
if (rain) {
weather += Math.max(0, rainLevel - thunderLevel);
}
if (thunder) {
weather += thunderLevel;
}
return Math.min(1, Math.max(0, weather)) * fade(timeOfDay);
}
private float fade(long timeOfDay) {
if (startFadeIn < 0) {
return 1;
}
// Every time from the start of the fade in, so a layer that shows over midnight wraps.
int fullIn = wrap(endFadeIn - startFadeIn);
int out = wrap(startFadeOut - startFadeIn);
int gone = wrap(endFadeOut - startFadeIn);
int now = wrap(timeOfDay - startFadeIn);
if (now < fullIn) {
return (float) now / fullIn;
}
if (now < out) {
return 1;
}
if (now < gone) {
return 1 - (float) (now - out) / (gone - out);
}
return 0;
}
/** The fades in ticks; none at all for a layer always shown, null if they can't be read. */
private static int @Nullable [] fades(String[] text) {
if (text[0] == null && text[1] == null && text[2] == null && text[3] == null) {
return new int[] {-1, -1, -1, -1};
}
if (text[0] == null || text[1] == null || text[2] == null) {
return null;
}
int[] fades = new int[4];
for (int i = 0; i < 3; i++) {
fades[i] = time(text[i]);
if (fades[i] < 0) {
return null;
}
}
// OptiFine's default: the fade out takes as long as the fade in.
fades[3] = text[3] == null ? wrap(fades[2] + fades[1] - fades[0]) : time(text[3]);
return fades[3] < 0 ? null : fades;
}
/** {@code hh:mm} as ticks from dawn (6:00 is 0), or -1. */
static int time(String text) {
int colon = text.indexOf(':');
if (colon < 0) {
return -1;
}
try {
int hours = Integer.parseInt(text.substring(0, colon).strip());
int minutes = Integer.parseInt(text.substring(colon + 1).strip());
if (hours < 0 || hours > 24 || minutes < 0 || minutes > 59) {
return -1;
}
return wrap(hours * 1000 + minutes * 1000 / 60 - 6000);
} catch (NumberFormatException e) {
return -1;
}
}
/**
* A source as OptiFine resolves it: {@code ./} from the file's folder, {@code ~/} from
* {@code optifine}, {@code assets/<namespace>/} or a namespace for that namespace, a bare name
* in the file's folder, and any other path from {@code assets/minecraft}. Null if it isn't a
* path the game can name.
*/
static @Nullable String resolve(String source, String folder) {
String path = source.strip();
String namespace = "minecraft";
if (path.startsWith("./")) {
path = folder + "/" + path.substring(2);
} else if (path.startsWith("~/")) {
path = "optifine/" + path.substring(2);
} else {
if (path.startsWith("/")) {
path = path.substring(1);
}
int colon = path.indexOf(':');
if (colon > 0) {
namespace = path.substring(0, colon);
path = path.substring(colon + 1);
} else if (path.startsWith("assets/") && path.indexOf('/', 7) > 7) {
namespace = path.substring(7, path.indexOf('/', 7));
path = path.substring(path.indexOf('/', 7) + 1);
} else if (path.indexOf('/') < 0) {
path = folder.isEmpty() ? path : folder + "/" + path;
}
}
return validPath(namespace, path) ? namespace + ":" + path : null;
}
/** What the game takes for a resource's namespace and path. */
private static boolean validPath(String namespace, String path) {
if (namespace.isEmpty() || path.isEmpty() || path.contains("..")) {
return false;
}
for (int i = 0; i < namespace.length(); i++) {
if (!nameChar(namespace.charAt(i))) {
return false;
}
}
for (int i = 0; i < path.length(); i++) {
if (path.charAt(i) != '/' && !nameChar(path.charAt(i))) {
return false;
}
}
return true;
}
private static boolean nameChar(char c) {
return (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_' || c == '-' || c == '.';
}
/**
* Where a file comes in its folder's order: the number in {@code sky12.properties}; a file
* without one goes last.
*/
public static int order(String file) {
String name = file.substring(file.lastIndexOf('/') + 1);
int end = name.indexOf('.') < 0 ? name.length() : name.indexOf('.');
int start = end;
while (start > 0 && Character.isDigit(name.charAt(start - 1))) {
start--;
}
if (start == end || end - start > 6) {
return Integer.MAX_VALUE;
}
return Integer.parseInt(name.substring(start, end));
}
private static Blend blend(String text) {
return switch (text.strip().toLowerCase(Locale.ROOT)) {
case "alpha" -> Blend.ALPHA;
case "subtract" -> Blend.SUBTRACT;
case "multiply" -> Blend.MULTIPLY;
case "dodge" -> Blend.DODGE;
case "burn" -> Blend.BURN;
case "screen" -> Blend.SCREEN;
case "overlay" -> Blend.OVERLAY;
case "replace" -> Blend.REPLACE;
default -> Blend.ADD;
};
}
private static float number(String text, float fallback) {
try {
float value = Float.parseFloat(text);
return Float.isFinite(value) ? value : fallback;
} catch (NumberFormatException e) {
return fallback;
}
}
/** Three numbers, made length 1; the sun's axis if they aren't. */
private static float[] axis(String text) {
String[] parts = text.strip().split("\\s+", -1);
if (parts.length == 3) {
float x = number(parts[0], Float.NaN);
float y = number(parts[1], Float.NaN);
float z = number(parts[2], Float.NaN);
float length = (float) Math.sqrt(x * x + y * y + z * z);
if (length > 1.0E-4F) {
return new float[] {x / length, y / length, z / length};
}
}
return new float[] {0, 0, 1};
}
private static int wrap(long ticks) {
return (int) Math.floorMod(ticks, (long) DAY);
}
}
@@ -0,0 +1,5 @@
/** Custom Sky: resource packs' skies in OptiFine's format. */
@NullMarked
package incari.features.customsky;
import org.jspecify.annotations.NullMarked;
@@ -0,0 +1,24 @@
package incari.features.customsky;
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.customsky", 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.customsky..");
}
@@ -0,0 +1,28 @@
package incari.features.customsky;
import static org.assertj.core.api.Assertions.assertThat;
import incari.framework.testing.TestGame;
import org.junit.jupiter.api.Test;
class CustomSkyTest {
private final CustomSky module = new CustomSky();
private final TestGame game = new TestGame(module);
@Test
void showsThePackSkiesAtTheChosenBrightness() {
module.setEnabled(true);
assertThat(game.packSkies).isEqualTo(1);
module.brightness.set(40);
game.tick();
assertThat(game.packSkies).isEqualTo(0.4F);
}
@Test
void offGivesTheGameItsSkyBack() {
module.setEnabled(true);
module.setEnabled(false);
assertThat(game.packSkies).isZero();
}
}
@@ -0,0 +1,104 @@
package incari.features.customsky;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.within;
import org.junit.jupiter.api.Test;
class SkyLayerTest {
private static final String FILE = "optifine/sky/world0/sky1.properties";
@Test
void aBareFileIsItsOwnTextureAlwaysShownAdded() {
SkyLayer layer = SkyLayer.parse("", FILE);
assertThat(layer).isNotNull();
assertThat(layer.source()).isEqualTo("minecraft:optifine/sky/world0/sky1.png");
assertThat(layer.blend()).isEqualTo(SkyLayer.Blend.ADD);
assertThat(layer.brightness(18000, 0, 0)).isEqualTo(1);
assertThat(layer.angle(1.5F)).isEqualTo(1.5F);
assertThat(layer.axisZ()).isEqualTo(1);
}
@Test
void readsOptiFinesKeys() {
SkyLayer layer = SkyLayer.parse("""
# a night sky
source=./stars.png
blend=alpha
rotate=true
speed=2
axis=0.0 2.0 0.0
""", FILE);
assertThat(layer).isNotNull();
assertThat(layer.source()).isEqualTo("minecraft:optifine/sky/world0/stars.png");
assertThat(layer.blend()).isEqualTo(SkyLayer.Blend.ALPHA);
assertThat(layer.angle(1)).isEqualTo(2);
assertThat(layer.axisY()).isEqualTo(1);
assertThat(SkyLayer.parse("rotate=false", FILE).angle(1)).isZero();
}
@Test
void resolvesSourcesAsOptiFineDoes() {
String folder = "optifine/sky/world0";
assertThat(SkyLayer.resolve("sky2.png", folder)).isEqualTo("minecraft:optifine/sky/world0/sky2.png");
assertThat(SkyLayer.resolve("~/sky/clouds.png", folder)).isEqualTo("minecraft:optifine/sky/clouds.png");
assertThat(SkyLayer.resolve("/assets/minecraft/mcpatcher/sky/a.png", folder))
.isEqualTo("minecraft:mcpatcher/sky/a.png");
assertThat(SkyLayer.resolve("textures/sky/a.png", folder)).isEqualTo("minecraft:textures/sky/a.png");
assertThat(SkyLayer.resolve("pack:sky/a.png", folder)).isEqualTo("pack:sky/a.png");
assertThat(SkyLayer.resolve("Sky Night.png", folder)).isNull();
}
@Test
void fadesInAndOutOverMidnight() {
// Night stars: in from 18:00 to 19:00, out from 05:00 to 06:00.
SkyLayer layer = SkyLayer.parse("startFadeIn=18:00\nendFadeIn=19:00\nstartFadeOut=5:00\nendFadeOut=6:00", FILE);
assertThat(layer).isNotNull();
assertThat(layer.brightness(SkyLayer.time("12:00"), 0, 0)).isZero();
assertThat(layer.brightness(SkyLayer.time("18:30"), 0, 0)).isCloseTo(0.5F, within(0.01F));
assertThat(layer.brightness(SkyLayer.time("0:00"), 0, 0)).isEqualTo(1);
assertThat(layer.brightness(SkyLayer.time("5:30"), 0, 0)).isCloseTo(0.5F, within(0.01F));
}
@Test
void anEndFadeOutLeftOutTakesAsLongAsTheFadeIn() {
SkyLayer layer = SkyLayer.parse("startFadeIn=18:00\nendFadeIn=20:00\nstartFadeOut=4:00", FILE);
assertThat(layer).isNotNull();
assertThat(layer.brightness(SkyLayer.time("5:00"), 0, 0)).isCloseTo(0.5F, within(0.01F));
assertThat(layer.brightness(SkyLayer.time("6:30"), 0, 0)).isZero();
}
@Test
void halfTheFadeTimesIsNoLayer() {
assertThat(SkyLayer.parse("startFadeIn=18:00", FILE)).isNull();
assertThat(SkyLayer.parse("startFadeIn=dusk\nendFadeIn=19:00\nstartFadeOut=5:00", FILE))
.isNull();
}
@Test
void clearSkiesFadeWithTheRain() {
SkyLayer clear = SkyLayer.parse("", FILE);
assertThat(clear.brightness(0, 1, 0)).isZero();
assertThat(clear.brightness(0, 0.25F, 0)).isEqualTo(0.75F);
SkyLayer storm = SkyLayer.parse("weather=thunder", FILE);
assertThat(storm.brightness(0, 0, 0)).isZero();
assertThat(storm.brightness(0, 1, 1)).isEqualTo(1);
}
@Test
void timesCountFromDawn() {
assertThat(SkyLayer.time("6:00")).isZero();
assertThat(SkyLayer.time("12:00")).isEqualTo(6000);
assertThat(SkyLayer.time("0:00")).isEqualTo(18000);
assertThat(SkyLayer.time("6:30")).isEqualTo(500);
assertThat(SkyLayer.time("noon")).isEqualTo(-1);
}
@Test
void ordersFilesByTheirNumber() {
assertThat(SkyLayer.order("optifine/sky/world0/sky2.properties"))
.isLessThan(SkyLayer.order("optifine/sky/world0/sky10.properties"));
assertThat(SkyLayer.order("optifine/sky/world0/sun.properties")).isEqualTo(Integer.MAX_VALUE);
}
}
@@ -0,0 +1,31 @@
# fastcrystal: Fast Crystal
An end crystal you hit, and a charged respawn anchor you set off, are gone on your screen at once,
not a ping later, so the next one can go in its place sooner. Prediction only
([ADR 0073](../../docs/adr/0073-combat-prediction-not-automation.md)): your click sends the one
packet it always did, nothing is clicked for you, and one the server keeps comes back. Off by
default.
| Setting | Kind | Default |
| --- | --- | --- |
| Crystals | On/off | On |
| Anchors | On/off: anchors outside the Nether (where they explode) | On |
The module holds `Game.predictBreaks`; the client's `ModuleBreaks` acts on it:
| Hook | What |
| --- | --- |
| `MultiPlayerGameMode.attack`, after the attack packet | Takes the crystal away, unless the hit does no damage or the crystal is invulnerable |
| `ClientPacketListener.handleRemoveEntities` | The server removed it: nothing to put back |
| `RespawnAnchorBlock.useWithoutItem`, client side | Sets the anchor to air in the game's block prediction; the server's acknowledgement restores it if it stays |
A crystal the server hasn't removed after twice the ping plus 0.3 s (0.6 to 3 s) comes back.
The Rust build's mod ([`rust/mods/fastcrystal`](../../rust/mods/fastcrystal/)) does the same on
Horizon's prediction hooks: `object_attacked` takes the crystal off (`native_take_crystal`), `tick`
puts back one the server kept (`native_return_crystal`), and `block_used` shows the anchor as air
under the use's sequence (`native_predict_air`).
```sh
./gradlew :features:fastcrystal:check
```
@@ -0,0 +1,16 @@
plugins {
`java-library`
}
// Fast Crystal: crystals and anchors gone on this client as soon as the player breaks them.
// 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,50 @@
package incari.features.fastcrystal;
import incari.framework.Category;
import incari.framework.Module;
import incari.framework.setting.BooleanSetting;
/**
* Fast Crystal: an end crystal the player hits, and a charged respawn anchor they set off, go from
* this client at once instead of a round trip later, so the next one can go in its place without
* waiting out the ping. Prediction only (as the game predicts a broken block): the player's own
* click still sends the one packet it always did, nothing is clicked for them, and one the server
* keeps comes back. The choice is handed to the game once per change; the client checks it on a
* hit or a use.
*/
public final class FastCrystal extends Module {
final BooleanSetting crystals = settings()
.bool("crystals", "Crystals", true)
.describedAs("A crystal you hit is gone at once, so the next can go in its place.");
final BooleanSetting anchors = settings()
.bool("anchors", "Anchors", true)
.describedAs("A charged anchor you set off is gone at once, outside the Nether.");
/** Fast Crystal, off until the player turns it on. */
public FastCrystal() {
super(
"fastcrystal",
"Fast Crystal",
"Crystals and anchors go as you break them, not a ping later.",
Category.COMBAT);
crystals.onChange(this::changed);
anchors.onChange(this::changed);
}
private void changed() {
if (isEnabled()) {
system().game().predictBreaks(crystals.get(), anchors.get());
}
}
@Override
protected void onEnable() {
system().game().predictBreaks(crystals.get(), anchors.get());
}
@Override
protected void onDisable() {
system().game().predictBreaks(false, false);
}
}
@@ -0,0 +1,5 @@
/** Fast Crystal: end crystals and respawn anchors gone on this client as soon as the player breaks them. */
@NullMarked
package incari.features.fastcrystal;
import org.jspecify.annotations.NullMarked;
@@ -0,0 +1,24 @@
package incari.features.fastcrystal;
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.fastcrystal", 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.fastcrystal..");
}
@@ -0,0 +1,51 @@
package incari.features.fastcrystal;
import static org.assertj.core.api.Assertions.assertThat;
import incari.framework.testing.TestGame;
import org.junit.jupiter.api.Test;
class FastCrystalTest {
private final FastCrystal module = new FastCrystal();
private final TestGame game = new TestGame(module);
@Test
void offUntilTurnedOnAndOffAgainAfter() {
assertThat(module.isEnabled()).isFalse();
assertThat(game.predictCrystals).isFalse();
assertThat(game.predictAnchors).isFalse();
module.setEnabled(true);
assertThat(game.predictCrystals).isTrue();
assertThat(game.predictAnchors).isTrue();
module.setEnabled(false);
assertThat(game.predictCrystals).isFalse();
assertThat(game.predictAnchors).isFalse();
}
@Test
void eachKindCanBeLeftToTheGame() {
module.setEnabled(true);
module.anchors.set(false);
assertThat(game.predictCrystals).isTrue();
assertThat(game.predictAnchors).isFalse();
module.crystals.set(false);
module.anchors.set(true);
assertThat(game.predictCrystals).isFalse();
assertThat(game.predictAnchors).isTrue();
}
@Test
void aSettingChangedWhileOffWaitsForTheModule() {
module.anchors.set(false);
assertThat(game.predictAnchors).isFalse();
assertThat(game.predictCrystals).isFalse();
module.setEnabled(true);
assertThat(game.predictCrystals).isTrue();
assertThat(game.predictAnchors).isFalse();
}
}
@@ -0,0 +1,13 @@
# fpsdisplay: FPS Display
Frames drawn in the last second. ([ADR 0052](../../docs/adr/0052-hud-modules.md))
| Setting | Kind | Default |
| --- | --- | --- |
| Format | 120 FPS, FPS: 120, 120 | 120 FPS |
| Color by speed | on/off (green from 60, amber from 30, red below) | off |
| HUD: FPS | position and scale | top left, under Toggle Sprint's line (y 14), 1x |
```sh
./gradlew :features:fpsdisplay:check
```
@@ -0,0 +1,16 @@
plugins {
`java-library`
}
// FPS Display (ADR 0052): the frame rate on the HUD.
// 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,100 @@
package incari.features.fpsdisplay;
import incari.framework.Category;
import incari.framework.Module;
import incari.framework.hud.Anchor;
import incari.framework.hud.HudCanvas;
import incari.framework.hud.TextElement;
import incari.framework.hud.Tone;
import incari.framework.setting.BooleanSetting;
import incari.framework.setting.ChoiceSetting;
import org.jspecify.annotations.Nullable;
/** FPS Display: the frames drawn in the last second, as the debug screen counts them. */
public final class FpsDisplay extends Module {
/** How the count is written. */
public enum Format {
/** "120 FPS". */
AFTER("120 FPS"),
/** "FPS: 120". */
BEFORE("FPS: 120"),
/** "120". */
NUMBER("120");
private final String label;
Format(String label) {
this.label = label;
}
/** What the settings screen calls it. */
public String label() {
return label;
}
}
final ChoiceSetting<Format> format = settings()
.choice("format", "Format", Format.values(), Format.AFTER, Format::label)
.describedAs("How the FPS is shown.");
final BooleanSetting speedColors = settings()
.bool("speed-colors", "Color by speed", false)
.describedAs("Green from 60 frames a second, amber from 30, red below.");
/** FPS Display, off until the player turns it on. */
public FpsDisplay() {
super("fpsdisplay", "FPS Display", "Shows how many frames a second the game draws.", Category.HUD);
hud(new Counter());
}
/** "120 FPS" in {@code format}. */
static String text(Format format, int fps) {
return switch (format) {
case AFTER -> fps + " FPS";
case BEFORE -> "FPS: " + fps;
case NUMBER -> Integer.toString(fps);
};
}
/** The count, on the glass. */
private final class Counter extends TextElement {
private int cachedFps = -1;
private @Nullable Format cachedFormat;
private String cached = "";
Counter() {
super("fps", "FPS", Anchor.TOP_LEFT, 2, 14);
}
@Override
protected @Nullable String text(HudCanvas canvas) {
int fps = system().game().fps();
Format chosen = format.get();
if (fps != cachedFps || chosen != cachedFormat) {
cachedFps = fps;
cachedFormat = chosen;
cached = FpsDisplay.text(chosen, fps);
}
return cached;
}
@Override
protected @Nullable String widest() {
return switch (format.get()) {
case AFTER -> "000 FPS";
case BEFORE -> "FPS: 000";
case NUMBER -> "000";
};
}
@Override
protected Tone tone() {
if (!speedColors.get()) {
return Tone.TEXT;
}
int fps = system().game().fps();
return fps >= 60 ? Tone.POSITIVE : fps >= 30 ? Tone.WARNING : Tone.NEGATIVE;
}
}
}
@@ -0,0 +1,5 @@
/** FPS Display (ADR 0052): the frame rate on the HUD. */
@NullMarked
package incari.features.fpsdisplay;
import org.jspecify.annotations.NullMarked;
@@ -0,0 +1,24 @@
package incari.features.fpsdisplay;
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.fpsdisplay", 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.fpsdisplay..");
}
@@ -0,0 +1,45 @@
package incari.features.fpsdisplay;
import static org.assertj.core.api.Assertions.assertThat;
import incari.framework.setting.BooleanSetting;
import incari.framework.testing.TestGame;
import org.junit.jupiter.api.Test;
class FpsDisplayTest {
private final FpsDisplay module = new FpsDisplay();
private final TestGame game = new TestGame(module);
@Test
void drawsNothingWhileOff() {
assertThat(game.drawHud().drawn).isEmpty();
}
@Test
void writesTheFrameRateOnTheGlass() {
module.setEnabled(true);
game.fps = 144;
assertThat(game.drawHud().drawn)
.contains("fill 50x14 at 2,14 BACKGROUND")
.anyMatch(line -> line.startsWith("text \"144 FPS\""));
}
@Test
void followsTheFormat() {
assertThat(FpsDisplay.text(FpsDisplay.Format.BEFORE, 60)).isEqualTo("FPS: 60");
assertThat(FpsDisplay.text(FpsDisplay.Format.NUMBER, 7)).isEqualTo("7");
}
@Test
void colorsBySpeedWhenAsked() {
module.setEnabled(true);
((BooleanSetting) module.settings().get("speed-colors")).set(true);
game.fps = 24;
assertThat(game.drawHud().drawn)
.anyMatch(line -> line.startsWith("text \"24 FPS\"") && line.endsWith("NEGATIVE"));
game.fps = 75;
assertThat(game.drawHud().drawn)
.anyMatch(line -> line.startsWith("text \"75 FPS\"") && line.endsWith("POSITIVE"));
}
}
@@ -0,0 +1,14 @@
# freelook: Freelook
Hold (or toggle) the key to look around without turning your player; letting go puts the view back. ([ADR 0053](../../docs/adr/0053-visual-and-combat-modules.md))
| Setting | Kind | Default |
| --- | --- | --- |
| Freelook key | keybind | Left Alt |
| Key | Hold, Toggle | Hold |
| Camera | Behind, In front, First person | Behind |
| Invert up and down | on/off | off |
```sh
./gradlew :features:freelook:check
```
@@ -0,0 +1,16 @@
plugins {
`java-library`
}
// Freelook (ADR 0053): hold a key to turn the camera round the player without turning them.
// 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,161 @@
package incari.features.freelook;
import incari.framework.Category;
import incari.framework.Module;
import incari.framework.event.CameraAngles;
import incari.framework.event.Events;
import incari.framework.event.Turn;
import incari.framework.game.Game;
import incari.framework.game.Perspective;
import incari.framework.setting.BooleanSetting;
import incari.framework.setting.ChoiceSetting;
import incari.framework.setting.Key;
import incari.framework.setting.KeySetting;
/**
* Freelook: while its key is held (or after a press, as a toggle), the mouse turns the camera round
* the player instead of the player, so they can look behind them while running on. Letting go
* snaps the camera back to where the player faces.
*/
public final class Freelook extends Module {
/** Left Alt's scancode. */
static final int LEFT_ALT = 226;
/** How the key works. */
public enum Mode {
HOLD("Hold"),
TOGGLE("Toggle");
private final String label;
Mode(String label) {
this.label = label;
}
/** What the settings screen calls it. */
public String label() {
return label;
}
}
/** Where the camera goes while looking. */
public enum View {
BACK("Behind"),
FRONT("In front"),
FIRST("First person");
private final String label;
View(String label) {
this.label = label;
}
/** What the settings screen calls it. */
public String label() {
return label;
}
}
final KeySetting key = settings()
.key("look", "Freelook key", Key.keyboard(LEFT_ALT))
.describedAs("Hold (or press) to look around without turning.");
final ChoiceSetting<Mode> mode = settings()
.choice("mode", "Key", Mode.values(), Mode.HOLD, Mode::label)
.describedAs("Hold the key to look around, or press it once to start and again to stop.");
final ChoiceSetting<View> view = settings()
.choice("view", "Camera", View.values(), View.BACK, View::label)
.describedAs("Where the camera goes while you look around.");
final BooleanSetting invert = settings()
.bool("invert", "Invert up and down", false)
.describedAs("Moving the mouse up looks down while looking around.");
private boolean toggled;
private boolean active;
/** Whether the camera's angles are still to be taken from the player's on the next frame. */
private boolean fresh;
private float yaw;
private float pitch;
private Perspective before = Perspective.FIRST_PERSON;
/** Freelook, off until the player turns it on. */
public Freelook() {
super("freelook", "Freelook", "Hold a key to look around without turning.", Category.VISUAL);
key.onPress(() -> toggled = !toggled);
on(Events.TICK, this::tick);
on(Events.TURN, this::onTurn);
on(Events.CAMERA, this::onCamera);
}
/** Whether the camera's turning on its own now. */
boolean looking() {
return active;
}
private void tick() {
boolean want = system().game().player() != null && (mode.get() == Mode.HOLD ? key.isDown() : toggled);
if (want != active) {
if (want) {
start();
} else {
stop();
}
}
}
private void start() {
Game game = system().game();
active = true;
fresh = true;
before = game.perspective();
Perspective wanted =
switch (view.get()) {
case BACK -> Perspective.THIRD_PERSON_BACK;
case FRONT -> Perspective.THIRD_PERSON_FRONT;
case FIRST -> Perspective.FIRST_PERSON;
};
if (wanted != before) {
game.setPerspective(wanted);
}
}
private void stop() {
active = false;
toggled = false;
Game game = system().game();
if (game.perspective() != before) {
game.setPerspective(before);
}
}
@Override
protected void onDisable() {
if (active) {
stop();
}
toggled = false;
}
private void onTurn(Turn turn) {
if (!active) {
return;
}
yaw += turn.yaw();
float down = invert.get() ? -turn.pitch() : turn.pitch();
pitch = Math.max(-90, Math.min(90, pitch + down));
turn.consume();
}
private void onCamera(CameraAngles camera) {
if (!active) {
return;
}
if (fresh) {
yaw = camera.yaw();
pitch = camera.pitch();
fresh = false;
}
camera.set(yaw, pitch);
}
}
@@ -0,0 +1,5 @@
/** Freelook (ADR 0053): hold a key to look around without turning. */
@NullMarked
package incari.features.freelook;
import org.jspecify.annotations.NullMarked;
@@ -0,0 +1,20 @@
package incari.features.freelook;
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.freelook", 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.freelook..");
}
@@ -0,0 +1,80 @@
package incari.features.freelook;
import static org.assertj.core.api.Assertions.assertThat;
import incari.framework.event.CameraAngles;
import incari.framework.event.Turn;
import incari.framework.game.Perspective;
import incari.framework.setting.ChoiceSetting;
import incari.framework.setting.Key;
import incari.framework.testing.TestGame;
import org.junit.jupiter.api.Test;
class FreelookTest {
private static final Key ALT = Key.keyboard(Freelook.LEFT_ALT);
private final Freelook module = new Freelook();
private final TestGame game = new TestGame(module);
@Test
void holdingTheKeyTurnsTheCameraNotThePlayer() {
module.setEnabled(true);
game.join();
game.hold(ALT, true);
game.tick();
assertThat(game.perspective).isEqualTo(Perspective.THIRD_PERSON_BACK);
CameraAngles start = game.camera(90, 10);
assertThat(start.changed()).isTrue();
Turn turn = game.turn(30, -5);
assertThat(turn.consumed()).isTrue();
CameraAngles after = game.camera(90, 10);
assertThat(after.yaw()).isEqualTo(120);
assertThat(after.pitch()).isEqualTo(5);
game.hold(ALT, false);
game.tick();
assertThat(game.perspective).isEqualTo(Perspective.FIRST_PERSON);
assertThat(game.turn(30, 0).consumed()).isFalse();
assertThat(game.camera(90, 10).changed()).isFalse();
}
@Test
void theToggleStaysOnUntilPressedAgain() {
module.setEnabled(true);
@SuppressWarnings("unchecked")
ChoiceSetting<Freelook.Mode> mode =
(ChoiceSetting<Freelook.Mode>) module.settings().get("mode");
mode.set(Freelook.Mode.TOGGLE);
game.join();
game.press(ALT);
game.tick();
game.tick();
assertThat(module.looking()).isTrue();
game.press(ALT);
game.tick();
assertThat(module.looking()).isFalse();
}
@Test
void lookingStraightUpIsAsFarAsItGoes() {
module.setEnabled(true);
game.join();
game.hold(ALT, true);
game.tick();
game.camera(0, 0);
game.turn(0, -500);
assertThat(game.camera(0, 0).pitch()).isEqualTo(-90);
}
@Test
void turningOffPutsTheViewBack() {
module.setEnabled(true);
game.join();
game.hold(ALT, true);
game.tick();
module.setEnabled(false);
assertThat(game.perspective).isEqualTo(Perspective.FIRST_PERSON);
}
}
@@ -0,0 +1,11 @@
# fullbright: Fullbright
Lights caves and nights like day, for you only, as night vision would (no potion icon, Brightness slider untouched).
| Setting | Kind | Default |
| --- | --- | --- |
| Brightness | 10-100% | 100%: fully lit |
```sh
./gradlew :features:fullbright:check
```
@@ -0,0 +1,16 @@
plugins {
`java-library`
}
// Fullbright: the world fully lit, as night vision lights 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,43 @@
package incari.features.fullbright;
import incari.framework.Category;
import incari.framework.Module;
import incari.framework.event.Events;
import incari.framework.setting.IntSetting;
/**
* Fullbright: caves and nights as light as day, on this client only. The game's lightmap is lit as
* night vision lights it ({@code Game.overrideBrightness}), so there's no potion icon or particles,
* and the Brightness slider stays the player's. A real night vision effect still shows if stronger.
*/
public final class Fullbright extends Module {
final IntSetting level = settings()
.integer("level", "Brightness", 10, 100, 100)
.formattedAs(percent -> percent + "%")
.describedAs("100%: everything fully lit, as with night vision.");
/** Fullbright, off until the player turns it on. */
public Fullbright() {
super(
"fullbright",
"Fullbright",
"Lights up caves and nights as if it were day, on your screen only.",
Category.VISUAL);
on(Events.TICK, this::apply);
}
private void apply() {
system().game().overrideBrightness(level.get() / 100F);
}
@Override
protected void onEnable() {
apply();
}
@Override
protected void onDisable() {
system().game().overrideBrightness(0);
}
}
@@ -0,0 +1,5 @@
/** Fullbright: the world fully lit, as night vision lights it. */
@NullMarked
package incari.features.fullbright;
import org.jspecify.annotations.NullMarked;
@@ -0,0 +1,24 @@
package incari.features.fullbright;
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.fullbright", 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.fullbright..");
}
@@ -0,0 +1,26 @@
package incari.features.fullbright;
import static org.assertj.core.api.Assertions.assertThat;
import incari.framework.testing.TestGame;
import org.junit.jupiter.api.Test;
class FullbrightTest {
private final Fullbright module = new Fullbright();
private final TestGame game = new TestGame(module);
@Test
void lightsTheWorldWhileOnAndGivesTheGamesLightBack() {
assertThat(game.brightness).isZero();
module.setEnabled(true);
assertThat(game.brightness).isEqualTo(1F);
module.level.set(50);
game.tick();
assertThat(game.brightness).isEqualTo(0.5F);
module.setEnabled(false);
assertThat(game.brightness).isZero();
}
}
@@ -0,0 +1,11 @@
# glintcolor: Enchant Glint
Colors the enchantment shimmer on items and armor your way. Speed and strength stay the game's accessibility options. Only you see it. ([ADR 0061](../../docs/adr/0061-cosmetics.md))
| Setting | Kind | Default |
| --- | --- | --- |
| Color | color | `#7FC8FF` |
```sh
./gradlew :features:glintcolor:check
```
@@ -0,0 +1,16 @@
plugins {
`java-library`
}
// Enchant Glint (ADR 0061): the enchantment glint in a color of the player's.
// 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,35 @@
package incari.features.glintcolor;
import incari.framework.Category;
import incari.framework.Module;
import incari.framework.event.Events;
import incari.framework.setting.ColorSetting;
/**
* Enchant Glint: the shimmer on enchanted items and armor in the player's color instead of purple.
* Its speed and strength are the game's own accessibility options.
*/
public final class EnchantGlint extends Module {
final ColorSetting color = settings().color("color", "Color", 0x7FC8FF).describedAs("The glint's color.");
/** Enchant Glint, off until the player turns it on. */
public EnchantGlint() {
super("glintcolor", "Enchant Glint", "Colors the shimmer on enchanted items and armor.", Category.VISUAL);
on(Events.TICK, this::apply);
}
private void apply() {
system().game().overrideGlintColor(color.get() & 0xFFFFFF);
}
@Override
protected void onEnable() {
apply();
}
@Override
protected void onDisable() {
system().game().overrideGlintColor(-1);
}
}
@@ -0,0 +1,5 @@
/** Enchant Glint (ADR 0061): the enchantment glint in a color of the player's. */
@NullMarked
package incari.features.glintcolor;
import org.jspecify.annotations.NullMarked;
@@ -0,0 +1,24 @@
package incari.features.glintcolor;
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.glintcolor", 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.glintcolor..");
}
@@ -0,0 +1,23 @@
package incari.features.glintcolor;
import static org.assertj.core.api.Assertions.assertThat;
import incari.framework.testing.TestGame;
import org.junit.jupiter.api.Test;
class EnchantGlintTest {
private final EnchantGlint module = new EnchantGlint();
private final TestGame game = new TestGame(module);
@Test
void colorsTheGlintWhileOn() {
module.setEnabled(true);
assertThat(game.glintColor).isEqualTo(0x7FC8FF);
module.color.set(0xFF8800);
game.tick();
assertThat(game.glintColor).isEqualTo(0xFF8800);
module.setEnabled(false);
assertThat(game.glintColor).isEqualTo(-1);
}
}
@@ -0,0 +1,21 @@
# hitboxes: Hitboxes
Draws the box each player or mob is hit by, as F3+B does, in your own color and width. The box your
crosshair is on can have its own color. Only you see it; it shows whatever the server's debug rules.
While F3+B is on, the game's own boxes show instead.
| Setting | Kind | Default |
| --- | --- | --- |
| Color | color | `#FFFFFF` |
| Opacity | 10-100% | 100% |
| Width | 1-6 pixels | 2 |
| Target color | on/off | on |
| Target's color | color (when Target color is on) | `#FF5555` |
| Show | Players, Players and mobs, Everything | Players and mobs |
| Eye height | on/off | on |
| Look direction | on/off | on |
| Your own | on/off (third person) | off |
```sh
./gradlew :features:hitboxes:check
```
@@ -0,0 +1,16 @@
plugins {
`java-library`
}
// Hitboxes: the box each entity is hit by, drawn in the world in the player's color and width.
// 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,79 @@
package incari.features.hitboxes;
import incari.framework.Category;
import incari.framework.Module;
import incari.framework.game.Hitboxes;
import incari.framework.setting.BooleanSetting;
import incari.framework.setting.ChoiceSetting;
import incari.framework.setting.ColorSetting;
import incari.framework.setting.FloatSetting;
import incari.framework.setting.IntSetting;
import incari.framework.setting.Setting;
/**
* Hitboxes: the box each entity is hit by, in the player's color and width, the one under the
* crosshair in another if they like; with the eye-height line and look arrow F3+B shows. The style
* is handed to the game once per change, not per tick: the client draws it every frame.
*/
public final class HitboxesModule extends Module {
final ColorSetting color = settings().color("color", "Color", 0xFFFFFF).describedAs("The boxes' color.");
final IntSetting opacity = settings()
.integer("opacity", "Opacity", 10, 100, 100)
.formattedAs(value -> value + "%")
.describedAs("How solid the boxes are.");
final FloatSetting width =
settings().decimal("width", "Width", 1, 6, 0.5F, 2).describedAs("How thick the lines are, in pixels.");
final BooleanSetting targetColored = settings()
.bool("target-colored", "Target color", true)
.describedAs("Colors the box your crosshair is on differently.");
final ColorSetting targetColor = settings()
.color("target-color", "Target's color", 0xFF5555)
.describedAs("The color of the box your crosshair is on.")
.visibleWhen(targetColored::get);
final ChoiceSetting<Hitboxes.Show> show = settings()
.choice("show", "Show", Hitboxes.Show.values(), Hitboxes.Show.LIVING, Hitboxes.Show::label)
.describedAs("Which entities get a box.");
final BooleanSetting eyeLine =
settings().bool("eye-line", "Eye height", true).describedAs("A red line where each one's eyes are.");
final BooleanSetting lookLine =
settings().bool("look-line", "Look direction", true).describedAs("A blue arrow the way each one looks.");
final BooleanSetting own =
settings().bool("own", "Your own", false).describedAs("Your own box too, in third person.");
/** Hitboxes, off until the player turns it on. */
public HitboxesModule() {
super("hitboxes", "Hitboxes", "Shows the box each player or mob is hit by.", Category.COMBAT);
for (Setting<?> setting : settings()) {
setting.onChange(this::changed);
}
}
private void changed() {
if (isEnabled()) {
system().game().overrideHitboxes(style());
}
}
@Override
protected void onEnable() {
system().game().overrideHitboxes(style());
}
@Override
protected void onDisable() {
system().game().overrideHitboxes(null);
}
/** What the settings say, as the game takes it. */
Hitboxes style() {
int argb = withOpacity(color.get(), opacity.get());
int target = targetColored.get() ? withOpacity(targetColor.get(), opacity.get()) : argb;
return new Hitboxes(argb, target, width.get(), show.get(), eyeLine.get(), lookLine.get(), own.get());
}
/** {@code rgb} at {@code percent} opacity. */
static int withOpacity(int rgb, int percent) {
return Math.round(percent * 255 / 100.0F) << 24 | (rgb & 0xFFFFFF);
}
}
@@ -0,0 +1,5 @@
/** Hitboxes: the box each entity is hit by, drawn in the world in the player's color and width. */
@NullMarked
package incari.features.hitboxes;
import org.jspecify.annotations.NullMarked;
@@ -0,0 +1,20 @@
package incari.features.hitboxes;
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.hitboxes", 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.hitboxes..");
}
@@ -0,0 +1,49 @@
package incari.features.hitboxes;
import static org.assertj.core.api.Assertions.assertThat;
import incari.framework.game.Hitboxes;
import incari.framework.testing.TestGame;
import org.junit.jupiter.api.Test;
class HitboxesModuleTest {
private final HitboxesModule module = new HitboxesModule();
private final TestGame game = new TestGame(module);
@Test
void drawsTheBoxesWhileOnAndNoneAfter() {
assertThat(game.hitboxes).isNull();
module.setEnabled(true);
assertThat(game.hitboxes)
.isEqualTo(new Hitboxes(0xFFFFFFFF, 0xFFFF5555, 2, Hitboxes.Show.LIVING, true, true, false));
module.setEnabled(false);
assertThat(game.hitboxes).isNull();
}
@Test
void aChangedSettingReachesTheGameAtOnceButOnlyWhileOn() {
module.setEnabled(true);
module.color.set(0x00FF00);
module.opacity.set(50);
module.show.set(Hitboxes.Show.PLAYERS);
assertThat(game.hitboxes).isNotNull();
assertThat(game.hitboxes.color()).isEqualTo(0x8000FF00);
assertThat(game.hitboxes.show()).isEqualTo(Hitboxes.Show.PLAYERS);
module.targetColored.set(false);
assertThat(game.hitboxes.targetColor()).isEqualTo(game.hitboxes.color());
module.setEnabled(false);
module.width.set(4);
assertThat(game.hitboxes).isNull();
}
@Test
void opacityScalesTheAlpha() {
assertThat(HitboxesModule.withOpacity(0xFF123456, 100)).isEqualTo(0xFF123456);
assertThat(HitboxesModule.withOpacity(0x123456, 10) >>> 24).isEqualTo(26);
}
}
@@ -0,0 +1,12 @@
# hitcolor: Hit Color
Changes the red flash of hurt mobs and players to your color. Only you see it. ([ADR 0061](../../docs/adr/0061-cosmetics.md))
| Setting | Kind | Default |
| --- | --- | --- |
| Color | color | `#5AB8FF` |
| Strength | 10-100% | 30%: the game's own strength |
```sh
./gradlew :features:hitcolor:check
```
@@ -0,0 +1,16 @@
plugins {
`java-library`
}
// Hit Color (ADR 0061): the tint on hurt mobs and players, in a color of the player's.
// 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,41 @@
package incari.features.hitcolor;
import incari.framework.Category;
import incari.framework.Module;
import incari.framework.event.Events;
import incari.framework.setting.ColorSetting;
import incari.framework.setting.IntSetting;
/**
* Hit Color: the flash a mob or player gives when hurt, in the player's color instead of the
* game's red. On this client only.
*/
public final class HitColor extends Module {
final ColorSetting color =
settings().color("color", "Color", 0x5AB8FF).describedAs("The color hurt mobs and players flash.");
final IntSetting strength = settings()
.integer("strength", "Strength", 10, 100, 30)
.formattedAs(value -> value + "%")
.describedAs("How strongly they're tinted. The game's red is 30%.");
/** Hit Color, off until the player turns it on. */
public HitColor() {
super("hitcolor", "Hit Color", "Changes the color hurt mobs and players flash.", Category.VISUAL);
on(Events.TICK, this::apply);
}
private void apply() {
system().game().overrideHitColor(color.get() & 0xFFFFFF, strength.get());
}
@Override
protected void onEnable() {
apply();
}
@Override
protected void onDisable() {
system().game().overrideHitColor(0, 0);
}
}
@@ -0,0 +1,5 @@
/** Hit Color (ADR 0061): the tint on hurt mobs and players, in a color of the player's. */
@NullMarked
package incari.features.hitcolor;
import org.jspecify.annotations.NullMarked;

Some files were not shown because too many files have changed in this diff Show More