From ab1037bcfd9f504af53f1c2bb93f1956c1ece4f7 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 11 Sep 2018 11:56:59 -0700 Subject: [PATCH] blockstateinterface reorg --- src/main/java/baritone/cache/CachedWorld.java | 16 ++---------- .../baritone/utils/BlockStateInterface.java | 26 +++++++++---------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/main/java/baritone/cache/CachedWorld.java b/src/main/java/baritone/cache/CachedWorld.java index d56882b4..d903c2cd 100644 --- a/src/main/java/baritone/cache/CachedWorld.java +++ b/src/main/java/baritone/cache/CachedWorld.java @@ -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 getLocationsOf(String block, int minimum, int maxRegionDistanceSq) { LinkedList res = new LinkedList<>(); int playerRegionX = playerFeet().getX() >> 9; diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index 1ccd5ac6..bb4d094d 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -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() {