Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.20+ Advancements Support #106

Merged
merged 8 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/java/ninjabrainbot/gui/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import ninjabrainbot.model.input.ActiveInstanceInputHandler;
import ninjabrainbot.model.input.ButtonInputHandler;
import ninjabrainbot.model.input.FossilInputHandler;
import ninjabrainbot.model.input.GeneralLocationInputHandler;
import ninjabrainbot.model.input.HotkeyInputHandler;
import ninjabrainbot.model.input.IButtonInputHandler;
import ninjabrainbot.model.input.PlayerPositionInputHandler;
Expand Down Expand Up @@ -104,10 +105,11 @@ private void initModel() {

private void initInputHandlers() {
Progress.setTask("Initializing input handlers", 0.08f);
coordinateInputSource = disposeHandler.add(new CoordinateInputSource(clipboardReader));
coordinateInputSource = disposeHandler.add(new CoordinateInputSource(clipboardReader, 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 GeneralLocationInputHandler(coordinateInputSource, dataState, actionExecutor));
disposeHandler.add(new ActiveInstanceInputHandler(activeInstanceProvider, domainModel, dataState, environmentState, actionExecutor, preferences));
disposeHandler.add(new HotkeyInputHandler(preferences, domainModel, dataState, actionExecutor));
buttonInputHandler = new ButtonInputHandler(domainModel, dataState, actionExecutor);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/ninjabrainbot/gui/frames/ThemeEditorDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import ninjabrainbot.model.datastate.divine.Fossil;
import ninjabrainbot.model.datastate.endereye.IEnderEyeThrow;
import ninjabrainbot.model.datastate.endereye.NormalEnderEyeThrow;
import ninjabrainbot.model.datastate.endereye.MCDimension;
import ninjabrainbot.model.information.InformationMessageList;
import ninjabrainbot.util.Assert;
import ninjabrainbot.util.I18n;
Expand Down Expand Up @@ -171,8 +172,8 @@ private ThemedPanel createPreviewsPanel(StyleManager styleManager) {
NinjabrainBotPreferences defaultPreferences = new NinjabrainBotPreferences(new UnsavedPreferences());
ArrayList<IEnderEyeThrow> eyeThrows = new ArrayList<>();

IEnderEyeThrow t1 = new NormalEnderEyeThrow(new DetailedPlayerPosition(659.70, 80, 1950.30, -253.82, -31.75, false), 0).withCorrection(0.01);
IEnderEyeThrow t2 = new NormalEnderEyeThrow(new DetailedPlayerPosition(-3.75, 80, 2002.63, -184.67, -31.75, false), 0).withCorrection(-0.01).withToggledAltStd();
IEnderEyeThrow t1 = new NormalEnderEyeThrow(new DetailedPlayerPosition(659.70, 80, 1950.30, -253.82, -31.75, MCDimension.OVERWORLD), 0).withCorrection(0.01);
IEnderEyeThrow t2 = new NormalEnderEyeThrow(new DetailedPlayerPosition(-3.75, 80, 2002.63, -184.67, -31.75, MCDimension.OVERWORLD), 0).withCorrection(-0.01).withToggledAltStd();
eyeThrows.add(t1);
eyeThrows.add(t2);
Fossil f = new Fossil(3);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,73 @@
package ninjabrainbot.gui.mainwindow.alladvancements;

import java.awt.Dimension;
import java.util.Objects;
import java.util.ArrayList;

import javax.swing.BoxLayout;
import javax.swing.ImageIcon;

import ninjabrainbot.Main;
import ninjabrainbot.event.IDisposable;
import ninjabrainbot.event.Subscription;
import ninjabrainbot.model.datastate.alladvancements.IAllAdvancementsDataState;
import ninjabrainbot.gui.components.panels.ThemedPanel;
import ninjabrainbot.gui.style.StyleManager;
import ninjabrainbot.io.preferences.NinjabrainBotPreferences;
import ninjabrainbot.model.input.IButtonInputHandler;

public class AllAdvancementsPanel extends ThemedPanel {
public class AllAdvancementsPanel extends ThemedPanel implements IDisposable {

private final NinjabrainBotPreferences preferences;
private static final ImageIcon strongholdIcon = new ImageIcon(Objects.requireNonNull(Main.class.getResource("/stronghold_icon.png")));
private static final ImageIcon shulkerIcon = new ImageIcon(Objects.requireNonNull(Main.class.getResource("/spawn_icon.png")));
private static final ImageIcon outpostIcon = new ImageIcon(Objects.requireNonNull(Main.class.getResource("/outpost_icon.png")));
private static final ImageIcon monumentIcon = new ImageIcon(Objects.requireNonNull(Main.class.getResource("/monument_icon.png")));
private static final ImageIcon deepDarkIcon = new ImageIcon(Objects.requireNonNull(Main.class.getResource("/deep_dark_icon.png")));
private static final ImageIcon shulkerTransportIcon = new ImageIcon(Objects.requireNonNull(Main.class.getResource("/shulker_transport_icon.png")));
private static final ImageIcon cityQueryIcon = new ImageIcon(Objects.requireNonNull(Main.class.getResource("/city_query_icon.png")));
private static final ImageIcon generalLocationIcon = new ImageIcon(Objects.requireNonNull(Main.class.getResource("/general_location_icon.png")));

public AllAdvancementsPanel(StyleManager styleManager, IButtonInputHandler buttonInputHandler, IAllAdvancementsDataState allAdvancementsDataState) {
private final ArrayList<StructurePanel> oneDotTwentyPlusPanels = new ArrayList<>();
final Subscription generalLocationSubscription;

public AllAdvancementsPanel(StyleManager styleManager, IButtonInputHandler buttonInputHandler, IAllAdvancementsDataState allAdvancementsDataState, NinjabrainBotPreferences preferences) {
super(styleManager);
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
add(new AllAdvancementsHeader(styleManager));
add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.strongholdPosition(), strongholdIcon, false, true));
add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.spawnPosition(), shulkerIcon, true, true));
add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.outpostPosition(), outpostIcon, true, true));
add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.monumentPosition(), monumentIcon, true, false));
add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.strongholdPosition(), strongholdIcon, false, true, true));
add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.spawnPosition(), shulkerIcon, true, true, true));
add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.outpostPosition(), outpostIcon, true, true, true));
add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.monumentPosition(), monumentIcon, true, true, true));
oneDotTwentyPlusPanels.add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.deepDarkPosition(), deepDarkIcon, true, true, true));
oneDotTwentyPlusPanels.add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.shulkerTransportPosition(), shulkerTransportIcon, true, true, false));
oneDotTwentyPlusPanels.add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.cityQueryPosition(), cityQueryIcon, true, true, false));
oneDotTwentyPlusPanels.add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.generalLocationPosition(), generalLocationIcon, true, false, false));
generalLocationSubscription = allAdvancementsDataState.generalLocationPosition().subscribeEDT(__ -> updateOneDotTwentyPlusAAEnabled());
for (StructurePanel panel : oneDotTwentyPlusPanels) {
add(panel);
}
for (StructurePanel panel : oneDotTwentyPlusPanels) {
panel.setEnabled(preferences.oneDotTwentyPlusAA.get());
panel.setVisible(preferences.oneDotTwentyPlusAA.get());
}
this.preferences = preferences;
}

