This commit is contained in:
Leijurv
2023-06-18 18:06:32 -07:00
parent 1dbfc9abe3
commit 812be14375
2 changed files with 134 additions and 9 deletions

View File

@@ -28,8 +28,12 @@ import baritone.utils.BlockStateInterface;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityFireworkRocket;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.*;
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.chunk.Chunk;
import java.util.*;
@@ -44,7 +48,8 @@ public final class ElytraBehavior extends Behavior implements Helper {
private static final long NETHER_SEED = 146008555100680L;
// Used exclusively for PathRenderer
public List<Pair<Vec3d, Vec3d>> lines;
public List<Pair<Vec3d, Vec3d>> clearLines;
public List<Pair<Vec3d, Vec3d>> blockedLines;
public BlockPos aimPos;
public List<BetterBlockPos> visiblePath;
@@ -56,7 +61,8 @@ public final class ElytraBehavior extends Behavior implements Helper {
public ElytraBehavior(Baritone baritone) {
super(baritone);
this.context = new NetherPathfinderContext(NETHER_SEED);
this.lines = new ArrayList<>();
this.clearLines = new ArrayList<>();
this.blockedLines = new ArrayList<>();
this.visiblePath = Collections.emptyList();
this.pathManager = new PathManager();
}
@@ -300,7 +306,8 @@ public final class ElytraBehavior extends Behavior implements Helper {
if (event.getType() == TickEvent.Type.OUT) {
return;
}
this.lines.clear();
this.clearLines.clear();
this.blockedLines.clear();
final List<BetterBlockPos> path = this.pathManager.getPath();
if (path.isEmpty()) {
@@ -376,8 +383,12 @@ public final class ElytraBehavior extends Behavior implements Helper {
continue;
}
forceUseFirework = pitch.second();
logDirect("final dy " + dy);
logDirect("i " + i);
logDirect("playerNear " + playerNear);
logDirect("relaxation " + relaxation);
goingTo = pos;
this.aimPos = goingTo.add(0, dy, 0);
this.aimPos = path.get(i).add(0, dy, 0);
baritone.getLookBehavior().updateTarget(new Rotation(yaw, pitch.first()), false);
break outermost;
}
@@ -444,8 +455,18 @@ public final class ElytraBehavior extends Behavior implements Helper {
}
private boolean clearView(Vec3d start, Vec3d dest) {
lines.add(new Pair<>(start, dest));
return !rayTraceBlocks(start.x, start.y, start.z, dest.x, dest.y, dest.z);
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) {
clearLines.add(new Pair<>(start, dest));
return true;
} else {
blockedLines.add(new Pair<>(start, dest));
return false;
}
}
private Pair<Float, Boolean> solvePitch(Vec3d goalDirection, int steps, int relaxation, boolean currentlyBoosted) {
@@ -663,4 +684,98 @@ public final class ElytraBehavior extends Behavior implements Helper {
private static int fastFloor(final double v) {
return ((int) (v + FLOOR_DOUBLE_D)) - FLOOR_DOUBLE_I;
}
private boolean rayTraceBlocks(Vec3d start, Vec3d end) {
int x1 = MathHelper.floor(end.x);
int y1 = MathHelper.floor(end.y);
int z1 = MathHelper.floor(end.z);
int x2 = MathHelper.floor(start.x);
int y2 = MathHelper.floor(start.y);
int z2 = MathHelper.floor(start.z);
BlockPos blockpos = new BlockPos(x2, y2, z2);
IBlockState iblockstate = ctx.world().getBlockState(blockpos);
if (!passable(iblockstate)) {
return true;
}
int steps = 200;
while (steps-- >= 0) {
if (Double.isNaN(start.x) || Double.isNaN(start.y) || Double.isNaN(start.z)) {
return false;
}
if (x2 == x1 && y2 == y1 && z2 == z1) {
return false;
}
boolean hitX = true;
boolean hitY = true;
boolean hitZ = true;
double nextX = 999.0D;
double nextY = 999.0D;
double nextZ = 999.0D;
if (x1 > x2) {
nextX = (double) x2 + 1.0D;
} else if (x1 < x2) {
nextX = (double) x2 + 0.0D;
} else {
hitX = false;
}
if (y1 > y2) {
nextY = (double) y2 + 1.0D;
} else if (y1 < y2) {
nextY = (double) y2 + 0.0D;
} else {
hitY = false;
}
if (z1 > z2) {
nextZ = (double) z2 + 1.0D;
} else if (z1 < z2) {
nextZ = (double) z2 + 0.0D;
} else {
hitZ = false;
}
double stepX = 999.0D;
double stepY = 999.0D;
double stepZ = 999.0D;
double dirX = end.x - start.x;
double dirY = end.y - start.y;
double dirZ = end.z - start.z;
if (hitX) {
stepX = (nextX - start.x) / dirX;
}
if (hitY) {
stepY = (nextY - start.y) / dirY;
}
if (hitZ) {
stepZ = (nextZ - start.z) / dirZ;
}
if (stepX == -0.0D) {
stepX = -1.0E-4D;
}
if (stepY == -0.0D) {
stepY = -1.0E-4D;
}
if (stepZ == -0.0D) {
stepZ = -1.0E-4D;
}
EnumFacing dir;
if (stepX < stepY && stepX < stepZ) {
dir = x1 > x2 ? EnumFacing.WEST : EnumFacing.EAST;
start = new Vec3d(nextX, start.y + dirY * stepX, start.z + dirZ * stepX);
} else if (stepY < stepZ) {
dir = y1 > y2 ? EnumFacing.DOWN : EnumFacing.UP;
start = new Vec3d(start.x + dirX * stepY, nextY, start.z + dirZ * stepY);
} else {
dir = z1 > z2 ? EnumFacing.NORTH : EnumFacing.SOUTH;
start = new Vec3d(start.x + dirX * stepZ, start.y + dirY * stepZ, nextZ);
}
x2 = MathHelper.floor(start.x) - (dir == EnumFacing.EAST ? 1 : 0);
y2 = MathHelper.floor(start.y) - (dir == EnumFacing.UP ? 1 : 0);
z2 = MathHelper.floor(start.z) - (dir == EnumFacing.SOUTH ? 1 : 0);
blockpos = new BlockPos(x2, y2, z2);
IBlockState iblockstate1 = ctx.world().getBlockState(blockpos);
if (!passable(iblockstate1)) {
return true;
}
}
return false;
}
}

View File

@@ -108,11 +108,21 @@ public final class PathRenderer implements IRenderer {
if (elytra.aimPos != null) {
drawGoal(ctx.player(), new GoalBlock(elytra.aimPos), partialTicks, Color.GREEN);
}
if (!elytra.lines.isEmpty() && Baritone.settings().renderRaytraces.value) {
if (!elytra.clearLines.isEmpty() && Baritone.settings().renderRaytraces.value) {
IRenderer.startLines(Color.GREEN, settings.pathRenderLineWidthPixels.value, settings.renderPathIgnoreDepth.value);
boolean orig = settings.renderPathAsLine.value;
settings.renderPathAsLine.value = true;
for (Pair<Vec3d, Vec3d> line : elytra.clearLines) {
emitLine(line.first().x, line.first().y, line.first().z, line.second().x, line.second().y, line.second().z);
}
settings.renderPathAsLine.value = orig;
IRenderer.endLines(settings.renderPathIgnoreDepth.value);
}
if (!elytra.blockedLines.isEmpty() && Baritone.settings().renderRaytraces.value) {
IRenderer.startLines(Color.BLUE, settings.pathRenderLineWidthPixels.value, settings.renderPathIgnoreDepth.value);
boolean orig = settings.renderPathAsLine.value;
settings.renderPathAsLine.value = true;
for (Pair<Vec3d, Vec3d> line : elytra.lines) {
for (Pair<Vec3d, Vec3d> line : elytra.blockedLines) {
emitLine(line.first().x, line.first().y, line.first().z, line.second().x, line.second().y, line.second().z);
}
settings.renderPathAsLine.value = orig;