mirror of https://github.com/cabaletta/baritone
Interpolate path positions
- Update `nether-pathfinder` to 0.17 - Utilize new batched visibility raytracing to efficiently trace bounding box paths
This commit is contained in:
parent
cd1c07deef
commit
753b1cf1c3
|
@ -175,9 +175,9 @@ dependencies {
|
||||||
transitive = false
|
transitive = false
|
||||||
}
|
}
|
||||||
launchAnnotationProcessor 'org.spongepowered:mixin:0.8.4-SNAPSHOT:processor'
|
launchAnnotationProcessor 'org.spongepowered:mixin:0.8.4-SNAPSHOT:processor'
|
||||||
launchImplementation('dev.babbaj:nether-pathfinder:0.16')
|
launchImplementation('dev.babbaj:nether-pathfinder:0.17')
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
implementation 'dev.babbaj:nether-pathfinder:0.16'
|
implementation 'dev.babbaj:nether-pathfinder:0.17'
|
||||||
}
|
}
|
||||||
|
|
||||||
mixin {
|
mixin {
|
||||||
|
|
|
@ -379,19 +379,30 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
|
||||||
outermost:
|
outermost:
|
||||||
for (int relaxation = 0; relaxation < 3; relaxation++) { // try for a strict solution first, then relax more and more (if we're in a corner or near some blocks, it will have to relax its constraints a bit)
|
for (int relaxation = 0; relaxation < 3; relaxation++) { // try for a strict solution first, then relax more and more (if we're in a corner or near some blocks, it will have to relax its constraints a bit)
|
||||||
int[] heights = firework ? new int[]{20, 10, 5, 0} : new int[]{0}; // attempt to gain height, if we can, so as not to waste the boost
|
int[] heights = firework ? new int[]{20, 10, 5, 0} : new int[]{0}; // attempt to gain height, if we can, so as not to waste the boost
|
||||||
|
float[] interps = new float[] {1.0f, 0.75f, 0.5f, 0.25f};
|
||||||
int steps = relaxation < 2 ? firework ? 5 : Baritone.settings().elytraSimulationTicks.value : 3;
|
int steps = relaxation < 2 ? firework ? 5 : Baritone.settings().elytraSimulationTicks.value : 3;
|
||||||
int lookahead = relaxation == 0 ? 2 : 3; // ideally this would be expressed as a distance in blocks, rather than a number of voxel steps
|
int lookahead = relaxation == 0 ? 2 : 3; // ideally this would be expressed as a distance in blocks, rather than a number of voxel steps
|
||||||
//int minStep = Math.max(0, playerNear - relaxation);
|
//int minStep = Math.max(0, playerNear - relaxation);
|
||||||
int minStep = playerNear;
|
int minStep = playerNear;
|
||||||
for (int i = Math.min(playerNear + 20, path.size() - 1); i >= minStep; i--) {
|
for (int i = Math.min(playerNear + 20, path.size() - 1); i >= minStep; i--) {
|
||||||
for (int dy : heights) {
|
for (int dy : heights) {
|
||||||
Vec3d dest = this.pathManager.pathAt(i).add(0, dy, 0);
|
for (float interp : interps) {
|
||||||
|
Vec3d dest;
|
||||||
|
if (interp == 1 || i == minStep) {
|
||||||
|
dest = this.pathManager.pathAt(i);
|
||||||
|
} else {
|
||||||
|
dest = this.pathManager.pathAt(i).scale(interp)
|
||||||
|
.add(this.pathManager.pathAt(i - 1).scale(1.0d - interp));
|
||||||
|
}
|
||||||
|
|
||||||
|
dest = dest.add(0, dy, 0);
|
||||||
if (dy != 0) {
|
if (dy != 0) {
|
||||||
if (i + lookahead >= path.size()) {
|
if (i + lookahead >= path.size()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (start.distanceTo(dest) < 40) {
|
if (start.distanceTo(dest) < 40) {
|
||||||
if (!clearView(dest, this.pathManager.pathAt(i + lookahead).add(0, dy, 0), false) || !clearView(dest, this.pathManager.pathAt(i + lookahead), false)) {
|
if (!clearView(dest, this.pathManager.pathAt(i + lookahead).add(0, dy, 0), false)
|
||||||
|
|| !clearView(dest, this.pathManager.pathAt(i + lookahead), false)) {
|
||||||
// aka: don't go upwards if doing so would prevent us from being able to see the next position **OR** the modified next position
|
// aka: don't go upwards if doing so would prevent us from being able to see the next position **OR** the modified next position
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -416,13 +427,14 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
forceUseFirework = pitch.second();
|
forceUseFirework = pitch.second();
|
||||||
goingTo = path.get(i);
|
goingTo = new BetterBlockPos(dest.x, dest.y, dest.z);
|
||||||
this.aimPos = path.get(i).add(0, dy, 0);
|
this.aimPos = goingTo;
|
||||||
baritone.getLookBehavior().updateTarget(new Rotation(yaw, pitch.first()), false);
|
baritone.getLookBehavior().updateTarget(new Rotation(yaw, pitch.first()), false);
|
||||||
break outermost;
|
break outermost;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (relaxation == 2) {
|
if (relaxation == 2) {
|
||||||
logDirect("no pitch solution, probably gonna crash in a few ticks LOL!!!");
|
logDirect("no pitch solution, probably gonna crash in a few ticks LOL!!!");
|
||||||
return;
|
return;
|
||||||
|
@ -520,22 +532,14 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
|
||||||
bb.maxX + ox, bb.maxY + oy, bb.minZ + oz,
|
bb.maxX + ox, bb.maxY + oy, bb.minZ + oz,
|
||||||
bb.maxX + ox, bb.maxY + oy, bb.maxZ + oz,
|
bb.maxX + ox, bb.maxY + oy, bb.maxZ + oz,
|
||||||
};
|
};
|
||||||
|
return this.context.raytrace(8, src, dst, NetherPathfinderContext.Visibility.ALL);
|
||||||
// Batch together all 8 traces
|
|
||||||
final boolean[] hitOut = new boolean[8];
|
|
||||||
this.context.raytrace(src, dst, hitOut);
|
|
||||||
for (boolean hit : hitOut) {
|
|
||||||
if (hit) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean clearView(Vec3d start, Vec3d dest, boolean ignoreLava) {
|
private boolean clearView(Vec3d start, Vec3d dest, boolean ignoreLava) {
|
||||||
final boolean clear;
|
final boolean clear;
|
||||||
if (!ignoreLava) {
|
if (!ignoreLava) {
|
||||||
clear = !this.context.raytrace(start.x, start.y, start.z, dest.x, dest.y, dest.z);
|
// if start == dest then the cpp raytracer dies
|
||||||
|
clear = start.equals(dest) || !this.context.raytrace(start.x, start.y, start.z, dest.x, dest.y, dest.z);
|
||||||
} else {
|
} else {
|
||||||
clear = ctx.world().rayTraceBlocks(start, dest, false, false, false) == null;
|
clear = ctx.world().rayTraceBlocks(start, dest, false, false, false) == null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ import dev.babbaj.pathfinder.NetherPathfinder;
|
||||||
import dev.babbaj.pathfinder.PathSegment;
|
import dev.babbaj.pathfinder.PathSegment;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
import net.minecraft.world.chunk.BlockStateContainer;
|
import net.minecraft.world.chunk.BlockStateContainer;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||||
|
@ -82,6 +81,18 @@ public final class NetherPathfinderContext {
|
||||||
NetherPathfinder.raytrace(this.context, true, hitOut.length, src, dst, hitOut, null);
|
NetherPathfinder.raytrace(this.context, true, hitOut.length, src, dst, hitOut, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean raytrace(final int count, final double[] src, final double[] dst, int visibility) {
|
||||||
|
switch (visibility) {
|
||||||
|
case Visibility.ALL:
|
||||||
|
return NetherPathfinder.isVisibleMulti(this.context, true, count, src, dst, false);
|
||||||
|
case Visibility.NONE:
|
||||||
|
return !NetherPathfinder.isVisibleMulti(this.context, true, count, src, dst, true);
|
||||||
|
case Visibility.ANY:
|
||||||
|
return NetherPathfinder.isVisibleMulti(this.context, true, count, src, dst, true);
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("lol");
|
||||||
|
}
|
||||||
|
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
NetherPathfinder.cancel(this.context);
|
NetherPathfinder.cancel(this.context);
|
||||||
}
|
}
|
||||||
|
@ -133,4 +144,13 @@ public final class NetherPathfinderContext {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final class Visibility {
|
||||||
|
|
||||||
|
private Visibility() {}
|
||||||
|
|
||||||
|
public static final int ALL = 0;
|
||||||
|
public static final int NONE = 1;
|
||||||
|
public static final int ANY = 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue