support for building selected litematic

This commit is contained in:
Thojo0 2023-11-05 00:25:16 +00:00
parent e183dcba17
commit b2c26b751a
5 changed files with 44 additions and 10 deletions

View File

@ -58,6 +58,8 @@ public interface IBuilderProcess extends IBaritoneProcess {
void buildOpenSchematic();
void buildOpenLitematic();
void buildOpenLitematic(int i);
void pause();

View File

@ -40,11 +40,13 @@ public class LitematicaCommand extends Command {
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();
}
}

View File

@ -215,6 +215,20 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
}
}
@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()) {
@ -532,7 +546,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
}
Optional<Tuple<BetterBlockPos, Rotation>> toBreak = toBreakNearPlayer(bcc);
if (toBreak.isPresent() && isSafeToCancel && ctx.player().isOnGround()) {
if (toBreak.isPresent() && isSafeToCancel && ctx.player().onGround()) {
// 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();
@ -552,7 +566,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
}
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) {
Rotation rot = toPlace.get().rot;
baritone.getLookBehavior().updateTarget(rot, true);
ctx.player().getInventory().selected = toPlace.get().hotbarSelection;
@ -1063,9 +1077,6 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
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;
}
if (Baritone.settings().buildSkipBlocks.value.contains(desired.getBlock()) && !itemVerify) {
return true;
}

View File

@ -54,6 +54,17 @@ public final class LitematicaHelper {
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.

View File

@ -19,13 +19,21 @@ package fi.dy.masa.litematica.schematic.placement;
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;
}
}