Skip to content

Commit 6dcc0f9

Browse files
committed
tempfix to load world with chunk format >=7
Apparently some world converters convert chunks to older chunk format that cause crash. So here fix for that.
1 parent 4d1ef68 commit 6dcc0f9

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/MiNET/MiNET/Worlds/LevelDbProvider.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
using MiNET.Utils;
4646
using MiNET.Utils.IO;
4747
using MiNET.Utils.Vectors;
48-
using Org.BouncyCastle.Asn1.Cms;
48+
using Newtonsoft.Json;
4949

5050
namespace MiNET.Worlds
5151
{
@@ -174,7 +174,7 @@ public ChunkColumn GetChunk(ChunkCoordinates coordinates, IWorldGenerator genera
174174
sw.Stop();
175175

176176
ChunkColumn chunkColumn = null;
177-
if (version != null && version.First() >= 10)
177+
if (version != null && version.First() >= 7)
178178
{
179179
chunkColumn = new ChunkColumn
180180
{
@@ -217,10 +217,9 @@ public ChunkColumn GetChunk(ChunkCoordinates coordinates, IWorldGenerator genera
217217

218218
//Log.Debug($"Read chunk from LevelDB {coordinates.X}, {coordinates.Z} in {sw.ElapsedMilliseconds} ms.");
219219

220-
if (blockEntityBytes != null)
220+
if (blockEntityBytes != null && version.First() >= 10)
221221
{
222222
Memory<byte> data = blockEntityBytes.AsMemory();
223-
224223
var file = new NbtFile
225224
{
226225
BigEndian = false,
@@ -239,6 +238,17 @@ public ChunkColumn GetChunk(ChunkCoordinates coordinates, IWorldGenerator genera
239238
chunkColumn.SetBlockEntity(new BlockCoordinates(x, y, z), (NbtCompound) blockEntityTag);
240239
} while (position < data.Length);
241240
}
241+
else
242+
{ //todo find out how to get block entities on chunk format 7
243+
//Memory<byte> data = blockEntityBytes.AsMemory();
244+
//string jsonString = System.Text.Encoding.UTF8.GetString(data.Span);
245+
//LegacyBlockEntities info = JsonConvert.DeserializeObject<LegacyBlockEntities>(jsonString);
246+
//if (info != null)
247+
//{
248+
//Log.Warn(info.IsEmpty);
249+
//Log.Warn(info.Length);
250+
//}
251+
}
242252
}
243253

244254
if (chunkColumn == null)
@@ -267,6 +277,12 @@ public ChunkColumn GetChunk(ChunkCoordinates coordinates, IWorldGenerator genera
267277
return chunkColumn;
268278
}
269279

280+
public class LegacyBlockEntities
281+
{
282+
public int Length { get; set; }
283+
public bool IsEmpty { get; set; }
284+
}
285+
270286
internal void ParseSection(SubChunk section, ReadOnlyMemory<byte> data)
271287
{
272288
var reader = new MemoryStreamReader(data);

0 commit comments

Comments
 (0)