Add setting to only build selected part of schematica schematic

This commit is contained in:
ZacSharp 2021-04-13 23:09:54 +02:00
parent 2cb6402189
commit c13cf4f29c
No known key found for this signature in database
GPG Key ID: 9453647B005083A3
3 changed files with 67 additions and 2 deletions

View File

@ -847,6 +847,11 @@ public final class Settings {
*/
public final Setting<Boolean> skipFailedLayers = new Setting<>(false);
/**
* Only build the selected part of the schematic when using #schematica
*/
public final Setting<Boolean> schematicaOnlyBuildSelection = new Setting<>(false);
/**
* How far to move before repeating the build. 0 to disable repeating on a certain axis, 0,0,0 to disable entirely
*/

View File

@ -43,6 +43,7 @@ import baritone.utils.BlockStateInterface;
import baritone.utils.NotificationHelper;
import baritone.utils.PathingCommandContext;
import baritone.utils.schematic.MapArtSchematic;
import baritone.utils.schematic.SelectionSchematic;
import baritone.utils.schematic.SchematicSystem;
import baritone.utils.schematic.schematica.SchematicaHelper;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
@ -150,10 +151,13 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
Optional<Tuple<IStaticSchematic, BlockPos>> schematic = SchematicaHelper.getOpenSchematic();
if (schematic.isPresent()) {
IStaticSchematic s = schematic.get().getFirst();
BlockPos origin = schematic.get().getSecond();
ISchematic schem = Baritone.settings().mapArtMode.value ? new MapArtSchematic(s) : s;
schem = Baritone.settings().schematicaOnlyBuildSelection.value ? new SelectionSchematic(schem, origin, baritone.getSelectionManager().getSelections()) : schem;
this.build(
schematic.get().getFirst().toString(),
Baritone.settings().mapArtMode.value ? new MapArtSchematic(s) : s,
schematic.get().getSecond()
schem,
origin
);
} else {
logDirect("No schematic currently open");

View File

@ -0,0 +1,56 @@
/*
* 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;
import baritone.api.schematic.ISchematic;
import baritone.api.schematic.MaskSchematic;
import baritone.api.selection.ISelection;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import java.util.stream.Stream;
public class SelectionSchematic extends MaskSchematic {
private final ISelection[] selections;
public SelectionSchematic(ISchematic schematic, BlockPos origin, ISelection[] selections) {
super(schematic);
baritone.api.utils.Helper.HELPER.logDirect(String.format("%s", selections[0].min()));
this.selections = Stream.of(selections).map(
sel -> sel
.shift(EnumFacing.WEST, origin.getX())
.shift(EnumFacing.DOWN, origin.getY())
.shift(EnumFacing.NORTH, origin.getZ()))
.toArray(ISelection[]::new);
baritone.api.utils.Helper.HELPER.logDirect(String.format("%s", this.selections[0].min()));
baritone.api.utils.Helper.HELPER.logDirect(String.format("%s", origin));
}
@Override
protected boolean partOfMask(int x, int y, int z, IBlockState currentState) {
for (ISelection selection : selections) {
if (x >= selection.min().x && y >= selection.min().y && z >= selection.min().z
&& x <= selection.max().x && y <= selection.max().y && z <= selection.max().z) {
return true;
}
}
return false;
}
}