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

Method save

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

Source from the content-addressed store, hash-verified

113
114
115 public synchronized final void save(String directory) {
116 if (!hasUnsavedChanges) {
117 return;
118 }
119 removeExpired();
120 try {
121 Path path = Paths.get(directory);
122 if (!Files.exists(path)) {
123 Files.createDirectories(path);
124
125 }
126 System.out.println("Saving region " + x + "," + z + " to disk " + path);
127 Path regionFile = getRegionFile(path, this.x, this.z);
128 if (!Files.exists(regionFile)) {
129 Files.createFile(regionFile);
130 }
131 try (
132 FileOutputStream fileOut = new FileOutputStream(regionFile.toFile());
133 GZIPOutputStream gzipOut = new GZIPOutputStream(fileOut, 16384);
134 DataOutputStream out = new DataOutputStream(gzipOut)
135 ) {
136 out.writeInt(CACHED_REGION_MAGIC);
137 for (int x = 0; x < 32; x++) {
138 for (int z = 0; z < 32; z++) {
139 CachedChunk chunk = this.chunks[x][z];
140 if (chunk == null) {
141 out.write(CHUNK_NOT_PRESENT);
142 } else {
143 out.write(CHUNK_PRESENT);
144 byte[] chunkBytes = chunk.toByteArray();
145 out.write(chunkBytes);
146 // Messy, but fills the empty 0s that should be trailing to fill up the space.
147 out.write(new byte[chunk.sizeInBytes - chunkBytes.length]);
148 }
149 }
150 }
151 for (int x = 0; x < 32; x++) {
152 for (int z = 0; z < 32; z++) {
153 if (chunks[x][z] != null) {
154 for (int i = 0; i < 256; i++) {
155 out.writeUTF(BlockUtils.blockToString(chunks[x][z].getOverview()[i].getBlock()));
156 }
157 }
158 }
159 }
160 for (int x = 0; x < 32; x++) {
161 for (int z = 0; z < 32; z++) {
162 if (chunks[x][z] != null) {
163 Map<String, List<BlockPos>> locs = chunks[x][z].getRelativeBlocks();
164 out.writeShort(locs.entrySet().size());
165 for (Map.Entry<String, List<BlockPos>> entry : locs.entrySet()) {
166 out.writeUTF(entry.getKey());
167 out.writeShort(entry.getValue().size());
168 for (BlockPos pos : entry.getValue()) {
169 out.writeByte((byte) (pos.getZ() << 4 | pos.getX()));
170 out.writeInt(pos.getY()-dimension.minY());
171 }
172 }

Callers

nothing calls this directly

Calls 14

removeExpiredMethod · 0.95
getRegionFileMethod · 0.95
toByteArrayMethod · 0.95
blockToStringMethod · 0.95
getOverviewMethod · 0.80
getRelativeBlocksMethod · 0.80
getYMethod · 0.80
getMethod · 0.65
getBlockMethod · 0.65
sizeMethod · 0.65
getValueMethod · 0.65
getZMethod · 0.65

Tested by

no test coverage detected