Skip to content

Commit 1018db7

Browse files
authored
Merge pull request #4315 from ZacSharp/1.20.4-update
Merge 1.19.4 into 1.20.4
2 parents 6d06713 + 354b26b commit 1018db7

File tree

7 files changed

+69
-46
lines changed

7 files changed

+69
-46
lines changed

.github/workflows/gradle_build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ jobs:
1313
runs-on: ubuntu-latest
1414

1515
steps:
16-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v4
1717
with:
1818
fetch-depth: 0
1919

2020
- name: Set up JDK 17
21-
uses: actions/setup-java@v3
21+
uses: actions/setup-java@v4
2222
with:
2323
java-version: '17'
2424
distribution: 'temurin'
@@ -31,13 +31,13 @@ jobs:
3131
run: ./gradlew build -Pmod_version="$(git describe --always --tags --first-parent | cut -c2-)"
3232

3333
- name: Archive Artifacts
34-
uses: actions/upload-artifact@v3
34+
uses: actions/upload-artifact@v4
3535
with:
3636
name: Artifacts
3737
path: dist/
3838

3939
- name: Archive mapping.txt
40-
uses: actions/upload-artifact@v3
40+
uses: actions/upload-artifact@v4
4141
with:
4242
name: Mappings
4343
path: mapping/

.github/workflows/run_tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1515
- name: Set up JDK 17
16-
uses: actions/setup-java@v3
16+
uses: actions/setup-java@v4
1717
with:
1818
java-version: '17'
1919
distribution: 'temurin'

src/api/java/baritone/api/Settings.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,12 @@ public final class Settings {
385385
*/
386386
public final Setting<Float> blockReachDistance = new Setting<>(4.5f);
387387

388+
/**
389+
* How many ticks between breaking a block and starting to break the next block. Default in game is 6 ticks.
390+
* Values under 2 will be clamped.
391+
*/
392+
public final Setting<Integer> blockBreakSpeed = new Setting<>(6);
393+
388394
/**
389395
* How many degrees to randomize the pitch and yaw every tick. Set to 0 to disable
390396
*/
@@ -1058,6 +1064,11 @@ public final class Settings {
10581064
*/
10591065
public final Setting<Double> breakCorrectBlockPenaltyMultiplier = new Setting<>(10d);
10601066

1067+
/**
1068+
* Multiply the cost of placing a block that's incorrect in the builder's schematic by this coefficient
1069+
*/
1070+
public final Setting<Double> placeIncorrectBlockPenaltyMultiplier = new Setting<>(2d);
1071+
10611072
/**
10621073
* When this setting is true, build a schematic with the highest X coordinate being the origin, instead of the lowest
10631074
*/

src/main/java/baritone/process/BuilderProcess.java

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import baritone.api.schematic.FillSchematic;
2929
import baritone.api.schematic.ISchematic;
3030
import baritone.api.schematic.IStaticSchematic;
31+
import baritone.api.schematic.MaskSchematic;
3132
import baritone.api.schematic.SubstituteSchematic;
3233
import baritone.api.schematic.format.ISchematicFormat;
3334
import baritone.api.utils.*;
@@ -85,6 +86,14 @@
8586

8687
public 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

src/main/java/baritone/utils/BlockBreakHelper.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package baritone.utils;
1919

20+
import baritone.api.BaritoneAPI;
2021
import baritone.api.utils.IPlayerContext;
2122
import net.minecraft.world.InteractionHand;
2223
import net.minecraft.world.phys.BlockHitResult;
@@ -27,9 +28,12 @@
2728
* @since 8/25/2018
2829
*/
2930
public final class BlockBreakHelper {
31+
// base ticks between block breaks caused by tick logic
32+
private static final int BASE_BREAK_DELAY = 2;
3033

3134
private final IPlayerContext ctx;
3235
private boolean didBreakLastTick;
36+
private int breakDelayTimer = 0;
3337

3438
BlockBreakHelper(IPlayerContext ctx) {
3539
this.ctx = ctx;
@@ -48,6 +52,10 @@ public void stopBreakingBlock() {
4852
}
4953

5054
public void tick(boolean isLeftClick) {
55+
if (breakDelayTimer > 0) {
56+
breakDelayTimer--;
57+
return;
58+
}
5159
HitResult trace = ctx.objectMouseOver();
5260
boolean isBlockTrace = trace != null && trace.getType() == HitResult.Type.BLOCK;
5361

@@ -68,6 +76,7 @@ public void tick(boolean isLeftClick) {
6876
didBreakLastTick = true;
6977
} else if (didBreakLastTick) {
7078
stopBreakingBlock();
79+
breakDelayTimer = BaritoneAPI.getSettings().blockBreakSpeed.value - BASE_BREAK_DELAY;
7180
didBreakLastTick = false;
7281
}
7382
}

src/main/java/baritone/utils/BlockPlaceHelper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import net.minecraft.world.phys.HitResult;
2626

2727
public class BlockPlaceHelper {
28+
// base ticks between places caused by tick logic
29+
private static final int BASE_PLACE_DELAY = 1;
2830

2931
private final IPlayerContext ctx;
3032
private int rightClickTimer;
@@ -42,7 +44,7 @@ public void tick(boolean rightClickRequested) {
4244
if (!rightClickRequested || ctx.player().isHandsBusy() || mouseOver == null || mouseOver.getType() != HitResult.Type.BLOCK) {
4345
return;
4446
}
45-
rightClickTimer = Baritone.settings().rightClickSpeed.value;
47+
rightClickTimer = Baritone.settings().rightClickSpeed.value - BASE_PLACE_DELAY;
4648
for (InteractionHand hand : InteractionHand.values()) {
4749
if (ctx.playerController().processRightClickBlock(ctx.player(), ctx.world(), hand, (BlockHitResult) mouseOver) == InteractionResult.SUCCESS) {
4850
ctx.player().swing(hand);

src/main/java/baritone/utils/schematic/MapArtSchematic.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,22 @@ protected boolean partOfMask(int x, int y, int z, BlockState currentState) {
4141
private static int[][] generateHeightMap(IStaticSchematic schematic) {
4242
int[][] heightMap = new int[schematic.widthX()][schematic.lengthZ()];
4343

44+
int missingColumns = 0;
4445
for (int x = 0; x < schematic.widthX(); x++) {
4546
for (int z = 0; z < schematic.lengthZ(); z++) {
4647
BlockState[] column = schematic.getColumn(x, z);
4748
OptionalInt lowestBlockY = lastIndexMatching(column, state -> !(state.getBlock() instanceof AirBlock));
4849
if (lowestBlockY.isPresent()) {
4950
heightMap[x][z] = lowestBlockY.getAsInt();
5051
} else {
51-
System.out.println("Column " + x + "," + z + " has no blocks, but it's apparently map art? wtf");
52-
System.out.println("Letting it be whatever");
53-
heightMap[x][z] = 256;
52+
missingColumns++;
53+
heightMap[x][z] = Integer.MAX_VALUE;
5454
}
5555
}
5656
}
57+
if (missingColumns != 0) {
58+
System.out.println(missingColumns + " columns had no block despite being in a map art, letting them be whatever");
59+
}
5760
return heightMap;
5861
}
5962

0 commit comments

Comments
 (0)