|
15 | 15 | */ |
16 | 16 | package org.glavo.nbt.chunk; |
17 | 17 |
|
| 18 | +import org.glavo.nbt.MinecraftEdition; |
18 | 19 | import org.glavo.nbt.NBTElement; |
| 20 | +import org.glavo.nbt.internal.input.InputContext; |
19 | 21 |
|
| 22 | +import java.io.IOException; |
20 | 23 | import java.util.Objects; |
21 | 24 |
|
22 | 25 | /// @see <a href="https://minecraft.wiki/w/Region_file_format">Region file format - Minecraft Wiki</a> |
23 | 26 | /// @see <a href="https://minecraft.wiki/w/Anvil_file_format">Anvil file format - Minecraft Wiki</a> |
24 | 27 | public final class Region implements NBTElement { |
25 | 28 | private static final int CHUNKS_PER_REGION_SIDE = 32; |
26 | 29 |
|
27 | | - // TODO |
| 30 | + static Region readRegion(InputContext context) throws IOException { |
| 31 | + if (context.edition != MinecraftEdition.JAVA_EDITION) { |
| 32 | + throw new IllegalArgumentException("Only Java Edition supports region file format"); |
| 33 | + } |
| 34 | + |
| 35 | + int[] diskInfo = context.rawReader.readIntArray(CHUNKS_PER_REGION_SIDE * CHUNKS_PER_REGION_SIDE); |
| 36 | + int[] timestamps = context.rawReader.readIntArray(CHUNKS_PER_REGION_SIDE * CHUNKS_PER_REGION_SIDE); |
| 37 | + |
| 38 | + for (int y = 0; y < CHUNKS_PER_REGION_SIDE; y++) { |
| 39 | + for (int x = 0; x < CHUNKS_PER_REGION_SIDE; x++) { |
| 40 | + int index = x + y * CHUNKS_PER_REGION_SIDE; |
| 41 | + |
| 42 | + int info = diskInfo[index]; |
| 43 | + int sectorOffset = info >>> 8; |
| 44 | + int sectorCount = info & 0xFF; |
| 45 | + int timestamp = timestamps[index]; |
| 46 | + |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + throw new AssertionError("Not implemented yet"); |
| 51 | + } |
| 52 | + |
28 | 53 | private final Chunk[] chunks = new Chunk[CHUNKS_PER_REGION_SIDE * CHUNKS_PER_REGION_SIDE]; |
29 | 54 |
|
30 | 55 | public Chunk getChunk(int x, int z) { |
|
0 commit comments