MCPcopy Create free account
hub / github.com/cabaletta/baritone / CachedRegion

Class CachedRegion

src/main/java/baritone/cache/CachedRegion.java:39–361  ·  view source on GitHub ↗

@author Brady @since 8/3/2018

Source from the content-addressed store, hash-verified

37 * @since 8/3/2018
38 */
39public final class CachedRegion implements ICachedRegion {
40
41 private static final byte CHUNK_NOT_PRESENT = 0;
42 private static final byte CHUNK_PRESENT = 1;
43
44 /**
45 * Magic value to detect invalid cache files, or incompatible cache files saved in an old version of Baritone
46 */
47 private static final int CACHED_REGION_MAGIC = 456022911;
48
49 /**
50 * All of the chunks in this region: A 32x32 array of them.
51 */
52 private final CachedChunk[][] chunks = new CachedChunk[32][32];
53
54 /**
55 * The region x coordinate
56 */
57 private final int x;
58
59 /**
60 * The region z coordinate
61 */
62 private final int z;
63
64 private final DimensionType dimension;
65
66 /**
67 * Has this region been modified since its most recent load or save
68 */
69 private boolean hasUnsavedChanges;
70
71 CachedRegion(int x, int z, DimensionType dimension) {
72 this.x = x;
73 this.z = z;
74 this.hasUnsavedChanges = false;
75 this.dimension = dimension;
76 }
77
78 @Override
79 public final BlockState getBlock(int x, int y, int z) {
80 int adjY = y - dimension.minY();
81 CachedChunk chunk = chunks[x >> 4][z >> 4];
82 if (chunk != null) {
83 return chunk.getBlock(x & 15, adjY, z & 15, dimension);
84 }
85 return null;
86 }
87
88 @Override
89 public final boolean isCached(int x, int z) {
90 return chunks[x >> 4][z >> 4] != null;
91 }
92
93 public final ArrayList<BlockPos> getLocationsOf(String block) {
94 ArrayList<BlockPos> res = new ArrayList<>();
95 for (int chunkX = 0; chunkX < 32; chunkX++) {
96 for (int chunkZ = 0; chunkZ < 32; chunkZ++) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected