SaveSection2D(二维存档区)
基本信息
| 属性 |
值 |
| 实现类 |
cubicchunks.regionlib.impl.save.SaveSection2D |
| 继承 |
SaveSection<SaveSection2D, EntryLocation2D> |
| key 类型 |
EntryLocation2D(实现 IKey<EntryLocation2D>) |
| 每区域条目数 |
ENTRIES_PER_REGION = (1 << 5) * (1 << 5) = 1024 |
| 区域文件名 |
<regX>.<regZ>.2dr |
| 目录 |
SaveCubeColumns.create() 里固定为 <directory>/region2d |
| 扇区大小 |
512(SimpleRegionFactory.createDefault(..., 512)) |
⚠️ 这不是一个 Minecraft 维度。 本 mod 没有 WorldProvider、没有 DimensionType、没有 registerDimension(见分类页的"本 mod 没有的内容")。这里的"2D"指存档数据空间是二维的(只有 X/Z 两个坐标轴,对应原版世界的"柱列 column"),与下界、末地这些游戏维度无关。归到 dimension/ 只是因为它是本 mod 里唯一"多套坐标空间变体"的地方。
坐标 ↔ 区域 / id 的换算
public static final int LOC_BITS = 5; // 32
public static final int LOC_BITMASK = (1 << 5) - 1; // 31
public static final int ENTRIES_PER_REGION = 1024;
getRegionKey() → new RegionKey(regX + "." + regZ + ".2dr") // regX = entryX >> 5
getId() → ((entryX & 31) << 5) | (entryZ & 31)
| 性质 |
说明 |
equals |
比较 entryX 与 entryZ 两字段 |
hashCode |
31 * entryX + entryZ |
| 字段访问 |
getEntryX() / getEntryZ() |
toString |
EntryLocation2D{entryX=…, entryZ=…} |
| 可变性 |
两个字段都是 final,类整体不可变(符合 IKey “should be immutable” 的约定) |
EntryLocation2D.Provider
IKeyProvider<EntryLocation2D> 的实现,作为 EntryLocation2D 的静态内部类。
| 方法 |
行为 |
getKeyCount(RegionKey) |
恒返回 ENTRIES_PER_REGION = 1024 |
isValid(RegionKey) |
key.getName().matches("-?\\d+\\.-?\\d+\\.2dr") |
fromRegionAndId(RegionKey, int) |
先 isValid 校验,不通过抛 IllegalArgumentException("Invalid name " + regionKey.getName());然后按 split("\\.") 拆出 [regX, regZ],relativeX = id >>> 5、relativeZ = id & 31,还原成 `new EntryLocation2D(regX << 5 |
构造与工厂
| 签名 |
说明 |
SaveSection2D(IRegionProvider<EntryLocation2D> regionProvider) |
单提供者(继承自 SaveSection) |
SaveSection2D(IRegionProvider<EntryLocation2D>... regionProvider) |
变参 → super(Arrays.asList(regionProvider)),多提供者回退链靠这个构造 |
static SaveSection2D createAt(Path directory) |
标准装配,见下 |
createAt(Path) 装的是两层回退(详见 多提供者回退链):
| 顺序 |
IRegionProvider |
底层 IRegion |
存在判定 |
| 1 |
SharedCachedRegionProvider(SimpleRegionFactory.createDefault(new EntryLocation2D.Provider(), directory, 512)) |
Region(512 B 扇区) |
Files.exists(directory.resolve(key.getName())) |
| 2 |
SharedCachedRegionProvider(new SimpleRegionFactory<>(new EntryLocation2D.Provider(), directory, (kp, rk) -> new ExtRegion<>(directory, Collections.emptyList(), kp, rk), (kp, rk) -> Files.exists(directory.resolve(rk.getName() + ".ext")))) |
ExtRegion(.ext 目录) |
Files.exists(dir/<name>.ext) |
数据访问
SaveSection2D 自身没有覆写任何数据方法,全部来自 SaveSection:save(K, ByteBuffer) / save(Map) / load(K, boolean) / load(Collection, boolean) / allKeys(boolean) / allEntries(boolean) / hasEntry(K) / flush() / close()。
SaveCubeColumns 把它包装成对外入口:
| 方法 |
签名 |
| 单条写 |
save2d(EntryLocation2D location, ByteBuffer data) |
| 批量写 |
save2d(Map<EntryLocation2D, ByteBuffer> entries) |
| 单条读 |
load(EntryLocation2D location, boolean createRegion) → Optional<ByteBuffer> |
| 批量读 |
load2D(Collection<EntryLocation2D> positions, boolean createRegion) → BatchReadResult<EntryLocation2D> |
| 取本节 |
getSaveSection2D() |
SaveCubeColumns 上有两个同签名的 load 重载(一个收 EntryLocation3D、一个收 EntryLocation2D),靠实参静态类型区分;批量接口则必须用 load2D / load3D 这两个不同名字。
数值
| 数值 |
值 |
| 单区域条目数 |
1024 |
| 单条目字节上限 |
130556(255 扇区 × 512 − 4 字节长度前缀);超出自动落 .ext |
| 单区域扇区数 |
头表 1024 × 4 字节 = 4096 字节 = 8 扇区(entryMapSectors),开局即标记为已占用 |
相关条目