This repository has been archived by the owner on Feb 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add position, angle, array, slot and bytearray data type; release v0.…
…0.1a
- Loading branch information
Showing
32 changed files
with
335 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using fNbt; | ||
|
||
namespace nylium.Core.Inventory { | ||
|
||
public class InventorySlot { | ||
|
||
public int ItemId { get; } | ||
public sbyte Count { get; } | ||
public NbtFile NBT { get; } | ||
|
||
public InventorySlot(int itemId, sbyte count, NbtFile nbt) { | ||
ItemId = itemId; | ||
Count = count; | ||
NBT = nbt; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64;linux-musl-x64;linux-arm;linux-arm64</RuntimeIdentifiers> | ||
<LangVersion>9.0</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CoreFNBT" Version="1.0.9" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace nylium.Networking.DataTypes { | ||
|
||
public class Angle : DataType<double> { | ||
|
||
public Angle() : base(0) { } | ||
public Angle(double value) : base(value) { } | ||
|
||
public override int Read(Stream stream) { | ||
byte[] read = new byte[1]; | ||
int bytesRead = stream.Read(read, 0, 1); | ||
|
||
Value = (360 / 256) * read[0]; | ||
return bytesRead; | ||
} | ||
|
||
public override void Write(Stream stream) { | ||
stream.Write(new byte[1] { (byte) Math.Round((256 / 360) * Value, MidpointRounding.AwayFromZero) }); ; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq.Expressions; | ||
using System.Reflection; | ||
|
||
namespace nylium.Networking.DataTypes { | ||
|
||
public class Array<I, T> : DataType<T[]> where T : DataType<I> { | ||
|
||
private static readonly Func<T> defaultCtor; | ||
|
||
public int Count { get; } | ||
|
||
static Array() { | ||
ConstructorInfo constructor = typeof(T).GetConstructor(new Type[0]); | ||
defaultCtor = Expression.Lambda<Func<T>>(Expression.New(constructor)).Compile(); | ||
} | ||
|
||
public Array(int count) : base(new T[count]) { | ||
Count = count; | ||
} | ||
|
||
public Array(T[] value) : base(value) { | ||
Count = value.Length; | ||
} | ||
|
||
public override int Read(Stream stream) { | ||
int bytesRead = 0; | ||
T[] arr = new T[Count]; | ||
|
||
for(int i = 0; i < Count; i++) { | ||
T t = defaultCtor(); | ||
bytesRead += t.Read(stream); | ||
|
||
arr[i] = t; | ||
} | ||
|
||
return bytesRead; | ||
} | ||
|
||
public override void Write(Stream stream) { | ||
for(int i = 0; i < Count; i++) { | ||
Value[Count].Write(stream); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace nylium.Networking.DataTypes { | ||
|
||
public class ByteArray : DataType<sbyte[]> { | ||
|
||
public int Count { get; } | ||
|
||
public ByteArray(int count) : base(new sbyte[count]) { | ||
Count = count; | ||
} | ||
|
||
public ByteArray(sbyte[] value) : base(value) { } | ||
|
||
public override int Read(Stream stream) { | ||
return stream.Read((byte[]) (Array) Value, 0, Count); | ||
} | ||
|
||
public override void Write(Stream stream) { | ||
stream.Write((byte[]) (Array) Value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.