| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public void build(String name, ISchematic schematic, Vec3i origin) { |
| 101 | this.name = name; |
| 102 | this.schematic = schematic; |
| 103 | this.realSchematic = null; |
| 104 | boolean buildingSelectionSchematic = schematic instanceof SelectionSchematic; |
| 105 | if (!Baritone.settings().buildSubstitutes.value.isEmpty()) { |
| 106 | this.schematic = new SubstituteSchematic(this.schematic, Baritone.settings().buildSubstitutes.value); |
| 107 | } |
| 108 | if (Baritone.settings().buildSchematicMirror.value != net.minecraft.world.level.block.Mirror.NONE) { |
| 109 | this.schematic = new MirroredSchematic(this.schematic, Baritone.settings().buildSchematicMirror.value); |
| 110 | } |
| 111 | if (Baritone.settings().buildSchematicRotation.value != net.minecraft.world.level.block.Rotation.NONE) { |
| 112 | this.schematic = new RotatedSchematic(this.schematic, Baritone.settings().buildSchematicRotation.value); |
| 113 | } |
| 114 | // TODO this preserves the old behavior, but maybe we should bake the setting value right here |
| 115 | this.schematic = new MaskSchematic(this.schematic) { |
| 116 | @Override |
| 117 | public boolean partOfMask(int x, int y, int z, BlockState current) { |
| 118 | // partOfMask is only called inside the schematic so desiredState is not null |
| 119 | return !Baritone.settings().buildSkipBlocks.value.contains(this.desiredState(x, y, z, current, Collections.emptyList()).getBlock()); |
| 120 | } |
| 121 | }; |
| 122 | int x = origin.getX(); |
| 123 | int y = origin.getY(); |
| 124 | int z = origin.getZ(); |
| 125 | if (Baritone.settings().schematicOrientationX.value) { |
| 126 | x += schematic.widthX(); |
| 127 | } |
| 128 | if (Baritone.settings().schematicOrientationY.value) { |
| 129 | y += schematic.heightY(); |
| 130 | } |
| 131 | if (Baritone.settings().schematicOrientationZ.value) { |
| 132 | z += schematic.lengthZ(); |
| 133 | } |
| 134 | this.origin = new Vec3i(x, y, z); |
| 135 | this.paused = false; |
| 136 | this.layer = Baritone.settings().startAtLayer.value; |
| 137 | this.stopAtHeight = schematic.heightY(); |
| 138 | if (Baritone.settings().buildOnlySelection.value && buildingSelectionSchematic) { // currently redundant but safer maybe |
| 139 | if (baritone.getSelectionManager().getSelections().length == 0) { |
| 140 | logDirect("Poor little kitten forgot to set a selection while BuildOnlySelection is true"); |
| 141 | this.stopAtHeight = 0; |
| 142 | } else if (Baritone.settings().buildInLayers.value) { |
| 143 | OptionalInt minim = Stream.of(baritone.getSelectionManager().getSelections()).mapToInt(sel -> sel.min().y).min(); |
| 144 | OptionalInt maxim = Stream.of(baritone.getSelectionManager().getSelections()).mapToInt(sel -> sel.max().y).max(); |
| 145 | if (minim.isPresent() && maxim.isPresent()) { |
| 146 | int startAtHeight = Baritone.settings().layerOrder.value ? y + schematic.heightY() - maxim.getAsInt() : minim.getAsInt() - y; |
| 147 | this.stopAtHeight = (Baritone.settings().layerOrder.value ? y + schematic.heightY() - minim.getAsInt() : maxim.getAsInt() - y) + 1; |
| 148 | this.layer = Math.max(this.layer, startAtHeight / Baritone.settings().layerHeight.value); // startAtLayer or startAtHeight, whichever is highest |
| 149 | logDebug(String.format("Schematic starts at y=%s with height %s", y, schematic.heightY())); |
| 150 | logDebug(String.format("Selection starts at y=%s and ends at y=%s", minim.getAsInt(), maxim.getAsInt())); |
| 151 | logDebug(String.format("Considering relevant height %s - %s", startAtHeight, this.stopAtHeight)); |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | this.numRepeats = 0; |