blockstateinterface reorg

This commit is contained in:
Leijurv 2018-09-11 11:56:59 -07:00
parent 3dfde818d3
commit ab1037bcfd
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 14 additions and 28 deletions

View File

@ -18,10 +18,9 @@
package baritone.cache;
import baritone.Baritone;
import baritone.utils.pathing.IBlockTypeAccess;
import baritone.utils.Helper;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.Chunk;
@ -37,7 +36,7 @@ import java.util.concurrent.LinkedBlockingQueue;
* @author Brady
* @since 8/4/2018 12:02 AM
*/
public final class CachedWorld implements IBlockTypeAccess {
public final class CachedWorld implements Helper {
/**
* The maximum number of regions in any direction from (0,0)
@ -92,16 +91,6 @@ public final class CachedWorld implements IBlockTypeAccess {
}
}
@Override
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
CachedRegion region = getRegion(x >> 9, z >> 9);
if (region == null) {
return null;
}
return region.getBlock(x & 511, y, z & 511);
}
public final boolean isCached(BlockPos pos) {
int x = pos.getX();
int z = pos.getZ();
@ -112,7 +101,6 @@ public final class CachedWorld implements IBlockTypeAccess {
return region.isCached(x & 511, z & 511);
}
public final LinkedList<BlockPos> getLocationsOf(String block, int minimum, int maxRegionDistanceSq) {
LinkedList<BlockPos> res = new LinkedList<>();
int playerRegionX = playerFeet().getX() >> 9;

View File

@ -74,25 +74,23 @@ public class BlockStateInterface implements Helper {
// same idea here, skip the Long2ObjectOpenHashMap.get if at all possible
// except here, it's 512x512 tiles instead of 16x16, so even better repetition
CachedRegion cached = prevCached;
if (cached != null && cached.getX() == x >> 9 && cached.getZ() == z >> 9) {
IBlockState type = cached.getBlock(x & 511, y, z & 511);
if (type == null) {
if (cached == null || cached.getX() != x >> 9 || cached.getZ() != z >> 9) {
WorldData world = WorldProvider.INSTANCE.getCurrentWorld();
if (world == null) {
return AIR;
}
return type;
}
WorldData world = WorldProvider.INSTANCE.getCurrentWorld();
if (world != null) {
CachedRegion region = world.cache.getRegion(x >> 9, z >> 9);
if (region != null) {
prevCached = region;
IBlockState type = region.getBlock(x & 511, y, z & 511);
if (type != null) {
return type;
}
if (region == null) {
return AIR;
}
prevCached = region;
cached = region;
}
return AIR;
IBlockState type = cached.getBlock(x & 511, y, z & 511);
if (type == null) {
return AIR;
}
return type;
}
public static void clearCachedChunk() {