public void updateOneDotTwentyPlusAAEnabled() {
// print contents of oneDotTwentyPlusPanels for debugging

for (StructurePanel panel : oneDotTwentyPlusPanels) {
panel.setEnabled(preferences.oneDotTwentyPlusAA.get());
panel.setVisible(preferences.oneDotTwentyPlusAA.get());
}

this.revalidate();
this.repaint();
}

@Override
public void dispose() {
generalLocationSubscription.dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ public class StructurePanel extends ThemedPanel implements IDisposable {
final ThemedLabel nether;
final ThemedLabel angle;

private final boolean showNether;
private final boolean showBorder;
private final WrappedColor borderColor;

private final DisposeHandler disposeHandler = new DisposeHandler();
private Subscription angleSubscription;

public StructurePanel(StyleManager styleManager, IButtonInputHandler buttonInputHandler, IObservable<StructurePosition> structurePosition, ImageIcon icon, boolean addDeleteButton, boolean showBorder) {
public StructurePanel(StyleManager styleManager, IButtonInputHandler buttonInputHandler, IObservable<StructurePosition> structurePosition, ImageIcon icon, boolean addDeleteButton, boolean showBorder, boolean showNether) {
super(styleManager);
setOpaque(true);
ThemedLabel iconLabel = new ThemedLabel(styleManager, true);
Expand All @@ -53,6 +54,7 @@ public StructurePanel(StyleManager styleManager, IButtonInputHandler buttonInput
add(angle);
add(deleteButton);

this.showNether = showNether;
this.showBorder = showBorder;
borderColor = styleManager.currentTheme.COLOR_DIVIDER;
setBackgroundColor(styleManager.currentTheme.COLOR_SLIGHTLY_WEAK);
Expand All @@ -75,8 +77,9 @@ private RemoveStructureButton createDeleteButton(StyleManager styleManager, IObs
public void onStructurePositionUpdated(StructurePosition structurePosition) {
if (structurePosition != null) {
location.setText(String.format("(%.0f, %.0f)", structurePosition.xInOverworld(), structurePosition.zInOverworld()));
nether.setText(String.format("(%.0f, %.0f)", structurePosition.xInNether(), structurePosition.zInNether()));
angle.setText(String.format("%.1f", structurePosition.getTravelAngle()));
if (showNether)
nether.setText(String.format("(%.0f, %.0f)", structurePosition.xInNether(), structurePosition.zInNether()));
} else {
location.setText("");
nether.setText("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public MainTextArea(StyleManager styleManager, IButtonInputHandler buttonInputHa
detailedTriangulation = new DetailedTriangulationPanel(styleManager, preferences);
blind = new BlindPanel(styleManager);
divine = new DivinePanel(styleManager);
allAdvancements = new AllAdvancementsPanel(styleManager, buttonInputHandler, dataState.allAdvancementsDataState());
allAdvancements = new AllAdvancementsPanel(styleManager, buttonInputHandler, dataState.allAdvancementsDataState(), preferences);
add(basicTriangulation, TRIANGULATION);
add(detailedTriangulation, TRIANGULATION_DETAILED);
add(blind, BLIND);
Expand All @@ -61,11 +61,18 @@ public MainTextArea(StyleManager styleManager, IButtonInputHandler buttonInputHa
updateResult();
}

private void updateOneDotTwentyPlusAAEnabled() {
allAdvancements.updateOneDotTwentyPlusAAEnabled();
// Update the size of the panel
whenSizeModified.notifySubscribers(this);
}

private void setupSubscriptions() {
// Settings
disposeHandler.add(preferences.showNetherCoords.whenModified().subscribeEDT(this::setNetherCoordsEnabled));
disposeHandler.add(preferences.showAngleUpdates.whenModified().subscribeEDT(this::setAngleUpdatesEnabled));
disposeHandler.add(preferences.view.whenModified().subscribeEDT(__ -> onViewTypeChanged()));
disposeHandler.add(preferences.oneDotTwentyPlusAA.whenModified().subscribeEDT(__ -> updateOneDotTwentyPlusAAEnabled()));
// Data state
disposeHandler.add(dataState.calculatorResult().subscribeEDT(this::setResult));
disposeHandler.add(dataState.blindResult().subscribeEDT(this::setResult));
Expand Down Expand Up @@ -145,6 +152,8 @@ private void setAngleUpdatesEnabled(boolean b) {
public Dimension getPreferredSize() {
if (preferences.view.get() == MainViewType.BASIC && !dataState.allAdvancementsDataState().allAdvancementsModeEnabled().get()) {
return basicTriangulation.getPreferredSize();
} else if (dataState.allAdvancementsDataState().allAdvancementsModeEnabled().get()) {
return allAdvancements.getPreferredSize();
} else {
return detailedTriangulation.getPreferredSize();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
public class AllAdvancementsOptionsPanel extends StackPanel {

private final NinjabrainBotPreferences preferences;
private final CheckboxPanel oneDotTwentyPlusAA;
private final RadioButtonPanel switchTypeRadioButtonPanel;
private final HotkeyPanel toggleHotkeyPanel;

Expand All @@ -36,15 +37,21 @@ public int getTextSize(SizePreference p) {
}
});
add(new CheckboxPanel(styleManager, I18n.get("settings.enable_all_advancements_mode"), preferences.allAdvancements));


add(oneDotTwentyPlusAA = new CheckboxPanel(styleManager, I18n.get("settings.enable_120plus_all_advancements_mode"), preferences.oneDotTwentyPlusAA));

add(switchTypeRadioButtonPanel = new RadioButtonPanel(styleManager, I18n.get("settings.all_advancements.switch_type"), preferences.allAdvancementsToggleType, true));
add(toggleHotkeyPanel = new HotkeyPanel(styleManager, I18n.get("settings.all_advancements.toggle_aa_mode_hotkey"), preferences.hotkeyToggleAllAdvancementsMode));

updateComponentsEnabled();
preferences.allAdvancements.whenModified().subscribeEDT(this::updateComponentsEnabled);
preferences.oneDotTwentyPlusAA.whenModified().subscribeEDT(this::updateComponentsEnabled);
preferences.allAdvancementsToggleType.whenModified().subscribeEDT(this::updateComponentsEnabled);
}

private void updateComponentsEnabled() {
oneDotTwentyPlusAA.setEnabled(preferences.allAdvancements.get());
switchTypeRadioButtonPanel.setEnabled(preferences.allAdvancements.get());
toggleHotkeyPanel.setEnabled(preferences.allAdvancements.get() && preferences.allAdvancementsToggleType.get() == AllAdvancementsToggleType.Hotkey);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,24 @@ public IDataComponent<StructurePosition> outpostPosition() {
public IDataComponent<StructurePosition> monumentPosition() {
return new DataComponent<>(null);
}

@Override
public IDataComponent<StructurePosition> deepDarkPosition() {
return new DataComponent<>(null);
}

@Override
public IDataComponent<StructurePosition> cityQueryPosition() {
return new DataComponent<>(null);
}

@Override
public IDataComponent<StructurePosition> shulkerTransportPosition() {
return new DataComponent<>(null);
}

@Override
public IDataComponent<StructurePosition> generalLocationPosition() {
return new DataComponent<>(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public boolean isInNether() {
return false;
}

@Override
public boolean isInEnd() {
return false;
}

@Override
public double horizontalAngle() {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class NinjabrainBotPreferences {
public final BooleanPreference overlayAutoHide;
public final BooleanPreference overlayHideWhenLocked;
public final BooleanPreference allAdvancements;
public final BooleanPreference oneDotTwentyPlusAA;
public final BooleanPreference informationMismeasureEnabled;
public final BooleanPreference informationDirectionHelpEnabled;
public final BooleanPreference informationCombinedCertaintyEnabled;
Expand Down Expand Up @@ -117,6 +118,7 @@ public NinjabrainBotPreferences(IPreferenceSource source) {
overlayAutoHide = new BooleanPreference("overlay_auto_hide", false, source);
overlayHideWhenLocked = new BooleanPreference("overlay_lock_hide", false, source);
allAdvancements = new BooleanPreference("all_advancements", false, source);
oneDotTwentyPlusAA = new BooleanPreference("one_dot_twenty_plus_aa", false, source);
informationMismeasureEnabled = new BooleanPreference("mismeasure_warning_enabled", false, source);
informationDirectionHelpEnabled = new BooleanPreference("direction_help_enabled", false, source);
informationCombinedCertaintyEnabled = new BooleanPreference("combined_offset_information_enabled", true, source);
Expand Down
Loading