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

Support for building selected litematic #4178

Open
wants to merge 3 commits into
base: 1.19.4
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions src/api/java/baritone/api/process/IBuilderProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ default boolean build(String schematicFile, BlockPos origin) {

void buildOpenSchematic();

void buildOpenLitematic();

void buildOpenLitematic(int i);

void pause();
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/baritone/command/defaults/LitematicaCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ public void execute(String label, IArgConsumer args) throws CommandException {
if (args.is(Integer.class)) {
schematic = args.getAs(Integer.class) - 1;
}
}
try {
baritone.getBuilderProcess().buildOpenLitematic(schematic);
} catch (IndexOutOfBoundsException e) {
logDirect("Pleas provide a valid index.");
try {
baritone.getBuilderProcess().buildOpenLitematic(schematic);
} catch (IndexOutOfBoundsException e) {
logDirect("Pleas provide a valid index.");
}
} else {
baritone.getBuilderProcess().buildOpenLitematic();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

baritone.getBuilderProcess().buildOpenLitematic(LitematicaHelper.getSelectedIndex());
this would remove the need of a second buildOpenLitematic method in BuilderProcess however it also wouldnt be wrong to remove the manual selection entirely and just keep the one that builds the schematic litematica has selected.

Copy link
Author

@thojo0 thojo0 Nov 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jeah that's right, i added the second one with the idea that you can easily use it through the api, but of course you can just send the command directly to the execute function, what works better anyways often.

generally adding options i think is good but for intuition maybe only using the selected one makes sense.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about building placements by name? It's intuitive and with proper tab completion is't easy to use.

For easier API usage I think the best option would be a method taking the desired SchematicPlacement (Why are we even using indices in the first place?). Adding buildOpenLitematic() is good for consistency with buildOpenSchematic() though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

names wont work well because you can have multiple schematics with the same name open. how would you decide which schematic is meant if you have 2 "myHouse.litematic"
as to why integers are used instead of SchematicPlacements thats because SchematicPlacement is a class from litematica and i didnt want to add a dependency to a optional mod to the BuilderProcess this way the only Class with a direct dependency on litematica should be LitematicaHelper and methods of that class should only be called after the LitematicaHelper.isLitematicaPresent() method returned true

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added an branch with only the selected placement thojo0/baritone/only_selected_litematic
i will add a pull request if requested for that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

names wont work well because you can have multiple schematics with the same name open

We are talking about placements here and I though litematica enforces unique names on those, like it does for selection and subregion names. But apparently you can have indistinguishable placements. Reporting an error for duplicates would be an option, though it's certainly not as nice anymore.

}
}

Expand Down
21 changes: 16 additions & 5 deletions src/main/java/baritone/process/BuilderProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,20 @@ public void buildOpenSchematic() {
}
}

@Override
public void buildOpenLitematic() {
if (LitematicaHelper.isLitematicaPresent()) {
Integer selectedIndex = LitematicaHelper.getSelectedIndex();
if (selectedIndex != -1) {
buildOpenLitematic(selectedIndex);
} else {
logDirect("No schematic currently selected");
}
} else {
logDirect("Litematica is not present");
}
}

@Override
public void buildOpenLitematic(int i) {
if (LitematicaHelper.isLitematicaPresent()) {
Expand Down Expand Up @@ -532,7 +546,7 @@ public int lengthZ() {
}

Optional<Tuple<BetterBlockPos, Rotation>> toBreak = toBreakNearPlayer(bcc);
if (toBreak.isPresent() && isSafeToCancel && ctx.player().isOnGround()) {
if (toBreak.isPresent() && isSafeToCancel && ctx.player().onGround()) {
thojo0 marked this conversation as resolved.
Show resolved Hide resolved
// we'd like to pause to break this block
// only change look direction if it's safe (don't want to fuck up an in progress parkour for example
Rotation rot = toBreak.get().getB();
Expand All @@ -552,7 +566,7 @@ public int lengthZ() {
}
List<BlockState> desirableOnHotbar = new ArrayList<>();
Optional<Placement> toPlace = searchForPlacables(bcc, desirableOnHotbar);
if (toPlace.isPresent() && isSafeToCancel && ctx.player().isOnGround() && ticks <= 0) {
if (toPlace.isPresent() && isSafeToCancel && ctx.player().onGround() && ticks <= 0) {
thojo0 marked this conversation as resolved.
Show resolved Hide resolved
Rotation rot = toPlace.get().rot;
baritone.getLookBehavior().updateTarget(rot, true);
ctx.player().getInventory().selected = toPlace.get().hotbarSelection;
Expand Down Expand Up @@ -1063,9 +1077,6 @@ private boolean valid(BlockState current, BlockState desired, boolean itemVerify
if (desired.getBlock() instanceof AirBlock && Baritone.settings().buildIgnoreBlocks.value.contains(current.getBlock())) {
return true;
}
if (!(current.getBlock() instanceof AirBlock) && Baritone.settings().buildIgnoreExisting.value && !itemVerify) {
return true;
}
thojo0 marked this conversation as resolved.
Show resolved Hide resolved
if (Baritone.settings().buildSkipBlocks.value.contains(desired.getBlock()) && !itemVerify) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ public static boolean hasLoadedSchematic() {
return DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().size() > 0;
}

/**
* @return the index of the currently selected schematic. -1 if none selected.
*/
public static Integer getSelectedIndex() {
try {
return DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().indexOf(DataManager.getSchematicPlacementManager().getSelectedSchematicPlacement());
} catch (NullPointerException e) {
return -1;
}
}

/**
* @param i index of the Schematic in the schematic placement list.
* @return the name of the requested schematic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;

public class SchematicPlacementManager {
private final List<SchematicPlacement> schematicPlacements = new ArrayList<>();

@Nullable
private SchematicPlacement selectedPlacement;

//in case of a java.lang.NoSuchMethodError try change the name of this method to getAllSchematicPlacements()
//there are inconsistencies in the litematica mod about the naming of this method
public List<SchematicPlacement> getAllSchematicsPlacements() {
return schematicPlacements;
}

public SchematicPlacement getSelectedSchematicPlacement() {
return selectedPlacement;
}
}