28
28
import baritone .api .schematic .FillSchematic ;
29
29
import baritone .api .schematic .ISchematic ;
30
30
import baritone .api .schematic .IStaticSchematic ;
31
+ import baritone .api .schematic .MaskSchematic ;
31
32
import baritone .api .schematic .SubstituteSchematic ;
32
33
import baritone .api .schematic .format .ISchematicFormat ;
33
34
import baritone .api .utils .*;
85
86
86
87
public final class BuilderProcess extends BaritoneProcessHelper implements IBuilderProcess {
87
88
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
+
88
97
private HashSet <BetterBlockPos > incorrectPositions ;
89
98
private LongOpenHashSet observedCompleted ; // positions that are completed even if they're out of render distance and we can't make sure right now
90
99
private String name ;
@@ -111,6 +120,14 @@ public void build(String name, ISchematic schematic, Vec3i origin) {
111
120
if (!Baritone .settings ().buildSubstitutes .value .isEmpty ()) {
112
121
this .schematic = new SubstituteSchematic (this .schematic , Baritone .settings ().buildSubstitutes .value );
113
122
}
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
+ };
114
131
int x = origin .getX ();
115
132
int y = origin .getY ();
116
133
int z = origin .getZ ();
@@ -169,15 +186,15 @@ public boolean build(String name, File schematic, Vec3i origin) {
169
186
if (!format .isPresent ()) {
170
187
return false ;
171
188
}
172
- ISchematic parsed ;
189
+ IStaticSchematic parsed ;
173
190
try {
174
191
parsed = format .get ().parse (new FileInputStream (schematic ));
175
192
} catch (Exception e ) {
176
193
e .printStackTrace ();
177
194
return false ;
178
195
}
179
- parsed = applyMapArtAndSelection (origin , ( IStaticSchematic ) parsed );
180
- build (name , parsed , origin );
196
+ ISchematic schem = applyMapArtAndSelection (origin , parsed );
197
+ build (name , schem , origin );
181
198
return true ;
182
199
}
183
200
@@ -197,17 +214,10 @@ public void buildOpenSchematic() {
197
214
if (SchematicaHelper .isSchematicaPresent ()) {
198
215
Optional <Tuple <IStaticSchematic , BlockPos >> schematic = SchematicaHelper .getOpenSchematic ();
199
216
if (schematic .isPresent ()) {
200
- IStaticSchematic s = schematic .get ().getA ();
217
+ IStaticSchematic raw = schematic .get ().getA ();
201
218
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 );
211
221
} else {
212
222
logDirect ("No schematic currently open" );
213
223
}
@@ -439,8 +449,8 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
439
449
return onTick (calcFailed , isSafeToCancel , 0 );
440
450
}
441
451
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
444
454
return new PathingCommand (null , PathingCommandType .SET_GOAL_AND_PATH );
445
455
}
446
456
approxPlaceable = approxPlaceable (36 );
@@ -684,8 +694,7 @@ private void fullRecalc(BuilderCalculationContext bcc) {
684
694
continue ;
685
695
}
686
696
// 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 ))) {
689
698
// and we've never seen this position be correct
690
699
// therefore mark as incorrect
691
700
incorrectPositions .add (new BetterBlockPos (blockX , blockY , blockZ ));
@@ -1010,15 +1019,7 @@ private List<BlockState> approxPlaceable(int size) {
1010
1019
return result ;
1011
1020
}
1012
1021
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 ) {
1022
1023
if (first .getBlock () != second .getBlock ()) {
1023
1024
return false ;
1024
1025
}
@@ -1031,15 +1032,15 @@ private boolean sameBlockstate(BlockState first, BlockState second) {
1031
1032
ImmutableMap <Property <?>, Comparable <?>> map2 = second .getValues ();
1032
1033
for (Property <?> prop : map1 .keySet ()) {
1033
1034
if (map1 .get (prop ) != map2 .get (prop )
1034
- && !(ignoreDirection && orientationProps .contains (prop ))
1035
+ && !(ignoreDirection && ORIENTATION_PROPS .contains (prop ))
1035
1036
&& !ignoredProps .contains (prop .getName ())) {
1036
1037
return false ;
1037
1038
}
1038
1039
}
1039
1040
return true ;
1040
1041
}
1041
1042
1042
- private boolean containsBlockState (Collection <BlockState > states , BlockState state ) {
1043
+ private static boolean containsBlockState (Collection <BlockState > states , BlockState state ) {
1043
1044
for (BlockState testee : states ) {
1044
1045
if (sameBlockstate (testee , state )) {
1045
1046
return true ;
@@ -1048,7 +1049,7 @@ private boolean containsBlockState(Collection<BlockState> states, BlockState sta
1048
1049
return false ;
1049
1050
}
1050
1051
1051
- private boolean valid (BlockState current , BlockState desired , boolean itemVerify ) {
1052
+ private static boolean valid (BlockState current , BlockState desired , boolean itemVerify ) {
1052
1053
if (desired == null ) {
1053
1054
return true ;
1054
1055
}
@@ -1067,9 +1068,6 @@ private boolean valid(BlockState current, BlockState desired, boolean itemVerify
1067
1068
if (!(current .getBlock () instanceof AirBlock ) && Baritone .settings ().buildIgnoreExisting .value && !itemVerify ) {
1068
1069
return true ;
1069
1070
}
1070
- if (Baritone .settings ().buildSkipBlocks .value .contains (desired .getBlock ()) && !itemVerify ) {
1071
- return true ;
1072
- }
1073
1071
if (Baritone .settings ().buildValidSubstitutes .value .getOrDefault (desired .getBlock (), Collections .emptyList ()).contains (current .getBlock ()) && !itemVerify ) {
1074
1072
return true ;
1075
1073
}
@@ -1113,12 +1111,12 @@ public double costOfPlacingAt(int x, int y, int z, BlockState current) {
1113
1111
return COST_INF ;
1114
1112
}
1115
1113
BlockState sch = getSchematic (x , y , z , current );
1116
- if (sch != null && ! Baritone . settings (). buildSkipBlocks . value . contains ( sch . getBlock ()) ) {
1114
+ if (sch != null ) {
1117
1115
// TODO this can return true even when allowPlace is off.... is that an issue?
1118
1116
if (sch .getBlock () instanceof AirBlock ) {
1119
1117
// we want this to be air, but they're asking if they can place here
1120
1118
// 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
1122
1120
}
1123
1121
if (placeable .contains (sch )) {
1124
1122
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) {
1131
1129
}
1132
1130
// we want it to be something that we don't have
1133
1131
// even more of a pain to place something wrong
1134
- return placeBlockCost * 3 ;
1132
+ return placeBlockCost * 1.5 * Baritone . settings (). placeIncorrectBlockPenaltyMultiplier . value ;
1135
1133
} else {
1136
1134
if (hasThrowaway ) {
1137
1135
return placeBlockCost ;
@@ -1147,7 +1145,7 @@ public double breakCostMultiplierAt(int x, int y, int z, BlockState current) {
1147
1145
return COST_INF ;
1148
1146
}
1149
1147
BlockState sch = getSchematic (x , y , z , current );
1150
- if (sch != null && ! Baritone . settings (). buildSkipBlocks . value . contains ( sch . getBlock ()) ) {
1148
+ if (sch != null ) {
1151
1149
if (sch .getBlock () instanceof AirBlock ) {
1152
1150
// it should be air
1153
1151
// regardless of current contents, we can break it
0 commit comments