Skip to content

Commit

Permalink
Merge pull request Ninjabrain1#77 from ExeRSolver/revert-boateye-removal
Browse files Browse the repository at this point in the history
Revert "Remove boat throws"
  • Loading branch information
Ninjabrain1 authored Jan 2, 2024
2 parents ccbaa72 + 7b1eaba commit 3549b6b
Show file tree
Hide file tree
Showing 14 changed files with 178 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/main/java/ninjabrainbot/gui/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private void initModel() {
private void initInputHandlers() {
Progress.setTask("Initializing input handlers", 0.08f);
coordinateInputSource = disposeHandler.add(new CoordinateInputSource(clipboardReader));
IEnderEyeThrowFactory enderEyeThrowFactory = new EnderEyeThrowFactory(preferences);
IEnderEyeThrowFactory enderEyeThrowFactory = new EnderEyeThrowFactory(preferences, dataState.boatDataState());
disposeHandler.add(new PlayerPositionInputHandler(coordinateInputSource, dataState, actionExecutor, preferences, enderEyeThrowFactory));
disposeHandler.add(new FossilInputHandler(coordinateInputSource, dataState, actionExecutor));
disposeHandler.add(new ActiveInstanceInputHandler(activeInstanceProvider, domainModel, dataState, environmentState, actionExecutor, preferences));
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/ninjabrainbot/gui/frames/CalibrationDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public CalibrationDialog(StyleManager styleManager, NinjabrainBotPreferences pre
this.preferences = preferences;
this.owner = owner;
actionExecutor.disable();
calibrator = disposeHandler.add(calibratorFactory.createCalibrator());
calibrator = disposeHandler.add(calibratorFactory.createCalibrator(isBoatCalibrator(preferences)));

JPanel panel2 = new JPanel();
panel2.setOpaque(false);
Expand Down Expand Up @@ -114,7 +114,11 @@ public void startCalibrating() {
private void done() {
if (calibrator.isStrongholdDetermined()) {
float std = (float) calibrator.getSTD(preferences.mcVersion.get());
preferences.sigma.set(std);
if (isBoatCalibrator(preferences)) {
preferences.sigmaBoat.set(std);
} else {
preferences.sigma.set(std);
}
}
dispose();
}
Expand Down Expand Up @@ -171,8 +175,12 @@ private void updateHistogram() {
}
}

private static boolean isBoatCalibrator(NinjabrainBotPreferences preferences) {
return preferences.useTallRes.get() && preferences.usePreciseAngle.get();
}

private static String getTitle(NinjabrainBotPreferences preferences) {
return I18n.get("calibrator.title");
return I18n.get("calibrator.title") + (isBoatCalibrator(preferences) ? String.format(" (%s)", I18n.get("settings.boat_standard_deviation")) : "");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public int getTextSize(SizePreference p) {
titlebarPanel.addButton(settingsButton);
NotificationsButton notificationsButton = new NotificationsButton(styleManager, this, preferences, updateChecker);
titlebarPanel.addButton(notificationsButton);
titlebarPanel.addButton(new BoatIcon(styleManager, dataState.boatDataState().boatState(), preferences, disposeHandler));
}

@Override
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/ninjabrainbot/gui/mainwindow/BoatIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class BoatIcon extends ThemedLabel {
public BoatIcon(StyleManager styleManager, IObservable<BoatState> boatState, NinjabrainBotPreferences preferences, DisposeHandler sh) {
super(styleManager);
setIcon(getBoatIcon(boatState.get()));
// setVisible(preferences.useTallRes.get() && preferences.usePreciseAngle.get());
//
// sh.add(boatState.subscribeEDT(b -> setIcon(getBoatIcon(b))));
// sh.add(preferences.useTallRes.whenModified().subscribeEDT(b -> setVisible(b && preferences.usePreciseAngle.get())));
// sh.add(preferences.usePreciseAngle.whenModified().subscribeEDT(this::setVisible));
setVisible(preferences.useTallRes.get() && preferences.usePreciseAngle.get());

sh.add(boatState.subscribeEDT(b -> setIcon(getBoatIcon(b))));
sh.add(preferences.useTallRes.whenModified().subscribeEDT(b -> setVisible(b && preferences.usePreciseAngle.get())));
sh.add(preferences.usePreciseAngle.whenModified().subscribeEDT(this::setVisible));
}

private static final HashMap<String, ImageIcon> cachedIcons = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,24 @@
import ninjabrainbot.gui.components.labels.ThemedLabel;
import ninjabrainbot.gui.components.layout.StackPanel;
import ninjabrainbot.gui.components.preferences.CheckboxPanel;
import ninjabrainbot.gui.components.preferences.DoublePreferencePanel;
import ninjabrainbot.gui.components.preferences.FloatPreferencePanel;
import ninjabrainbot.gui.components.preferences.HotkeyPanel;
import ninjabrainbot.gui.frames.OptionsFrame;
import ninjabrainbot.gui.style.SizePreference;
import ninjabrainbot.gui.style.StyleManager;
import ninjabrainbot.io.KeyboardListener;
import ninjabrainbot.io.preferences.NinjabrainBotPreferences;
import ninjabrainbot.util.I18n;

public class HighPrecisionOptionsPanel extends JPanel {

private final CheckboxPanel sensitivityCheckbox;
private final FloatPreferencePanel resolutionHeight;
private final DoublePreferencePanel sensitivity;
private final FloatPreferencePanel boatErrorLimit;
private final FloatPreferencePanel sigmaBoat;
private HotkeyPanel enterBoatHotkey;

public HighPrecisionOptionsPanel(StyleManager styleManager, NinjabrainBotPreferences preferences, DisposeHandler disposeHandler) {
setOpaque(false);
Expand All @@ -40,12 +48,48 @@ public int getTextSize(SizePreference p) {
resolutionHeight.setEnabled(preferences.useTallRes.get());
column1.add(resolutionHeight);

// Precise Sens Column
sensitivityCheckbox = new CheckboxPanel(styleManager, I18n.get("settings.use_precise_angle"), preferences.usePreciseAngle);
sensitivityCheckbox.setEnabled(preferences.useTallRes.get());
column1.add(sensitivityCheckbox);

sensitivity = new DoublePreferencePanel(styleManager, I18n.get("settings.sensitivity"), preferences.sensitivity);
sensitivity.setWidth(150);
sensitivity.setDecimals(10);
sensitivity.setEnabled(preferences.usePreciseAngle.get() && preferences.useTallRes.get());
column1.add(sensitivity);
if (KeyboardListener.registered) {
enterBoatHotkey = new HotkeyPanel(styleManager, I18n.get("settings.enter_boat"), preferences.hotkeyBoat);
enterBoatHotkey.setEnabled(preferences.usePreciseAngle.get() && preferences.useTallRes.get());
column1.add(enterBoatHotkey);
}
boatErrorLimit = new FloatPreferencePanel(styleManager, I18n.get("settings.boat_error"), preferences.boatErrorLimit);
boatErrorLimit.setDecimals(2);
boatErrorLimit.setEnabled(preferences.usePreciseAngle.get() && preferences.useTallRes.get());
column1.add(boatErrorLimit);

sigmaBoat = new FloatPreferencePanel(styleManager, I18n.get("settings.boat_standard_deviation"), preferences.sigmaBoat);
sigmaBoat.setEnabled(preferences.usePreciseAngle.get() && preferences.useTallRes.get());
column1.add(sigmaBoat);

disposeHandler.add(preferences.useTallRes.whenModified().subscribeEDT(b -> setTallResolutionEnabled(b, preferences)));
disposeHandler.add(preferences.usePreciseAngle.whenModified().subscribeEDT(this::setPreciseAngleEnabled));
disposeHandler.add(preferences.sigmaBoat.whenModified().subscribeEDT(sigmaBoat::updateValue));
}

private void setTallResolutionEnabled(boolean b, NinjabrainBotPreferences preferences) {
resolutionHeight.setEnabled(b);
resolutionHeight.descLabel.updateColors();
sensitivityCheckbox.setEnabled(b);
sensitivityCheckbox.descLabel.updateColors();
setPreciseAngleEnabled(b && preferences.usePreciseAngle.get());
}

private void setPreciseAngleEnabled(boolean b) {
sensitivity.setEnabled(b);
enterBoatHotkey.setEnabled(b);
boatErrorLimit.setEnabled(b);
sigmaBoat.setEnabled(b);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class NinjabrainBotPreferences {
public final IntPreference theme;
public final HotkeyPreference hotkeyIncrement;
public final HotkeyPreference hotkeyDecrement;
public final HotkeyPreference hotkeyBoat;
public final HotkeyPreference hotkeyReset;
public final HotkeyPreference hotkeyUndo;
public final HotkeyPreference hotkeyRedo;
Expand Down Expand Up @@ -43,6 +44,7 @@ public class NinjabrainBotPreferences {
public final BooleanPreference altClipboardReader;
public final BooleanPreference useAltStd;
public final BooleanPreference useTallRes;
public final BooleanPreference usePreciseAngle;
public final BooleanPreference useOverlay;
public final BooleanPreference overlayAutoHide;
public final BooleanPreference overlayHideWhenLocked;
Expand Down Expand Up @@ -75,6 +77,7 @@ public NinjabrainBotPreferences(IPreferenceSource source) {
hotkeyMinimize = new HotkeyPreference("hotkey_minimize", source);
hotkeyAltStd = new HotkeyPreference("hotkey_alt_std", source);
hotkeyLock = new HotkeyPreference("hotkey_lock", source);
hotkeyBoat = new HotkeyPreference("hotkey_boat", source);
hotkeyToggleAllAdvancementsMode = new HotkeyPreference("hotkey_toggle_aa_mode", source);
// Float
sigma = new FloatPreference("sigma", 0.1f, 0.001f, 1f, source);
Expand All @@ -100,6 +103,7 @@ public NinjabrainBotPreferences(IPreferenceSource source) {
altClipboardReader = new BooleanPreference("alt_clipboard_reader", false, source);
useAltStd = new BooleanPreference("use_alt_std", false, source);
useTallRes = new BooleanPreference("use_tall_res", false, source);
usePreciseAngle = new BooleanPreference("use_precise_angle", false, source);
useOverlay = new BooleanPreference("use_obs_overlay", false, source);
overlayAutoHide = new BooleanPreference("overlay_auto_hide", false, source);
overlayHideWhenLocked = new BooleanPreference("overlay_lock_hide", false, source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import ninjabrainbot.model.datastate.divine.IDivineContext;
import ninjabrainbot.model.datastate.endereye.IEnderEyeThrow;
import ninjabrainbot.model.datastate.endereye.NormalEnderEyeThrow;
import ninjabrainbot.model.datastate.highprecision.BoatEnderEyeThrow;
import ninjabrainbot.model.datastate.stronghold.Chunk;
import ninjabrainbot.model.domainmodel.IListComponent;
import ninjabrainbot.model.domainmodel.ListComponent;
Expand Down Expand Up @@ -49,7 +50,9 @@ public class Calibrator implements IDisposable {
private final DisposeHandler disposeHandler = new DisposeHandler();
private final ObservableProperty<Calibrator> whenModified = new ObservableProperty<>();

public Calibrator(CalculatorSettings calculatorSettings, IPlayerPositionInputSource playerPositionInputSource, NinjabrainBotPreferences preferences) {
private final boolean isBoatThrowCalibrator;

public Calibrator(CalculatorSettings calculatorSettings, IPlayerPositionInputSource playerPositionInputSource, NinjabrainBotPreferences preferences, boolean isBoatThrowCalibrator) {
try {
keyPresser = new KeyPresser();
} catch (AWTException e) {
Expand All @@ -63,11 +66,17 @@ public Calibrator(CalculatorSettings calculatorSettings, IPlayerPositionInputSou
disposeHandler.add(preferences.hotkeyDecrement.whenTriggered().subscribe(__ -> new ChangeLastAngleAction(throwList, locked, preferences, false).execute()));
disposeHandler.add(throwList.subscribe(__ -> whenModified.notifySubscribers(this)));
ready = false;
this.isBoatThrowCalibrator = isBoatThrowCalibrator;
}

private void onNewPlayerPositionInputted(IDetailedPlayerPosition playerPosition) {
try {
add(new NormalEnderEyeThrow(playerPosition, preferences.crosshairCorrection.get()));
if (isBoatThrowCalibrator) {
add(new BoatEnderEyeThrow(playerPosition, preferences, 0));
}
else {
add(new NormalEnderEyeThrow(playerPosition, preferences.crosshairCorrection.get()));
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -108,6 +117,12 @@ private void add(IEnderEyeThrow t) throws InterruptedException {
double nextZ = t.zInOverworld() + deltaZ * 0.8 - Math.sin(phi) * perpendicularDistance;
// Face in the general direction of the stronghold
double nextAlpha = getAlpha(prediction, nextX, nextZ) + (Math.random() - 0.5) * 10.0;
if (isBoatThrowCalibrator) {
double preMultiplier = preferences.sensitivity.get() * 0.6f + 0.2f;
preMultiplier = preMultiplier * preMultiplier * preMultiplier * 8.0f;
double minInc = preMultiplier * 0.15D;
nextAlpha = Math.round(nextAlpha / minInc) * minInc;
}
tp(nextX, nextZ, nextAlpha, -31.2);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public CalibratorFactory(IObservable<CalculatorSettings> calculatorSettings, IPl
}

@Override
public Calibrator createCalibrator() {
return new Calibrator(calculatorSettings.get(), playerPositionInputSource, preferences);
public Calibrator createCalibrator(boolean isBoatCalibrator) {
return new Calibrator(calculatorSettings.get(), playerPositionInputSource, preferences, isBoatCalibrator);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public interface ICalibratorFactory {

Calibrator createCalibrator();
Calibrator createCalibrator(boolean isBoatCalibrator);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,28 @@
import ninjabrainbot.io.preferences.NinjabrainBotPreferences;
import ninjabrainbot.model.datastate.common.IDetailedPlayerPosition;
import ninjabrainbot.model.datastate.common.IPlayerPosition;
import ninjabrainbot.model.datastate.highprecision.BoatEnderEyeThrow;
import ninjabrainbot.model.datastate.highprecision.IBoatDataState;
import ninjabrainbot.util.Assert;

public class EnderEyeThrowFactory implements IEnderEyeThrowFactory {

private final NinjabrainBotPreferences preferences;
private final IBoatDataState boatDataState;

public EnderEyeThrowFactory(NinjabrainBotPreferences preferences) {
public EnderEyeThrowFactory(NinjabrainBotPreferences preferences, IBoatDataState boatDataState) {
this.preferences = preferences;
this.boatDataState = boatDataState;
}

@Override
public IEnderEyeThrow createEnderEyeThrowFromDetailedPlayerPosition(IDetailedPlayerPosition detailedPlayerPosition) {
Assert.isTrue(detailedPlayerPosition.isInOverworld());

boolean isBoatThrow = preferences.useTallRes.get() && preferences.usePreciseAngle.get() && boatDataState.boatAngle().get() != null;
if (isBoatThrow)
return new BoatEnderEyeThrow(detailedPlayerPosition, preferences, boatDataState.boatAngle().get());

return new NormalEnderEyeThrow(detailedPlayerPosition, preferences.crosshairCorrection.get());
}

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/ninjabrainbot/model/input/HotkeyInputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public HotkeyInputHandler(NinjabrainBotPreferences preferences, IDomainModel dom
disposeHandler.add(preferences.hotkeyIncrement.whenTriggered().subscribe(__ -> changeLastAngleIfNotLocked(true)));
disposeHandler.add(preferences.hotkeyDecrement.whenTriggered().subscribe(__ -> changeLastAngleIfNotLocked(false)));
disposeHandler.add(preferences.hotkeyAltStd.whenTriggered().subscribe(this::toggleAltStdIfNotLocked));
disposeHandler.add(preferences.hotkeyBoat.whenTriggered().subscribe(this::toggleEnteringBoatIfNotLocked));
disposeHandler.add(preferences.hotkeyLock.whenTriggered().subscribe(__ -> actionExecutor.executeImmediately(new ToggleLockedAction(dataState))));
disposeHandler.add(preferences.usePreciseAngle.whenModified().subscribe(this::resetBoatState));
}

private void resetIfNotLocked() {
Expand Down Expand Up @@ -61,6 +63,16 @@ private void toggleAltStdIfNotLocked() {
actionExecutor.executeImmediately(new ToggleAltStdOnLastThrowAction(dataState, preferences));
}

private void toggleEnteringBoatIfNotLocked() {
if (preferences.usePreciseAngle.get() && !dataState.locked().get() && !dataState.allAdvancementsDataState().allAdvancementsModeEnabled().get())
actionExecutor.executeImmediately(new ToggleEnteringBoatAction(dataState));
}

private void resetBoatState(){
if (!preferences.usePreciseAngle.get() && dataState.boatDataState().enteringBoat().get())
actionExecutor.executeImmediately(new ToggleEnteringBoatAction(dataState));
}

@Override
public void dispose() {
disposeHandler.dispose();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package ninjabrainbot.integrationtests;

import ninjabrainbot.gui.mainwindow.BoatIcon;
import ninjabrainbot.gui.mainwindow.main.MainTextAreaTestAdapter;
import ninjabrainbot.model.datastate.highprecision.BoatState;
import ninjabrainbot.util.TestUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

public class BoatCalculatedTravelTests {

private static final String input1 =
"/execute in minecraft:overworld run tp @s 1274.04 92.55 1064.56 -78.75 32.82," +
"/execute in minecraft:overworld run tp @s 1275.31 93.00 1064.81 -146.11 -32.13," +
"7," +
"133,-14";
private static final String input2 =
"/execute in minecraft:overworld run tp @s -1380.20 80.00 1138.90 -143.16 28.53," +
"/execute in minecraft:overworld run tp @s -1376.84 80.00 1132.87 -60.46 -31.73," +
"5," +
"-43,95";
private static final String input3 =
"/execute in minecraft:overworld run tp @s 3430.24 62.07 -4805.87 104.06 74.04," +
"/execute in minecraft:overworld run tp @s 3430.24 63.09 -4805.87 93.92 -31.81," +
"23," +
"111,-308";

@ParameterizedTest
@CsvSource({ input1, input2, input3 })
public void oneEyeBoatCalculatedTravelEyeSpies(String boatF3c, String enderEyeF3c, int subpixelCorrections, int strongholdChunkX, int strongholdChunkZ) {
// Arrange
IntegrationTestBuilder testBuilder = new IntegrationTestBuilder().withBoatSettings();
MainTextAreaTestAdapter mainTextAreaTestAdapter = testBuilder.createMainTextArea();
BoatIcon boatIcon = testBuilder.createBoatIcon();

// Act + Assert
TestUtils.awaitSwingEvents();
Assertions.assertTrue(boatIcon.isVisible());
Assertions.assertEquals(boatIcon.getIcon(), BoatIcon.getBoatIcon(BoatState.NONE));

testBuilder.triggerHotkey(testBuilder.preferences.hotkeyBoat);
TestUtils.awaitSwingEvents();
Assertions.assertEquals(boatIcon.getIcon(), BoatIcon.getBoatIcon(BoatState.MEASURING));

testBuilder.setClipboard(boatF3c);
TestUtils.awaitSwingEvents();
Assertions.assertEquals(boatIcon.getIcon(), BoatIcon.getBoatIcon(BoatState.VALID));

testBuilder.setClipboard(enderEyeF3c);
testBuilder.inputSubpixelCorrections(subpixelCorrections);

// Assert
TestUtils.awaitSwingEvents();
Assertions.assertEquals(boatIcon.getIcon(), BoatIcon.getBoatIcon(BoatState.VALID));
mainTextAreaTestAdapter.assertDetailedTriangulationTopPredictionIsEqualTo(strongholdChunkX, strongholdChunkZ);
mainTextAreaTestAdapter.assertDetailedTriangulationTopNetherCoordsIsEqualTo(2 * strongholdChunkX, 2 * strongholdChunkZ);

double angleError = testBuilder.dataState.calculatorResult().get().getBestPrediction().getAngleError(testBuilder.dataState.getThrowList().get(0));
final double toRad = Math.PI / 180.0;
double smallestPossibleCorrection = Math.atan(2 * Math.tan(15 * toRad) / testBuilder.preferences.resolutionHeight.get()) / Math.cos(-31 * toRad) / toRad;
Assertions.assertTrue(Math.abs(angleError) < smallestPossibleCorrection);
}

}
Loading

0 comments on commit 3549b6b

Please sign in to comment.