Add `experimentalRaytrace` setting for native raytrace

Update `nether-pathfinder` to 0.15
This commit is contained in:
Brady 2023-06-19 00:34:22 -05:00
parent 1da7ab2c22
commit 67efb7a5b6
No known key found for this signature in database
GPG Key ID: 73A788379A197567
4 changed files with 74 additions and 13 deletions

View File

@ -175,9 +175,9 @@ dependencies {
transitive = false
}
launchAnnotationProcessor 'org.spongepowered:mixin:0.8.4-SNAPSHOT:processor'
launchImplementation('dev.babbaj:nether-pathfinder:0.12')
launchImplementation('dev.babbaj:nether-pathfinder:0.15')
testImplementation 'junit:junit:4.12'
implementation 'dev.babbaj:nether-pathfinder:0.12'
implementation 'dev.babbaj:nether-pathfinder:0.15'
}
mixin {

View File

@ -62,7 +62,10 @@ public final class Settings {
public final Setting<Boolean> conserveFireworks = new Setting<>(true);
public final Setting<Boolean> renderRaytraces = new Setting<>(false);
public final Setting<Boolean> elytraFreeLook = new Setting<>(false);
// Experimental Elytra Settings
public final Setting<Boolean> experimentalTakeoff = new Setting<>(false);
public final Setting<Boolean> experimentalRaytrace = new Setting<>(false);
/**
* Allow Baritone to break blocks

View File

@ -40,7 +40,6 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import java.util.*;
@ -169,9 +168,9 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
private Vec3d pathAt(int i) {
return new Vec3d(
this.path.get(i).x + 0.000123,
this.path.get(i).y + 0.000456,
this.path.get(i).z + 0.000789
this.path.get(i).x,
this.path.get(i).y,
this.path.get(i).z
);
}
@ -502,6 +501,44 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
}
final AxisAlignedBB bb = ctx.player().getEntityBoundingBox().grow(growAmount);
if (Baritone.settings().experimentalRaytrace.value) {
final double ox = dest.x - start.x;
final double oy = dest.y - start.y;
final double oz = dest.z - start.z;
final double[] src = new double[] {
bb.minX, bb.minY, bb.minZ,
bb.minX, bb.minY, bb.maxZ,
bb.minX, bb.maxY, bb.minZ,
bb.minX, bb.maxY, bb.maxZ,
bb.maxX, bb.minY, bb.minZ,
bb.maxX, bb.minY, bb.maxZ,
bb.maxX, bb.maxY, bb.minZ,
bb.maxX, bb.maxY, bb.maxZ,
};
final double[] dst = new double[] {
bb.minX + ox, bb.minY + oy, bb.minZ + oz,
bb.minX + ox, bb.minY + oy, bb.maxZ + oz,
bb.minX + ox, bb.maxY + oy, bb.minZ + oz,
bb.minX + ox, bb.maxY + oy, bb.maxZ + oz,
bb.maxX + ox, bb.minY + oy, bb.minZ + oz,
bb.maxX + ox, bb.minY + oy, bb.maxZ + oz,
bb.maxX + ox, bb.maxY + oy, bb.minZ + oz,
bb.maxX + ox, bb.maxY + oy, bb.maxZ + oz,
};
// 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;
}
final Vec3d[] corners = new Vec3d[]{
new Vec3d(bb.minX, bb.minY, bb.minZ),
new Vec3d(bb.minX, bb.minY, bb.maxZ),
@ -522,12 +559,12 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
}
private boolean clearView(Vec3d start, Vec3d dest) {
boolean oxy = !rayTraceBlocks(start.x, start.y, start.z, dest.x, dest.y, dest.z);
boolean meow = !rayTraceBlocks(start, dest);
if (oxy != meow) {
logDirect(start + " " + dest + " " + oxy + " " + meow);
}
if (oxy) {
boolean clear = !(Baritone.settings().experimentalRaytrace.value
? this.context.raytrace(start.x, start.y, start.z, dest.x, dest.y, dest.z)
: this.rayTraceBlocks(start.x, start.y, start.z, dest.x, dest.y, dest.z) // ox method
);
if (clear) {
clearLines.add(new Pair<>(start, dest));
return true;
} else {

View File

@ -21,6 +21,7 @@ import dev.babbaj.pathfinder.NetherPathfinder;
import dev.babbaj.pathfinder.PathSegment;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.chunk.BlockStateContainer;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
@ -57,10 +58,30 @@ public final class NetherPathfinderContext {
this.context,
src.getX(), src.getY(), src.getZ(),
dst.getX(), dst.getY(), dst.getZ(),
true
true,
10000
), this.executor);
}
public boolean raytrace(final double startX, final double startY, final double startZ,
final double endX, final double endY, final double endZ) {
final boolean[] hitOut = new boolean[1];
NetherPathfinder.raytrace(
this.context,
true,
1,
new double[] { startX, startY, startZ },
new double[] { endX, endY, endZ },
hitOut,
null
);
return hitOut[0];
}
public void raytrace(final double[] src, final double[] dst, final boolean[] hitOut) {
NetherPathfinder.raytrace(this.context, true, hitOut.length, src, dst, hitOut, null);
}
public void cancel() {
NetherPathfinder.cancel(this.context);
}