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

Method load

src/main/java/baritone/cache/CachedRegion.java:191–308  ·  view source on GitHub ↗
(String directory)

Source from the content-addressed store, hash-verified

189 }
190
191 public synchronized void load(String directory) {
192 try {
193 Path path = Paths.get(directory);
194 if (!Files.exists(path)) {
195 Files.createDirectories(path);
196 }
197
198 Path regionFile = getRegionFile(path, this.x, this.z);
199 if (!Files.exists(regionFile)) {
200 return;
201 }
202
203 System.out.println("Loading region " + x + "," + z + " from disk " + path);
204 long start = System.nanoTime() / 1000000L;
205
206 try (
207 FileInputStream fileIn = new FileInputStream(regionFile.toFile());
208 GZIPInputStream gzipIn = new GZIPInputStream(fileIn, 32768);
209 DataInputStream in = new DataInputStream(gzipIn)
210 ) {
211 int magic = in.readInt();
212 if (magic != CACHED_REGION_MAGIC) {
213 // in the future, if we change the format on disk
214 // we can keep converters for the old format
215 // by switching on the magic value, and either loading it normally, or loading through a converter.
216 throw new IOException("Bad magic value " + magic);
217 }
218 boolean[][] present = new boolean[32][32];
219 BitSet[][] bitSets = new BitSet[32][32];
220 Map<String, List<BlockPos>>[][] location = new Map[32][32];
221 BlockState[][][] overview = new BlockState[32][32][];
222 long[][] cacheTimestamp = new long[32][32];
223 for (int x = 0; x < 32; x++) {
224 for (int z = 0; z < 32; z++) {
225 int isChunkPresent = in.read();
226 switch (isChunkPresent) {
227 case CHUNK_PRESENT:
228 byte[] bytes = new byte[CachedChunk.sizeInBytes(CachedChunk.size(dimension.height()))];
229 in.readFully(bytes);
230 bitSets[x][z] = BitSet.valueOf(bytes);
231 location[x][z] = new HashMap<>();
232 //this is top block in columns
233 overview[x][z] = new BlockState[256];
234 present[x][z] = true;
235 break;
236 case CHUNK_NOT_PRESENT:
237 break;
238 default:
239 throw new IOException("Malformed stream");
240 }
241 }
242 }
243 for (int x = 0; x < 32; x++) {
244 for (int z = 0; z < 32; z++) {
245 if (present[x][z]) {
246 for (int i = 0; i < 256; i++) {
247 overview[x][z][i] = BlockUtils.stringToBlockRequired(in.readUTF()).defaultBlockState();
248 }

Callers 2

getOrCreateRegionMethod · 0.95
reloadAllFromDiskMethod · 0.45

Calls 9

getRegionFileMethod · 0.95
sizeInBytesMethod · 0.95
sizeMethod · 0.95
stringToBlockRequiredMethod · 0.95
removeExpiredMethod · 0.95
putMethod · 0.80
addMethod · 0.80
getMethod · 0.65
readMethod · 0.45

Tested by

no test coverage detected