Skip to content

Commit

Permalink
Merge pull request #106 from VDPineapple/main
Browse files Browse the repository at this point in the history
1.20+ Advancements Support
  • Loading branch information
Ninjabrain1 authored Sep 5, 2024
2 parents 8df999f + 29d7d97 commit 12f4b7a
Show file tree
Hide file tree
Showing 43 changed files with 442 additions and 167 deletions.
6 changes: 3 additions & 3 deletions src/main/java/ninjabrainbot/gui/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import ninjabrainbot.io.AutoResetTimer;
import ninjabrainbot.io.ClipboardReader;
import ninjabrainbot.io.KeyboardListener;
import ninjabrainbot.io.api.NinjabrainBotHttpServer;
import ninjabrainbot.io.mcinstance.ActiveInstanceProviderFactory;
import ninjabrainbot.io.mcinstance.IActiveInstanceProvider;
import ninjabrainbot.io.overlay.NinjabrainBotOverlayImageWriter;
import ninjabrainbot.io.overlay.OBSOverlay;
import ninjabrainbot.io.preferences.NinjabrainBotPreferences;
import ninjabrainbot.io.api.NinjabrainBotHttpServer;
import ninjabrainbot.io.updatechecker.GithubUpdateChecker;
import ninjabrainbot.model.ModelState;
import ninjabrainbot.model.actions.IActionExecutor;
Expand All @@ -34,7 +34,7 @@
import ninjabrainbot.model.information.PortalLinkingWarningProvider;
import ninjabrainbot.model.input.ActiveInstanceInputHandler;
import ninjabrainbot.model.input.ButtonInputHandler;
import ninjabrainbot.model.input.FossilInputHandler;
import ninjabrainbot.model.input.F3ILocationInputHandler;
import ninjabrainbot.model.input.HotkeyInputHandler;
import ninjabrainbot.model.input.IButtonInputHandler;
import ninjabrainbot.model.input.PlayerPositionInputHandler;
Expand Down Expand Up @@ -109,7 +109,7 @@ private void initInputHandlers() {
coordinateInputSource = disposeHandler.add(new CoordinateInputSource(clipboardReader));
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 F3ILocationInputHandler(coordinateInputSource, dataState, actionExecutor, preferences));
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, 1);
IEnderEyeThrow t2 = new NormalEnderEyeThrow(new DetailedPlayerPosition(-3.75, 80, 2002.63, -184.67, -31.75, false), 0).withCorrection(-0.01, -1).withToggledAltStd();
IEnderEyeThrow t1 = new NormalEnderEyeThrow(new DetailedPlayerPosition(659.70, 80, 1950.30, -253.82, -31.75, MCDimension.OVERWORLD), 0).withCorrection(0.01, 1);
IEnderEyeThrow t2 = new NormalEnderEyeThrow(new DetailedPlayerPosition(-3.75, 80, 2002.63, -184.67, -31.75, MCDimension.OVERWORLD), 0).withCorrection(-0.01, -1).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,64 @@
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 {

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<>();

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));
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() {
for (StructurePanel panel : oneDotTwentyPlusPanels) {
panel.setEnabled(preferences.oneDotTwentyPlusAA.get());
panel.setVisible(preferences.oneDotTwentyPlusAA.get());
}

this.revalidate();
this.repaint();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ninjabrainbot.gui.mainwindow.alladvancements;

import javax.swing.border.EmptyBorder;

import ninjabrainbot.event.DisposeHandler;
import ninjabrainbot.event.IDisposable;
import ninjabrainbot.event.IObservable;
Expand All @@ -18,6 +20,7 @@ public RemoveStructureButton(StyleManager styleManager, IObservable<StructurePos
setBackgroundColor(styleManager.currentTheme.COLOR_SLIGHTLY_WEAK);
setForegroundColor(styleManager.currentTheme.TEXT_COLOR_NEUTRAL);
setHoverColor(styleManager.currentTheme.COLOR_EXIT_BUTTON_HOVER);
setBorder(new EmptyBorder(0, 6, 0, 6));
addActionListener(__ -> {
if (structurePosition.get() != null)
buttonInputHandler.onRemoveAllAdvancementsStructureButtonPressed(structurePosition.get());
Expand Down
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
16 changes: 12 additions & 4 deletions src/main/java/ninjabrainbot/gui/mainwindow/main/MainTextArea.java
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 @@ -65,12 +65,13 @@ 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.view.whenModified().subscribeEDT(this::onViewTypeChanged));
disposeHandler.add(preferences.oneDotTwentyPlusAA.whenModified().subscribeEDT(this::updateOneDotTwentyPlusAAEnabled));
// Data state
disposeHandler.add(dataState.calculatorResult().subscribeEDT(this::setResult));
disposeHandler.add(dataState.blindResult().subscribeEDT(this::setResult));
disposeHandler.add(dataState.divineResult().subscribeEDT(this::setResult));
disposeHandler.add(dataState.resultType().subscribeEDT(__ -> updateResult()));
disposeHandler.add(dataState.resultType().subscribeEDT(this::updateResult));
}

private void onViewTypeChanged() {
Expand Down Expand Up @@ -141,9 +142,16 @@ private void setAngleUpdatesEnabled(boolean b) {
whenSizeModified.notifySubscribers(this);
}

private void updateOneDotTwentyPlusAAEnabled() {
allAdvancements.updateOneDotTwentyPlusAAEnabled();
whenSizeModified.notifySubscribers(this);
}

@Override
public Dimension getPreferredSize() {
if (preferences.view.get() == MainViewType.BASIC && !dataState.allAdvancementsDataState().allAdvancementsModeEnabled().get()) {
if (dataState.allAdvancementsDataState().allAdvancementsModeEnabled().get()) {
return allAdvancements.getPreferredSize();
} else if (preferences.view.get() == MainViewType.BASIC) {
return basicTriangulation.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 @@ -53,6 +53,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 @@ -120,6 +121,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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ public void execute() {
allAdvancementsDataState.monumentPosition().reset();
return;
}
if (allAdvancementsDataState.shulkerTransportPosition().get() == structurePosition) {
allAdvancementsDataState.shulkerTransportPosition().reset();
return;
}
if (allAdvancementsDataState.deepDarkPosition().get() == structurePosition) {
allAdvancementsDataState.deepDarkPosition().reset();
return;
}
if (allAdvancementsDataState.cityQueryPosition().get() == structurePosition) {
allAdvancementsDataState.cityQueryPosition().reset();
return;
}
if (allAdvancementsDataState.generalLocationPosition().get() == structurePosition) {
allAdvancementsDataState.generalLocationPosition().reset();
return;
}
throw new IllegalArgumentException(String.format("Cannot remove structure position %s because it not present in the data state.", structurePosition));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ninjabrainbot.model.actions.alladvancements;

import ninjabrainbot.model.actions.IAction;
import ninjabrainbot.model.datastate.alladvancements.IAllAdvancementsDataState;
import ninjabrainbot.model.datastate.common.StructurePosition;
import ninjabrainbot.model.datastate.endereye.F3IData;

public class SetAllAdvancementsGeneralLocationAction implements IAction {

private final IAllAdvancementsDataState allAdvancementsDataState;
private final StructurePosition structurePosition;

public SetAllAdvancementsGeneralLocationAction(IAllAdvancementsDataState allAdvancementsDataState, F3IData f3iData) {
this.allAdvancementsDataState = allAdvancementsDataState;
this.structurePosition = new StructurePosition(f3iData.x, f3iData.z);
}

@Override
public void execute() {
allAdvancementsDataState.generalLocationPosition().set(structurePosition);
}
}
Loading

0 comments on commit 12f4b7a

Please sign in to comment.