2828import baritone .api .schematic .FillSchematic ;
2929import baritone .api .schematic .ISchematic ;
3030import baritone .api .schematic .IStaticSchematic ;
31+ import baritone .api .schematic .MaskSchematic ;
3132import baritone .api .schematic .SubstituteSchematic ;
3233import baritone .api .schematic .format .ISchematicFormat ;
3334import baritone .api .utils .*;
8586
8687public final class BuilderProcess extends BaritoneProcessHelper implements IBuilderProcess {
8788
89+ private static final Set <Property <?>> ORIENTATION_PROPS =
90+ ImmutableSet .of (
91+ RotatedPillarBlock .AXIS , HorizontalDirectionalBlock .FACING ,
92+ StairBlock .FACING , StairBlock .HALF , StairBlock .SHAPE ,
93+ PipeBlock .NORTH , PipeBlock .EAST , PipeBlock .SOUTH , PipeBlock .WEST , PipeBlock .UP ,
94+ TrapDoorBlock .OPEN , TrapDoorBlock .HALF
95+ );
96+
8897 private HashSet <BetterBlockPos > incorrectPositions ;
8998 private LongOpenHashSet observedCompleted ; // positions that are completed even if they're out of render distance and we can't make sure right now
9099 private String name ;
@@ -111,6 +120,14 @@ public void build(String name, ISchematic schematic, Vec3i origin) {
111120 if (!Baritone .settings ().buildSubstitutes .value .isEmpty ()) {
112121 this .schematic = new SubstituteSchematic (this .schematic , Baritone .settings ().buildSubstitutes .value );
113122 }
123+ // TODO this preserves the old behavior, but maybe we should bake the setting value right here
124+ this .schematic = new MaskSchematic (this .schematic ) {
125+ @ Override
126+ public boolean partOfMask (int x , int y , int z , BlockState current ) {
127+ // partOfMask is only called inside the schematic so desiredState is not null
128+ return !Baritone .settings ().buildSkipBlocks .value .contains (this .desiredState (x , y , z , current , Collections .emptyList ()).getBlock ());
129+ }
130+ };
114131 int x = origin .getX ();
115132 int y = origin .getY ();
116133 int z = origin .getZ ();
@@ -169,15 +186,15 @@ public boolean build(String name, File schematic, Vec3i origin) {
169186 if (!format .isPresent ()) {
170187 return false ;
171188 }
172- ISchematic parsed ;
189+ IStaticSchematic parsed ;
173190 try {
174191 parsed = format .get ().parse (new FileInputStream (schematic ));
175192 } catch (Exception e ) {
176193 e .printStackTrace ();
177194 return false ;
178195 }
179- parsed = applyMapArtAndSelection (origin , ( IStaticSchematic ) parsed );
180- build (name , parsed , origin );
196+ ISchematic schem = applyMapArtAndSelection (origin , parsed );
197+ build (name , schem , origin );
181198 return true ;
182199 }
183200
@@ -197,17 +214,10 @@ public void buildOpenSchematic() {
197214 if (SchematicaHelper .isSchematicaPresent ()) {
198215 Optional <Tuple <IStaticSchematic , BlockPos >> schematic = SchematicaHelper .getOpenSchematic ();
199216 if (schematic .isPresent ()) {
200- IStaticSchematic s = schematic .get ().getA ();
217+ IStaticSchematic raw = schematic .get ().getA ();
201218 BlockPos origin = schematic .get ().getB ();
202- ISchematic schem = Baritone .settings ().mapArtMode .value ? new MapArtSchematic (s ) : s ;
203- if (Baritone .settings ().buildOnlySelection .value ) {
204- schem = new SelectionSchematic (schem , origin , baritone .getSelectionManager ().getSelections ());
205- }
206- this .build (
207- schematic .get ().getA ().toString (),
208- schem ,
209- origin
210- );
219+ ISchematic schem = applyMapArtAndSelection (origin , raw );
220+ this .build (raw .toString (), schem , origin );
211221 } else {
212222 logDirect ("No schematic currently open" );
213223 }
@@ -439,8 +449,8 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
439449 return onTick (calcFailed , isSafeToCancel , 0 );
440450 }
441451
442- public PathingCommand onTick (boolean calcFailed , boolean isSafeToCancel , int recursions ) {
443- if (recursions > 1000 ) { // onTick calls itself, don't crash
452+ private PathingCommand onTick (boolean calcFailed , boolean isSafeToCancel , int recursions ) {
453+ if (recursions > 100 ) { // onTick calls itself, don't crash
444454 return new PathingCommand (null , PathingCommandType .SET_GOAL_AND_PATH );
445455 }
446456 approxPlaceable = approxPlaceable (36 );
@@ -684,8 +694,7 @@ private void fullRecalc(BuilderCalculationContext bcc) {
684694 continue ;
685695 }
686696 // this is not in render distance
687- if (!observedCompleted .contains (BetterBlockPos .longHash (blockX , blockY , blockZ ))
688- && !Baritone .settings ().buildSkipBlocks .value .contains (schematic .desiredState (x , y , z , current , this .approxPlaceable ).getBlock ())) {
697+ if (!observedCompleted .contains (BetterBlockPos .longHash (blockX , blockY , blockZ ))) {
689698 // and we've never seen this position be correct
690699 // therefore mark as incorrect
691700 incorrectPositions .add (new BetterBlockPos (blockX , blockY , blockZ ));
@@ -1010,15 +1019,7 @@ private List<BlockState> approxPlaceable(int size) {
10101019 return result ;
10111020 }
10121021
1013- public static final Set <Property <?>> orientationProps =
1014- ImmutableSet .of (
1015- RotatedPillarBlock .AXIS , HorizontalDirectionalBlock .FACING ,
1016- StairBlock .FACING , StairBlock .HALF , StairBlock .SHAPE ,
1017- PipeBlock .NORTH , PipeBlock .EAST , PipeBlock .SOUTH , PipeBlock .WEST , PipeBlock .UP ,
1018- TrapDoorBlock .OPEN , TrapDoorBlock .HALF
1019- );
1020-
1021- private boolean sameBlockstate (BlockState first , BlockState second ) {
1022+ private static boolean sameBlockstate (BlockState first , BlockState second ) {
10221023 if (first .getBlock () != second .getBlock ()) {
10231024 return false ;
10241025 }
@@ -1031,15 +1032,15 @@ private boolean sameBlockstate(BlockState first, BlockState second) {
10311032 ImmutableMap <Property <?>, Comparable <?>> map2 = second .getValues ();
10321033 for (Property <?> prop : map1 .keySet ()) {
10331034 if (map1 .get (prop ) != map2 .get (prop )
1034- && !(ignoreDirection && orientationProps .contains (prop ))
1035+ && !(ignoreDirection && ORIENTATION_PROPS .contains (prop ))
10351036 && !ignoredProps .contains (prop .getName ())) {
10361037 return false ;
10371038 }
10381039 }
10391040 return true ;
10401041 }
10411042
1042- private boolean containsBlockState (Collection <BlockState > states , BlockState state ) {
1043+ private static boolean containsBlockState (Collection <BlockState > states , BlockState state ) {
10431044 for (BlockState testee : states ) {
10441045 if (sameBlockstate (testee , state )) {
10451046 return true ;
@@ -1048,7 +1049,7 @@ private boolean containsBlockState(Collection<BlockState> states, BlockState sta
10481049 return false ;
10491050 }
10501051
1051- private boolean valid (BlockState current , BlockState desired , boolean itemVerify ) {
1052+ private static boolean valid (BlockState current , BlockState desired , boolean itemVerify ) {
10521053 if (desired == null ) {
10531054 return true ;
10541055 }
@@ -1067,9 +1068,6 @@ private boolean valid(BlockState current, BlockState desired, boolean itemVerify
10671068 if (!(current .getBlock () instanceof AirBlock ) && Baritone .settings ().buildIgnoreExisting .value && !itemVerify ) {
10681069 return true ;
10691070 }
1070- if (Baritone .settings ().buildSkipBlocks .value .contains (desired .getBlock ()) && !itemVerify ) {
1071- return true ;
1072- }
10731071 if (Baritone .settings ().buildValidSubstitutes .value .getOrDefault (desired .getBlock (), Collections .emptyList ()).contains (current .getBlock ()) && !itemVerify ) {
10741072 return true ;
10751073 }
@@ -1113,12 +1111,12 @@ public double costOfPlacingAt(int x, int y, int z, BlockState current) {
11131111 return COST_INF ;
11141112 }
11151113 BlockState sch = getSchematic (x , y , z , current );
1116- if (sch != null && ! Baritone . settings (). buildSkipBlocks . value . contains ( sch . getBlock ()) ) {
1114+ if (sch != null ) {
11171115 // TODO this can return true even when allowPlace is off.... is that an issue?
11181116 if (sch .getBlock () instanceof AirBlock ) {
11191117 // we want this to be air, but they're asking if they can place here
11201118 // this won't be a schematic block, this will be a throwaway
1121- return placeBlockCost * 2 ; // we're going to have to break it eventually
1119+ return placeBlockCost * Baritone . settings (). placeIncorrectBlockPenaltyMultiplier . value ; // we're going to have to break it eventually
11221120 }
11231121 if (placeable .contains (sch )) {
11241122 return 0 ; // thats right we gonna make it FREE to place a block where it should go in a structure
@@ -1131,7 +1129,7 @@ public double costOfPlacingAt(int x, int y, int z, BlockState current) {
11311129 }
11321130 // we want it to be something that we don't have
11331131 // even more of a pain to place something wrong
1134- return placeBlockCost * 3 ;
1132+ return placeBlockCost * 1.5 * Baritone . settings (). placeIncorrectBlockPenaltyMultiplier . value ;
11351133 } else {
11361134 if (hasThrowaway ) {
11371135 return placeBlockCost ;
@@ -1147,7 +1145,7 @@ public double breakCostMultiplierAt(int x, int y, int z, BlockState current) {
11471145 return COST_INF ;
11481146 }
11491147 BlockState sch = getSchematic (x , y , z , current );
1150- if (sch != null && ! Baritone . settings (). buildSkipBlocks . value . contains ( sch . getBlock ()) ) {
1148+ if (sch != null ) {
11511149 if (sch .getBlock () instanceof AirBlock ) {
11521150 // it should be air
11531151 // regardless of current contents, we can break it
0 commit comments