use top block in pathing, and reliability improvements
This commit is contained in:
parent
38aad9d92c
commit
e730f3a84d
@ -222,6 +222,11 @@ public class Settings {
|
|||||||
*/
|
*/
|
||||||
public Setting<Boolean> freeLook = new Setting<>(true);
|
public Setting<Boolean> freeLook = new Setting<>(true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exclusively use cached chunks for pathing
|
||||||
|
*/
|
||||||
|
public Setting<Boolean> pathThroughCachedOnly = new Setting<>(false);
|
||||||
|
|
||||||
public final Map<String, Setting<?>> byLowerName;
|
public final Map<String, Setting<?>> byLowerName;
|
||||||
public final List<Setting<?>> allSettings;
|
public final List<Setting<?>> allSettings;
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@ package baritone.bot.chunk;
|
|||||||
|
|
||||||
import baritone.bot.utils.pathing.IBlockTypeAccess;
|
import baritone.bot.utils.pathing.IBlockTypeAccess;
|
||||||
import baritone.bot.utils.pathing.PathingBlockType;
|
import baritone.bot.utils.pathing.PathingBlockType;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
@ -76,7 +78,23 @@ public final class CachedChunk implements IBlockTypeAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final PathingBlockType getBlockType(int x, int y, int z) {
|
public final IBlockState getBlock(int x, int y, int z) {
|
||||||
|
int internalPos = z << 4 | x;
|
||||||
|
if (heightMap[internalPos] == y) {
|
||||||
|
// we have this exact block, it's a surface block
|
||||||
|
String name = overview[internalPos];
|
||||||
|
if (!name.contains(":")) {
|
||||||
|
name = "minecraft:" + name;
|
||||||
|
}
|
||||||
|
IBlockState state = Block.getBlockFromName(name).getDefaultState();
|
||||||
|
System.out.println("Saying that " + x + "," + y + "," + z + " is " + state);
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
PathingBlockType type = getType(x, y, z);
|
||||||
|
return ChunkPacker.pathingTypeToBlock(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PathingBlockType getType(int x, int y, int z) {
|
||||||
int index = getPositionIndex(x, y, z);
|
int index = getPositionIndex(x, y, z);
|
||||||
return PathingBlockType.fromBits(data.get(index), data.get(index + 1));
|
return PathingBlockType.fromBits(data.get(index), data.get(index + 1));
|
||||||
}
|
}
|
||||||
@ -87,8 +105,9 @@ public final class CachedChunk implements IBlockTypeAccess {
|
|||||||
int index = z << 4 | x;
|
int index = z << 4 | x;
|
||||||
heightMap[index] = 0;
|
heightMap[index] = 0;
|
||||||
for (int y = 256; y >= 0; y--) {
|
for (int y = 256; y >= 0; y--) {
|
||||||
if (getBlockType(x, y, z) != PathingBlockType.AIR) {
|
if (getType(x, y, z) != PathingBlockType.AIR) {
|
||||||
heightMap[index] = y;
|
heightMap[index] = y;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,13 +18,12 @@
|
|||||||
package baritone.bot.chunk;
|
package baritone.bot.chunk;
|
||||||
|
|
||||||
import baritone.bot.utils.pathing.IBlockTypeAccess;
|
import baritone.bot.utils.pathing.IBlockTypeAccess;
|
||||||
import baritone.bot.utils.pathing.PathingBlockType;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
@ -70,10 +69,10 @@ public final class CachedRegion implements IBlockTypeAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final PathingBlockType getBlockType(int x, int y, int z) {
|
public final IBlockState getBlock(int x, int y, int z) {
|
||||||
CachedChunk chunk = this.getChunk(x >> 4, z >> 4);
|
CachedChunk chunk = this.getChunk(x >> 4, z >> 4);
|
||||||
if (chunk != null) {
|
if (chunk != null) {
|
||||||
return chunk.getBlockType(x & 15, y, z & 15);
|
return chunk.getBlock(x & 15, y, z & 15);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -174,6 +173,7 @@ public final class CachedRegion implements IBlockTypeAccess {
|
|||||||
// by switching on the magic value, and either loading it normally, or loading through a converter.
|
// by switching on the magic value, and either loading it normally, or loading through a converter.
|
||||||
throw new IOException("Bad magic value " + magic);
|
throw new IOException("Bad magic value " + magic);
|
||||||
}
|
}
|
||||||
|
CachedChunk[][] tmpCached = new CachedChunk[32][32];
|
||||||
for (int z = 0; z < 32; z++) {
|
for (int z = 0; z < 32; z++) {
|
||||||
for (int x = 0; x < 32; x++) {
|
for (int x = 0; x < 32; x++) {
|
||||||
int isChunkPresent = in.read();
|
int isChunkPresent = in.read();
|
||||||
@ -181,10 +181,10 @@ public final class CachedRegion implements IBlockTypeAccess {
|
|||||||
case CHUNK_PRESENT:
|
case CHUNK_PRESENT:
|
||||||
byte[] bytes = new byte[CachedChunk.SIZE_IN_BYTES];
|
byte[] bytes = new byte[CachedChunk.SIZE_IN_BYTES];
|
||||||
in.readFully(bytes);
|
in.readFully(bytes);
|
||||||
this.chunks[x][z] = new CachedChunk(x, z, BitSet.valueOf(bytes), new String[256]);
|
tmpCached[x][z] = new CachedChunk(x, z, BitSet.valueOf(bytes), new String[256]);
|
||||||
break;
|
break;
|
||||||
case CHUNK_NOT_PRESENT:
|
case CHUNK_NOT_PRESENT:
|
||||||
this.chunks[x][z] = null;
|
tmpCached[x][z] = null;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IOException("Malformed stream");
|
throw new IOException("Malformed stream");
|
||||||
@ -193,11 +193,10 @@ public final class CachedRegion implements IBlockTypeAccess {
|
|||||||
}
|
}
|
||||||
for (int z = 0; z < 32; z++) {
|
for (int z = 0; z < 32; z++) {
|
||||||
for (int x = 0; x < 32; x++) {
|
for (int x = 0; x < 32; x++) {
|
||||||
if (chunks[x][z] != null) {
|
if (tmpCached[x][z] != null) {
|
||||||
for (int i = 0; i < 256; i++) {
|
for (int i = 0; i < 256; i++) {
|
||||||
chunks[x][z].getOverview()[i] = in.readUTF();
|
tmpCached[x][z].getOverview()[i] = in.readUTF();
|
||||||
}
|
}
|
||||||
System.out.println(Arrays.asList(chunks[x][z].getOverview()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -205,6 +204,12 @@ public final class CachedRegion implements IBlockTypeAccess {
|
|||||||
if (fileEndMagic != ~magic) {
|
if (fileEndMagic != ~magic) {
|
||||||
throw new IOException("Bad end of file magic");
|
throw new IOException("Bad end of file magic");
|
||||||
}
|
}
|
||||||
|
// only if the entire file was uncorrupted do we actually set the chunks
|
||||||
|
for (int x = 0; x < 32; x++) {
|
||||||
|
for (int z = 0; z < 32; z++) {
|
||||||
|
this.chunks[x][z] = tmpCached[x][z];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
hasUnsavedChanges = false;
|
hasUnsavedChanges = false;
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
|
@ -18,9 +18,9 @@
|
|||||||
package baritone.bot.chunk;
|
package baritone.bot.chunk;
|
||||||
|
|
||||||
import baritone.bot.utils.pathing.IBlockTypeAccess;
|
import baritone.bot.utils.pathing.IBlockTypeAccess;
|
||||||
import baritone.bot.utils.pathing.PathingBlockType;
|
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
@ -66,13 +66,13 @@ public final class CachedWorld implements IBlockTypeAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final PathingBlockType getBlockType(int x, int y, int z) {
|
public final IBlockState getBlock(int x, int y, int z) {
|
||||||
// no point in doing getOrCreate region, if we don't have it we don't have it
|
// no point in doing getOrCreate region, if we don't have it we don't have it
|
||||||
CachedRegion region = getRegion(x >> 9, z >> 9);
|
CachedRegion region = getRegion(x >> 9, z >> 9);
|
||||||
if (region == null) {
|
if (region == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return region.getBlockType(x & 511, y, z & 511);
|
return region.getBlock(x & 511, y, z & 511);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCachedChunk(CachedChunk chunk) {
|
private void updateCachedChunk(CachedChunk chunk) {
|
||||||
|
@ -26,6 +26,7 @@ import net.minecraft.block.BlockAir;
|
|||||||
import net.minecraft.block.BlockDoublePlant;
|
import net.minecraft.block.BlockDoublePlant;
|
||||||
import net.minecraft.block.BlockTallGrass;
|
import net.minecraft.block.BlockTallGrass;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
@ -106,4 +107,20 @@ public final class ChunkPacker implements Helper {
|
|||||||
|
|
||||||
return PathingBlockType.SOLID;
|
return PathingBlockType.SOLID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static IBlockState pathingTypeToBlock(PathingBlockType type) {
|
||||||
|
if (type != null) {
|
||||||
|
switch (type) {
|
||||||
|
case AIR:
|
||||||
|
return Blocks.AIR.getDefaultState();
|
||||||
|
case WATER:
|
||||||
|
return Blocks.WATER.getDefaultState();
|
||||||
|
case AVOID:
|
||||||
|
return Blocks.LAVA.getDefaultState();
|
||||||
|
case SOLID:
|
||||||
|
return Blocks.OBSIDIAN.getDefaultState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
|||||||
boolean isPositionCached = false;
|
boolean isPositionCached = false;
|
||||||
if (cache) {
|
if (cache) {
|
||||||
if (CachedWorldProvider.INSTANCE.getCurrentWorld() != null) {
|
if (CachedWorldProvider.INSTANCE.getCurrentWorld() != null) {
|
||||||
if (CachedWorldProvider.INSTANCE.getCurrentWorld().getBlockType(dest) != null) {
|
if (CachedWorldProvider.INSTANCE.getCurrentWorld().getBlock(dest) != null) {
|
||||||
isPositionCached = true;
|
isPositionCached = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ package baritone.bot.utils;
|
|||||||
import baritone.bot.Baritone;
|
import baritone.bot.Baritone;
|
||||||
import baritone.bot.chunk.CachedWorld;
|
import baritone.bot.chunk.CachedWorld;
|
||||||
import baritone.bot.chunk.CachedWorldProvider;
|
import baritone.bot.chunk.CachedWorldProvider;
|
||||||
import baritone.bot.utils.pathing.PathingBlockType;
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockFalling;
|
import net.minecraft.block.BlockFalling;
|
||||||
import net.minecraft.block.BlockLiquid;
|
import net.minecraft.block.BlockLiquid;
|
||||||
@ -31,31 +30,24 @@ import net.minecraft.world.chunk.Chunk;
|
|||||||
|
|
||||||
public class BlockStateInterface implements Helper {
|
public class BlockStateInterface implements Helper {
|
||||||
|
|
||||||
public static IBlockState get(BlockPos pos) { // wrappers for future chunk caching capability
|
public static IBlockState get(BlockPos pos) { // wrappers for chunk caching capability
|
||||||
|
|
||||||
// Invalid vertical position
|
// Invalid vertical position
|
||||||
if (pos.getY() < 0 || pos.getY() >= 256)
|
if (pos.getY() < 0 || pos.getY() >= 256)
|
||||||
return Blocks.AIR.getDefaultState();
|
return Blocks.AIR.getDefaultState();
|
||||||
|
|
||||||
Chunk chunk = mc.world.getChunk(pos);
|
if (!Baritone.settings().pathThroughCachedOnly.get()) {
|
||||||
if (chunk.isLoaded()) {
|
Chunk chunk = mc.world.getChunk(pos);
|
||||||
return chunk.getBlockState(pos);
|
if (chunk.isLoaded()) {
|
||||||
|
return chunk.getBlockState(pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (Baritone.settings().chunkCaching.get()) {
|
if (Baritone.settings().chunkCaching.get()) {
|
||||||
CachedWorld world = CachedWorldProvider.INSTANCE.getCurrentWorld();
|
CachedWorld world = CachedWorldProvider.INSTANCE.getCurrentWorld();
|
||||||
if (world != null) {
|
if (world != null) {
|
||||||
PathingBlockType type = world.getBlockType(pos);
|
IBlockState type = world.getBlock(pos);
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
switch (type) {
|
return type;
|
||||||
case AIR:
|
|
||||||
return Blocks.AIR.getDefaultState();
|
|
||||||
case WATER:
|
|
||||||
return Blocks.WATER.getDefaultState();
|
|
||||||
case AVOID:
|
|
||||||
return Blocks.LAVA.getDefaultState();
|
|
||||||
case SOLID:
|
|
||||||
return Blocks.OBSIDIAN.getDefaultState();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package baritone.bot.utils.pathing;
|
package baritone.bot.utils.pathing;
|
||||||
|
|
||||||
import baritone.bot.utils.Helper;
|
import baritone.bot.utils.Helper;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -26,9 +27,9 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
*/
|
*/
|
||||||
public interface IBlockTypeAccess extends Helper {
|
public interface IBlockTypeAccess extends Helper {
|
||||||
|
|
||||||
PathingBlockType getBlockType(int x, int y, int z);
|
IBlockState getBlock(int x, int y, int z);
|
||||||
|
|
||||||
default PathingBlockType getBlockType(BlockPos pos) {
|
default IBlockState getBlock(BlockPos pos) {
|
||||||
return getBlockType(pos.getX(), pos.getY(), pos.getZ());
|
return getBlock(pos.getX(), pos.getY(), pos.getZ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user