diff --git a/Obsidian.API/_Interfaces/INetStream.cs b/Obsidian.API/_Interfaces/INetStream.cs new file mode 100644 index 00000000..325ed100 --- /dev/null +++ b/Obsidian.API/_Interfaces/INetStream.cs @@ -0,0 +1,7 @@ +namespace Obsidian.API; +public interface INetStream : IDisposable, IAsyncDisposable +{ + public long Length { get; } + + public long Position { get; set; } +} diff --git a/Obsidian.API/_Interfaces/INetStreamReader.cs b/Obsidian.API/_Interfaces/INetStreamReader.cs new file mode 100644 index 00000000..2da3bd34 --- /dev/null +++ b/Obsidian.API/_Interfaces/INetStreamReader.cs @@ -0,0 +1,39 @@ +namespace Obsidian.API; +public interface INetStreamReader : INetStream +{ + public bool CanRead { get; } + + public sbyte ReadSignedByte(); + public byte ReadUnsignedByte(); + public bool ReadBoolean(); + public ushort ReadUnsignedShort(); + public short ReadShort(); + public int ReadInt(); + public long ReadLong(); + public ulong ReadUnsignedLong(); + public float ReadFloat(); + public double ReadDouble(); + public string ReadString(int maxLength = short.MaxValue); + public int ReadVarInt(); + public byte[] ReadUInt8Array(int length = 0); + public long ReadVarLong(); + + public DateTimeOffset ReadDateTimeOffset(); + + public Vector ReadPosition(); + public Vector ReadAbsolutePosition(); + public VectorF ReadPositionF(); + public VectorF ReadAbsolutePositionF(); + public VectorF ReadAbsoluteFloatPositionF(); + + public SoundPosition ReadSoundPosition(); + + public Angle ReadAngle(); + public Angle ReadFloatAngle(); + public ChatMessage ReadChat(); + public byte[] ReadByteArray(); + public Guid ReadGuid(); + public Guid? ReadOptionalGuid(); + public ItemStack ReadItemStack(); + public Velocity ReadVelocity(); +} diff --git a/Obsidian.API/_Interfaces/INetStreamWriter.cs b/Obsidian.API/_Interfaces/INetStreamWriter.cs new file mode 100644 index 00000000..3f9862af --- /dev/null +++ b/Obsidian.API/_Interfaces/INetStreamWriter.cs @@ -0,0 +1,35 @@ +namespace Obsidian.API; +public interface INetStreamWriter : INetStream +{ + public bool CanWrite { get; } + public void WriteByte(sbyte value); + public void WriteUnsignedByte(byte value); + public void WriteBoolean(bool value); + + public void WriteUnsignedShort(ushort value); + public void WriteShort(short value); + + public void WriteInt(int value); + + public void WriteLong(long value); + + public void WriteFloat(float value); + public void WriteDouble(double value); + + public void WriteString(string value, int maxLength = short.MaxValue); + public void WriteVarInt(int value); + public void WriteVarInt(Enum value); + + public void WriteLongArray(long[] values); + public void WriteVarLong(long value); + + public void WriteBitSet(BitSet bitset, bool isFixed = false); + public void WriteChat(ChatMessage chatMessage); + public void WriteItemStack(ItemStack itemStack); + public void WriteDateTimeOffset(DateTimeOffset date); + public void WriteSoundEffect(SoundEffect sound); + public void WriteByteArray(byte[] values); + public void WriteUuid(Guid value); + + public byte[] ToArray(); +} diff --git a/Obsidian/Net/MinecraftStream.Reading.cs b/Obsidian/Net/MinecraftStream.Reading.cs index 132f39c0..03369251 100644 --- a/Obsidian/Net/MinecraftStream.Reading.cs +++ b/Obsidian/Net/MinecraftStream.Reading.cs @@ -9,7 +9,7 @@ namespace Obsidian.Net; -public partial class MinecraftStream +public partial class MinecraftStream : INetStreamReader { [ReadMethod] diff --git a/Obsidian/Net/MinecraftStream.Writing.cs b/Obsidian/Net/MinecraftStream.Writing.cs index 3aebc36f..8799b4dc 100644 --- a/Obsidian/Net/MinecraftStream.Writing.cs +++ b/Obsidian/Net/MinecraftStream.Writing.cs @@ -1,5 +1,4 @@ -using Obsidian.API; -using Obsidian.API.Advancements; +using Obsidian.API.Advancements; using Obsidian.API.Crafting; using Obsidian.API.Inventory; using Obsidian.API.Registry.Codecs.ArmorTrims.TrimMaterial; @@ -26,7 +25,7 @@ namespace Obsidian.Net; -public partial class MinecraftStream +public partial class MinecraftStream : INetStreamWriter { [WriteMethod] public void WriteByte(sbyte value)