LitematicaCommand added to build loaded schematics

This commit is contained in:
schmar03 2022-09-28 12:09:38 +02:00
parent 7a48824ced
commit d928e705b9
5 changed files with 159 additions and 0 deletions

View File

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

View File

@ -43,6 +43,7 @@ public final class DefaultCommands {
new RepackCommand(baritone), new RepackCommand(baritone),
new BuildCommand(baritone), new BuildCommand(baritone),
new SchematicaCommand(baritone), new SchematicaCommand(baritone),
new LitematicaCommand(baritone),
new ComeCommand(baritone), new ComeCommand(baritone),
new AxisCommand(baritone), new AxisCommand(baritone),
new ForceCancelCommand(baritone), new ForceCancelCommand(baritone),

View File

@ -0,0 +1,60 @@
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
public class LitematicaCommand extends Command {
public LitematicaCommand(IBaritone baritone) {
super(baritone, "litematica");
}
@Override
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
baritone.getBuilderProcess().buildOpenLitematic();
}
@Override
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Builds the loaded schematic";
}
@Override
public List<String> getLongDesc() {
return Arrays.asList(
"Builds the schematic currently open in Litematica.",
"",
"Usage:",
"> litematica"
);
}
}

View File

@ -44,9 +44,13 @@ import baritone.utils.PathingCommandContext;
import baritone.utils.schematic.MapArtSchematic; import baritone.utils.schematic.MapArtSchematic;
import baritone.utils.schematic.SelectionSchematic; import baritone.utils.schematic.SelectionSchematic;
import baritone.utils.schematic.SchematicSystem; import baritone.utils.schematic.SchematicSystem;
import baritone.utils.schematic.litematica.LitematicaHelper;
import baritone.utils.schematic.schematica.SchematicaHelper; import baritone.utils.schematic.schematica.SchematicaHelper;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import fi.dy.masa.litematica.data.DataManager;
import fi.dy.masa.litematica.schematic.placement.SchematicPlacement;
import fi.dy.masa.litematica.schematic.placement.SchematicPlacementManager;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.IProperty;
@ -176,6 +180,24 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
} }
} }
@Override
public void buildOpenLitematic() {
if (LitematicaHelper.isLitematicaPresent()) {
SchematicPlacementManager placementManager = DataManager.getSchematicPlacementManager();
List<SchematicPlacement> placementList = placementManager.getAllSchematicsPlacements();
if (placementList.size()>0) {
String name = LitematicaHelper.getName(placementList,0);
File schemFile = LitematicaHelper.getSchematicFile(placementList,0);
Vec3i origin = LitematicaHelper.getOrigin(placementList,0);
build(name, schemFile, origin);
} else {
logDirect("No schematic currently open");
}
logDirect("Litematica is not present");
}
}
public void clearArea(BlockPos corner1, BlockPos corner2) { public void clearArea(BlockPos corner1, BlockPos corner2) {
BlockPos origin = new BlockPos(Math.min(corner1.getX(), corner2.getX()), Math.min(corner1.getY(), corner2.getY()), Math.min(corner1.getZ(), corner2.getZ())); BlockPos origin = new BlockPos(Math.min(corner1.getX(), corner2.getX()), Math.min(corner1.getY(), corner2.getY()), Math.min(corner1.getZ(), corner2.getZ()));
int widthX = Math.abs(corner1.getX() - corner2.getX()) + 1; int widthX = Math.abs(corner1.getX() - corner2.getX()) + 1;

View File

@ -0,0 +1,74 @@
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.schematic.litematica;
import com.github.lunatrius.schematica.Schematica;
import fi.dy.masa.litematica.schematic.placement.SchematicPlacement;
import fi.dy.masa.litematica.schematic.placement.SchematicPlacementManager;
import net.minecraft.util.math.Vec3i;
import java.io.File;
import java.util.List;
public enum LitematicaHelper { ;
public static boolean isLitematicaPresent() {
try {
Class.forName(Schematica.class.getName());
return true;
} catch (ClassNotFoundException | NoClassDefFoundError ex) {
return false;
}
}
public static String getName(List<SchematicPlacement> placementList, int i) {
return placementList.get(i).getName();
}
public static Vec3i getOrigin(List<SchematicPlacement> placementList, int i) {
int x,y,z;
x=placementList.get(i).getOrigin().getX();
y=placementList.get(i).getOrigin().getY();
z=placementList.get(i).getOrigin().getZ();
return new Vec3i(x,y,z);
}
public static File getSchematicFile(List<SchematicPlacement> placementList, int i) {
return placementList.get(i).getSchematicFile();
}
}