Skip to content

Commit

Permalink
Expose MinecraftStream (#441)
Browse files Browse the repository at this point in the history
* Create & Implement INetStreamReader & INetStreamWriter

* Add simple stream necessities

* Oops

* Not for steam 😅
  • Loading branch information
Tides authored Jun 24, 2024
1 parent 07538bd commit f69de35
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 4 deletions.
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

0 comments on commit f69de35

Please sign in to comment.