Skip to content

Commit 2869503

Browse files
committed
Merge branch '1.19.4' into 1.20.5
2 parents 800545f + 93dee4f commit 2869503

26 files changed

Lines changed: 626 additions & 372 deletions

build.gradle

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,9 @@ allprojects {
7878
}
7979

8080
dependencies {
81-
compileOnly "org.spongepowered:mixin:0.8"
82-
compileOnly "org.ow2.asm:asm:9.7"
83-
// The following line declares the yarn mappings you may select this one as well.
84-
// mappings "net.fabricmc:yarn:1.17.1+build.32:v2"
85-
//launchImplementation('dev.babbaj:nether-pathfinder:1.3.0')
81+
compileOnly "org.spongepowered:mixin:${project.mixin_version}"
82+
compileOnly "org.ow2.asm:asm:${project.asm_version}"
83+
8684
implementation "dev.babbaj:nether-pathfinder:${project.nether_pathfinder_version}"
8785

8886
implementation 'com.google.code.findbugs:jsr305:3.0.2'

gradle.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ neoforge_version=43-beta
1717
fabric_version=0.15.11
1818

1919
nether_pathfinder_version=1.4.1
20+
21+
// These dependencies are used for common and tweaker
22+
// while mod loaders usually ship their own version
23+
mixin_version=0.8.5
24+
asm_version=9.7

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
import net.minecraft.world.item.Item;
3030
import net.minecraft.world.level.block.Block;
3131
import net.minecraft.world.level.block.Blocks;
32+
import net.minecraft.world.level.block.Mirror;
33+
import net.minecraft.world.level.block.Rotation;
34+
3235
import org.slf4j.Logger;
3336
import org.slf4j.LoggerFactory;
3437

@@ -1089,6 +1092,28 @@ public final class Settings {
10891092
*/
10901093
public final Setting<Boolean> schematicOrientationZ = new Setting<>(false);
10911094

1095+
/**
1096+
* Rotates the schematic before building it.
1097+
* Possible values are
1098+
* <ul>
1099+
* <li> NONE - No rotation </li>
1100+
* <li> CLOCKWISE_90 - Rotate 90° clockwise </li>
1101+
* <li> CLOCKWISE_180 - Rotate 180° clockwise </li>
1102+
* <li> COUNTERCLOCKWISE_90 - Rotate 270° clockwise </li>
1103+
* </ul>
1104+
*/
1105+
public final Setting<Rotation> buildSchematicRotation = new Setting<>(Rotation.NONE);
1106+
1107+
/**
1108+
* Mirrors the schematic before building it.
1109+
* Possible values are
1110+
* <ul>
1111+
* <li> FRONT_BACK - mirror the schematic along its local x axis </li>
1112+
* <li> LEFT_RIGHT - mirror the schematic along its local z axis </li>
1113+
* </ul>
1114+
*/
1115+
public final Setting<Mirror> buildSchematicMirror = new Setting<>(Mirror.NONE);
1116+
10921117
/**
10931118
* The fallback used by the build command when no extension is specified. This may be useful if schematics of a
10941119
* particular format are used often, and the user does not wish to have to specify the extension with every usage.
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* This file is part of Baritone.
3+
*
4+
* Baritone is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Baritone is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package baritone.api.schematic;
19+
20+
import net.minecraft.world.level.block.state.BlockState;
21+
import net.minecraft.world.level.block.Mirror;
22+
23+
import java.util.List;
24+
import java.util.stream.Collectors;
25+
26+
public class MirroredSchematic implements ISchematic {
27+
28+
private final ISchematic schematic;
29+
private final Mirror mirror;
30+
31+
public MirroredSchematic(ISchematic schematic, Mirror mirror) {
32+
this.schematic = schematic;
33+
this.mirror = mirror;
34+
}
35+
36+
@Override
37+
public boolean inSchematic(int x, int y, int z, BlockState currentState) {
38+
return schematic.inSchematic(
39+
mirrorX(x, widthX(), mirror),
40+
y,
41+
mirrorZ(z, lengthZ(), mirror),
42+
mirror(currentState, mirror)
43+
);
44+
}
45+
46+
@Override
47+
public BlockState desiredState(int x, int y, int z, BlockState current, List<BlockState> approxPlaceable) {
48+
return mirror(schematic.desiredState(
49+
mirrorX(x, widthX(), mirror),
50+
y,
51+
mirrorZ(z, lengthZ(), mirror),
52+
mirror(current, mirror),
53+
mirror(approxPlaceable, mirror)
54+
), mirror);
55+
}
56+
57+
@Override
58+
public void reset() {
59+
schematic.reset();
60+
}
61+
62+
@Override
63+
public int widthX() {
64+
return schematic.widthX();
65+
}
66+
67+
@Override
68+
public int heightY() {
69+
return schematic.heightY();
70+
}
71+
72+
@Override
73+
public int lengthZ() {
74+
return schematic.lengthZ();
75+
}
76+
77+
private static int mirrorX(int x, int sizeX, Mirror mirror) {
78+
switch (mirror) {
79+
case NONE:
80+
case LEFT_RIGHT:
81+
return x;
82+
case FRONT_BACK:
83+
return sizeX - x - 1;
84+
}
85+
throw new IllegalArgumentException("Unknown mirror");
86+
}
87+
88+
private static int mirrorZ(int z, int sizeZ, Mirror mirror) {
89+
switch (mirror) {
90+
case NONE:
91+
case FRONT_BACK:
92+
return z;
93+
case LEFT_RIGHT:
94+
return sizeZ - z - 1;
95+
}
96+
throw new IllegalArgumentException("Unknown mirror");
97+
}
98+
99+
private static BlockState mirror(BlockState state, Mirror mirror) {
100+
if (state == null) {
101+
return null;
102+
}
103+
return state.mirror(mirror);
104+
}
105+
106+
private static List<BlockState> mirror(List<BlockState> states, Mirror mirror) {
107+
if (states == null) {
108+
return null;
109+
}
110+
return states.stream()
111+
.map(s -> mirror(s, mirror))
112+
.collect(Collectors.toList());
113+
}
114+
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* This file is part of Baritone.
3+
*
4+
* Baritone is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Baritone is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package baritone.api.schematic;
19+
20+
import net.minecraft.world.level.block.state.BlockState;
21+
import net.minecraft.world.level.block.Rotation;
22+
23+
import java.util.List;
24+
import java.util.stream.Collectors;
25+
26+
public class RotatedSchematic implements ISchematic {
27+
28+
private final ISchematic schematic;
29+
private final Rotation rotation;
30+
private final Rotation inverseRotation;
31+
32+
public RotatedSchematic(ISchematic schematic, Rotation rotation) {
33+
this.schematic = schematic;
34+
this.rotation = rotation;
35+
// I don't think a 14 line switch would improve readability
36+
this.inverseRotation = rotation.getRotated(rotation).getRotated(rotation);
37+
}
38+
39+
@Override
40+
public boolean inSchematic(int x, int y, int z, BlockState currentState) {
41+
return schematic.inSchematic(
42+
rotateX(x, z, widthX(), lengthZ(), inverseRotation),
43+
y,
44+
rotateZ(x, z, widthX(), lengthZ(), inverseRotation),
45+
rotate(currentState, inverseRotation)
46+
);
47+
}
48+
49+
@Override
50+
public BlockState desiredState(int x, int y, int z, BlockState current, List<BlockState> approxPlaceable) {
51+
return rotate(schematic.desiredState(
52+
rotateX(x, z, widthX(), lengthZ(), inverseRotation),
53+
y,
54+
rotateZ(x, z, widthX(), lengthZ(), inverseRotation),
55+
rotate(current, inverseRotation),
56+
rotate(approxPlaceable, inverseRotation)
57+
), rotation);
58+
}
59+
60+
@Override
61+
public void reset() {
62+
schematic.reset();
63+
}
64+
65+
@Override
66+
public int widthX() {
67+
return flipsCoordinates(rotation) ? schematic.lengthZ() : schematic.widthX();
68+
}
69+
70+
@Override
71+
public int heightY() {
72+
return schematic.heightY();
73+
}
74+
75+
@Override
76+
public int lengthZ() {
77+
return flipsCoordinates(rotation) ? schematic.widthX() : schematic.lengthZ();
78+
}
79+
80+
/**
81+
* Wether {@code rotation} swaps the x and z components
82+
*/
83+
private static boolean flipsCoordinates(Rotation rotation) {
84+
return rotation == Rotation.CLOCKWISE_90 || rotation == Rotation.COUNTERCLOCKWISE_90;
85+
}
86+
87+
/**
88+
* The x component of x,y after applying the rotation
89+
*/
90+
private static int rotateX(int x, int z, int sizeX, int sizeZ, Rotation rotation) {
91+
switch (rotation) {
92+
case NONE:
93+
return x;
94+
case CLOCKWISE_90:
95+
return sizeZ - z - 1;
96+
case CLOCKWISE_180:
97+
return sizeX - x - 1;
98+
case COUNTERCLOCKWISE_90:
99+
return z;
100+
}
101+
throw new IllegalArgumentException("Unknown rotation");
102+
}
103+
104+
/**
105+
* The z component of x,y after applying the rotation
106+
*/
107+
private static int rotateZ(int x, int z, int sizeX, int sizeZ, Rotation rotation) {
108+
switch (rotation) {
109+
case NONE:
110+
return z;
111+
case CLOCKWISE_90:
112+
return x;
113+
case CLOCKWISE_180:
114+
return sizeZ - z - 1;
115+
case COUNTERCLOCKWISE_90:
116+
return sizeX - x - 1;
117+
}
118+
throw new IllegalArgumentException("Unknown rotation");
119+
}
120+
121+
private static BlockState rotate(BlockState state, Rotation rotation) {
122+
if (state == null) {
123+
return null;
124+
}
125+
return state.rotate(rotation);
126+
}
127+
128+
private static List<BlockState> rotate(List<BlockState> states, Rotation rotation) {
129+
if (states == null) {
130+
return null;
131+
}
132+
return states.stream()
133+
.map(s -> rotate(s, rotation))
134+
.collect(Collectors.toList());
135+
}
136+
}

src/api/java/baritone/api/utils/SettingsUtil.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import net.minecraft.resources.ResourceLocation;
2828
import net.minecraft.world.item.Item;
2929
import net.minecraft.world.level.block.Block;
30+
import net.minecraft.world.level.block.Mirror;
31+
import net.minecraft.world.level.block.Rotation;
32+
3033
import java.awt.*;
3134
import java.io.BufferedReader;
3235
import java.io.BufferedWriter;
@@ -220,7 +223,8 @@ private enum Parser implements ISettingParser {
220223
FLOAT(Float.class, Float::parseFloat),
221224
LONG(Long.class, Long::parseLong),
222225
STRING(String.class, String::new),
223-
DIRECTION(Direction.class, Direction::byName),
226+
MIRROR(Mirror.class, Mirror::valueOf, Mirror::name),
227+
ROTATION(Rotation.class, Rotation::valueOf, Rotation::name),
224228
COLOR(
225229
Color.class,
226230
str -> new Color(Integer.parseInt(str.split(",")[0]), Integer.parseInt(str.split(",")[1]), Integer.parseInt(str.split(",")[2])),

src/main/java/baritone/behavior/PathingBehavior.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public boolean secretInternalSetGoalAndPath(PathingCommand command) {
265265
if (goal == null) {
266266
return false;
267267
}
268-
if (goal.isInGoal(ctx.playerFeet()) || goal.isInGoal(expectedSegmentStart)) {
268+
if (goal.isInGoal(ctx.playerFeet())) {
269269
return false;
270270
}
271271
synchronized (pathPlanLock) {
@@ -553,7 +553,7 @@ private void findPathInNewThread(final BlockPos start, final boolean talkAboutIt
553553
});
554554
}
555555

556-
private static AbstractNodeCostSearch createPathfinder(BlockPos start, Goal goal, IPath previous, CalculationContext context) {
556+
private AbstractNodeCostSearch createPathfinder(BlockPos start, Goal goal, IPath previous, CalculationContext context) {
557557
Goal transformed = goal;
558558
if (Baritone.settings().simplifyUnloadedYCoord.value && goal instanceof IGoalRenderPos) {
559559
BlockPos pos = ((IGoalRenderPos) goal).getGoalPos();
@@ -562,7 +562,14 @@ private static AbstractNodeCostSearch createPathfinder(BlockPos start, Goal goal
562562
}
563563
}
564564
Favoring favoring = new Favoring(context.getBaritone().getPlayerContext(), previous, context);
565-
return new AStarPathFinder(start.getX(), start.getY(), start.getZ(), transformed, favoring, context);
565+
BetterBlockPos feet = ctx.playerFeet();
566+
var realStart = new BetterBlockPos(start);
567+
var sub = feet.subtract(realStart);
568+
if (feet.getY() == realStart.getY() && Math.abs(sub.getX()) <= 1 && Math.abs(sub.getZ()) <= 1) {
569+
realStart = feet;
570+
}
571+
return new AStarPathFinder(realStart, start.getX(), start.getY(), start.getZ(), transformed, favoring, context);
572+
566573
}
567574

568575
@Override

src/main/java/baritone/command/defaults/LitematicaCommand.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,9 @@ public LitematicaCommand(IBaritone baritone) {
3434

3535
@Override
3636
public void execute(String label, IArgConsumer args) throws CommandException {
37-
int schematic = 0;
38-
if (args.hasAny()) {
39-
args.requireMax(1);
40-
if (args.is(Integer.class)) {
41-
schematic = args.getAs(Integer.class) - 1;
42-
}
43-
}
44-
try {
45-
baritone.getBuilderProcess().buildOpenLitematic(schematic);
46-
} catch (IndexOutOfBoundsException e) {
47-
logDirect("Pleas provide a valid index.");
48-
}
37+
args.requireMax(1);
38+
int schematic = args.hasAny() ? args.getAs(Integer.class) - 1 : 0;
39+
baritone.getBuilderProcess().buildOpenLitematic(schematic);
4940
}
5041

5142
@Override

0 commit comments

Comments
 (0)