Add placement strategies S3-S8, strategy settings GUI and themes
- Strategies: precise, fly_hover, ground_walk, baritone_walk, hold_rmb, burst (pending set + AIMD); engine batches via PlaceStrategy.batchSize/tickBatch - GUI: strategy cycle, per-strategy option sliders, switchable themes (ThemePref) - Move ColumnTarget to interaction.place.target; layer baseline is now empty - Show blocks/s in status, action bar and GUI - Tests for batching, precise support, fly hover, ground walk, burst, hold rmb
This commit is contained in:
parent
d9df098064
commit
da99a448e1
47 changed files with 1507 additions and 115 deletions
37
README.md
37
README.md
|
|
@ -44,23 +44,34 @@ Gradle запускается на JVM 25: если дефолтная JVM др
|
|||
| `.build block <id>` | блок (`stone`, `minecraft:glass` или `hand` — блок из руки) |
|
||||
| `.build shape box\|checker\|walls` | форма застройки области |
|
||||
| `.build layers 1..3` | слоёв за один проход колонны |
|
||||
| `.build strategy <id>` | стратегия постановки (`band_stack`, `column_drop`) |
|
||||
| `.build set <ключ> <знач>` | параметр стратегии (`delayMs`, `reach`, `hover`, `flySpeed`, `bandLayers`) |
|
||||
| `.build strategy <id>` | стратегия постановки (см. таблицу ниже) |
|
||||
| `.build set <ключ> <знач>` | параметр стратегии (`delayMs`, `reach`, `hover`, `flySpeed`, `bandLayers`, `burst`) |
|
||||
|
||||
### GUI (Right Shift)
|
||||
|
||||
Pos1/Pos2 — зафиксировать текущую позицию ног; Старт/Пауза/Продолжить/Стоп;
|
||||
форма; слои; задержка установки; ID блока (Enter — применить). Внизу — живой
|
||||
статус: этап, прогресс, блоков/с, дыры. Во время стройки тот же статус раз в
|
||||
секунду дублируется над хотбаром.
|
||||
Pos1/Pos2 — зафиксировать текущую позицию ног; Старт/Пауза/Продолжить/Стоп; форма;
|
||||
стратегия (циклическая кнопка — панель параметров выбранной стратегии перестраивается
|
||||
автоматически); слайдеры параметров стратегии; тема (оранжевый/белый/мятный/песочный
|
||||
акцент, выбор сохраняется в `config/satura/render.json`); ID блока (Enter — применить).
|
||||
Внизу — живой статус: этап, прогресс, блоков/с, дыры. Во время стройки тот же статус
|
||||
раз в секунду дублируется над хотбаром.
|
||||
|
||||
### Стратегии постановки
|
||||
|
||||
- **BandStack** (дефолт) — за один визит колонны ставится 1–3 слоя снизу вверх.
|
||||
- **ColumnDrop** — по одному слою за визит.
|
||||
Обе летают над слоем и ставят в колонну под собой. Для серверов с жёстким
|
||||
анти-читом используй меньший `delayMs` и без полёта (наземные стратегии — план
|
||||
Фазы 9, S5/S6).
|
||||
| id | Что делает | Референс |
|
||||
|---|---|---|
|
||||
| `band_stack` (дефолт) | полёт над слоем, 1–3 слоя за визит колонны, клик под собой | yatwinkle |
|
||||
| `column_drop` | то же, но по одному слою за визит | yatwinkle |
|
||||
| `precise` | хавер над колонной + точный выбор опоры (UP → бока → DOWN), LOS-проверка, до 12 ретраев на ячейку | pveclient |
|
||||
| `fly_hover` | полёт к точке стояния (клик + нормаль × 2.4), скорость `min(0.34k, max(0.08k, dist·0.35k))` | pveclient FLY |
|
||||
| `ground_walk` | ходьба фейк-клавишами + пиллар-прыжки с постановкой под себя — для серверов без полёта | AutoBuild |
|
||||
| `baritone_walk` | Baritone только ходит (`GoalXZ`, `allowBreak/Place=false`), ставим по подходе (precise) | AutoBuild |
|
||||
| `hold_rmb` | ставит только пока зажата ПКМ (ручной контроль) | yatwinkle HOLD_RMB |
|
||||
| `burst` | несколько кликов за тик (1–8), pending-сет с TTL 3 тика, AIMD сам снижает burst/растит задержку при отказах | свой |
|
||||
|
||||
Для серверов с анти-читом: `band_stack`/`column_drop`/`burst` шлют клики без доворота
|
||||
камеры и летят через `setVelocity` — их могут флагать; безопасный дефолт — `precise`
|
||||
или `ground_walk` (меньший `delayMs`, наземное перемещение).
|
||||
|
||||
Настройки хранятся в `config/satura/default.json` и применяются при старте.
|
||||
|
||||
|
|
@ -75,9 +86,9 @@ gui → feature (только через фасад BuilderFeature)
|
|||
|
||||
- `core` — событие/команды/конфиг, ничего не знает о фичах;
|
||||
- `feature/builder` — селекция, план (формы), скан (ColumnCache), движок, Baritone-мост;
|
||||
- `interaction` — «руки»: постановка блоков (стратегии), инвентарь, движение;
|
||||
- `interaction` — «руки»: постановка блоков (8 стратегий), инвентарь, движение;
|
||||
- `gui` — экран и виджеты, общается с фичей только через фасад;
|
||||
- `render` — GUI-рендер (rect/blur/outline/MSDF-текст) и рамка выделения в мире.
|
||||
- `render` — GUI-рендер (rect/blur/outline/MSDF-текст), палитры `Theme` и рамка выделения в мире.
|
||||
|
||||
Правила кода: максимум 250 строк на `.java`-файл, максимум 4 файла на пакет,
|
||||
магические числа — в константы, гейт сборки — `./gradlew check` (Checkstyle +
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
# Известные нарушения слоёв (долг). Новые нарушения валят check; этот список только уменьшается.
|
||||
# Формат: путь-к-файлу -> пакет, который импортируется
|
||||
interaction/place/PlaceStrategy.java -> feature
|
||||
interaction/place/option/CommonOptions.java -> feature
|
||||
interaction/place/strategy/BandStack.java -> feature
|
||||
interaction/place/strategy/ColumnDrop.java -> feature
|
||||
interaction/place/strategy/ColumnPlacing.java -> feature
|
||||
# (список пуст: стратегии больше не импортируют feature — ColumnTarget переехал в interaction.place)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import dev.loki.satura.core.config.ConfigStore;
|
|||
import dev.loki.satura.core.event.EventBus;
|
||||
import dev.loki.satura.feature.builder.BuilderFeature;
|
||||
import dev.loki.satura.gui.BuilderUi;
|
||||
import dev.loki.satura.gui.ThemePref;
|
||||
import dev.loki.satura.render.RenderDebug;
|
||||
import dev.loki.satura.render.Renderer;
|
||||
import dev.loki.satura.render.world.Marks;
|
||||
|
|
@ -39,9 +40,10 @@ public final class SaturaClient implements ClientModInitializer {
|
|||
CoreServices.install(new CoreServices(events, commands, config));
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> builder.tick());
|
||||
RenderDebug.installIfEnabled(Renderer.shared());
|
||||
ThemePref.load(config);
|
||||
new SelectionRenderer(() -> new Marks(builder.selection().pos1(), builder.selection().pos2()),
|
||||
SELECTION_SEE_THROUGH).register();
|
||||
new BuilderUi(builder, new ActionBarOut()).register();
|
||||
new BuilderUi(builder, new ActionBarOut(), config).register();
|
||||
LOG.info("[satura] client init");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package dev.loki.satura.feature.builder;
|
||||
|
||||
import dev.loki.satura.core.config.Profile;
|
||||
import dev.loki.satura.feature.builder.plan.Planner;
|
||||
import dev.loki.satura.feature.builder.plan.shape.BoxShape;
|
||||
import dev.loki.satura.feature.builder.plan.shape.CheckerShape;
|
||||
import dev.loki.satura.feature.builder.plan.shape.Shape;
|
||||
|
|
@ -9,6 +8,7 @@ import dev.loki.satura.feature.builder.plan.shape.WallsShape;
|
|||
import dev.loki.satura.interaction.place.PlaceStrategy;
|
||||
import dev.loki.satura.interaction.place.option.CommonOptions;
|
||||
import dev.loki.satura.interaction.place.option.Option;
|
||||
import dev.loki.satura.interaction.place.option.OptionType;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
|
@ -23,6 +23,11 @@ public final class BuildSettings {
|
|||
public record Range(double min, double max, double step, double value) {
|
||||
}
|
||||
|
||||
/** GUI-facing slider description: no interaction types leak into the gui layer. */
|
||||
public record Slider(String key, String label, boolean integer,
|
||||
double min, double max, double step, double value) {
|
||||
}
|
||||
|
||||
static final String KEY_BLOCK = "block";
|
||||
static final String KEY_SHAPE = "shape";
|
||||
static final String KEY_LAYERS = "layers";
|
||||
|
|
@ -100,7 +105,7 @@ public final class BuildSettings {
|
|||
}
|
||||
|
||||
public void setLayers(final int value) {
|
||||
require(value >= Planner.MIN_BAND_LAYERS && value <= Planner.MAX_BAND_LAYERS, "слои: 1-3");
|
||||
require(value >= CommonOptions.MIN_LAYERS && value <= CommonOptions.MAX_LAYERS, "слои: 1-3");
|
||||
layers = value;
|
||||
strategies.values().stream().filter(s -> s.options().contains(CommonOptions.BAND_LAYERS))
|
||||
.forEach(s -> s.values().set(CommonOptions.BAND_LAYERS.key(), value));
|
||||
|
|
@ -116,6 +121,14 @@ public final class BuildSettings {
|
|||
.map(o -> new Range(o.min(), o.max(), o.step(), strategy().values().get(o)));
|
||||
}
|
||||
|
||||
/** All sliders of the current strategy, in declaration order (the GUI draws them generically). */
|
||||
public List<Slider> optionSliders() {
|
||||
return strategy().options().stream()
|
||||
.map(o -> new Slider(o.key(), o.label(), o.type() == OptionType.INT,
|
||||
o.min(), o.max(), o.step(), strategy().values().get(o)))
|
||||
.toList();
|
||||
}
|
||||
|
||||
public void setOption(final String key, final String value) {
|
||||
final double number;
|
||||
try {
|
||||
|
|
@ -151,7 +164,7 @@ public final class BuildSettings {
|
|||
|
||||
private static int parseLayers(final String raw) {
|
||||
final int v = Integer.parseInt(raw);
|
||||
return Math.max(Planner.MIN_BAND_LAYERS, Math.min(Planner.MAX_BAND_LAYERS, v));
|
||||
return Math.max(CommonOptions.MIN_LAYERS, Math.min(CommonOptions.MAX_LAYERS, v));
|
||||
}
|
||||
|
||||
private static void require(final boolean ok, final String message) {
|
||||
|
|
|
|||
|
|
@ -14,9 +14,21 @@ import dev.loki.satura.feature.builder.selection.Area;
|
|||
import dev.loki.satura.feature.builder.selection.PosCommand;
|
||||
import dev.loki.satura.feature.builder.selection.SelCommand;
|
||||
import dev.loki.satura.feature.builder.selection.Selection;
|
||||
import dev.loki.satura.interaction.movement.MovementController;
|
||||
import dev.loki.satura.interaction.movement.WalkPort;
|
||||
import dev.loki.satura.interaction.movement.io.MinecraftKeyInput;
|
||||
import dev.loki.satura.interaction.movement.io.MinecraftPlayerPose;
|
||||
import dev.loki.satura.interaction.place.PlaceStrategy;
|
||||
import dev.loki.satura.interaction.place.strategy.BandStack;
|
||||
import dev.loki.satura.interaction.place.strategy.ColumnDrop;
|
||||
import dev.loki.satura.interaction.place.strategy.ground.BaritoneWalk;
|
||||
import dev.loki.satura.interaction.place.strategy.ground.GroundMove;
|
||||
import dev.loki.satura.interaction.place.strategy.ground.GroundWalk;
|
||||
import dev.loki.satura.interaction.place.strategy.manual.BurstPlace;
|
||||
import dev.loki.satura.interaction.place.strategy.manual.HoldRmb;
|
||||
import dev.loki.satura.interaction.place.strategy.precise.FlyHover;
|
||||
import dev.loki.satura.interaction.place.strategy.precise.PrecisePlacement;
|
||||
import dev.loki.satura.interaction.place.strategy.precise.PreciseSupport;
|
||||
import dev.loki.satura.interaction.place.support.BlockPlacer;
|
||||
import dev.loki.satura.interaction.place.support.Cooldown;
|
||||
import dev.loki.satura.interaction.place.support.SupportFinder;
|
||||
|
|
@ -62,7 +74,26 @@ public final class BuilderFeature implements BuildControl {
|
|||
final ConfigStore store, final Walker walker) {
|
||||
final MinecraftClient client = MinecraftClient.getInstance();
|
||||
final BlockPlacer placer = new BlockPlacer(new SupportFinder(), new Cooldown());
|
||||
final List<PlaceStrategy> strategies = List.of(new BandStack(placer), new ColumnDrop(placer));
|
||||
final PreciseSupport precise = new PreciseSupport();
|
||||
final BlockPlacer precisePlacer = new BlockPlacer(precise, new Cooldown());
|
||||
final GroundMove ground = new GroundMove(new MovementController(
|
||||
new MinecraftKeyInput(client), new MinecraftPlayerPose(client)));
|
||||
final WalkPort port = new WalkPort() {
|
||||
@Override
|
||||
public boolean walkTo(final double x, final double z) {
|
||||
return walker.walkTo(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
walker.cancel();
|
||||
}
|
||||
};
|
||||
final List<PlaceStrategy> strategies = List.of(
|
||||
new BandStack(placer), new ColumnDrop(placer),
|
||||
new PrecisePlacement(precisePlacer), new FlyHover(precise, precisePlacer),
|
||||
new GroundWalk(ground, placer), new BaritoneWalk(port, precisePlacer),
|
||||
new HoldRmb(placer), new BurstPlace(precise));
|
||||
return new BuilderFeature(commands, () -> client.player == null ? null : client.player.getBlockPos(),
|
||||
new EngineAssembler(client, events, walker, new ChatOut(), new ActionBarOut()),
|
||||
new BuildSettings(store.loadOrEmpty(Profile.DEFAULT_NAME), strategies), store::saveQuietly);
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@ package dev.loki.satura.feature.builder.engine;
|
|||
import dev.loki.satura.core.event.Listener;
|
||||
import dev.loki.satura.core.event.world.BlockChangeEvent;
|
||||
import dev.loki.satura.feature.builder.engine.host.EngineDeps;
|
||||
import dev.loki.satura.feature.builder.plan.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.target.ColumnTarget;
|
||||
import dev.loki.satura.interaction.inventory.HotbarRefill;
|
||||
import dev.loki.satura.interaction.place.PlaceResult;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
|
|
@ -31,6 +32,7 @@ public final class BuildEngine {
|
|||
}
|
||||
|
||||
public void start() {
|
||||
deps.strategy().reset();
|
||||
deps.events().subscribe(blockListener);
|
||||
world = deps.game().worldToken();
|
||||
deps.cache().fullRescan();
|
||||
|
|
@ -98,7 +100,44 @@ public final class BuildEngine {
|
|||
session.pause(NO_BLOCKS, false);
|
||||
deps.chat().accept("Пауза: " + NO_BLOCKS + ". Положи блоки и .build resume");
|
||||
} else if (stock == HotbarRefill.State.READY) {
|
||||
deps.planner().next().ifPresentOrElse(this::place, this::finishOrRepair);
|
||||
place();
|
||||
}
|
||||
}
|
||||
|
||||
/** Asks the planner for a batch (the strategy declares its size) and applies every result. */
|
||||
private void place() {
|
||||
final int size = Math.max(1, deps.strategy().batchSize());
|
||||
final List<ColumnTarget> targets = deps.planner().nextBatch(size);
|
||||
if (targets.isEmpty()) {
|
||||
finishOrRepair();
|
||||
return;
|
||||
}
|
||||
final List<PlaceResult> results = size == 1
|
||||
? List.of(deps.strategy().tick(deps.ctx(), targets.get(0)))
|
||||
: deps.strategy().tickBatch(deps.ctx(), targets);
|
||||
for (int i = 0; i < Math.min(targets.size(), results.size()); i++) {
|
||||
apply(targets.get(i), results.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
private void apply(final ColumnTarget target, final PlaceResult result) {
|
||||
final var tracker = deps.tracker();
|
||||
tracker.observe(target.column(), deps.cache().done());
|
||||
session.at(target.column());
|
||||
switch (result) {
|
||||
case PLACED -> session.onPlaced();
|
||||
case FAILED -> {
|
||||
session.onFailed();
|
||||
if (tracker.failure()) {
|
||||
tracker.skip(target.column());
|
||||
}
|
||||
}
|
||||
case WAIT -> {
|
||||
if (tracker.stall()) {
|
||||
tracker.skip(target.column());
|
||||
}
|
||||
}
|
||||
default -> throw new IllegalStateException("unknown result: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -110,27 +149,6 @@ public final class BuildEngine {
|
|||
}
|
||||
}
|
||||
|
||||
private void place(final ColumnTarget target) {
|
||||
final var tracker = deps.tracker();
|
||||
tracker.observe(target.column(), deps.cache().done());
|
||||
session.at(target.column());
|
||||
final PlaceResult result = deps.strategy().tick(deps.ctx(), target);
|
||||
final boolean giveUp = switch (result) {
|
||||
case PLACED -> {
|
||||
session.onPlaced();
|
||||
yield false;
|
||||
}
|
||||
case FAILED -> {
|
||||
session.onFailed();
|
||||
yield tracker.failure();
|
||||
}
|
||||
case WAIT -> tracker.stall();
|
||||
};
|
||||
if (giveUp) {
|
||||
tracker.skip(target.column());
|
||||
}
|
||||
}
|
||||
|
||||
private void finishOrRepair() {
|
||||
if (deps.tracker().startRepair(deps.planner())) {
|
||||
deps.chat().accept("Ремонтный проход " + deps.tracker().passes() + ", дыр: "
|
||||
|
|
@ -145,6 +163,7 @@ public final class BuildEngine {
|
|||
}
|
||||
|
||||
private void halt() {
|
||||
deps.strategy().reset();
|
||||
deps.walker().cancel();
|
||||
if (deps.game().blockReason().isEmpty()) {
|
||||
deps.ctx().setVelocity(0, 0, 0);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package dev.loki.satura.feature.builder.plan;
|
|||
|
||||
import dev.loki.satura.feature.builder.plan.shape.Shape;
|
||||
import dev.loki.satura.feature.builder.selection.Area;
|
||||
import dev.loki.satura.interaction.place.target.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.option.CommonOptions;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
|
@ -11,9 +13,6 @@ import net.minecraft.util.math.BlockPos;
|
|||
/** Slices the area into Y windows and returns the next unfinished column in snake order. */
|
||||
public final class Planner {
|
||||
|
||||
public static final int MIN_BAND_LAYERS = 1;
|
||||
public static final int MAX_BAND_LAYERS = 3;
|
||||
|
||||
private final Area area;
|
||||
private final Shape shape;
|
||||
private final int bandLayers;
|
||||
|
|
@ -25,7 +24,7 @@ public final class Planner {
|
|||
final Predicate<BlockPos> done) {
|
||||
this.area = area;
|
||||
this.shape = shape;
|
||||
this.bandLayers = Math.max(MIN_BAND_LAYERS, Math.min(MAX_BAND_LAYERS, bandLayers));
|
||||
this.bandLayers = Math.max(CommonOptions.MIN_LAYERS, Math.min(CommonOptions.MAX_LAYERS, bandLayers));
|
||||
this.done = done;
|
||||
this.columns = area.columns();
|
||||
this.bandFloor = area.min().getY();
|
||||
|
|
@ -57,6 +56,31 @@ public final class Planner {
|
|||
bandFloor = area.min().getY();
|
||||
}
|
||||
|
||||
/**
|
||||
* Up to {@code max} unfinished columns of the current window, in snake order.
|
||||
* The window moves up only when every column of it is complete.
|
||||
*/
|
||||
public List<ColumnTarget> nextBatch(final int max) {
|
||||
final List<ColumnTarget> out = new ArrayList<>();
|
||||
if (max <= 0) {
|
||||
return out;
|
||||
}
|
||||
final int top = area.max().getY();
|
||||
while (bandFloor <= top && out.isEmpty()) {
|
||||
final int bandEnd = Math.min(bandFloor + bandLayers - 1, top);
|
||||
for (final BlockPos column : columns) {
|
||||
final List<BlockPos> pending = pending(column, bandFloor, bandEnd);
|
||||
if (!pending.isEmpty() && out.size() < max) {
|
||||
out.add(new ColumnTarget(column, pending));
|
||||
}
|
||||
}
|
||||
if (out.isEmpty()) {
|
||||
bandFloor = bandEnd + 1;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private List<BlockPos> pending(final BlockPos column, final int fromY, final int toY) {
|
||||
final List<BlockPos> cells = new ArrayList<>();
|
||||
for (int y = fromY; y <= toY; y++) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package dev.loki.satura.gui;
|
||||
|
||||
import dev.loki.satura.core.config.ConfigStore;
|
||||
import dev.loki.satura.feature.builder.BuilderFeature;
|
||||
import dev.loki.satura.gui.screen.BuilderScreen;
|
||||
import java.util.function.Consumer;
|
||||
|
|
@ -23,12 +24,14 @@ public final class BuilderUi {
|
|||
|
||||
private final BuilderFeature builder;
|
||||
private final Consumer<String> bar;
|
||||
private final ConfigStore store;
|
||||
private final KeyBinding openMenu;
|
||||
private final KeyBinding toggleBuild;
|
||||
|
||||
public BuilderUi(final BuilderFeature builder, final Consumer<String> bar) {
|
||||
public BuilderUi(final BuilderFeature builder, final Consumer<String> bar, final ConfigStore store) {
|
||||
this.builder = builder;
|
||||
this.bar = bar;
|
||||
this.store = store;
|
||||
this.openMenu = KeyBindingHelper.registerKeyBinding(
|
||||
new KeyBinding(KEY_MENU, GLFW.GLFW_KEY_RIGHT_SHIFT, CATEGORY));
|
||||
this.toggleBuild = KeyBindingHelper.registerKeyBinding(
|
||||
|
|
@ -43,7 +46,7 @@ public final class BuilderUi {
|
|||
private void tick(final MinecraftClient client) {
|
||||
while (openMenu.wasPressed()) {
|
||||
if (client.currentScreen == null) {
|
||||
client.setScreen(new BuilderScreen(builder, openMenu));
|
||||
client.setScreen(new BuilderScreen(builder, openMenu, store));
|
||||
}
|
||||
}
|
||||
while (toggleBuild.wasPressed()) {
|
||||
|
|
|
|||
26
src/main/java/dev/loki/satura/gui/ThemePref.java
Normal file
26
src/main/java/dev/loki/satura/gui/ThemePref.java
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package dev.loki.satura.gui;
|
||||
|
||||
import dev.loki.satura.core.config.ConfigStore;
|
||||
import dev.loki.satura.render.Theme;
|
||||
|
||||
/** Accent palette preference: loaded at start, saved on switch (profile "render"). */
|
||||
public final class ThemePref {
|
||||
|
||||
private static final String PROFILE = "render";
|
||||
private static final String KEY = "theme";
|
||||
|
||||
private ThemePref() {
|
||||
}
|
||||
|
||||
/** Reads the saved palette; call once at client start. */
|
||||
public static void load(final ConfigStore store) {
|
||||
Theme.set(Theme.byId(store.loadOrEmpty(PROFILE).get(KEY, Theme.ORANGE.id())));
|
||||
}
|
||||
|
||||
/** Switches the palette and persists the choice. */
|
||||
public static String apply(final ConfigStore store, final String id) {
|
||||
Theme.set(Theme.byId(id));
|
||||
store.saveQuietly(store.loadOrEmpty(PROFILE).with(KEY, Theme.get().id()));
|
||||
return "Тема: " + Theme.get().id();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +1,16 @@
|
|||
package dev.loki.satura.gui.screen;
|
||||
|
||||
import dev.loki.satura.core.config.ConfigStore;
|
||||
import dev.loki.satura.feature.builder.BuildSettings;
|
||||
import dev.loki.satura.feature.builder.BuilderFeature;
|
||||
import dev.loki.satura.feature.builder.engine.Stage;
|
||||
import dev.loki.satura.feature.builder.plan.Planner;
|
||||
import dev.loki.satura.gui.ThemePref;
|
||||
import dev.loki.satura.gui.widget.CycleButton;
|
||||
import dev.loki.satura.gui.widget.NumberSlider;
|
||||
import dev.loki.satura.render.Renderer;
|
||||
import dev.loki.satura.render.Theme;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
|
|
@ -19,16 +22,18 @@ import net.minecraft.client.option.KeyBinding;
|
|||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/** Builder screen: selection, start/pause/stop, shape, layers, delay, block, status line. */
|
||||
/**
|
||||
* Builder screen: selection, start/pause/stop, shape, strategy (with its own option sliders),
|
||||
* block id, theme, status line. Strategy change rebuilds the option area.
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidCatchingGenericException")
|
||||
public final class BuilderScreen extends Screen {
|
||||
|
||||
private static final int FIXED_ROWS = 5;
|
||||
private static final int FIXED_ROWS = 6;
|
||||
private static final int NOTICE_TICKS = 100;
|
||||
private static final int MAX_BLOCK_LEN = 64;
|
||||
private static final int POS1 = 1;
|
||||
private static final int POS2 = 2;
|
||||
private static final String OPT_DELAY = "delayMs";
|
||||
private static final String LANG_POS1 = "satura.gui.pos1";
|
||||
private static final String LANG_POS2 = "satura.gui.pos2";
|
||||
private static final String LANG_PAUSE = "satura.gui.pause";
|
||||
|
|
@ -36,6 +41,7 @@ public final class BuilderScreen extends Screen {
|
|||
|
||||
private final BuilderFeature builder;
|
||||
private final KeyBinding openMenu;
|
||||
private final ConfigStore store;
|
||||
private Panel panel;
|
||||
private ButtonWidget pos1Button;
|
||||
private ButtonWidget pos2Button;
|
||||
|
|
@ -43,17 +49,19 @@ public final class BuilderScreen extends Screen {
|
|||
private TextFieldWidget blockField;
|
||||
private Text notice = Text.empty();
|
||||
private int noticeTicks;
|
||||
private boolean reinitQueued;
|
||||
|
||||
public BuilderScreen(final BuilderFeature builder, final KeyBinding openMenu) {
|
||||
public BuilderScreen(final BuilderFeature builder, final KeyBinding openMenu, final ConfigStore store) {
|
||||
super(Text.translatable("satura.title"));
|
||||
this.builder = builder;
|
||||
this.openMenu = openMenu;
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
final Optional<BuildSettings.Range> delay = builder.settings().optionRange(OPT_DELAY);
|
||||
panel = new Panel(width, height, FIXED_ROWS + (delay.isPresent() ? 1 : 0));
|
||||
final List<BuildSettings.Slider> options = visibleOptions();
|
||||
panel = new Panel(width, height, FIXED_ROWS + options.size());
|
||||
final int inner = panel.inner();
|
||||
final int left = panel.left();
|
||||
final int half = (inner - Panel.GAP) / 2;
|
||||
|
|
@ -72,20 +80,17 @@ public final class BuilderScreen extends Screen {
|
|||
addDrawableChild(new CycleButton(left, y, inner, Panel.WIDGET_H, "satura.gui.shape",
|
||||
builder.shapeIds(), builder.settings().shapeId(), id -> run(() -> builder.setShape(id))));
|
||||
y += Panel.WIDGET_H + Panel.GAP;
|
||||
addDrawableChild(new NumberSlider(left, y, inner, Panel.WIDGET_H,
|
||||
new NumberSlider.Spec(Planner.MIN_BAND_LAYERS, Planner.MAX_BAND_LAYERS, 1,
|
||||
builder.settings().layers()),
|
||||
v -> Text.translatable("satura.gui.layers", formatInt(v)),
|
||||
v -> run(() -> builder.setLayers((int) Math.round(v)))));
|
||||
addDrawableChild(new CycleButton(left, y, inner, Panel.WIDGET_H, "satura.gui.strategy",
|
||||
builder.strategyIds(), builder.settings().strategy().id(), this::changeStrategy));
|
||||
y += Panel.WIDGET_H + Panel.GAP;
|
||||
if (delay.isPresent()) {
|
||||
final BuildSettings.Range r = delay.get();
|
||||
addDrawableChild(new NumberSlider(left, y, inner, Panel.WIDGET_H,
|
||||
new NumberSlider.Spec(r.min(), r.max(), r.step(), r.value()),
|
||||
v -> Text.translatable("satura.gui.delay", formatInt(v)),
|
||||
v -> run(() -> builder.setOption(OPT_DELAY, formatInt(v)))));
|
||||
for (final BuildSettings.Slider option : options) {
|
||||
addDrawableChild(optionSlider(left, y, inner, option));
|
||||
y += Panel.WIDGET_H + Panel.GAP;
|
||||
}
|
||||
addDrawableChild(new CycleButton(left, y, inner, Panel.WIDGET_H, "satura.gui.theme",
|
||||
Theme.all().stream().map(Theme::id).toList(), Theme.get().id(),
|
||||
id -> run(() -> setTheme(id))));
|
||||
y += Panel.WIDGET_H + Panel.GAP;
|
||||
blockField = new TextFieldWidget(textRenderer, left, y, inner, Panel.WIDGET_H,
|
||||
Text.translatable("satura.gui.block"));
|
||||
blockField.setMaxLength(MAX_BLOCK_LEN);
|
||||
|
|
@ -95,6 +100,11 @@ public final class BuilderScreen extends Screen {
|
|||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (reinitQueued) {
|
||||
reinitQueued = false;
|
||||
clearAndInit();
|
||||
return;
|
||||
}
|
||||
if (noticeTicks > 0) {
|
||||
noticeTicks--;
|
||||
}
|
||||
|
|
@ -111,7 +121,7 @@ public final class BuilderScreen extends Screen {
|
|||
panel.top() + Panel.PAD, Theme.TEXT);
|
||||
final String status = trim(builder.status());
|
||||
context.drawTextWithShadow(textRenderer, trim(notice.getString()),
|
||||
panel.left(), panel.statusY(), Theme.ACCENT_HOVER);
|
||||
panel.left(), panel.statusY(), Theme.get().accentHover());
|
||||
context.drawTextWithShadow(textRenderer, status,
|
||||
panel.left(), panel.statusY() + Panel.LINE_H, Theme.TEXT_MUTED);
|
||||
}
|
||||
|
|
@ -147,6 +157,35 @@ public final class BuilderScreen extends Screen {
|
|||
return false;
|
||||
}
|
||||
|
||||
/** Strategy options; truncated when the screen is too short (GUI scale 4). */
|
||||
private List<BuildSettings.Slider> visibleOptions() {
|
||||
final List<BuildSettings.Slider> options = builder.settings().optionSliders();
|
||||
final int usable = height - Panel.PAD * 2 - Panel.TITLE_H - Panel.GAP * 2
|
||||
- Panel.STATUS_ROWS * Panel.LINE_H;
|
||||
final int maxRows = usable / (Panel.WIDGET_H + Panel.GAP) - FIXED_ROWS;
|
||||
if (maxRows >= options.size()) {
|
||||
return options;
|
||||
}
|
||||
return maxRows <= 0 ? List.of() : options.subList(0, maxRows);
|
||||
}
|
||||
|
||||
private NumberSlider optionSlider(final int left, final int y, final int inner,
|
||||
final BuildSettings.Slider option) {
|
||||
return new NumberSlider(left, y, inner, Panel.WIDGET_H,
|
||||
new NumberSlider.Spec(option.min(), option.max(), option.step(), option.value()),
|
||||
v -> Text.literal(option.label() + ": " + format(option, v)),
|
||||
v -> run(() -> builder.setOption(option.key(), format(option, v))));
|
||||
}
|
||||
|
||||
private void changeStrategy(final String id) {
|
||||
run(() -> builder.setStrategy(id));
|
||||
reinitQueued = true;
|
||||
}
|
||||
|
||||
private String setTheme(final String id) {
|
||||
return ThemePref.apply(store, id);
|
||||
}
|
||||
|
||||
private void run(final Supplier<String> action) {
|
||||
try {
|
||||
showNotice(action.get());
|
||||
|
|
@ -185,8 +224,10 @@ public final class BuilderScreen extends Screen {
|
|||
return Text.translatable(key, pos.<String>map(BlockPos::toShortString).orElse("-"));
|
||||
}
|
||||
|
||||
private static String formatInt(final double value) {
|
||||
return String.valueOf(Math.round(value));
|
||||
private String format(final BuildSettings.Slider option, final double value) {
|
||||
return option.integer()
|
||||
? String.valueOf(Math.round(value))
|
||||
: String.format(Locale.ROOT, "%.1f", value);
|
||||
}
|
||||
|
||||
private String trim(final String text) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package dev.loki.satura.interaction.movement;
|
||||
|
||||
/** Long-distance walking port for strategies; Baritone sits behind it in production. */
|
||||
public interface WalkPort {
|
||||
|
||||
/** Start walking to (x, z); false if the walker is unavailable. */
|
||||
boolean walkTo(double x, double z);
|
||||
|
||||
void cancel();
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package dev.loki.satura.interaction.place;
|
|||
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
/** Everything a strategy touches in the game. A narrow interface so the logic can be tested with a fake. */
|
||||
|
|
@ -16,6 +17,12 @@ public interface PlaceContext {
|
|||
/** Whether the block is usable as a support. */
|
||||
boolean isSolid(BlockPos pos);
|
||||
|
||||
/** Whether the block face is visible from the eyes (line of sight). */
|
||||
boolean visible(BlockPos support, Direction face);
|
||||
|
||||
/** Whether the use key (right mouse button) is currently held. */
|
||||
boolean useKeyDown();
|
||||
|
||||
/** Right-click on a block; true if the client accepted the action. */
|
||||
boolean interact(BlockHitResult hit);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package dev.loki.satura.interaction.place;
|
||||
|
||||
import dev.loki.satura.feature.builder.plan.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.option.Option;
|
||||
import dev.loki.satura.interaction.place.option.OptionValues;
|
||||
import dev.loki.satura.interaction.place.target.ColumnTarget;
|
||||
import java.util.List;
|
||||
|
||||
/** A way to place blocks into a column. The engine calls {@link #tick} every tick until the column is complete. */
|
||||
|
|
@ -20,5 +20,23 @@ public interface PlaceStrategy {
|
|||
/** Current parameter values (live: the GUI may change them). */
|
||||
OptionValues values();
|
||||
|
||||
/** Columns the strategy wants per tick ({@code 1} = one placement attempt per tick). */
|
||||
default int batchSize() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** Release keys, cancel walking, drop transient state; called on start/stop/pause. */
|
||||
default void reset() {
|
||||
// stateless by default
|
||||
}
|
||||
|
||||
PlaceResult tick(PlaceContext ctx, ColumnTarget target);
|
||||
|
||||
/**
|
||||
* Place into several columns in one tick (burst). The returned list must match the input
|
||||
* order and size. Default: sequential single-target ticks.
|
||||
*/
|
||||
default List<PlaceResult> tickBatch(final PlaceContext ctx, final List<ColumnTarget> targets) {
|
||||
return targets.stream().map(t -> tick(ctx, t)).toList();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,15 @@ import net.minecraft.client.network.ClientPlayerEntity;
|
|||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.RaycastContext;
|
||||
|
||||
/** The real player and world behind {@link PlaceContext}. The client is passed to the constructor. */
|
||||
public final class MinecraftPlaceContext implements PlaceContext {
|
||||
|
||||
private static final float PITCH_DOWN = 90.0F;
|
||||
private static final double HALF = 0.5;
|
||||
|
||||
private final MinecraftClient client;
|
||||
|
||||
|
|
@ -35,6 +38,20 @@ public final class MinecraftPlaceContext implements PlaceContext {
|
|||
return !state.isAir() && state.isSolidBlock(client.world, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visible(final BlockPos support, final Direction face) {
|
||||
final ClientPlayerEntity player = client.player;
|
||||
final RaycastContext ray = new RaycastContext(player.getEyePos(), faceCenter(support, face),
|
||||
RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, player);
|
||||
final BlockHitResult hit = client.world.raycast(ray);
|
||||
return hit != null && hit.getBlockPos().equals(support);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useKeyDown() {
|
||||
return client.options.useKey.isPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean interact(final BlockHitResult hit) {
|
||||
return client.interactionManager.interactBlock(client.player, Hand.MAIN_HAND, hit).isAccepted();
|
||||
|
|
@ -67,4 +84,10 @@ public final class MinecraftPlaceContext implements PlaceContext {
|
|||
public long nowMs() {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
private static Vec3d faceCenter(final BlockPos support, final Direction face) {
|
||||
return new Vec3d(support.getX() + HALF + face.getOffsetX() * HALF,
|
||||
support.getY() + HALF + face.getOffsetY() * HALF,
|
||||
support.getZ() + HALF + face.getOffsetZ() * HALF);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
package dev.loki.satura.interaction.place.option;
|
||||
|
||||
import dev.loki.satura.feature.builder.plan.Planner;
|
||||
|
||||
/** Parameters shared by several strategies (values follow yatwinkle BaseBuilder). */
|
||||
@SuppressWarnings("PMD.DataClass")
|
||||
public final class CommonOptions {
|
||||
|
||||
/** Band window bounds, shared by the planner and the BAND_LAYERS option. */
|
||||
public static final int MIN_LAYERS = 1;
|
||||
public static final int MAX_LAYERS = 3;
|
||||
|
||||
public static final Option DELAY_MS =
|
||||
new Option("delayMs", "Задержка установки (мс)", OptionType.INT, 0, 300, 5, 0);
|
||||
public static final Option REACH =
|
||||
|
|
@ -15,8 +17,7 @@ public final class CommonOptions {
|
|||
public static final Option FLY_SPEED =
|
||||
new Option("flySpeed", "Скорость полёта", OptionType.DOUBLE, 0.05, 1.0, 0.05, 0.25);
|
||||
public static final Option BAND_LAYERS =
|
||||
new Option("bandLayers", "Слоёв за проход", OptionType.INT,
|
||||
Planner.MIN_BAND_LAYERS, Planner.MAX_BAND_LAYERS, 1, 2);
|
||||
new Option("bandLayers", "Слоёв за проход", OptionType.INT, MIN_LAYERS, MAX_LAYERS, 1, 2);
|
||||
|
||||
private CommonOptions() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package dev.loki.satura.interaction.place.strategy;
|
||||
|
||||
import dev.loki.satura.feature.builder.plan.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.target.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.PlaceContext;
|
||||
import dev.loki.satura.interaction.place.PlaceResult;
|
||||
import dev.loki.satura.interaction.place.PlaceStrategy;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package dev.loki.satura.interaction.place.strategy;
|
||||
|
||||
import dev.loki.satura.feature.builder.plan.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.target.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.PlaceContext;
|
||||
import dev.loki.satura.interaction.place.PlaceResult;
|
||||
import dev.loki.satura.interaction.place.PlaceStrategy;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package dev.loki.satura.interaction.place.strategy;
|
||||
|
||||
import dev.loki.satura.feature.builder.plan.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.target.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.PlaceContext;
|
||||
import dev.loki.satura.interaction.place.PlaceResult;
|
||||
import dev.loki.satura.interaction.place.option.CommonOptions;
|
||||
|
|
@ -9,36 +9,46 @@ import dev.loki.satura.interaction.place.support.BlockPlacer;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.IntSupplier;
|
||||
import java.util.function.Predicate;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
/** Core of the yatwinkle style: hover above the column, look down, place band layers bottom to top. */
|
||||
final class ColumnPlacing {
|
||||
public final class ColumnPlacing {
|
||||
|
||||
/** Margin: eyes 1.62 + ~0.08 (yatwinkle {@code layerY + reach - 1.7}). */
|
||||
static final double EYE_MARGIN = 1.7;
|
||||
public static final double EYE_MARGIN = 1.7;
|
||||
/** For this many ticks we do not repeat a click on the same cell until the server replies. */
|
||||
static final int PENDING_TTL_TICKS = 2;
|
||||
private static final double FEET_EPS = 0.1;
|
||||
private static final double CENTER = 0.5;
|
||||
/** Horizontal center of a block column. */
|
||||
public static final double CENTER = 0.5;
|
||||
|
||||
private final OptionValues values;
|
||||
private final IntSupplier layers;
|
||||
private final BlockPlacer placer;
|
||||
private final Predicate<PlaceContext> gate;
|
||||
private int ticks;
|
||||
private BlockPos lastPos;
|
||||
private int lastTick;
|
||||
|
||||
ColumnPlacing(final OptionValues values, final IntSupplier layers, final BlockPlacer placer) {
|
||||
this(values, layers, placer, ctx -> true);
|
||||
}
|
||||
|
||||
/** Gated variant: the click part runs only while the gate accepts the context (S7 HoldRmb). */
|
||||
public ColumnPlacing(final OptionValues values, final IntSupplier layers, final BlockPlacer placer,
|
||||
final Predicate<PlaceContext> gate) {
|
||||
this.values = values;
|
||||
this.layers = layers;
|
||||
this.placer = placer;
|
||||
this.gate = gate;
|
||||
}
|
||||
|
||||
PlaceResult tick(final PlaceContext ctx, final ColumnTarget target) {
|
||||
public PlaceResult tick(final PlaceContext ctx, final ColumnTarget target) {
|
||||
ticks++;
|
||||
final List<BlockPos> band = band(target.cells(), layers.getAsInt());
|
||||
if (band.isEmpty()) {
|
||||
if (band.isEmpty() || !gate.test(ctx)) {
|
||||
return PlaceResult.WAIT;
|
||||
}
|
||||
final BlockPos column = target.column();
|
||||
|
|
@ -83,7 +93,7 @@ final class ColumnPlacing {
|
|||
return band;
|
||||
}
|
||||
|
||||
static boolean overColumn(final Vec3d feet, final BlockPos column) {
|
||||
public static boolean overColumn(final Vec3d feet, final BlockPos column) {
|
||||
return (int) Math.floor(feet.x) == column.getX() && (int) Math.floor(feet.z) == column.getZ();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@ import net.minecraft.util.math.MathHelper;
|
|||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
/** setVelocity flight speed as in yatwinkle BaseBuilder.flyTo: straight vector to the point, no key physics. */
|
||||
final class FlightControl {
|
||||
public final class FlightControl {
|
||||
|
||||
private static final double ARRIVE_EPS = 0.05;
|
||||
|
||||
private FlightControl() {
|
||||
}
|
||||
|
||||
static Vec3d velocity(final Vec3d feet, final Vec3d goal, final double speed) {
|
||||
public static Vec3d velocity(final Vec3d feet, final Vec3d goal, final double speed) {
|
||||
final double dx = goal.x - feet.x;
|
||||
final double dz = goal.z - feet.z;
|
||||
final double dist = Math.hypot(dx, dz);
|
||||
|
|
@ -27,7 +27,7 @@ final class FlightControl {
|
|||
}
|
||||
|
||||
/** Flight height: min(bandTop+hover, layerY+reach-1.7), but not below the layer top (no standing in a block). */
|
||||
static double height(final int layerY, final int bandTop, final double hover,
|
||||
public static double height(final int layerY, final int bandTop, final double hover,
|
||||
final double reach, final double eyeMargin) {
|
||||
final double capped = Math.min(bandTop + hover, layerY + reach - eyeMargin);
|
||||
return Math.max(capped, bandTop + 1.0);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,82 @@
|
|||
package dev.loki.satura.interaction.place.strategy.ground;
|
||||
|
||||
import dev.loki.satura.interaction.movement.WalkPort;
|
||||
import dev.loki.satura.interaction.place.target.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.PlaceContext;
|
||||
import dev.loki.satura.interaction.place.PlaceResult;
|
||||
import dev.loki.satura.interaction.place.PlaceStrategy;
|
||||
import dev.loki.satura.interaction.place.option.CommonOptions;
|
||||
import dev.loki.satura.interaction.place.option.Option;
|
||||
import dev.loki.satura.interaction.place.option.OptionValues;
|
||||
import dev.loki.satura.interaction.place.support.BlockPlacer;
|
||||
import java.util.List;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
/**
|
||||
* S6 BaritoneWalk: Baritone (through the {@link WalkPort}) only walks to the column,
|
||||
* the placement itself is precise (LOS) once in reach. Aithereal settings are applied
|
||||
* by the bridge: allowBreak/allowPlace = false.
|
||||
*/
|
||||
public final class BaritoneWalk implements PlaceStrategy {
|
||||
|
||||
private static final List<Option> DECLARED = List.of(CommonOptions.DELAY_MS, CommonOptions.REACH);
|
||||
private static final double CENTER = 0.5;
|
||||
|
||||
private final OptionValues params = new OptionValues(DECLARED);
|
||||
private final WalkPort walk;
|
||||
private final BlockPlacer placer;
|
||||
private boolean enRoute;
|
||||
|
||||
public BaritoneWalk(final WalkPort walk, final BlockPlacer placer) {
|
||||
this.walk = walk;
|
||||
this.placer = placer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return "baritone_walk";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String label() {
|
||||
return "BaritoneWalk";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Option> options() {
|
||||
return DECLARED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionValues values() {
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
enRoute = false;
|
||||
walk.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlaceResult tick(final PlaceContext ctx, final ColumnTarget target) {
|
||||
final Vec3d feet = ctx.feetPos();
|
||||
final double dx = target.column().getX() + CENTER - feet.x;
|
||||
final double dz = target.column().getZ() + CENTER - feet.z;
|
||||
final double dist = Math.hypot(dx, dz);
|
||||
final double reach = params.get(CommonOptions.REACH);
|
||||
if (dist > reach - 1.0) {
|
||||
return walkTo(target);
|
||||
}
|
||||
walk.cancel();
|
||||
return placer.place(ctx, target.cells().get(0), reach, params.getInt(CommonOptions.DELAY_MS));
|
||||
}
|
||||
|
||||
private PlaceResult walkTo(final ColumnTarget target) {
|
||||
if (enRoute || walk.walkTo(target.column().getX() + CENTER, target.column().getZ() + CENTER)) {
|
||||
enRoute = true;
|
||||
return PlaceResult.WAIT;
|
||||
}
|
||||
return PlaceResult.FAILED;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package dev.loki.satura.interaction.place.strategy.ground;
|
||||
|
||||
import dev.loki.satura.interaction.movement.MovementController;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
/** Ground movement shared by the walking strategies: approach the column, pillar up. */
|
||||
public final class GroundMove {
|
||||
|
||||
private static final double CENTER = 0.5;
|
||||
|
||||
private final MovementController movement;
|
||||
|
||||
public GroundMove(final MovementController movement) {
|
||||
this.movement = movement;
|
||||
}
|
||||
|
||||
/** One walking tick towards the column; true when close enough to act. */
|
||||
public boolean approach(final Vec3d feet, final BlockPos column) {
|
||||
return movement.walkTo(column.getX() + CENTER, column.getZ() + CENTER);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
movement.stop();
|
||||
}
|
||||
|
||||
/** Holds the jump key (pillar); the placement cell is the one the feet just left. */
|
||||
public BlockPos pillarCell(final Vec3d feet) {
|
||||
movement.pillarKeys();
|
||||
return new BlockPos(MathHelper.floor(feet.x), MathHelper.floor(feet.y) - 1,
|
||||
MathHelper.floor(feet.z));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
package dev.loki.satura.interaction.place.strategy.ground;
|
||||
|
||||
import dev.loki.satura.interaction.place.target.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.PlaceContext;
|
||||
import dev.loki.satura.interaction.place.PlaceResult;
|
||||
import dev.loki.satura.interaction.place.PlaceStrategy;
|
||||
import dev.loki.satura.interaction.place.option.CommonOptions;
|
||||
import dev.loki.satura.interaction.place.option.Option;
|
||||
import dev.loki.satura.interaction.place.option.OptionValues;
|
||||
import dev.loki.satura.interaction.place.support.BlockPlacer;
|
||||
import java.util.List;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
/**
|
||||
* S5 GroundWalk (AutoBuild style): fake-key walking to the column, pillar-jumping when the
|
||||
* target is at or above the feet level, plain placement otherwise. For servers where flight
|
||||
* is banned.
|
||||
*/
|
||||
public final class GroundWalk implements PlaceStrategy {
|
||||
|
||||
private static final List<Option> DECLARED = List.of(CommonOptions.DELAY_MS, CommonOptions.REACH);
|
||||
private static final double APPROACH_DIST = 1.5;
|
||||
private static final double CENTER = 0.5;
|
||||
/** Feet must clear the cell top by this margin before the pillar click (no bbox collision). */
|
||||
private static final double PILLAR_CLEAR = 1.02;
|
||||
|
||||
private final OptionValues params = new OptionValues(DECLARED);
|
||||
private final GroundMove move;
|
||||
private final BlockPlacer placer;
|
||||
|
||||
public GroundWalk(final GroundMove move, final BlockPlacer placer) {
|
||||
this.move = move;
|
||||
this.placer = placer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return "ground_walk";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String label() {
|
||||
return "GroundWalk";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Option> options() {
|
||||
return DECLARED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionValues values() {
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
move.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlaceResult tick(final PlaceContext ctx, final ColumnTarget target) {
|
||||
final BlockPos cell = target.cells().get(0);
|
||||
final Vec3d feet = ctx.feetPos();
|
||||
if (far(feet, target.column())) {
|
||||
move.approach(feet, target.column());
|
||||
return PlaceResult.WAIT;
|
||||
}
|
||||
if (cell.getY() >= MathHelper.floor(feet.y)) {
|
||||
return climb(ctx, feet, cell);
|
||||
}
|
||||
return placer.place(ctx, cell, params.get(CommonOptions.REACH), params.getInt(CommonOptions.DELAY_MS));
|
||||
}
|
||||
|
||||
/** Jump and click into the empty cell the feet just left; support: the solid block under it. */
|
||||
private PlaceResult climb(final PlaceContext ctx, final Vec3d feet, final BlockPos cell) {
|
||||
final BlockPos under = move.pillarCell(feet);
|
||||
final boolean clickable = !ctx.isSolid(under)
|
||||
&& under.getY() < cell.getY()
|
||||
&& feet.y >= under.getY() + PILLAR_CLEAR
|
||||
&& ctx.isSolid(under.offset(Direction.DOWN));
|
||||
if (!clickable) {
|
||||
return PlaceResult.WAIT;
|
||||
}
|
||||
return placer.place(ctx, under, params.get(CommonOptions.REACH), params.getInt(CommonOptions.DELAY_MS));
|
||||
}
|
||||
|
||||
private static boolean far(final Vec3d feet, final BlockPos column) {
|
||||
final double dx = column.getX() + CENTER - feet.x;
|
||||
final double dz = column.getZ() + CENTER - feet.z;
|
||||
return Math.hypot(dx, dz) > APPROACH_DIST;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
package dev.loki.satura.interaction.place.strategy.manual;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
* Transient state of BurstPlace: the pending set (cells clicked, waiting for the server reply)
|
||||
* and AIMD - the burst size shrinks when rejects grow and grows back when the stream is clean.
|
||||
*/
|
||||
@SuppressWarnings({"PMD.LooseCoupling", "PMD.AvoidFieldNameMatchingMethodName"})
|
||||
final class BurstController {
|
||||
|
||||
static final int MIN_BURST = 1;
|
||||
static final int MAX_BURST = 8;
|
||||
static final int START_BURST = 2;
|
||||
static final int PENDING_TTL_TICKS = 3;
|
||||
static final int WINDOW_RESULTS = 20;
|
||||
static final int MIN_RESULTS_TO_ADJUST = 10;
|
||||
static final double REJECT_BACK_OFF = 0.2;
|
||||
static final double REJECT_EASE = 0.05;
|
||||
static final long DELAY_STEP_MS = 25;
|
||||
static final long MAX_EXTRA_DELAY_MS = 200;
|
||||
|
||||
private final Map<BlockPos, Integer> pending = new HashMap<>();
|
||||
private final Deque<Boolean> results = new ArrayDeque<>();
|
||||
private int currentBurst = START_BURST;
|
||||
private int cap = MAX_BURST;
|
||||
private long backoffMs;
|
||||
private int ticks;
|
||||
|
||||
/** One strategy tick: expire pending cells, age the burst counter. */
|
||||
void tick() {
|
||||
ticks++;
|
||||
pending.values().removeIf(expiry -> expiry <= ticks);
|
||||
}
|
||||
|
||||
boolean isPending(final BlockPos cell) {
|
||||
return pending.containsKey(cell);
|
||||
}
|
||||
|
||||
/** The cell was clicked; do not touch it until the server replies or the TTL runs out. */
|
||||
void markPending(final BlockPos cell) {
|
||||
pending.put(cell, ticks + PENDING_TTL_TICKS);
|
||||
}
|
||||
|
||||
int burst() {
|
||||
return currentBurst;
|
||||
}
|
||||
|
||||
/** The user option is the upper bound; AIMD moves the burst inside [1, cap]. */
|
||||
void setCap(final int cap) {
|
||||
this.cap = Math.max(MIN_BURST, Math.min(MAX_BURST, cap));
|
||||
currentBurst = Math.min(currentBurst, this.cap);
|
||||
}
|
||||
|
||||
/** Delay on top of the configured one, grown by AIMD when the server pushes back. */
|
||||
long extraDelayMs() {
|
||||
return backoffMs;
|
||||
}
|
||||
|
||||
/** Feed one placement outcome (click accepted or not). */
|
||||
void onResult(final boolean accepted) {
|
||||
results.addLast(accepted);
|
||||
while (results.size() > WINDOW_RESULTS) {
|
||||
results.removeFirst();
|
||||
}
|
||||
if (results.size() >= MIN_RESULTS_TO_ADJUST) {
|
||||
adjust();
|
||||
}
|
||||
}
|
||||
|
||||
private void adjust() {
|
||||
final long rejected = results.stream().filter(ok -> !ok).count();
|
||||
final double rate = 1.0 * rejected / results.size();
|
||||
if (rate >= REJECT_BACK_OFF) {
|
||||
currentBurst = Math.max(MIN_BURST, currentBurst - 1);
|
||||
backoffMs = Math.min(MAX_EXTRA_DELAY_MS, backoffMs + DELAY_STEP_MS);
|
||||
} else if (rate <= REJECT_EASE && (currentBurst < cap || backoffMs > 0)) {
|
||||
currentBurst = Math.min(cap, currentBurst + 1);
|
||||
backoffMs = Math.max(0, backoffMs - DELAY_STEP_MS);
|
||||
}
|
||||
results.clear();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
package dev.loki.satura.interaction.place.strategy.manual;
|
||||
|
||||
import dev.loki.satura.interaction.place.target.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.PlaceContext;
|
||||
import dev.loki.satura.interaction.place.PlaceResult;
|
||||
import dev.loki.satura.interaction.place.PlaceStrategy;
|
||||
import dev.loki.satura.interaction.place.option.CommonOptions;
|
||||
import dev.loki.satura.interaction.place.option.Option;
|
||||
import dev.loki.satura.interaction.place.option.OptionType;
|
||||
import dev.loki.satura.interaction.place.option.OptionValues;
|
||||
import dev.loki.satura.interaction.place.support.BlockPlacer;
|
||||
import dev.loki.satura.interaction.place.support.Cooldown;
|
||||
import dev.loki.satura.interaction.place.support.SupportSearch;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* S8 BurstPlace: several independent clicks per tick (different columns, different supports),
|
||||
* a pending set with TTL instead of waiting for the server, and AIMD - the burst and the delay
|
||||
* adapt to the reject rate. Click points are precise (LOS) to keep the reject share low.
|
||||
*/
|
||||
public final class BurstPlace implements PlaceStrategy {
|
||||
|
||||
/** How many clicks one tick may contain (user cap; AIMD moves inside 1..cap). */
|
||||
public static final Option BURST =
|
||||
new Option("burst", "Блоков за тик", OptionType.INT, BurstController.MIN_BURST,
|
||||
BurstController.MAX_BURST, 1, 4);
|
||||
|
||||
private static final List<Option> DECLARED = List.of(BURST, CommonOptions.DELAY_MS, CommonOptions.REACH);
|
||||
|
||||
private final OptionValues params = new OptionValues(DECLARED);
|
||||
private final BlockPlacer placer;
|
||||
private final BurstController ctrl = new BurstController();
|
||||
|
||||
public BurstPlace(final SupportSearch search) {
|
||||
this.placer = new BlockPlacer(search, new Cooldown());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return "burst";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String label() {
|
||||
return "Burst";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Option> options() {
|
||||
return DECLARED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionValues values() {
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int batchSize() {
|
||||
ctrl.setCap(params.getInt(BURST));
|
||||
return ctrl.burst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlaceResult tick(final PlaceContext ctx, final ColumnTarget target) {
|
||||
return tickBatch(ctx, List.of(target)).get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PlaceResult> tickBatch(final PlaceContext ctx, final List<ColumnTarget> targets) {
|
||||
ctrl.tick();
|
||||
final List<PlaceResult> results = new ArrayList<>(targets.size());
|
||||
for (final ColumnTarget target : targets) {
|
||||
results.add(placeOne(ctx, target));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private PlaceResult placeOne(final PlaceContext ctx, final ColumnTarget target) {
|
||||
final var cell = target.cells().stream().filter(c -> !ctrl.isPending(c)).findFirst();
|
||||
if (cell.isEmpty()) {
|
||||
return PlaceResult.WAIT;
|
||||
}
|
||||
final long delay = params.getInt(CommonOptions.DELAY_MS) + ctrl.extraDelayMs();
|
||||
final PlaceResult result = placer.place(ctx, cell.get(), params.get(CommonOptions.REACH), delay);
|
||||
if (result == PlaceResult.PLACED) {
|
||||
ctrl.markPending(cell.get());
|
||||
ctrl.onResult(true);
|
||||
} else if (result == PlaceResult.FAILED) {
|
||||
ctrl.onResult(false);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
package dev.loki.satura.interaction.place.strategy.manual;
|
||||
|
||||
import dev.loki.satura.interaction.place.target.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.PlaceContext;
|
||||
import dev.loki.satura.interaction.place.PlaceResult;
|
||||
import dev.loki.satura.interaction.place.PlaceStrategy;
|
||||
import dev.loki.satura.interaction.place.option.CommonOptions;
|
||||
import dev.loki.satura.interaction.place.option.Option;
|
||||
import dev.loki.satura.interaction.place.option.OptionValues;
|
||||
import dev.loki.satura.interaction.place.support.BlockPlacer;
|
||||
import dev.loki.satura.interaction.place.strategy.ColumnPlacing;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* S7 HoldRmb (yatwinkle {@code PlaceMode.HOLD_RMB}): the bot flies and aims by itself, but
|
||||
* places only while the use key (right mouse button) is held - manual control gate.
|
||||
*/
|
||||
public final class HoldRmb implements PlaceStrategy {
|
||||
|
||||
private static final List<Option> DECLARED = List.of(
|
||||
CommonOptions.DELAY_MS, CommonOptions.REACH, CommonOptions.HOVER, CommonOptions.FLY_SPEED);
|
||||
|
||||
private final OptionValues params = new OptionValues(DECLARED);
|
||||
private final ColumnPlacing core;
|
||||
|
||||
public HoldRmb(final BlockPlacer placer) {
|
||||
this.core = new ColumnPlacing(params, () -> 1, placer, PlaceContext::useKeyDown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return "hold_rmb";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String label() {
|
||||
return "HoldRmb";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Option> options() {
|
||||
return DECLARED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionValues values() {
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlaceResult tick(final PlaceContext ctx, final ColumnTarget target) {
|
||||
return core.tick(ctx, target);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
package dev.loki.satura.interaction.place.strategy.precise;
|
||||
|
||||
import dev.loki.satura.interaction.place.target.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.PlaceContext;
|
||||
import dev.loki.satura.interaction.place.PlaceResult;
|
||||
import dev.loki.satura.interaction.place.PlaceStrategy;
|
||||
import dev.loki.satura.interaction.place.option.CommonOptions;
|
||||
import dev.loki.satura.interaction.place.option.Option;
|
||||
import dev.loki.satura.interaction.place.option.OptionValues;
|
||||
import dev.loki.satura.interaction.place.support.BlockPlacer;
|
||||
import dev.loki.satura.interaction.place.strategy.FlightControl;
|
||||
import java.util.List;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
/**
|
||||
* S4 FlyHover (pveclient FLY): flies to the stand location derived from the click point
|
||||
* (on top of the support, or click + normal * offset for side faces), speed is capped by
|
||||
* the pveclient formula; places only after arrival.
|
||||
*/
|
||||
public final class FlyHover implements PlaceStrategy {
|
||||
|
||||
/** Stand offset along the support face normal (pveclient 2.4). */
|
||||
public static final double STAND_OFFSET = 2.4;
|
||||
|
||||
private static final List<Option> DECLARED = List.of(
|
||||
CommonOptions.DELAY_MS, CommonOptions.REACH, CommonOptions.FLY_SPEED);
|
||||
private static final double HOVER = 1.1;
|
||||
private static final double HOVER_TWO_LAYERS = 2.8;
|
||||
private static final double SPEED_MAX = 0.34;
|
||||
private static final double SPEED_MIN = 0.08;
|
||||
private static final double SPEED_DIST = 0.35;
|
||||
private static final double ARRIVE_DIST = 0.3;
|
||||
|
||||
private final OptionValues params = new OptionValues(DECLARED);
|
||||
private final PreciseSupport search;
|
||||
private final BlockPlacer placer;
|
||||
|
||||
public FlyHover(final PreciseSupport search, final BlockPlacer placer) {
|
||||
this.search = search;
|
||||
this.placer = placer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return "fly_hover";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String label() {
|
||||
return "FlyHover";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Option> options() {
|
||||
return DECLARED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionValues values() {
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlaceResult tick(final PlaceContext ctx, final ColumnTarget target) {
|
||||
final BlockPos cell = target.cells().get(0);
|
||||
final double reach = params.get(CommonOptions.REACH);
|
||||
// The stand point is up to STAND_OFFSET away, so validity is checked without the
|
||||
// current-position reach; the click itself is re-validated by the placer on arrival.
|
||||
final var placement = search.find(ctx, cell, Double.POSITIVE_INFINITY);
|
||||
if (placement.isEmpty()) {
|
||||
return PlaceResult.FAILED;
|
||||
}
|
||||
final Vec3d stand = standPos(placement.get(), target.cells().size());
|
||||
final Vec3d feet = ctx.feetPos();
|
||||
final double k = params.get(CommonOptions.FLY_SPEED);
|
||||
final Vec3d v = FlightControl.velocity(feet, stand, speed(feet.distanceTo(stand), k));
|
||||
ctx.setVelocity(v.x, v.y, v.z);
|
||||
if (feet.distanceTo(stand) > ARRIVE_DIST) {
|
||||
return PlaceResult.WAIT;
|
||||
}
|
||||
ctx.setVelocity(0, 0, 0);
|
||||
return placer.place(ctx, cell, reach, params.getInt(CommonOptions.DELAY_MS));
|
||||
}
|
||||
|
||||
/** For the UP face hover above the support top; for sides - the pveclient offset point. */
|
||||
private static Vec3d standPos(final dev.loki.satura.interaction.place.Placement placement,
|
||||
final int cells) {
|
||||
final Vec3d base = placement.standPos();
|
||||
final double hover = cells >= 2 ? HOVER_TWO_LAYERS : HOVER;
|
||||
if (placement.face() == Direction.UP) {
|
||||
return base.add(0.0, hover, 0.0);
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
||||
/** pveclient: min(0.34k, max(0.08k, dist * 0.35k)). */
|
||||
static double speed(final double dist, final double k) {
|
||||
return Math.min(SPEED_MAX * k, Math.max(SPEED_MIN * k, dist * SPEED_DIST * k));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
package dev.loki.satura.interaction.place.strategy.precise;
|
||||
|
||||
import dev.loki.satura.interaction.place.target.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.PlaceContext;
|
||||
import dev.loki.satura.interaction.place.PlaceResult;
|
||||
import dev.loki.satura.interaction.place.PlaceStrategy;
|
||||
import dev.loki.satura.interaction.place.option.CommonOptions;
|
||||
import dev.loki.satura.interaction.place.option.Option;
|
||||
import dev.loki.satura.interaction.place.option.OptionValues;
|
||||
import dev.loki.satura.interaction.place.support.BlockPlacer;
|
||||
import dev.loki.satura.interaction.place.strategy.ColumnPlacing;
|
||||
import dev.loki.satura.interaction.place.strategy.FlightControl;
|
||||
import java.util.List;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
/**
|
||||
* S3 PrecisePlacement: hovers above the column like the fast strategies, but every click goes
|
||||
* through {@link PreciseSupport} (LOS + face order); after {@code MAX_RETRIES} the cell is
|
||||
* given back to the engine for a re-target.
|
||||
*/
|
||||
public final class PrecisePlacement implements PlaceStrategy {
|
||||
|
||||
private static final List<Option> DECLARED = List.of(
|
||||
CommonOptions.DELAY_MS, CommonOptions.REACH, CommonOptions.HOVER, CommonOptions.FLY_SPEED);
|
||||
|
||||
private final OptionValues params = new OptionValues(DECLARED);
|
||||
private final BlockPlacer placer;
|
||||
private int retries;
|
||||
|
||||
public PrecisePlacement(final BlockPlacer placer) {
|
||||
this.placer = placer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return "precise";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String label() {
|
||||
return "Precise";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Option> options() {
|
||||
return DECLARED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionValues values() {
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlaceResult tick(final PlaceContext ctx, final ColumnTarget target) {
|
||||
final BlockPos cell = target.cells().get(0);
|
||||
hover(ctx, target.column(), cell.getY());
|
||||
if (!ColumnPlacing.overColumn(ctx.feetPos(), target.column())) {
|
||||
return PlaceResult.WAIT;
|
||||
}
|
||||
final PlaceResult result = placer.place(ctx, cell, params.get(CommonOptions.REACH),
|
||||
params.getInt(CommonOptions.DELAY_MS));
|
||||
if (result == PlaceResult.FAILED) {
|
||||
retries++;
|
||||
if (retries < PreciseSupport.MAX_RETRIES) {
|
||||
return PlaceResult.WAIT;
|
||||
}
|
||||
}
|
||||
retries = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
private void hover(final PlaceContext ctx, final BlockPos column, final int layerY) {
|
||||
ctx.enableFlight();
|
||||
final Vec3d feet = ctx.feetPos();
|
||||
final double height = FlightControl.height(layerY, layerY, params.get(CommonOptions.HOVER),
|
||||
params.get(CommonOptions.REACH), ColumnPlacing.EYE_MARGIN);
|
||||
final Vec3d goal = new Vec3d(column.getX() + ColumnPlacing.CENTER, height,
|
||||
column.getZ() + ColumnPlacing.CENTER);
|
||||
final Vec3d v = FlightControl.velocity(feet, goal, params.get(CommonOptions.FLY_SPEED));
|
||||
ctx.setVelocity(v.x, v.y, v.z);
|
||||
ctx.lookDown();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package dev.loki.satura.interaction.place.strategy.precise;
|
||||
|
||||
import dev.loki.satura.interaction.place.PlaceContext;
|
||||
import dev.loki.satura.interaction.place.Placement;
|
||||
import dev.loki.satura.interaction.place.support.SupportFinder;
|
||||
import dev.loki.satura.interaction.place.support.SupportSearch;
|
||||
import java.util.Optional;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
/**
|
||||
* pveclient {@code PlacementOption} style: faces UP, then the sides, then DOWN; every support
|
||||
* must pass a line-of-sight check; side faces are clicked slightly below the top (no seam).
|
||||
*/
|
||||
public final class PreciseSupport implements SupportSearch {
|
||||
|
||||
/** Retries on one cell before the caller has to re-target. */
|
||||
public static final int MAX_RETRIES = 12;
|
||||
|
||||
private static final double HALF = 0.5;
|
||||
private static final double TOP = 1.0;
|
||||
|
||||
@Override
|
||||
public Optional<Placement> find(final PlaceContext ctx, final BlockPos target, final double reach) {
|
||||
final Vec3d eye = ctx.eyePos();
|
||||
for (final Direction dir : searchOrder()) {
|
||||
final BlockPos support = target.offset(dir);
|
||||
if (!ctx.isSolid(support)) {
|
||||
continue;
|
||||
}
|
||||
final Direction face = dir.getOpposite();
|
||||
if (!ctx.visible(support, face)) {
|
||||
continue;
|
||||
}
|
||||
final Vec3d hit = SupportFinder.clickPoint(support, face);
|
||||
if (eye.distanceTo(hit) <= reach) {
|
||||
return Optional.of(new Placement(target, support, face, hit, standPos(support, face)));
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/** Order in which target neighbours are inspected: UP, then the 4 sides, DOWN last. */
|
||||
static Direction[] searchOrder() {
|
||||
return new Direction[] {
|
||||
Direction.UP, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST, Direction.DOWN
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* pveclient {@code getFlyStandLocation}: on top of the support for the UP face, click point +
|
||||
* normal * FlyHover.STAND_OFFSET for the other faces (the player flies, so this is always reachable).
|
||||
*/
|
||||
static Vec3d standPos(final BlockPos support, final Direction face) {
|
||||
if (face == Direction.UP) {
|
||||
return new Vec3d(support.getX() + HALF, support.getY() + TOP, support.getZ() + HALF);
|
||||
}
|
||||
return SupportFinder.clickPoint(support, face).add(
|
||||
face.getOffsetX() * FlyHover.STAND_OFFSET,
|
||||
face.getOffsetY() * FlyHover.STAND_OFFSET,
|
||||
face.getOffsetZ() * FlyHover.STAND_OFFSET);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,11 +9,15 @@ import net.minecraft.util.math.BlockPos;
|
|||
/** Common part of all strategies: cooldown, support lookup, click and hand swing. */
|
||||
public final class BlockPlacer {
|
||||
|
||||
private final SupportFinder finder;
|
||||
private final SupportSearch search;
|
||||
private final Cooldown cooldown;
|
||||
|
||||
public BlockPlacer(final SupportFinder finder, final Cooldown cooldown) {
|
||||
this.finder = finder;
|
||||
this((SupportSearch) finder, cooldown);
|
||||
}
|
||||
|
||||
public BlockPlacer(final SupportSearch search, final Cooldown cooldown) {
|
||||
this.search = search;
|
||||
this.cooldown = cooldown;
|
||||
}
|
||||
|
||||
|
|
@ -24,7 +28,7 @@ public final class BlockPlacer {
|
|||
if (!cooldown.ready(now, delayMs)) {
|
||||
return PlaceResult.WAIT;
|
||||
}
|
||||
final Optional<Placement> placement = finder.find(ctx, target, reach);
|
||||
final Optional<Placement> placement = search.find(ctx, target, reach);
|
||||
if (placement.isEmpty() || !ctx.interact(placement.get().hitResult())) {
|
||||
return PlaceResult.FAILED;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,12 +8,13 @@ import net.minecraft.util.math.Direction;
|
|||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
/** Support selection: below first, then the other 5 directions. */
|
||||
public final class SupportFinder {
|
||||
public final class SupportFinder implements SupportSearch {
|
||||
|
||||
/** Click a side face slightly below the block top so as not to hit the seam. */
|
||||
public static final double SIDE_CLICK_Y = 0.94;
|
||||
private static final double HALF = 0.5;
|
||||
|
||||
@Override
|
||||
public Optional<Placement> find(final PlaceContext ctx, final BlockPos target, final double reach) {
|
||||
final Vec3d eye = ctx.eyePos();
|
||||
for (final Direction dir : searchOrder()) {
|
||||
|
|
@ -37,7 +38,8 @@ public final class SupportFinder {
|
|||
};
|
||||
}
|
||||
|
||||
static Vec3d clickPoint(final BlockPos support, final Direction face) {
|
||||
/** Click point on the face: side faces slightly below the top (no seam), top/bottom - center. */
|
||||
public static Vec3d clickPoint(final BlockPos support, final Direction face) {
|
||||
final double x = support.getX() + HALF + face.getOffsetX() * HALF;
|
||||
final double z = support.getZ() + HALF + face.getOffsetZ() * HALF;
|
||||
final double y = face.getAxis().isHorizontal()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
package dev.loki.satura.interaction.place.support;
|
||||
|
||||
import dev.loki.satura.interaction.place.PlaceContext;
|
||||
import dev.loki.satura.interaction.place.Placement;
|
||||
import java.util.Optional;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/** How a strategy picks the support block and click point for a target cell. */
|
||||
public interface SupportSearch {
|
||||
|
||||
/** The placement to click; empty when no reachable support. */
|
||||
Optional<Placement> find(PlaceContext ctx, BlockPos target, double reach);
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package dev.loki.satura.feature.builder.plan;
|
||||
package dev.loki.satura.interaction.place.target;
|
||||
|
||||
import java.util.List;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
|
@ -47,14 +47,14 @@ public final class RenderDebug {
|
|||
float x = ORIGIN + PAD;
|
||||
renderer.text().draw(bold, "Satura render", x, ORIGIN + PAD, TITLE, Theme.TEXT);
|
||||
renderer.text().draw("Montserrat: rect + blur + outline", x, ORIGIN + LINE_1, BODY, Theme.TEXT_MUTED);
|
||||
renderer.text().drawGradient(bold, "Gradient text", x, ORIGIN + LINE_2, BODY, Theme.ACCENT_PRESSED,
|
||||
Theme.ACCENT_HOVER);
|
||||
renderer.text().drawGlow(bold, "Glow text", x, ORIGIN + LINE_3, TITLE, Theme.TEXT, Theme.ACCENT, 1f);
|
||||
renderer.text().drawGradient(bold, "Gradient text", x, ORIGIN + LINE_2, BODY, Theme.get().accentPressed(),
|
||||
Theme.get().accentHover());
|
||||
renderer.text().drawGlow(bold, "Glow text", x, ORIGIN + LINE_3, TITLE, Theme.TEXT, Theme.get().accent(), 1f);
|
||||
renderer.pushScissor(new Bounds(x, ORIGIN + CLIP_Y, CLIP_W, CLIP_H));
|
||||
renderer.text().draw("Scissor ok", x, ORIGIN + CLIP_Y, BODY, Theme.TEXT);
|
||||
renderer.popScissor();
|
||||
Bounds box = new Bounds(ORIGIN + BOX_X, ORIGIN + CLIP_Y - 4f, BOX_W, BOX_H);
|
||||
renderer.rect(box, Theme.RADIUS_SMALL, Theme.ACCENT);
|
||||
renderer.glow(box, Theme.RADIUS_SMALL, 0f, GLOW_SIZE, GLOW_INTENSITY, Theme.ACCENT);
|
||||
renderer.rect(box, Theme.RADIUS_SMALL, Theme.get().accent());
|
||||
renderer.glow(box, Theme.RADIUS_SMALL, 0f, GLOW_SIZE, GLOW_INTENSITY, Theme.get().accent());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,19 @@
|
|||
package dev.loki.satura.render;
|
||||
|
||||
/** Palette and styling sizes (minimalism): ARGB colors, radii in GUI units. */
|
||||
@SuppressWarnings("PMD.DataClass")
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Palette and styling (minimalism): one graphite base, four accent palettes. The active
|
||||
* palette is read at draw time (Theme.get()), the GUI switches it; ARGB colors, radii in GUI units.
|
||||
*/
|
||||
@SuppressWarnings({"PMD.DataClass", "PMD.AvoidFieldNameMatchingMethodName", "PMD.AvoidUsingVolatile"})
|
||||
public final class Theme {
|
||||
|
||||
/** Shared graphite base, identical for every accent. */
|
||||
public static final int BACKGROUND = 0xFF121212;
|
||||
public static final int BACKGROUND_ALT = 0xFF1A1A1A;
|
||||
public static final int PANEL = 0xFF202020;
|
||||
public static final int BORDER = 0xFF2E2E2E;
|
||||
|
||||
public static final int ACCENT = 0xFFE8792B;
|
||||
public static final int ACCENT_HOVER = 0xFFF08A3F;
|
||||
public static final int ACCENT_PRESSED = 0xFFC9621C;
|
||||
|
||||
public static final int TEXT = 0xFFE6E6E6;
|
||||
public static final int TEXT_MUTED = 0xFF8A8A8A;
|
||||
|
||||
|
|
@ -23,6 +24,60 @@ public final class Theme {
|
|||
public static final boolean GRADIENTS = false;
|
||||
public static final boolean GLOW = false;
|
||||
|
||||
private Theme() {
|
||||
/** Default: graphite + orange. */
|
||||
public static final Theme ORANGE = new Theme("orange", 0xFFE8792B, 0xFFF08A3F, 0xFFC9621C);
|
||||
/** Spare palettes (owner requirement): graphite + white / mint / sand accents. */
|
||||
public static final Theme WHITE = new Theme("white", 0xFFE6E6E6, 0xFFF5F5F5, 0xFFBFBFBF);
|
||||
public static final Theme MINT = new Theme("mint", 0xFF5FB59A, 0xFF74C6AC, 0xFF4A927C);
|
||||
public static final Theme SAND = new Theme("sand", 0xFFD9B26F, 0xFFE4C489, 0xFFB8945A);
|
||||
|
||||
private static final List<Theme> ALL = List.of(ORANGE, WHITE, MINT, SAND);
|
||||
|
||||
private static volatile Theme current = ORANGE;
|
||||
|
||||
private final String id;
|
||||
private final int accent;
|
||||
private final int accentHover;
|
||||
private final int accentPressed;
|
||||
|
||||
private Theme(final String id, final int accent, final int accentHover, final int accentPressed) {
|
||||
this.id = id;
|
||||
this.accent = accent;
|
||||
this.accentHover = accentHover;
|
||||
this.accentPressed = accentPressed;
|
||||
}
|
||||
|
||||
/** The palette to draw with; read it every frame, never cache the values. */
|
||||
public static Theme get() {
|
||||
return current;
|
||||
}
|
||||
|
||||
public static void set(final Theme theme) {
|
||||
current = theme;
|
||||
}
|
||||
|
||||
public static List<Theme> all() {
|
||||
return ALL;
|
||||
}
|
||||
|
||||
/** Palette by config id; unknown ids fall back to the default orange. */
|
||||
public static Theme byId(final String id) {
|
||||
return ALL.stream().filter(t -> t.id.equals(id)).findFirst().orElse(ORANGE);
|
||||
}
|
||||
|
||||
public String id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int accent() {
|
||||
return accent;
|
||||
}
|
||||
|
||||
public int accentHover() {
|
||||
return accentHover;
|
||||
}
|
||||
|
||||
public int accentPressed() {
|
||||
return accentPressed;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,10 +39,10 @@ public final class SelectionRenderer {
|
|||
Vec3d cam = ctx.worldState().cameraRenderState.pos;
|
||||
VertexConsumer out = ctx.consumers().getBuffer(LineLayers.get(seeThrough));
|
||||
MatrixStack.Entry entry = ctx.matrices().peek();
|
||||
box(entry, out, cam, min(a, b), max(a, b), FRAME_GROW, Theme.ACCENT, FRAME_WIDTH);
|
||||
box(entry, out, cam, min(a, b), max(a, b), FRAME_GROW, Theme.get().accent(), FRAME_WIDTH);
|
||||
if (m.first().isPresent() && m.second().isPresent()) {
|
||||
box(entry, out, cam, a, a, -MARKER_INSET, Theme.ACCENT_HOVER, MARKER_WIDTH);
|
||||
box(entry, out, cam, b, b, -MARKER_INSET, Theme.ACCENT_PRESSED, MARKER_WIDTH);
|
||||
box(entry, out, cam, a, a, -MARKER_INSET, Theme.get().accentHover(), MARKER_WIDTH);
|
||||
box(entry, out, cam, b, b, -MARKER_INSET, Theme.get().accentPressed(), MARKER_WIDTH);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
"satura.gui.resume": "Resume",
|
||||
"satura.gui.stop": "Stop",
|
||||
"satura.gui.shape": "Shape: %s",
|
||||
"satura.gui.strategy": "Strategy: %s",
|
||||
"satura.gui.theme": "Theme: %s",
|
||||
"satura.gui.layers": "Layers: %s",
|
||||
"satura.gui.delay": "Delay: %s ms",
|
||||
"satura.gui.block": "Block"
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
"satura.gui.resume": "Продолжить",
|
||||
"satura.gui.stop": "Стоп",
|
||||
"satura.gui.shape": "Форма: %s",
|
||||
"satura.gui.strategy": "Стратегия: %s",
|
||||
"satura.gui.theme": "Тема: %s",
|
||||
"satura.gui.layers": "Слоёв: %s",
|
||||
"satura.gui.delay": "Задержка: %s мс",
|
||||
"satura.gui.block": "Блок"
|
||||
|
|
|
|||
|
|
@ -31,6 +31,17 @@ class BuildEngineTest {
|
|||
assertTrue(h.engine.snapshot().blocksPerSecond() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void burstStrategyBuildsBothColumnsInOneTick() {
|
||||
final EngineHarness h = started();
|
||||
h.batchSize = 3;
|
||||
h.ticks(1);
|
||||
assertEquals(2, h.engine.snapshot().done());
|
||||
assertEquals(2, h.engine.snapshot().placed());
|
||||
h.ticks(2);
|
||||
assertEquals(Stage.DONE, h.engine.stage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void failedColumnBecomesHoleAndIsRepairedLater() {
|
||||
final EngineHarness h = started();
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import dev.loki.satura.core.event.world.BlockChangeEvent;
|
|||
import dev.loki.satura.feature.builder.engine.host.EngineDeps;
|
||||
import dev.loki.satura.feature.builder.engine.host.GameState;
|
||||
import dev.loki.satura.feature.builder.engine.walk.Walker;
|
||||
import dev.loki.satura.feature.builder.plan.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.target.ColumnTarget;
|
||||
import dev.loki.satura.feature.builder.plan.Planner;
|
||||
import dev.loki.satura.feature.builder.plan.shape.BoxShape;
|
||||
import dev.loki.satura.feature.builder.scan.ColumnCache;
|
||||
|
|
@ -41,6 +41,7 @@ final class EngineHarness {
|
|||
Object world = "w1";
|
||||
long now;
|
||||
int cancels;
|
||||
int batchSize = 1;
|
||||
Function<ColumnTarget, PlaceResult> strategyRule = t -> PlaceResult.PLACED;
|
||||
final ColumnCache cache;
|
||||
final RepairTracker tracker = new RepairTracker(2);
|
||||
|
|
@ -99,6 +100,11 @@ final class EngineHarness {
|
|||
return new OptionValues(List.of());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int batchSize() {
|
||||
return batchSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlaceResult tick(final dev.loki.satura.interaction.place.PlaceContext ctx,
|
||||
final ColumnTarget target) {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import dev.loki.satura.feature.builder.plan.shape.BoxShape;
|
|||
import dev.loki.satura.feature.builder.plan.shape.CheckerShape;
|
||||
import dev.loki.satura.feature.builder.plan.shape.WallsShape;
|
||||
import dev.loki.satura.feature.builder.selection.Area;
|
||||
import dev.loki.satura.interaction.place.target.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.option.CommonOptions;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
|
@ -54,6 +56,22 @@ class PlannerTest {
|
|||
assertEquals(new BlockPos(2, 10, 0), t.column());
|
||||
}
|
||||
|
||||
@Test
|
||||
void nextBatchReturnsDistinctColumnsAndDrains() {
|
||||
final Set<BlockPos> built = new HashSet<>();
|
||||
final Planner p = new Planner(area(3, 1, 1), new BoxShape(), 1, built::contains);
|
||||
final List<ColumnTarget> batch = p.nextBatch(2);
|
||||
assertEquals(2, batch.size());
|
||||
assertEquals(new BlockPos(0, 10, 0), batch.get(0).column());
|
||||
assertEquals(new BlockPos(1, 10, 0), batch.get(1).column());
|
||||
batch.forEach(t -> built.addAll(t.cells()));
|
||||
final List<ColumnTarget> rest = p.nextBatch(2);
|
||||
assertEquals(1, rest.size());
|
||||
assertEquals(new BlockPos(2, 10, 0), rest.get(0).column());
|
||||
built.addAll(rest.get(0).cells());
|
||||
assertTrue(p.nextBatch(2).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void bandsAdvanceUpwardAndClampLayers() {
|
||||
final Set<BlockPos> built = new HashSet<>();
|
||||
|
|
@ -69,7 +87,7 @@ class PlannerTest {
|
|||
assertTrue(p.next().isEmpty());
|
||||
|
||||
final Planner big = new Planner(area(1, 5, 1), new BoxShape(), 99, pos -> false);
|
||||
assertEquals(Planner.MAX_BAND_LAYERS, big.next().orElseThrow().cells().size());
|
||||
assertEquals(CommonOptions.MAX_LAYERS, big.next().orElseThrow().cells().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
/** Fake world/player for strategy tests. */
|
||||
|
|
@ -13,9 +14,11 @@ public final class FakeContext implements PlaceContext {
|
|||
|
||||
public final Set<BlockPos> solids = new HashSet<>();
|
||||
public final List<BlockHitResult> clicks = new ArrayList<>();
|
||||
public final Set<BlockPos> hidden = new HashSet<>();
|
||||
public Vec3d feet;
|
||||
public long now;
|
||||
public boolean accept = true;
|
||||
public boolean useKey = true;
|
||||
public int swings;
|
||||
public int lookDowns;
|
||||
public Vec3d velocity = Vec3d.ZERO;
|
||||
|
|
@ -39,6 +42,16 @@ public final class FakeContext implements PlaceContext {
|
|||
return solids.contains(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visible(final BlockPos support, final Direction face) {
|
||||
return !hidden.contains(support);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useKeyDown() {
|
||||
return useKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean interact(final BlockHitResult hit) {
|
||||
clicks.add(hit);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package dev.loki.satura.interaction.place.strategy;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import dev.loki.satura.feature.builder.plan.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.target.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.FakeContext;
|
||||
import dev.loki.satura.interaction.place.PlaceResult;
|
||||
import dev.loki.satura.interaction.place.PlaceStrategy;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,110 @@
|
|||
package dev.loki.satura.interaction.place.strategy.ground;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import dev.loki.satura.interaction.movement.MovementController;
|
||||
import dev.loki.satura.interaction.movement.io.KeyInput;
|
||||
import dev.loki.satura.interaction.movement.io.PlayerPose;
|
||||
import dev.loki.satura.interaction.place.target.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.FakeContext;
|
||||
import dev.loki.satura.interaction.place.PlaceResult;
|
||||
import dev.loki.satura.interaction.place.support.BlockPlacer;
|
||||
import dev.loki.satura.interaction.place.support.Cooldown;
|
||||
import dev.loki.satura.interaction.place.support.SupportFinder;
|
||||
import java.util.List;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class GroundWalkTest {
|
||||
|
||||
private static final BlockPos COLUMN = new BlockPos(0, 0, 0);
|
||||
|
||||
private static final class Pose implements PlayerPose {
|
||||
double x;
|
||||
double z;
|
||||
float yaw;
|
||||
|
||||
@Override public double x() { return x; }
|
||||
@Override public double y() { return 0; }
|
||||
@Override public double z() { return z; }
|
||||
@Override public double eyeY() { return 1.62; }
|
||||
@Override public float yaw() { return yaw; }
|
||||
@Override public float pitch() { return 0; }
|
||||
@Override public void setYaw(final float v) { yaw = v; }
|
||||
@Override public void setPitch(final float v) { }
|
||||
@Override public boolean horizontalCollision() { return false; }
|
||||
}
|
||||
|
||||
private static final class Keys implements KeyInput {
|
||||
boolean forward;
|
||||
boolean jump;
|
||||
|
||||
@Override public void setForward(final boolean p) { forward = p; }
|
||||
@Override public void setBack(final boolean p) { }
|
||||
@Override public void setLeft(final boolean p) { }
|
||||
@Override public void setRight(final boolean p) { }
|
||||
@Override public void setJump(final boolean p) { jump = p; }
|
||||
@Override public void setSneak(final boolean p) { }
|
||||
}
|
||||
|
||||
private static ColumnTarget target(final int y) {
|
||||
return new ColumnTarget(COLUMN, List.of(new BlockPos(0, y, 0)));
|
||||
}
|
||||
|
||||
private static GroundWalk strategy(final Pose pose, final Keys keys) {
|
||||
return new GroundWalk(new GroundMove(new MovementController(keys, pose)),
|
||||
new BlockPlacer(new SupportFinder(), new Cooldown()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void walksToFarColumn() {
|
||||
final Pose pose = new Pose();
|
||||
pose.x = 15;
|
||||
final Keys keys = new Keys();
|
||||
final FakeContext ctx = new FakeContext(new Vec3d(15, 10.0, 0.5));
|
||||
ctx.solids.add(new BlockPos(0, 9, 0));
|
||||
final GroundWalk s = strategy(pose, keys);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
assertEquals(PlaceResult.WAIT, s.tick(ctx, target(10)));
|
||||
}
|
||||
assertTrue(keys.forward);
|
||||
assertTrue(ctx.clicks.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void placesCellBelowFeetLevel() {
|
||||
final Pose pose = new Pose();
|
||||
final Keys keys = new Keys();
|
||||
final FakeContext ctx = new FakeContext(new Vec3d(0.5, 11.0, 0.5));
|
||||
ctx.solids.add(new BlockPos(0, 9, 0));
|
||||
assertEquals(PlaceResult.PLACED, strategy(pose, keys).tick(ctx, target(10)));
|
||||
assertEquals(new BlockPos(0, 9, 0), ctx.clicks.get(0).getBlockPos());
|
||||
assertFalse(keys.jump);
|
||||
}
|
||||
|
||||
@Test
|
||||
void targetAtFeetLevelTriggersPillarJump() {
|
||||
final Pose pose = new Pose();
|
||||
final Keys keys = new Keys();
|
||||
final FakeContext ctx = new FakeContext(new Vec3d(0.5, 10.0, 0.5));
|
||||
ctx.solids.add(new BlockPos(0, 9, 0));
|
||||
assertEquals(PlaceResult.WAIT, strategy(pose, keys).tick(ctx, target(10)));
|
||||
assertTrue(keys.jump);
|
||||
assertTrue(ctx.clicks.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void resetReleasesKeys() {
|
||||
final Pose pose = new Pose();
|
||||
final Keys keys = new Keys();
|
||||
final FakeContext ctx = new FakeContext(new Vec3d(0.5, 10.0, 0.5));
|
||||
ctx.solids.add(new BlockPos(0, 9, 0));
|
||||
final GroundWalk s = strategy(pose, keys);
|
||||
s.tick(ctx, target(10));
|
||||
s.reset();
|
||||
assertFalse(keys.jump);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
package dev.loki.satura.interaction.place.strategy.manual;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import dev.loki.satura.interaction.place.target.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.FakeContext;
|
||||
import dev.loki.satura.interaction.place.PlaceResult;
|
||||
import dev.loki.satura.interaction.place.strategy.precise.PreciseSupport;
|
||||
import java.util.List;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class BurstPlaceTest {
|
||||
|
||||
private static ColumnTarget target(final int x) {
|
||||
return new ColumnTarget(new BlockPos(x, 0, 0), List.of(new BlockPos(x, 10, 0)));
|
||||
}
|
||||
|
||||
private static FakeContext ctx() {
|
||||
final FakeContext ctx = new FakeContext(new Vec3d(0.5, 11.0, 0.5));
|
||||
ctx.solids.add(new BlockPos(0, 9, 0));
|
||||
ctx.solids.add(new BlockPos(1, 9, 0));
|
||||
return ctx;
|
||||
}
|
||||
|
||||
@Test
|
||||
void placesSeveralColumnsPerTick() {
|
||||
final BurstPlace s = new BurstPlace(new PreciseSupport());
|
||||
final FakeContext ctx = ctx();
|
||||
final List<PlaceResult> results = s.tickBatch(ctx, List.of(target(0), target(1)));
|
||||
assertEquals(List.of(PlaceResult.PLACED, PlaceResult.PLACED), results);
|
||||
assertEquals(2, ctx.clicks.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void pendingCellsAreSkippedUntilTtlExpires() {
|
||||
final BurstPlace s = new BurstPlace(new PreciseSupport());
|
||||
final FakeContext ctx = ctx();
|
||||
assertEquals(PlaceResult.PLACED, s.tick(ctx, target(0)));
|
||||
assertEquals(PlaceResult.WAIT, s.tick(ctx, target(0)));
|
||||
assertEquals(1, ctx.clicks.size());
|
||||
for (int i = 0; i < BurstController.PENDING_TTL_TICKS + 1; i++) {
|
||||
s.tickBatch(ctx, List.of(target(0)));
|
||||
}
|
||||
assertTrue(ctx.clicks.size() > 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aimdBacksOffWhenServerRejects() {
|
||||
final BurstPlace s = new BurstPlace(new PreciseSupport());
|
||||
final FakeContext ctx = ctx();
|
||||
ctx.accept = false;
|
||||
final int startBurst = s.batchSize();
|
||||
for (int i = 0; i < BurstController.MIN_RESULTS_TO_ADJUST + 1; i++) {
|
||||
ctx.now += 500;
|
||||
s.tickBatch(ctx, List.of(target(0), target(1)));
|
||||
}
|
||||
assertTrue(s.batchSize() < startBurst);
|
||||
assertTrue(s.values().getInt(dev.loki.satura.interaction.place.option.CommonOptions.DELAY_MS) >= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void burstOptionIsTheCap() {
|
||||
final BurstPlace s = new BurstPlace(new PreciseSupport());
|
||||
s.values().set("burst", 1);
|
||||
assertEquals(1, s.batchSize());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package dev.loki.satura.interaction.place.strategy.manual;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import dev.loki.satura.interaction.place.target.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.FakeContext;
|
||||
import dev.loki.satura.interaction.place.PlaceResult;
|
||||
import dev.loki.satura.interaction.place.support.BlockPlacer;
|
||||
import dev.loki.satura.interaction.place.support.Cooldown;
|
||||
import dev.loki.satura.interaction.place.support.SupportFinder;
|
||||
import java.util.List;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class HoldRmbTest {
|
||||
|
||||
private static ColumnTarget target(final int y) {
|
||||
return new ColumnTarget(new BlockPos(0, 0, 0), List.of(new BlockPos(0, y, 0)));
|
||||
}
|
||||
|
||||
private static FakeContext ctxAt(final double y) {
|
||||
final FakeContext c = new FakeContext(new Vec3d(0.5, y, 0.5));
|
||||
c.solids.add(new BlockPos(0, 9, 0));
|
||||
return c;
|
||||
}
|
||||
|
||||
private static HoldRmb strategy() {
|
||||
return new HoldRmb(new BlockPlacer(new SupportFinder(), new Cooldown()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void waitsWithoutUseKeyEvenOverColumn() {
|
||||
final HoldRmb s = strategy();
|
||||
final FakeContext c = ctxAt(11.0);
|
||||
c.useKey = false;
|
||||
assertEquals(PlaceResult.WAIT, s.tick(c, target(10)));
|
||||
assertEquals(0, c.clicks.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void placesWhileUseKeyHeld() {
|
||||
final HoldRmb s = strategy();
|
||||
final FakeContext c = ctxAt(11.0);
|
||||
assertEquals(PlaceResult.PLACED, s.tick(c, target(10)));
|
||||
assertEquals(1, c.clicks.size());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
package dev.loki.satura.interaction.place.strategy.precise;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import dev.loki.satura.interaction.place.target.ColumnTarget;
|
||||
import dev.loki.satura.interaction.place.FakeContext;
|
||||
import dev.loki.satura.interaction.place.PlaceResult;
|
||||
import dev.loki.satura.interaction.place.support.BlockPlacer;
|
||||
import dev.loki.satura.interaction.place.support.Cooldown;
|
||||
import dev.loki.satura.interaction.place.support.SupportFinder;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class FlyHoverTest {
|
||||
|
||||
private static final BlockPos COLUMN = new BlockPos(0, 0, 0);
|
||||
|
||||
private static ColumnTarget target(final int y) {
|
||||
return new ColumnTarget(COLUMN, java.util.List.of(new BlockPos(0, y, 0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void speedFollowsPveclientFormula() {
|
||||
assertEquals(0.34, FlyHover.speed(10.0, 1.0), 1e-9);
|
||||
assertEquals(0.08, FlyHover.speed(0.1, 1.0), 1e-9);
|
||||
assertEquals(0.175, FlyHover.speed(0.5, 1.0), 1e-9);
|
||||
assertEquals(0.68, FlyHover.speed(10.0, 2.0), 1e-9);
|
||||
}
|
||||
|
||||
@Test
|
||||
void fliesToStandPointThenPlaces() {
|
||||
final FlyHover s = new FlyHover(new PreciseSupport(),
|
||||
new BlockPlacer(new SupportFinder(), new Cooldown()));
|
||||
final FakeContext ctx = new FakeContext(new Vec3d(0.5, 11.1, 20.5));
|
||||
ctx.solids.add(new BlockPos(0, 9, 0));
|
||||
assertEquals(PlaceResult.WAIT, s.tick(ctx, target(10)));
|
||||
// default flySpeed k = 0.25: speed = min(0.34k, max(0.08k, dist*0.35k)) = 0.085
|
||||
assertEquals(-0.085, ctx.velocity.z, 1e-9);
|
||||
ctx.feet = new Vec3d(0.5, 11.1, 0.5);
|
||||
assertEquals(PlaceResult.PLACED, s.tick(ctx, target(10)));
|
||||
assertEquals(new BlockPos(0, 9, 0), ctx.clicks.get(0).getBlockPos());
|
||||
}
|
||||
|
||||
@Test
|
||||
void failsWithoutSupport() {
|
||||
final FlyHover s = new FlyHover(new PreciseSupport(),
|
||||
new BlockPlacer(new SupportFinder(), new Cooldown()));
|
||||
final FakeContext ctx = new FakeContext(new Vec3d(0.5, 11.1, 0.5));
|
||||
assertEquals(PlaceResult.FAILED, s.tick(ctx, target(10)));
|
||||
assertTrue(ctx.clicks.isEmpty());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package dev.loki.satura.interaction.place.strategy.precise;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import dev.loki.satura.interaction.place.FakeContext;
|
||||
import dev.loki.satura.interaction.place.Placement;
|
||||
import java.util.Optional;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class PreciseSupportTest {
|
||||
|
||||
private static final BlockPos TARGET = new BlockPos(0, 10, 0);
|
||||
|
||||
@Test
|
||||
void orderIsUpFirstSidesThenDown() {
|
||||
final Direction[] order = PreciseSupport.searchOrder();
|
||||
assertEquals(Direction.UP, order[0]);
|
||||
assertEquals(Direction.DOWN, order[order.length - 1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
void picksVisibleSupportBelow() {
|
||||
final FakeContext ctx = new FakeContext(new Vec3d(0.5, 11.0, 0.5));
|
||||
ctx.solids.add(new BlockPos(0, 9, 0));
|
||||
final Optional<Placement> found = new PreciseSupport().find(ctx, TARGET, 4.5);
|
||||
assertTrue(found.isPresent());
|
||||
assertEquals(new BlockPos(0, 9, 0), found.get().support());
|
||||
assertEquals(Direction.UP, found.get().face());
|
||||
assertEquals(new Vec3d(0.5, 10.0, 0.5), found.get().standPos());
|
||||
}
|
||||
|
||||
@Test
|
||||
void skipsHiddenSupport() {
|
||||
final FakeContext ctx = new FakeContext(new Vec3d(0.5, 11.0, 0.5));
|
||||
ctx.solids.add(new BlockPos(0, 9, 0));
|
||||
ctx.hidden.add(new BlockPos(0, 9, 0));
|
||||
assertTrue(new PreciseSupport().find(ctx, TARGET, 4.5).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void skipsSupportOutOfReach() {
|
||||
final FakeContext ctx = new FakeContext(new Vec3d(0.5, 11.0, 30.5));
|
||||
ctx.solids.add(new BlockPos(0, 9, 0));
|
||||
assertTrue(new PreciseSupport().find(ctx, TARGET, 4.5).isEmpty());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue