Archive incari-client (client, 26.3, clean)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
+79
@@ -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);
|
||||
}
|
||||
}
|
||||
+5
@@ -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;
|
||||
+20
@@ -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..");
|
||||
}
|
||||
+49
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user