MCPcopy Create free account
hub / github.com/cuberite/cuberite / ZapRegionInRawChunkData

Method ZapRegionInRawChunkData

Tools/BlockZapper/Zapper.cpp:184–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

182
183
184void cZapper::ZapRegionInRawChunkData(const cRegion & a_Region, AString & a_ChunkData, int a_ChunkX, int a_ChunkZ)
185{
186 // Decompress the data:
187 char Uncompressed[CHUNK_INFLATE_MAX];
188 z_stream strm;
189 strm.zalloc = (alloc_func)NULL;
190 strm.zfree = (free_func)NULL;
191 strm.opaque = NULL;
192 inflateInit(&strm);
193 strm.next_out = (Bytef *)Uncompressed;
194 strm.avail_out = sizeof(Uncompressed);
195 strm.next_in = (Bytef *)a_ChunkData.data();
196 strm.avail_in = a_ChunkData.size();
197 int res = inflate(&strm, Z_FINISH);
198 inflateEnd(&strm);
199 if (res != Z_STREAM_END)
200 {
201 fprintf(stderr, "Chunk [%d, %d] failed to decompress: error %d. Skipping chunk.", a_ChunkX, a_ChunkZ, res);
202 return;
203 }
204
205 /*
206 // DEBUG: Output src to a file:
207 cFile f1;
208 if (f1.Open(Printf("chunk_%d_%d_in.nbt", a_ChunkX, a_ChunkZ), cFile::fmWrite))
209 {
210 f1.Write(Uncompressed, strm.total_out);
211 }
212 //*/
213
214 cParsedNBT NBT(Uncompressed, strm.total_out);
215 if (!NBT.IsValid())
216 {
217 fprintf(stderr, "Chunk [%d, %d] failed to parse. Skipping chunk.", a_ChunkX, a_ChunkZ);
218 return;
219 }
220 ZapRegionInNBTChunk(a_Region, NBT, a_ChunkX, a_ChunkZ);
221
222 cFastNBTWriter Writer;
223 for (int ch = NBT.GetFirstChild(0); ch >= 0; ch = NBT.GetNextSibling(ch))
224 {
225 SerializeNBTTag(NBT, ch, Writer);
226 }
227 Writer.Finish();
228
229 /*
230 // DEBUG: Output dst to a file:
231 cFile f2;
232 if (f2.Open(Printf("chunk_%d_%d_out.nbt", a_ChunkX, a_ChunkZ), cFile::fmWrite))
233 {
234 f2.Write(Writer.GetResult().data(), Writer.GetResult().size());
235 }
236 //*/
237
238 // Compress the serialized data into "Uncompressed" (reuse buffer)
239 CompressString(Writer.GetResult().data(), Writer.GetResult().size(), a_ChunkData);
240}
241

Callers

nothing calls this directly

Calls 7

CompressStringFunction · 0.85
sizeMethod · 0.80
GetFirstChildMethod · 0.80
GetNextSiblingMethod · 0.80
GetResultMethod · 0.80
IsValidMethod · 0.45
FinishMethod · 0.45

Tested by

no test coverage detected