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

Method LoadFromSchematicNBT

src/WorldStorage/SchematicFileSerializer.cpp:163–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161
162
163bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cParsedNBT & a_NBT)
164{
165 int TMaterials = a_NBT.FindChildByName(a_NBT.GetRoot(), "Materials");
166 if ((TMaterials > 0) && (a_NBT.GetType(TMaterials) == TAG_String))
167 {
168 AString Materials = a_NBT.GetString(TMaterials);
169 if (Materials.compare("Alpha") != 0)
170 {
171 LOG("Materials tag is present and \"%s\" instead of \"Alpha\". Possibly a wrong-format schematic file.", Materials.c_str());
172 return false;
173 }
174 }
175 int TSizeX = a_NBT.FindChildByName(a_NBT.GetRoot(), "Width");
176 int TSizeY = a_NBT.FindChildByName(a_NBT.GetRoot(), "Height");
177 int TSizeZ = a_NBT.FindChildByName(a_NBT.GetRoot(), "Length");
178 if (
179 (TSizeX < 0) || (TSizeY < 0) || (TSizeZ < 0) ||
180 (a_NBT.GetType(TSizeX) != TAG_Short) ||
181 (a_NBT.GetType(TSizeY) != TAG_Short) ||
182 (a_NBT.GetType(TSizeZ) != TAG_Short)
183 )
184 {
185 LOG("Dimensions are missing from the schematic file (%d, %d, %d), (%d, %d, %d)",
186 TSizeX, TSizeY, TSizeZ,
187 a_NBT.GetType(TSizeX), a_NBT.GetType(TSizeY), a_NBT.GetType(TSizeZ)
188 );
189 return false;
190 }
191
192 int SizeX = a_NBT.GetShort(TSizeX);
193 int SizeY = a_NBT.GetShort(TSizeY);
194 int SizeZ = a_NBT.GetShort(TSizeZ);
195 if ((SizeX < 1) || (SizeY < 1) || (SizeZ < 1))
196 {
197 LOG("Dimensions are invalid in the schematic file: %d, %d, %d", SizeX, SizeY, SizeZ);
198 return false;
199 }
200
201 int TBlockTypes = a_NBT.FindChildByName(a_NBT.GetRoot(), "Blocks");
202 int TBlockMetas = a_NBT.FindChildByName(a_NBT.GetRoot(), "Data");
203 if ((TBlockTypes < 0) || (a_NBT.GetType(TBlockTypes) != TAG_ByteArray))
204 {
205 LOG("BlockTypes are invalid in the schematic file: %d", TBlockTypes);
206 return false;
207 }
208 bool AreMetasPresent = (TBlockMetas > 0) && (a_NBT.GetType(TBlockMetas) == TAG_ByteArray);
209
210 a_BlockArea.Clear();
211 a_BlockArea.SetSize(SizeX, SizeY, SizeZ, AreMetasPresent ? (cBlockArea::baTypes | cBlockArea::baMetas) : cBlockArea::baTypes);
212
213 int TOffsetX = a_NBT.FindChildByName(a_NBT.GetRoot(), "WEOffsetX");
214 int TOffsetY = a_NBT.FindChildByName(a_NBT.GetRoot(), "WEOffsetY");
215 int TOffsetZ = a_NBT.FindChildByName(a_NBT.GetRoot(), "WEOffsetZ");
216
217 if (
218 (TOffsetX < 0) || (TOffsetY < 0) || (TOffsetZ < 0) ||
219 (a_NBT.GetType(TOffsetX) != TAG_Int) ||
220 (a_NBT.GetType(TOffsetY) != TAG_Int) ||

Callers

nothing calls this directly

Calls 15

LOGFunction · 0.85
GetRootMethod · 0.80
GetStringMethod · 0.80
compareMethod · 0.80
c_strMethod · 0.80
GetShortMethod · 0.80
SetWEOffsetMethod · 0.80
GetIntMethod · 0.80
GetBlockCountMethod · 0.80
GetDataLengthMethod · 0.80
GetDataMethod · 0.80
FindChildByNameMethod · 0.45

Tested by

no test coverage detected