Skip to content

Commit

Permalink
Refactor AllAdvancementsDataState, and add 1.20 AA structures to API
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninjabrain1 committed Sep 12, 2024
1 parent 177d1fe commit e2f87ab
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 295 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import ninjabrainbot.gui.components.panels.ThemedPanel;
import ninjabrainbot.gui.style.StyleManager;
import ninjabrainbot.io.preferences.NinjabrainBotPreferences;
import ninjabrainbot.model.datastate.alladvancements.AllAdvancementsStructureType;
import ninjabrainbot.model.datastate.alladvancements.IAllAdvancementsDataState;
import ninjabrainbot.model.input.IButtonInputHandler;

Expand All @@ -31,14 +32,14 @@ public AllAdvancementsPanel(StyleManager styleManager, IButtonInputHandler butto
super(styleManager);
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
add(new AllAdvancementsHeader(styleManager));
add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.strongholdInformation(), strongholdIcon, false, true, true));
add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.spawnInformation(), shulkerIcon, true, true, true));
add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.outpostInformation(), outpostIcon, true, true, true));
add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.monumentInformation(), monumentIcon, true, true, true));
oneDotTwentyPlusPanels.add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.deepDarkInformation(), deepDarkIcon, true, true, true));
oneDotTwentyPlusPanels.add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.shulkerTransportInformation(), shulkerTransportIcon, true, true, false));
oneDotTwentyPlusPanels.add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.cityQueryInformation(), cityQueryIcon, true, true, false));
oneDotTwentyPlusPanels.add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.generalLocationInformation(), generalLocationIcon, true, false, false));
add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.getStructureInformation(AllAdvancementsStructureType.Stronghold), strongholdIcon, false, true, true));
add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.getStructureInformation(AllAdvancementsStructureType.Spawn), shulkerIcon, true, true, true));
add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.getStructureInformation(AllAdvancementsStructureType.Outpost), outpostIcon, true, true, true));
add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.getStructureInformation(AllAdvancementsStructureType.Monument), monumentIcon, true, true, true));
oneDotTwentyPlusPanels.add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.getStructureInformation(AllAdvancementsStructureType.DeepDark), deepDarkIcon, true, true, true));
oneDotTwentyPlusPanels.add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.getStructureInformation(AllAdvancementsStructureType.ShulkerTransport), shulkerTransportIcon, true, true, false));
oneDotTwentyPlusPanels.add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.getStructureInformation(AllAdvancementsStructureType.CityQuery), cityQueryIcon, true, true, false));
oneDotTwentyPlusPanels.add(new StructurePanel(styleManager, buttonInputHandler, allAdvancementsDataState.getStructureInformation(AllAdvancementsStructureType.GeneralLocation), generalLocationIcon, true, false, false));
for (StructurePanel panel : oneDotTwentyPlusPanels) {
add(panel);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ninjabrainbot.gui.themeeditor;

import ninjabrainbot.model.datastate.alladvancements.AllAdvancementsStructureType;
import ninjabrainbot.model.datastate.alladvancements.IAllAdvancementsDataState;
import ninjabrainbot.model.datastate.alladvancements.IAllAdvancementsPosition;
import ninjabrainbot.model.datastate.common.DetachedDomainModel;
Expand All @@ -25,77 +26,12 @@ public IDataComponent<Boolean> hasEnteredEnd() {
}

@Override
public IDataComponent<IAllAdvancementsPosition> spawnPosition() {
public IDataComponent<IAllAdvancementsPosition> getAllAdvancementsPosition(AllAdvancementsStructureType allAdvancementsStructureType) {
return new DataComponent<>("", domainModel);
}

@Override
public IDataComponent<IAllAdvancementsPosition> outpostPosition() {
return new DataComponent<>("", domainModel);
}

@Override
public IDataComponent<IAllAdvancementsPosition> monumentPosition() {
return new DataComponent<>("", domainModel);
}

@Override
public IDataComponent<IAllAdvancementsPosition> deepDarkPosition() {
return new DataComponent<>("", domainModel);
}

@Override
public IDataComponent<IAllAdvancementsPosition> cityQueryPosition() {
return new DataComponent<>("", domainModel);
}

@Override
public IDataComponent<IAllAdvancementsPosition> shulkerTransportPosition() {
return new DataComponent<>("", domainModel);
}

@Override
public IDataComponent<IAllAdvancementsPosition> generalLocationPosition() {
return new DataComponent<>("", domainModel);
}

@Override
public IDomainModelComponent<StructureInformation> strongholdInformation() {
return new InferredComponent<>(null);
}

@Override
public IDomainModelComponent<StructureInformation> spawnInformation() {
return new InferredComponent<>(null);
}

@Override
public IDomainModelComponent<StructureInformation> outpostInformation() {
return new InferredComponent<>(null);
}

@Override
public IDomainModelComponent<StructureInformation> monumentInformation() {
return new InferredComponent<>(null);
}

@Override
public IDomainModelComponent<StructureInformation> deepDarkInformation() {
return new InferredComponent<>(null);
}

@Override
public IDomainModelComponent<StructureInformation> cityQueryInformation() {
return new InferredComponent<>(null);
}

@Override
public IDomainModelComponent<StructureInformation> shulkerTransportInformation() {
return new InferredComponent<>(null);
}

@Override
public IDomainModelComponent<StructureInformation> generalLocationInformation() {
public IDomainModelComponent<StructureInformation> getStructureInformation(AllAdvancementsStructureType allAdvancementsStructureType) {
return new InferredComponent<>(null);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ninjabrainbot.io.api.queries;

import ninjabrainbot.model.datastate.IDataState;
import ninjabrainbot.model.datastate.alladvancements.AllAdvancementsStructureType;
import ninjabrainbot.model.datastate.common.StructureInformation;
import org.json.JSONObject;

Expand All @@ -19,10 +20,10 @@ public AllAdvancementsQuery(boolean isPretty) {
public String get(IDataState dataState) {
JSONObject rootObject = new JSONObject();
rootObject.put("isAllAdvancementsModeEnabled", dataState.allAdvancementsDataState().allAdvancementsModeEnabled().get());
rootObject.put("strongholdPosition", convertPosition(dataState.allAdvancementsDataState().strongholdInformation().get()));
rootObject.put("spawnPosition", convertPosition(dataState.allAdvancementsDataState().spawnInformation().get()));
rootObject.put("outpostPosition", convertPosition(dataState.allAdvancementsDataState().outpostInformation().get()));
rootObject.put("monumentPosition", convertPosition(dataState.allAdvancementsDataState().monumentInformation().get()));
for (AllAdvancementsStructureType allAdvancementsStructureType : AllAdvancementsStructureType.values()){
String key = mapAllAdvancementsStructureTypeName(allAdvancementsStructureType);
rootObject.put(key, convertPosition(dataState.allAdvancementsDataState().getStructureInformation(allAdvancementsStructureType).get()));
}
return rootObject.toString(isPretty ? 4 : 0);
}

Expand All @@ -43,4 +44,26 @@ private JSONObject convertPosition(StructureInformation structureInformation) {
return structurePositionObject;
}

private String mapAllAdvancementsStructureTypeName(AllAdvancementsStructureType allAdvancementsStructureType){
switch (allAdvancementsStructureType){
case Spawn:
return "spawn";
case Outpost:
return "outpost";
case Monument:
return "monument";
case Stronghold:
return "stronghold";
case DeepDark:
return "deepDark";
case CityQuery:
return "cityQuery";
case ShulkerTransport:
return "shulkerTransport";
case GeneralLocation:
return "generalLocation";
}
throw new IllegalArgumentException("Unknown all advancements structure type: " + allAdvancementsStructureType);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ninjabrainbot.model.actions.alladvancements;

import ninjabrainbot.model.actions.IAction;
import ninjabrainbot.model.datastate.alladvancements.AllAdvancementsStructureType;
import ninjabrainbot.model.datastate.alladvancements.IAllAdvancementsDataState;
import ninjabrainbot.model.datastate.common.StructureInformation;

Expand All @@ -16,33 +17,11 @@ public RemoveStructureAction(IAllAdvancementsDataState allAdvancementsDataState,

@Override
public void execute() {
if (allAdvancementsDataState.spawnInformation().get() == structureInformation) {
allAdvancementsDataState.spawnPosition().reset();
return;
}
if (allAdvancementsDataState.outpostInformation().get() == structureInformation) {
allAdvancementsDataState.outpostPosition().reset();
return;
}
if (allAdvancementsDataState.monumentInformation().get() == structureInformation) {
allAdvancementsDataState.monumentPosition().reset();
return;
}
if (allAdvancementsDataState.shulkerTransportInformation().get() == structureInformation) {
allAdvancementsDataState.shulkerTransportPosition().reset();
return;
}
if (allAdvancementsDataState.deepDarkInformation().get() == structureInformation) {
allAdvancementsDataState.deepDarkPosition().reset();
return;
}
if (allAdvancementsDataState.cityQueryInformation().get() == structureInformation) {
allAdvancementsDataState.cityQueryPosition().reset();
return;
}
if (allAdvancementsDataState.generalLocationInformation().get() == structureInformation) {
allAdvancementsDataState.generalLocationPosition().reset();
return;
for (AllAdvancementsStructureType allAdvancementsStructureType : AllAdvancementsStructureType.values()) {
if (allAdvancementsDataState.getStructureInformation(allAdvancementsStructureType).get() == structureInformation) {
allAdvancementsDataState.getAllAdvancementsPosition(allAdvancementsStructureType).reset();
return;
}
}
throw new IllegalArgumentException(String.format("Cannot remove structure position %s because it not present in the data state.", structureInformation));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ninjabrainbot.model.actions.IAction;
import ninjabrainbot.model.datastate.alladvancements.AllAdvancementsPosition;
import ninjabrainbot.model.datastate.alladvancements.AllAdvancementsStructureType;
import ninjabrainbot.model.datastate.alladvancements.IAllAdvancementsDataState;
import ninjabrainbot.model.datastate.endereye.F3IData;

Expand All @@ -17,6 +18,6 @@ public SetAllAdvancementsGeneralLocationAction(IAllAdvancementsDataState allAdva

@Override
public void execute() {
allAdvancementsDataState.generalLocationPosition().set(allAdvancementsPosition);
allAdvancementsDataState.getAllAdvancementsPosition(AllAdvancementsStructureType.GeneralLocation).set(allAdvancementsPosition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public TryAddAllAdvancementsStructureAction(IDataState dataState, IDetailedPlaye
@Override
public void execute() {
AllAdvancementsStructureType structureType = getAllAdvancementStructureTypeFromPlayerPosition(playerPosition);
if (structureType == AllAdvancementsStructureType.Unknown)
if (structureType == null)
return;

IAllAdvancementsPosition structurePosition = getStructurePosition(structureType);

IDataComponent<IAllAdvancementsPosition> dataComponent = getDataComponentFromStructureType(structureType);
IDataComponent<IAllAdvancementsPosition> dataComponent = allAdvancementsDataState.getAllAdvancementsPosition(structureType);
// Cities can be queried multiple times, so overwrite the position.
if (structureType != AllAdvancementsStructureType.CityQuery && dataComponent.get() != null)
return;
Expand All @@ -40,10 +40,10 @@ public void execute() {

private AllAdvancementsStructureType getAllAdvancementStructureTypeFromPlayerPosition(IDetailedPlayerPosition t) {
if (t.isInNether())
return AllAdvancementsStructureType.Unknown;
return null;

if (t.isInEnd())
return preferences.oneDotTwentyPlusAA.get() ? AllAdvancementsStructureType.ShulkerTransport : AllAdvancementsStructureType.Unknown;
return preferences.oneDotTwentyPlusAA.get() ? AllAdvancementsStructureType.ShulkerTransport : null;

if (Math.abs(t.xInOverworld()) <= 300 && Math.abs(t.zInOverworld()) <= 300 && Math.abs(Math.round(t.yInPlayerDimension()) - t.yInPlayerDimension()) < 0.001)
return AllAdvancementsStructureType.Spawn;
Expand Down Expand Up @@ -100,26 +100,4 @@ private IAllAdvancementsPosition getCityRegionCentre(IDetailedPlayerPosition t)
int cityRegionCentreZ = 24 * (int) Math.round((chunkZ - 8) / 24D) + 8;
return new AllAdvancementsPosition(cityRegionCentreX * 16 + 8, cityRegionCentreZ * 16 + 8);
}

private IDataComponent<IAllAdvancementsPosition> getDataComponentFromStructureType(AllAdvancementsStructureType structureType) {
switch (structureType) {
case Spawn:
return allAdvancementsDataState.spawnPosition();
case Outpost:
return allAdvancementsDataState.outpostPosition();
case Monument:
return allAdvancementsDataState.monumentPosition();
case DeepDark:
return allAdvancementsDataState.deepDarkPosition();
case CityQuery:
return allAdvancementsDataState.cityQueryPosition();
case ShulkerTransport:
return allAdvancementsDataState.shulkerTransportPosition();
case GeneralLocation:
return allAdvancementsDataState.generalLocationPosition();
default:
throw new IllegalArgumentException("Setting of structure type " + structureType + " is not supported.");
}
}

}
Loading

0 comments on commit e2f87ab

Please sign in to comment.