Skip to content

Commit 6455903

Browse files
committed
Attempt at updating to 1.18.2
1 parent b953313 commit 6455903

31 files changed

+597
-274
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
55

66
MCJarServer
7-
MCServerSharp.Server/GameData
7+
MCServerSharp.Server/GameData*
88

99
# User-specific files
1010
*.rsuser

MCServerSharp.AnvilStorage/AnvilRegionReader.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,8 @@ private async Task LoadFullAsync(CancellationToken cancellationToken)
165165

166166
public static ChunkColumnPosition GetColumnPosition(NbtElement chunkRoot)
167167
{
168-
NbtElement levelCompound = chunkRoot["Level"];
169-
int columnX = levelCompound["xPos"].GetInt();
170-
int columnZ = levelCompound["zPos"].GetInt();
168+
int columnX = chunkRoot["xPos"].GetInt();
169+
int columnZ = chunkRoot["zPos"].GetInt();
171170
return new ChunkColumnPosition(columnX, columnZ);
172171
}
173172

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
3+
namespace MCServerSharp.Collections
4+
{
5+
public class BitSet
6+
{
7+
private long[] _longs;
8+
9+
public bool this[int index]
10+
{
11+
get => (_longs[index / 64] & (1L << (index % 64))) != 0;
12+
set
13+
{
14+
if (value)
15+
{
16+
_longs[index / 64] |= (1L << (index % 64));
17+
}
18+
else
19+
{
20+
_longs[index / 64] &= ~(1L << (index % 64));
21+
}
22+
}
23+
}
24+
25+
public BitSet(int capacity)
26+
{
27+
_longs = new long[(capacity + 63) / 64];
28+
}
29+
30+
public Span<long> AsSpan()
31+
{
32+
return _longs.AsSpan();
33+
}
34+
}
35+
}

MCServerSharp.Base/Data/Types/Chat.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public Chat(Utf8String? value)
1414
public static Chat Text(string text)
1515
{
1616
byte[] serialized = JsonSerializer.SerializeToUtf8Bytes(new { text });
17-
return new Chat(new Utf8String(serialized));
17+
return new Chat(Utf8String.WrapUnsafe(serialized));
1818
}
1919
}
2020
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+

2+
namespace MCServerSharp
3+
{
4+
public enum SculkSensorPhase
5+
{
6+
Inactive,
7+
Active,
8+
Cooldown,
9+
}
10+
}

MCServerSharp.Base/Enums/Thickness.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+

2+
namespace MCServerSharp
3+
{
4+
public enum Thickness
5+
{
6+
TipMerge,
7+
Tip,
8+
Frustum,
9+
Middle,
10+
Base,
11+
}
12+
}

MCServerSharp.Base/Enums/Tilt.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+

2+
namespace MCServerSharp
3+
{
4+
public enum Tilt
5+
{
6+
None,
7+
Unstable,
8+
Partial,
9+
Full,
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+

2+
namespace MCServerSharp
3+
{
4+
public enum VerticalDirection
5+
{
6+
Up,
7+
Down,
8+
}
9+
}

MCServerSharp.Base/IO/NetBinaryWriter.cs

+5-16
Original file line numberDiff line numberDiff line change
@@ -199,19 +199,9 @@ public void WriteRawUtf8(ReadOnlyMemory<char> value)
199199
WriteRawUtf8(value.Span);
200200
}
201201

202-
public void WriteUtf8(string? value)
203-
{
204-
WriteUtf8((ReadOnlySpan<char>)value);
205-
}
206-
207-
public void WriteRawUtf8(string? value)
208-
{
209-
WriteRawUtf8((ReadOnlySpan<char>)value);
210-
}
211-
212202
private void WriteString(ReadOnlySpan<char> value, Encoding encoding)
213203
{
214-
if (value == null)
204+
if (value.IsEmpty)
215205
{
216206
Write((VarInt)0);
217207
return;
@@ -226,12 +216,11 @@ private void WriteString(ReadOnlySpan<char> value, Encoding encoding)
226216
[SkipLocalsInit]
227217
private void WriteStringRaw(ReadOnlySpan<char> value, Encoding encoding)
228218
{
229-
if (value.IsEmpty)
230-
return;
231-
232219
int sliceSize = 512;
233-
int maxBytesPerSlice = encoding.GetMaxByteCount(sliceSize);
234-
Span<byte> byteBuffer = stackalloc byte[maxBytesPerSlice];
220+
Span<byte> byteBuffer = stackalloc byte[2048];
221+
222+
if (encoding.GetMaxByteCount(sliceSize) > byteBuffer.Length)
223+
throw new ArgumentException(null, nameof(encoding));
235224

236225
int charOffset = 0;
237226
int charsLeft = value.Length;

MCServerSharp.Base/Maths/ChunkColumnPosition.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public override bool Equals(object? obj)
6060

6161
public override string ToString()
6262
{
63-
return "{X:" + X + ", Z:" + Z + "}";
63+
return $"{{X:{X}, Z:{Z}}}";
6464
}
6565

6666
public static bool operator ==(ChunkColumnPosition a, ChunkColumnPosition b)

MCServerSharp.Net/Data/IO/NetBinaryWriterTypeExtensions.cs

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Buffers.Binary;
33
using System.Runtime.CompilerServices;
4+
using MCServerSharp.Collections;
45

56
namespace MCServerSharp.Data.IO
67
{
@@ -31,6 +32,13 @@ public static void Write(this NetBinaryWriter writer, Utf8Identifier identifier)
3132
writer.Write(identifier.Value);
3233
}
3334

35+
public static void Write(this NetBinaryWriter writer, BitSet bitSet)
36+
{
37+
Span<long> span = bitSet.AsSpan();
38+
writer.WriteVar(span.Length);
39+
writer.Write(span);
40+
}
41+
3442
[SkipLocalsInit]
3543
public static void Write(this NetBinaryWriter writer, UUID uuid)
3644
{

0 commit comments

Comments
 (0)