better cache, needs more testing
This commit is contained in:
parent
558c14a375
commit
2133ab39b7
35
src/main/java/baritone/cache/CachedChunk.java
vendored
35
src/main/java/baritone/cache/CachedChunk.java
vendored
@ -86,6 +86,7 @@ public final class CachedChunk {
|
||||
temp.add(Blocks.WEB);
|
||||
temp.add(Blocks.NETHER_WART);
|
||||
temp.add(Blocks.LADDER);
|
||||
temp.add(Blocks.VINE);
|
||||
BLOCKS_TO_KEEP_TRACK_OF = Collections.unmodifiableSet(temp);
|
||||
}
|
||||
|
||||
@ -118,6 +119,8 @@ public final class CachedChunk {
|
||||
*/
|
||||
private final BitSet data;
|
||||
|
||||
private final BitSet special;
|
||||
|
||||
/**
|
||||
* The block names of each surface level block for generating an overview
|
||||
*/
|
||||
@ -139,12 +142,27 @@ public final class CachedChunk {
|
||||
this.heightMap = new int[256];
|
||||
this.specialBlockLocations = specialBlockLocations;
|
||||
this.cacheTimestamp = cacheTimestamp;
|
||||
this.special = new BitSet();
|
||||
calculateHeightMap();
|
||||
setSpecial();
|
||||
}
|
||||
|
||||
private final void setSpecial() {
|
||||
for (List<BlockPos> list : specialBlockLocations.values()) {
|
||||
for (BlockPos pos : list) {
|
||||
System.out.println("Turning on bit");
|
||||
special.set(getPositionIndex(pos.getX(), pos.getY(), pos.getZ()) >> 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final IBlockState getBlock(int x, int y, int z, int dimension) {
|
||||
int index = getPositionIndex(x, y, z);
|
||||
PathingBlockType type = getType(index);
|
||||
int internalPos = z << 4 | x;
|
||||
if (heightMap[internalPos] == y) {
|
||||
if (heightMap[internalPos] == y && type != PathingBlockType.AVOID) {
|
||||
// if the top block in a column is water, we cache it as AVOID but we don't want to just return default state water (which is not flowing) beacuse then it would try to path through it
|
||||
|
||||
// we have this exact block, it's a surface block
|
||||
/*System.out.println("Saying that " + x + "," + y + "," + z + " is " + state);
|
||||
if (!Minecraft.getMinecraft().world.getBlockState(new BlockPos(x + this.x * 16, y, z + this.z * 16)).getBlock().equals(state.getBlock())) {
|
||||
@ -152,15 +170,24 @@ public final class CachedChunk {
|
||||
}*/
|
||||
return overview[internalPos];
|
||||
}
|
||||
PathingBlockType type = getType(x, y, z);
|
||||
if (special.get(index >> 1)) {
|
||||
// this block is special
|
||||
for (Map.Entry<String, List<BlockPos>> entry : specialBlockLocations.entrySet()) {
|
||||
for (BlockPos pos : entry.getValue()) {
|
||||
if (pos.getX() == x && pos.getY() == y && pos.getZ() == z) {
|
||||
return ChunkPacker.stringToBlock(entry.getKey()).getDefaultState();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type == PathingBlockType.SOLID && y == 127 && dimension == -1) {
|
||||
return Blocks.BEDROCK.getDefaultState();
|
||||
}
|
||||
return ChunkPacker.pathingTypeToBlock(type, dimension);
|
||||
}
|
||||
|
||||
private PathingBlockType getType(int x, int y, int z) {
|
||||
int index = getPositionIndex(x, y, z);
|
||||
private PathingBlockType getType(int index) {
|
||||
return PathingBlockType.fromBits(data.get(index), data.get(index + 1));
|
||||
}
|
||||
|
||||
|
13
src/main/java/baritone/cache/ChunkPacker.java
vendored
13
src/main/java/baritone/cache/ChunkPacker.java
vendored
@ -90,7 +90,8 @@ public final class ChunkPacker {
|
||||
IBlockState[] blocks = new IBlockState[256];
|
||||
|
||||
for (int z = 0; z < 16; z++) {
|
||||
https://www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html
|
||||
https:
|
||||
//www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int y = 255; y >= 0; y--) {
|
||||
int index = CachedChunk.getPositionIndex(x, y, z);
|
||||
@ -124,10 +125,16 @@ public final class ChunkPacker {
|
||||
if (block == Blocks.WATER || block == Blocks.FLOWING_WATER) {
|
||||
// only water source blocks are plausibly usable, flowing water should be avoid
|
||||
// FLOWING_WATER is a waterfall, it doesn't really matter and caching it as AVOID just makes it look wrong
|
||||
if (!MovementHelper.possiblyFlowing(state)) {
|
||||
if (MovementHelper.possiblyFlowing(state)) {
|
||||
return PathingBlockType.AVOID;
|
||||
}
|
||||
if (x == 0 || x == 15 || z == 0 || z == 15) {
|
||||
if (BlockLiquid.getSlopeAngle(chunk.getWorld(), new BlockPos(x + chunk.x << 4, y, z + chunk.z << 4), state.getMaterial(), state) == -1000.0F) {
|
||||
return PathingBlockType.WATER;
|
||||
}
|
||||
if (BlockLiquid.getSlopeAngle(chunk.getWorld(), new BlockPos(x + chunk.x << 4, y, z + chunk.z << 4), state.getMaterial(), state) != -1000.0F) {
|
||||
return PathingBlockType.AVOID;
|
||||
}
|
||||
if (MovementHelper.possiblyFlowing(chunk.getBlockState(x + 1, y, z)) || MovementHelper.possiblyFlowing(chunk.getBlockState(x - 1, y, z)) || MovementHelper.possiblyFlowing(chunk.getBlockState(x, y, z + 1)) || MovementHelper.possiblyFlowing(chunk.getBlockState(x, y, z - 1))) {
|
||||
return PathingBlockType.AVOID;
|
||||
}
|
||||
return PathingBlockType.WATER;
|
||||
|
Loading…
Reference in New Issue
Block a user