Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose MinecraftStream #441

Merged
merged 4 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Obsidian.API/_Interfaces/INetStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Obsidian.API;
public interface INetStream : IDisposable, IAsyncDisposable
{
public long Length { get; }

public long Position { get; set; }
}
39 changes: 39 additions & 0 deletions Obsidian.API/_Interfaces/INetStreamReader.cs
Original file line number Diff line number Diff line change
@@ -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();
}
35 changes: 35 additions & 0 deletions Obsidian.API/_Interfaces/INetStreamWriter.cs
Original file line number Diff line number Diff line change
@@ -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();
}
2 changes: 1 addition & 1 deletion Obsidian/Net/MinecraftStream.Reading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Obsidian.Net;

public partial class MinecraftStream
public partial class MinecraftStream : INetStreamReader
{

[ReadMethod]
Expand Down
5 changes: 2 additions & 3 deletions Obsidian/Net/MinecraftStream.Writing.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -26,7 +25,7 @@

namespace Obsidian.Net;

public partial class MinecraftStream
public partial class MinecraftStream : INetStreamWriter
{
[WriteMethod]
public void WriteByte(sbyte value)
Expand Down
Loading