mirror of https://github.com/cabaletta/baritone
fix invalid player move packet, and a bunch of things in world scanner
This commit is contained in:
parent
d5c317b88b
commit
563028a5b3
|
@ -36,6 +36,9 @@ public class Rotation {
|
||||||
public Rotation(float yaw, float pitch) {
|
public Rotation(float yaw, float pitch) {
|
||||||
this.yaw = yaw;
|
this.yaw = yaw;
|
||||||
this.pitch = pitch;
|
this.pitch = pitch;
|
||||||
|
if (Float.isInfinite(yaw) || Float.isNaN(yaw) || Float.isInfinite(pitch) || Float.isNaN(pitch)) {
|
||||||
|
throw new IllegalStateException(yaw + " " + pitch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -29,6 +29,7 @@ import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
import net.minecraft.util.math.shapes.VoxelShape;
|
||||||
|
import net.minecraft.util.math.shapes.VoxelShapes;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@ -180,6 +181,9 @@ public final class RotationUtils {
|
||||||
|
|
||||||
IBlockState state = entity.world.getBlockState(pos);
|
IBlockState state = entity.world.getBlockState(pos);
|
||||||
VoxelShape shape = state.getShape(entity.world, pos);
|
VoxelShape shape = state.getShape(entity.world, pos);
|
||||||
|
if (shape.isEmpty()) {
|
||||||
|
shape = VoxelShapes.fullCube();
|
||||||
|
}
|
||||||
for (Vec3d sideOffset : BLOCK_SIDE_MULTIPLIERS) {
|
for (Vec3d sideOffset : BLOCK_SIDE_MULTIPLIERS) {
|
||||||
double xDiff = shape.getStart(EnumFacing.Axis.X) * sideOffset.x + shape.getEnd(EnumFacing.Axis.X) * (1 - sideOffset.x);
|
double xDiff = shape.getStart(EnumFacing.Axis.X) * sideOffset.x + shape.getEnd(EnumFacing.Axis.X) * (1 - sideOffset.x);
|
||||||
double yDiff = shape.getStart(EnumFacing.Axis.Y) * sideOffset.y + shape.getEnd(EnumFacing.Axis.Y) * (1 - sideOffset.y);
|
double yDiff = shape.getStart(EnumFacing.Axis.Y) * sideOffset.y + shape.getEnd(EnumFacing.Axis.Y) * (1 - sideOffset.y);
|
||||||
|
|
|
@ -21,7 +21,6 @@ import net.minecraft.block.BlockFire;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.AxisAlignedBB;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
import net.minecraft.util.math.shapes.VoxelShape;
|
||||||
|
@ -46,9 +45,15 @@ public final class VecUtils {
|
||||||
public static Vec3d calculateBlockCenter(World world, BlockPos pos) {
|
public static Vec3d calculateBlockCenter(World world, BlockPos pos) {
|
||||||
IBlockState b = world.getBlockState(pos);
|
IBlockState b = world.getBlockState(pos);
|
||||||
VoxelShape shape = b.getCollisionShape(world, pos);
|
VoxelShape shape = b.getCollisionShape(world, pos);
|
||||||
|
if (shape.isEmpty()) {
|
||||||
|
return getBlockPosCenter(pos);
|
||||||
|
}
|
||||||
double xDiff = (shape.getStart(EnumFacing.Axis.X) + shape.getEnd(EnumFacing.Axis.X)) / 2;
|
double xDiff = (shape.getStart(EnumFacing.Axis.X) + shape.getEnd(EnumFacing.Axis.X)) / 2;
|
||||||
double yDiff = (shape.getStart(EnumFacing.Axis.Y) + shape.getEnd(EnumFacing.Axis.Y)) / 2;
|
double yDiff = (shape.getStart(EnumFacing.Axis.Y) + shape.getEnd(EnumFacing.Axis.Y)) / 2;
|
||||||
double zDiff = (shape.getStart(EnumFacing.Axis.Z) + shape.getEnd(EnumFacing.Axis.Z)) / 2;
|
double zDiff = (shape.getStart(EnumFacing.Axis.Z) + shape.getEnd(EnumFacing.Axis.Z)) / 2;
|
||||||
|
if (Double.isNaN(xDiff) || Double.isNaN(yDiff) || Double.isNaN(zDiff)) {
|
||||||
|
throw new IllegalStateException(b + " " + pos + " " + shape);
|
||||||
|
}
|
||||||
if (b.getBlock() instanceof BlockFire) {//look at bottom of fire when putting it out
|
if (b.getBlock() instanceof BlockFire) {//look at bottom of fire when putting it out
|
||||||
yDiff = 0;
|
yDiff = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,15 +28,15 @@ import net.minecraft.world.chunk.BlockStateContainer;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
import net.minecraft.world.chunk.ChunkSection;
|
import net.minecraft.world.chunk.ChunkSection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
import java.util.stream.IntStream;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public enum WorldScanner implements IWorldScanner {
|
public enum WorldScanner implements IWorldScanner {
|
||||||
|
|
||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
|
private static final int[] DEFAULT_COORDINATE_ITERATION_ORDER = IntStream.range(0, 16).toArray();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BlockPos> scanChunkRadius(IPlayerContext ctx, List<Block> blocks, int max, int yLevelThreshold, int maxSearchRadius) {
|
public List<BlockPos> scanChunkRadius(IPlayerContext ctx, List<Block> blocks, int max, int yLevelThreshold, int maxSearchRadius) {
|
||||||
if (blocks.contains(null)) {
|
if (blocks.contains(null)) {
|
||||||
|
@ -53,6 +53,9 @@ public enum WorldScanner implements IWorldScanner {
|
||||||
int playerChunkZ = ctx.playerFeet().getZ() >> 4;
|
int playerChunkZ = ctx.playerFeet().getZ() >> 4;
|
||||||
int playerY = ctx.playerFeet().getY();
|
int playerY = ctx.playerFeet().getY();
|
||||||
|
|
||||||
|
int playerYBlockStateContainerIndex = playerY >> 4;
|
||||||
|
int[] coordinateIterationOrder = IntStream.range(0, 16).boxed().sorted(Comparator.comparingInt(y -> Math.abs(y - playerYBlockStateContainerIndex))).mapToInt(x -> x).toArray();
|
||||||
|
|
||||||
int searchRadiusSq = 0;
|
int searchRadiusSq = 0;
|
||||||
boolean foundWithinY = false;
|
boolean foundWithinY = false;
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -72,7 +75,9 @@ public enum WorldScanner implements IWorldScanner {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
allUnloaded = false;
|
allUnloaded = false;
|
||||||
scanChunkInto(chunkX << 4, chunkZ << 4, chunk, blocks, res, max, yLevelThreshold, playerY);
|
if (scanChunkInto(chunkX << 4, chunkZ << 4, chunk, blocks, res, max, yLevelThreshold, playerY, coordinateIterationOrder)) {
|
||||||
|
foundWithinY = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((allUnloaded && foundChunks)
|
if ((allUnloaded && foundChunks)
|
||||||
|
@ -100,13 +105,15 @@ public enum WorldScanner implements IWorldScanner {
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<BlockPos> res = new ArrayList<>();
|
ArrayList<BlockPos> res = new ArrayList<>();
|
||||||
scanChunkInto(pos.x << 4, pos.z << 4, chunk, blocks, res, max, yLevelThreshold, playerY);
|
scanChunkInto(pos.x << 4, pos.z << 4, chunk, blocks, res, max, yLevelThreshold, playerY, DEFAULT_COORDINATE_ITERATION_ORDER);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scanChunkInto(int chunkX, int chunkZ, Chunk chunk, List<Block> search, Collection<BlockPos> result, int max, int yLevelThreshold, int playerY) {
|
private boolean scanChunkInto(int chunkX, int chunkZ, Chunk chunk, List<Block> search, Collection<BlockPos> result, int max, int yLevelThreshold, int playerY, int[] coordinateIterationOrder) {
|
||||||
ChunkSection[] chunkInternalStorageArray = chunk.getSections();
|
ChunkSection[] chunkInternalStorageArray = chunk.getSections();
|
||||||
for (int y0 = 0; y0 < 16; y0++) {
|
boolean foundWithinY = false;
|
||||||
|
for (int yIndex = 0; yIndex < 16; yIndex++) {
|
||||||
|
int y0 = coordinateIterationOrder[yIndex];
|
||||||
ChunkSection extendedblockstorage = chunkInternalStorageArray[y0];
|
ChunkSection extendedblockstorage = chunkInternalStorageArray[y0];
|
||||||
if (extendedblockstorage == null) {
|
if (extendedblockstorage == null) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -121,14 +128,22 @@ public enum WorldScanner implements IWorldScanner {
|
||||||
IBlockState state = bsc.get(x, y, z);
|
IBlockState state = bsc.get(x, y, z);
|
||||||
if (search.contains(state.getBlock())) {
|
if (search.contains(state.getBlock())) {
|
||||||
int yy = yReal | y;
|
int yy = yReal | y;
|
||||||
result.add(new BlockPos(chunkX | x, yy, chunkZ | z));
|
if (result.size() >= max) {
|
||||||
if (result.size() >= max && Math.abs(yy - playerY) < yLevelThreshold) {
|
if (Math.abs(yy - playerY) < yLevelThreshold) {
|
||||||
return;
|
foundWithinY = true;
|
||||||
|
} else {
|
||||||
|
if (foundWithinY) {
|
||||||
|
// have found within Y in this chunk, so don't need to consider outside Y
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
result.add(new BlockPos(chunkX | x, yy, chunkZ | z));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return foundWithinY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue