Initial commit
This commit is contained in:
commit
e26e31f432
12
.gitignore
vendored
Normal file
12
.gitignore
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
*.user
|
||||||
|
*.userprefs
|
||||||
|
*.suo
|
||||||
|
*.pidb
|
||||||
|
_ReSharper*/
|
||||||
|
TestResults/
|
||||||
|
*.mdf
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
packages/
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "externals/fNbt"]
|
||||||
|
path = externals/fNbt
|
||||||
|
url = https://github.com/SirCmpwn/fNbt.git
|
7
LICENSE
Normal file
7
LICENSE
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Copyright (c) 2015 Drew DeVault
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
50
README.md
Normal file
50
README.md
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
# TrueCraft
|
||||||
|
|
||||||
|
An open-source implementation of Minecraft Beta 1.7.3 (July 2011).
|
||||||
|
|
||||||
|
## What is TrueCraft
|
||||||
|
|
||||||
|
This is a completely
|
||||||
|
[clean-room](https://en.wikipedia.org/wiki/Clean_room_design) implementation of
|
||||||
|
Minecraft as it appeared in July of 2011. Contributors must verify that they
|
||||||
|
have never read any decompiled Minecraft code before submitting their changes
|
||||||
|
upstream.
|
||||||
|
|
||||||
|
## Why make it?
|
||||||
|
|
||||||
|
(begin opinionated section)
|
||||||
|
|
||||||
|
Minecraft Beta 1.7.3 was the perfect version of Minecraft. Most of what Mojang
|
||||||
|
added afterwards was fluff and, collectively, ruined the game. The goal of this
|
||||||
|
project is to take that perfect version and bring it back to life by effectively
|
||||||
|
forking Minecraft. We want the old spirit of Minecraft back, but actively
|
||||||
|
maintained and with a community that once again may thrive.
|
||||||
|
|
||||||
|
(end opinionated section)
|
||||||
|
|
||||||
|
I got tired of maintaining Craft.Net. I never had time to add features, I was
|
||||||
|
just keeping up the latest updates from Mojang to a game I liked less and less.
|
||||||
|
This project sets the goal in stone - implement Minecraft Beta 1.7.3. It's not a
|
||||||
|
moving target and I don't dislike that version of the game.
|
||||||
|
|
||||||
|
## Status
|
||||||
|
|
||||||
|
This project is very early in development, so don't expect to gain much from it.
|
||||||
|
The server will come first, and then the client. After then, some of the good
|
||||||
|
features from future versions of Minecraft will be implemented (like creative
|
||||||
|
mode, sprinting, etc).
|
||||||
|
|
||||||
|
Note that large-scale refactorings are probably going to be common for a while.
|
||||||
|
Minecraft is not very well designed and it's TrueCraft's responsibility to hide
|
||||||
|
this behind nicer abstractions.
|
||||||
|
|
||||||
|
## Community
|
||||||
|
|
||||||
|
There isn't much of one yet, but this is a sort of spiritual successor to
|
||||||
|
Craft.Net. The folks in #craft.net on Freenode will probably talk to you about
|
||||||
|
this project if you ask nicely.
|
||||||
|
|
||||||
|
## Blah blah blah
|
||||||
|
|
||||||
|
TrueCraft is not associated with Mojang or Minecraft in any sort of official
|
||||||
|
capacity.
|
196
TrueCraft.API/BoundingBox.cs
Normal file
196
TrueCraft.API/BoundingBox.cs
Normal file
@ -0,0 +1,196 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace TrueCraft.API
|
||||||
|
{
|
||||||
|
public enum ContainmentType
|
||||||
|
{
|
||||||
|
Disjoint,
|
||||||
|
Contains,
|
||||||
|
Intersects
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mostly taken from the MonoXna project, which is licensed under the MIT license
|
||||||
|
public struct BoundingBox : IEquatable<BoundingBox>
|
||||||
|
{
|
||||||
|
#region Public Fields
|
||||||
|
|
||||||
|
public Vector3 Min;
|
||||||
|
public Vector3 Max;
|
||||||
|
public const int CornerCount = 8;
|
||||||
|
|
||||||
|
#endregion Public Fields
|
||||||
|
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public BoundingBox(Vector3 min, Vector3 max)
|
||||||
|
{
|
||||||
|
this.Min = min;
|
||||||
|
this.Max = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BoundingBox(BoundingBox b)
|
||||||
|
{
|
||||||
|
this.Min = new Vector3(b.Min);
|
||||||
|
this.Max = new Vector3(b.Max);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public ContainmentType Contains(BoundingBox box)
|
||||||
|
{
|
||||||
|
//test if all corner is in the same side of a face by just checking min and max
|
||||||
|
if (box.Max.X < Min.X
|
||||||
|
|| box.Min.X > Max.X
|
||||||
|
|| box.Max.Y < Min.Y
|
||||||
|
|| box.Min.Y > Max.Y
|
||||||
|
|| box.Max.Z < Min.Z
|
||||||
|
|| box.Min.Z > Max.Z)
|
||||||
|
return ContainmentType.Disjoint;
|
||||||
|
|
||||||
|
|
||||||
|
if (box.Min.X >= Min.X
|
||||||
|
&& box.Max.X <= Max.X
|
||||||
|
&& box.Min.Y >= Min.Y
|
||||||
|
&& box.Max.Y <= Max.Y
|
||||||
|
&& box.Min.Z >= Min.Z
|
||||||
|
&& box.Max.Z <= Max.Z)
|
||||||
|
return ContainmentType.Contains;
|
||||||
|
|
||||||
|
return ContainmentType.Intersects;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Contains(Vector3 vec)
|
||||||
|
{
|
||||||
|
return Min.X <= vec.X && vec.X <= Max.X &&
|
||||||
|
Min.Y <= vec.Y && vec.Y <= Max.Y &&
|
||||||
|
Min.Z <= vec.Z && vec.Z <= Max.Z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BoundingBox CreateFromPoints(IEnumerable<Vector3> points)
|
||||||
|
{
|
||||||
|
if (points == null)
|
||||||
|
throw new ArgumentNullException();
|
||||||
|
|
||||||
|
bool empty = true;
|
||||||
|
Vector3 vector2 = new Vector3(float.MaxValue);
|
||||||
|
Vector3 vector1 = new Vector3(float.MinValue);
|
||||||
|
foreach (Vector3 vector3 in points)
|
||||||
|
{
|
||||||
|
vector2 = Vector3.Min(vector2, vector3);
|
||||||
|
vector1 = Vector3.Max(vector1, vector3);
|
||||||
|
empty = false;
|
||||||
|
}
|
||||||
|
if (empty)
|
||||||
|
throw new ArgumentException();
|
||||||
|
|
||||||
|
return new BoundingBox(vector2, vector1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Offsets this BoundingBox. Does not modify this object, but returns a new one
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// The offset bounding box.
|
||||||
|
/// </returns>
|
||||||
|
/// <param name='Offset'>
|
||||||
|
/// The offset.
|
||||||
|
/// </param>
|
||||||
|
public BoundingBox OffsetBy(Vector3 Offset)
|
||||||
|
{
|
||||||
|
return new BoundingBox(Min + Offset, Max + Offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector3[] GetCorners()
|
||||||
|
{
|
||||||
|
return new Vector3[]
|
||||||
|
{
|
||||||
|
new Vector3(this.Min.X, this.Max.Y, this.Max.Z),
|
||||||
|
new Vector3(this.Max.X, this.Max.Y, this.Max.Z),
|
||||||
|
new Vector3(this.Max.X, this.Min.Y, this.Max.Z),
|
||||||
|
new Vector3(this.Min.X, this.Min.Y, this.Max.Z),
|
||||||
|
new Vector3(this.Min.X, this.Max.Y, this.Min.Z),
|
||||||
|
new Vector3(this.Max.X, this.Max.Y, this.Min.Z),
|
||||||
|
new Vector3(this.Max.X, this.Min.Y, this.Min.Z),
|
||||||
|
new Vector3(this.Min.X, this.Min.Y, this.Min.Z)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals(BoundingBox other)
|
||||||
|
{
|
||||||
|
return (this.Min == other.Min) && (this.Max == other.Max);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
return (obj is BoundingBox) && this.Equals((BoundingBox)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return this.Min.GetHashCode() + this.Max.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Intersects(BoundingBox box)
|
||||||
|
{
|
||||||
|
bool result;
|
||||||
|
Intersects(ref box, out result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Intersects(ref BoundingBox box, out bool result)
|
||||||
|
{
|
||||||
|
if ((this.Max.X >= box.Min.X) && (this.Min.X <= box.Max.X))
|
||||||
|
{
|
||||||
|
if ((this.Max.Y < box.Min.Y) || (this.Min.Y > box.Max.Y))
|
||||||
|
{
|
||||||
|
result = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = (this.Max.Z >= box.Min.Z) && (this.Min.Z <= box.Max.Z);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(BoundingBox a, BoundingBox b)
|
||||||
|
{
|
||||||
|
return a.Equals(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(BoundingBox a, BoundingBox b)
|
||||||
|
{
|
||||||
|
return !a.Equals(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return string.Format("{{Min:{0} Max:{1}}}", this.Min.ToString(), this.Max.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public double Height
|
||||||
|
{
|
||||||
|
get { return Max.Y - Min.Y; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public double Width
|
||||||
|
{
|
||||||
|
get { return Max.X - Min.X; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public double Depth
|
||||||
|
{
|
||||||
|
get { return Max.Z - Min.Z; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
453
TrueCraft.API/Coordinates.cs
Normal file
453
TrueCraft.API/Coordinates.cs
Normal file
@ -0,0 +1,453 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace TrueCraft.API
|
||||||
|
{
|
||||||
|
public struct Coordinates2D : IEquatable<Coordinates2D>
|
||||||
|
{
|
||||||
|
public int X, Z;
|
||||||
|
|
||||||
|
public Coordinates2D(int value)
|
||||||
|
{
|
||||||
|
X = Z = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Coordinates2D(int x, int z)
|
||||||
|
{
|
||||||
|
X = x;
|
||||||
|
Z = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Coordinates2D(Coordinates2D v)
|
||||||
|
{
|
||||||
|
X = v.X;
|
||||||
|
Z = v.Z;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts this Coordinates2D to a string in the format <x, z>.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return string.Format("<{0},{1}>", X, Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Math
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the distance between two Coordinates2D objects.
|
||||||
|
/// </summary>
|
||||||
|
public double DistanceTo(Coordinates2D other)
|
||||||
|
{
|
||||||
|
return Math.Sqrt(Square(other.X - X) +
|
||||||
|
Square(other.Z - Z));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the square of a num.
|
||||||
|
/// </summary>
|
||||||
|
private int Square(int num)
|
||||||
|
{
|
||||||
|
return num * num;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Finds the distance of this Coordinates2D from Coordinates2D.Zero
|
||||||
|
/// </summary>
|
||||||
|
public double Distance
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return DistanceTo(Zero);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates2D Min(Coordinates2D value1, Coordinates2D value2)
|
||||||
|
{
|
||||||
|
return new Coordinates2D(
|
||||||
|
Math.Min(value1.X, value2.X),
|
||||||
|
Math.Min(value1.Z, value2.Z)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates2D Max(Coordinates2D value1, Coordinates2D value2)
|
||||||
|
{
|
||||||
|
return new Coordinates2D(
|
||||||
|
Math.Max(value1.X, value2.X),
|
||||||
|
Math.Max(value1.Z, value2.Z)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Operators
|
||||||
|
|
||||||
|
public static bool operator !=(Coordinates2D a, Coordinates2D b)
|
||||||
|
{
|
||||||
|
return !a.Equals(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(Coordinates2D a, Coordinates2D b)
|
||||||
|
{
|
||||||
|
return a.Equals(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates2D operator +(Coordinates2D a, Coordinates2D b)
|
||||||
|
{
|
||||||
|
return new Coordinates2D(a.X + b.X, a.Z + b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates2D operator -(Coordinates2D a, Coordinates2D b)
|
||||||
|
{
|
||||||
|
return new Coordinates2D(a.X - b.X, a.Z - b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates2D operator -(Coordinates2D a)
|
||||||
|
{
|
||||||
|
return new Coordinates2D(
|
||||||
|
-a.X,
|
||||||
|
-a.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates2D operator *(Coordinates2D a, Coordinates2D b)
|
||||||
|
{
|
||||||
|
return new Coordinates2D(a.X * b.X, a.Z * b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates2D operator /(Coordinates2D a, Coordinates2D b)
|
||||||
|
{
|
||||||
|
return new Coordinates2D(a.X / b.X, a.Z / b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates2D operator %(Coordinates2D a, Coordinates2D b)
|
||||||
|
{
|
||||||
|
return new Coordinates2D(a.X % b.X, a.Z % b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates2D operator +(Coordinates2D a, int b)
|
||||||
|
{
|
||||||
|
return new Coordinates2D(a.X + b, a.Z + b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates2D operator -(Coordinates2D a, int b)
|
||||||
|
{
|
||||||
|
return new Coordinates2D(a.X - b, a.Z - b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates2D operator *(Coordinates2D a, int b)
|
||||||
|
{
|
||||||
|
return new Coordinates2D(a.X * b, a.Z * b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates2D operator /(Coordinates2D a, int b)
|
||||||
|
{
|
||||||
|
return new Coordinates2D(a.X / b, a.Z / b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates2D operator %(Coordinates2D a, int b)
|
||||||
|
{
|
||||||
|
return new Coordinates2D(a.X % b, a.Z % b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates2D operator +(int a, Coordinates2D b)
|
||||||
|
{
|
||||||
|
return new Coordinates2D(a + b.X, a + b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates2D operator -(int a, Coordinates2D b)
|
||||||
|
{
|
||||||
|
return new Coordinates2D(a - b.X, a - b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates2D operator *(int a, Coordinates2D b)
|
||||||
|
{
|
||||||
|
return new Coordinates2D(a * b.X, a * b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates2D operator /(int a, Coordinates2D b)
|
||||||
|
{
|
||||||
|
return new Coordinates2D(a / b.X, a / b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates2D operator %(int a, Coordinates2D b)
|
||||||
|
{
|
||||||
|
return new Coordinates2D(a % b.X, a % b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static explicit operator Coordinates2D(Coordinates3D a)
|
||||||
|
{
|
||||||
|
return new Coordinates2D(a.X, a.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constants
|
||||||
|
|
||||||
|
public static readonly Coordinates2D Zero = new Coordinates2D(0);
|
||||||
|
public static readonly Coordinates2D One = new Coordinates2D(1);
|
||||||
|
|
||||||
|
public static readonly Coordinates2D Forward = new Coordinates2D(0, 1);
|
||||||
|
public static readonly Coordinates2D Backward = new Coordinates2D(0, -1);
|
||||||
|
public static readonly Coordinates2D Left = new Coordinates2D(-1, 0);
|
||||||
|
public static readonly Coordinates2D Right = new Coordinates2D(1, 0);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public bool Equals(Coordinates2D other)
|
||||||
|
{
|
||||||
|
return other.X.Equals(X) && other.Z.Equals(Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(null, obj)) return false;
|
||||||
|
if (obj.GetType() != typeof(Coordinates2D)) return false;
|
||||||
|
return Equals((Coordinates2D)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
int result = X.GetHashCode();
|
||||||
|
result = (result * 397) ^ Z.GetHashCode();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct Coordinates3D : IEquatable<Coordinates3D>
|
||||||
|
{
|
||||||
|
public int X, Y, Z;
|
||||||
|
|
||||||
|
public Coordinates3D(int value)
|
||||||
|
{
|
||||||
|
X = Y = Z = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Coordinates3D(int x, int y, int z)
|
||||||
|
{
|
||||||
|
X = x;
|
||||||
|
Y = y;
|
||||||
|
Z = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Coordinates3D(Coordinates3D v)
|
||||||
|
{
|
||||||
|
X = v.X;
|
||||||
|
Y = v.Y;
|
||||||
|
Z = v.Z;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts this Coordinates3D to a string in the format <x, y, z>.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return string.Format("<{0},{1},{2}>", X, Y, Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Math
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the distance between two Coordinates3D objects.
|
||||||
|
/// </summary>
|
||||||
|
public double DistanceTo(Coordinates3D other)
|
||||||
|
{
|
||||||
|
return Math.Sqrt(Square(other.X - X) +
|
||||||
|
Square(other.Y - Y) +
|
||||||
|
Square(other.Z - Z));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the square of a num.
|
||||||
|
/// </summary>
|
||||||
|
private int Square(int num)
|
||||||
|
{
|
||||||
|
return num * num;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Finds the distance of this Coordinate3D from Coordinates3D.Zero
|
||||||
|
/// </summary>
|
||||||
|
public double Distance
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return DistanceTo(Zero);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates3D Min(Coordinates3D value1, Coordinates3D value2)
|
||||||
|
{
|
||||||
|
return new Coordinates3D(
|
||||||
|
Math.Min(value1.X, value2.X),
|
||||||
|
Math.Min(value1.Y, value2.Y),
|
||||||
|
Math.Min(value1.Z, value2.Z)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates3D Max(Coordinates3D value1, Coordinates3D value2)
|
||||||
|
{
|
||||||
|
return new Coordinates3D(
|
||||||
|
Math.Max(value1.X, value2.X),
|
||||||
|
Math.Max(value1.Y, value2.Y),
|
||||||
|
Math.Max(value1.Z, value2.Z)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Operators
|
||||||
|
|
||||||
|
public static bool operator !=(Coordinates3D a, Coordinates3D b)
|
||||||
|
{
|
||||||
|
return !a.Equals(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(Coordinates3D a, Coordinates3D b)
|
||||||
|
{
|
||||||
|
return a.Equals(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates3D operator +(Coordinates3D a, Coordinates3D b)
|
||||||
|
{
|
||||||
|
return new Coordinates3D(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates3D operator -(Coordinates3D a, Coordinates3D b)
|
||||||
|
{
|
||||||
|
return new Coordinates3D(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates3D operator -(Coordinates3D a)
|
||||||
|
{
|
||||||
|
return new Coordinates3D(-a.X, -a.Y, -a.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates3D operator *(Coordinates3D a, Coordinates3D b)
|
||||||
|
{
|
||||||
|
return new Coordinates3D(a.X * b.X, a.Y * b.Y, a.Z * b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates3D operator /(Coordinates3D a, Coordinates3D b)
|
||||||
|
{
|
||||||
|
return new Coordinates3D(a.X / b.X, a.Y / b.Y, a.Z / b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates3D operator %(Coordinates3D a, Coordinates3D b)
|
||||||
|
{
|
||||||
|
return new Coordinates3D(a.X % b.X, a.Y % b.Y, a.Z % b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates3D operator +(Coordinates3D a, int b)
|
||||||
|
{
|
||||||
|
return new Coordinates3D(a.X + b, a.Y + b, a.Z + b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates3D operator -(Coordinates3D a, int b)
|
||||||
|
{
|
||||||
|
return new Coordinates3D(a.X - b, a.Y - b, a.Z - b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates3D operator *(Coordinates3D a, int b)
|
||||||
|
{
|
||||||
|
return new Coordinates3D(a.X * b, a.Y * b, a.Z * b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates3D operator /(Coordinates3D a, int b)
|
||||||
|
{
|
||||||
|
return new Coordinates3D(a.X / b, a.Y / b, a.Z / b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates3D operator %(Coordinates3D a, int b)
|
||||||
|
{
|
||||||
|
return new Coordinates3D(a.X % b, a.Y % b, a.Z % b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates3D operator +(int a, Coordinates3D b)
|
||||||
|
{
|
||||||
|
return new Coordinates3D(a + b.X, a + b.Y, a + b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates3D operator -(int a, Coordinates3D b)
|
||||||
|
{
|
||||||
|
return new Coordinates3D(a - b.X, a - b.Y, a - b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates3D operator *(int a, Coordinates3D b)
|
||||||
|
{
|
||||||
|
return new Coordinates3D(a * b.X, a * b.Y, a * b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates3D operator /(int a, Coordinates3D b)
|
||||||
|
{
|
||||||
|
return new Coordinates3D(a / b.X, a / b.Y, a / b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Coordinates3D operator %(int a, Coordinates3D b)
|
||||||
|
{
|
||||||
|
return new Coordinates3D(a % b.X, a % b.Y, a % b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static explicit operator Coordinates3D(Coordinates2D a)
|
||||||
|
{
|
||||||
|
return new Coordinates3D(a.X, 0, a.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator Coordinates3D(Vector3 a)
|
||||||
|
{
|
||||||
|
return new Coordinates3D((int)a.X, (int)a.Y, (int)a.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator Vector3(Coordinates3D a)
|
||||||
|
{
|
||||||
|
return new Vector3(a.X, a.Y, a.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constants
|
||||||
|
|
||||||
|
public static readonly Coordinates3D Zero = new Coordinates3D(0);
|
||||||
|
public static readonly Coordinates3D One = new Coordinates3D(1);
|
||||||
|
|
||||||
|
public static readonly Coordinates3D Up = new Coordinates3D(0, 1, 0);
|
||||||
|
public static readonly Coordinates3D Down = new Coordinates3D(0, -1, 0);
|
||||||
|
public static readonly Coordinates3D Left = new Coordinates3D(-1, 0, 0);
|
||||||
|
public static readonly Coordinates3D Right = new Coordinates3D(1, 0, 0);
|
||||||
|
public static readonly Coordinates3D Backwards = new Coordinates3D(0, 0, -1);
|
||||||
|
public static readonly Coordinates3D Forwards = new Coordinates3D(0, 0, 1);
|
||||||
|
|
||||||
|
public static readonly Coordinates3D East = new Coordinates3D(1, 0, 0);
|
||||||
|
public static readonly Coordinates3D West = new Coordinates3D(-1, 0, 0);
|
||||||
|
public static readonly Coordinates3D North = new Coordinates3D(0, 0, -1);
|
||||||
|
public static readonly Coordinates3D South = new Coordinates3D(0, 0, 1);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public bool Equals(Coordinates3D other)
|
||||||
|
{
|
||||||
|
return other.X.Equals(X) && other.Y.Equals(Y) && other.Z.Equals(Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(null, obj)) return false;
|
||||||
|
if (obj.GetType() != typeof(Coordinates3D)) return false;
|
||||||
|
return Equals((Coordinates3D)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
int result = X.GetHashCode();
|
||||||
|
result = (result * 397) ^ Y.GetHashCode();
|
||||||
|
result = (result * 397) ^ Z.GetHashCode();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
12
TrueCraft.API/Difficulty.cs
Normal file
12
TrueCraft.API/Difficulty.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace TrueCraft.API
|
||||||
|
{
|
||||||
|
public enum Difficulty
|
||||||
|
{
|
||||||
|
Peaceful = 0,
|
||||||
|
Easy = 1,
|
||||||
|
Normal = 2,
|
||||||
|
Hard = 3
|
||||||
|
}
|
||||||
|
}
|
10
TrueCraft.API/Dimension.cs
Normal file
10
TrueCraft.API/Dimension.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace TrueCraft.API
|
||||||
|
{
|
||||||
|
public enum Dimension
|
||||||
|
{
|
||||||
|
Nether = -1,
|
||||||
|
Overworld = 0
|
||||||
|
}
|
||||||
|
}
|
10
TrueCraft.API/GameMode.cs
Normal file
10
TrueCraft.API/GameMode.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace TrueCraft.API
|
||||||
|
{
|
||||||
|
public enum GameMode
|
||||||
|
{
|
||||||
|
Survival = 0,
|
||||||
|
Creative = 1
|
||||||
|
}
|
||||||
|
}
|
223
TrueCraft.API/ItemStack.cs
Normal file
223
TrueCraft.API/ItemStack.cs
Normal file
@ -0,0 +1,223 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
|
using fNbt;
|
||||||
|
using fNbt.Serialization;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.API
|
||||||
|
{
|
||||||
|
public struct ItemStack : ICloneable, IEquatable<ItemStack>
|
||||||
|
{
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
int hashCode = _Id.GetHashCode();
|
||||||
|
hashCode = (hashCode * 397) ^ _Count.GetHashCode();
|
||||||
|
hashCode = (hashCode * 397) ^ _Metadata.GetHashCode();
|
||||||
|
hashCode = (hashCode * 397) ^ Index;
|
||||||
|
hashCode = (hashCode * 397) ^ (Nbt != null ? Nbt.GetHashCode() : 0);
|
||||||
|
return hashCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(ItemStack left, ItemStack right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(ItemStack left, ItemStack right)
|
||||||
|
{
|
||||||
|
return !left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack(short id) : this()
|
||||||
|
{
|
||||||
|
_Id = id;
|
||||||
|
_Count = 1;
|
||||||
|
Metadata = 0;
|
||||||
|
Nbt = null;
|
||||||
|
Index = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack(short id, sbyte count) : this(id)
|
||||||
|
{
|
||||||
|
Count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack(short id, sbyte count, short metadata) : this(id, count)
|
||||||
|
{
|
||||||
|
Metadata = metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack(short id, sbyte count, short metadata, NbtCompound nbt) : this(id, count, metadata)
|
||||||
|
{
|
||||||
|
Nbt = nbt;
|
||||||
|
if (Count == 0)
|
||||||
|
{
|
||||||
|
Id = -1;
|
||||||
|
Metadata = 0;
|
||||||
|
Nbt = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack FromStream(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
var slot = ItemStack.EmptyStack;
|
||||||
|
slot.Id = stream.ReadInt16();
|
||||||
|
if (slot.Empty)
|
||||||
|
return slot;
|
||||||
|
slot.Count = stream.ReadInt8();
|
||||||
|
slot.Metadata = stream.ReadInt16();
|
||||||
|
var length = stream.ReadInt16();
|
||||||
|
if (length == -1)
|
||||||
|
return slot;
|
||||||
|
slot.Nbt = new NbtCompound();
|
||||||
|
var buffer = stream.ReadUInt8Array(length);
|
||||||
|
var nbt = new NbtFile();
|
||||||
|
nbt.LoadFromBuffer(buffer, 0, length, NbtCompression.GZip, null);
|
||||||
|
slot.Nbt = nbt.RootTag;
|
||||||
|
return slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteTo(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt16(Id);
|
||||||
|
if (Empty)
|
||||||
|
return;
|
||||||
|
stream.WriteInt8(Count);
|
||||||
|
stream.WriteInt16(Metadata);
|
||||||
|
if (Nbt == null)
|
||||||
|
{
|
||||||
|
stream.WriteInt16(-1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var mStream = new MemoryStream();
|
||||||
|
var file = new NbtFile(Nbt);
|
||||||
|
file.SaveToStream(mStream, NbtCompression.GZip);
|
||||||
|
stream.WriteInt16((short)mStream.Position);
|
||||||
|
stream.WriteUInt8Array(mStream.GetBuffer());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack FromNbt(NbtCompound compound)
|
||||||
|
{
|
||||||
|
var s = ItemStack.EmptyStack;
|
||||||
|
s.Id = compound.Get<NbtShort>("id").Value;
|
||||||
|
s.Metadata = compound.Get<NbtShort>("Damage").Value;
|
||||||
|
s.Count = (sbyte)compound.Get<NbtByte>("Count").Value;
|
||||||
|
s.Index = compound.Get<NbtByte>("Slot").Value;
|
||||||
|
if (compound.Get<NbtCompound>("tag") != null)
|
||||||
|
s.Nbt = compound.Get<NbtCompound>("tag");
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NbtCompound ToNbt()
|
||||||
|
{
|
||||||
|
var c = new NbtCompound();
|
||||||
|
c.Add(new NbtShort("id", Id));
|
||||||
|
c.Add(new NbtShort("Damage", Metadata));
|
||||||
|
c.Add(new NbtByte("Count", (byte)Count));
|
||||||
|
c.Add(new NbtByte("Slot", (byte)Index));
|
||||||
|
if (Nbt != null)
|
||||||
|
c.Add(new NbtCompound("tag"));
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
[NbtIgnore]
|
||||||
|
public bool Empty
|
||||||
|
{
|
||||||
|
get { return Id == -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public short Id
|
||||||
|
{
|
||||||
|
get { return _Id; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_Id = value;
|
||||||
|
if (_Id == -1)
|
||||||
|
{
|
||||||
|
_Count = 0;
|
||||||
|
Metadata = 0;
|
||||||
|
Nbt = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public sbyte Count
|
||||||
|
{
|
||||||
|
get { return _Count; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_Count = value;
|
||||||
|
if (_Count == 0)
|
||||||
|
{
|
||||||
|
_Id = -1;
|
||||||
|
Metadata = 0;
|
||||||
|
Nbt = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public short Metadata
|
||||||
|
{
|
||||||
|
get { return _Metadata; }
|
||||||
|
set { _Metadata = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private short _Id;
|
||||||
|
private sbyte _Count;
|
||||||
|
private short _Metadata;
|
||||||
|
[IgnoreOnNull]
|
||||||
|
public NbtCompound Nbt { get; set; }
|
||||||
|
[NbtIgnore]
|
||||||
|
public int Index;
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
if (Empty)
|
||||||
|
return "(Empty)";
|
||||||
|
string result = "ID: " + Id;
|
||||||
|
if (Count != 1) result += "; Count: " + Count;
|
||||||
|
if (Metadata != 0) result += "; Metadata: " + Metadata;
|
||||||
|
if (Nbt != null) result += Environment.NewLine + Nbt.ToString();
|
||||||
|
return "(" + result + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
public object Clone()
|
||||||
|
{
|
||||||
|
return new ItemStack(Id, Count, Metadata, Nbt);
|
||||||
|
}
|
||||||
|
|
||||||
|
[NbtIgnore]
|
||||||
|
public static ItemStack EmptyStack
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return new ItemStack(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CanMerge(ItemStack other)
|
||||||
|
{
|
||||||
|
if (this.Empty || other.Empty)
|
||||||
|
return true;
|
||||||
|
return _Id == other._Id && _Metadata == other._Metadata && Equals(Nbt, other.Nbt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(null, obj)) return false;
|
||||||
|
return obj is ItemStack && Equals((ItemStack)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals(ItemStack other)
|
||||||
|
{
|
||||||
|
return _Id == other._Id && _Count == other._Count && _Metadata == other._Metadata && Index == other.Index && Equals(Nbt, other.Nbt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
37
TrueCraft.API/MetadataByte.cs
Normal file
37
TrueCraft.API/MetadataByte.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.API
|
||||||
|
{
|
||||||
|
public class MetadataByte : MetadataEntry
|
||||||
|
{
|
||||||
|
public override byte Identifier { get { return 0; } }
|
||||||
|
public override string FriendlyName { get { return "byte"; } }
|
||||||
|
|
||||||
|
public byte Value;
|
||||||
|
|
||||||
|
public static implicit operator MetadataByte(byte value)
|
||||||
|
{
|
||||||
|
return new MetadataByte(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetadataByte()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetadataByte(byte value)
|
||||||
|
{
|
||||||
|
Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void FromStream(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
Value = stream.ReadUInt8();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteTo(IMinecraftStream stream, byte index)
|
||||||
|
{
|
||||||
|
stream.WriteUInt8(GetKey(index));
|
||||||
|
stream.WriteUInt8(Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
89
TrueCraft.API/MetadataDictionary.cs
Normal file
89
TrueCraft.API/MetadataDictionary.cs
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.API
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Used to send metadata with entities
|
||||||
|
/// </summary>
|
||||||
|
public class MetadataDictionary
|
||||||
|
{
|
||||||
|
private readonly Dictionary<byte, MetadataEntry> entries;
|
||||||
|
|
||||||
|
public MetadataDictionary()
|
||||||
|
{
|
||||||
|
entries = new Dictionary<byte, MetadataEntry>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Count
|
||||||
|
{
|
||||||
|
get { return entries.Count; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetadataEntry this[byte index]
|
||||||
|
{
|
||||||
|
get { return entries[index]; }
|
||||||
|
set { entries[index] = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MetadataDictionary FromStream(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
var value = new MetadataDictionary();
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
byte key = stream.ReadUInt8();
|
||||||
|
if (key == 127) break;
|
||||||
|
|
||||||
|
byte type = (byte)((key & 0xE0) >> 5);
|
||||||
|
byte index = (byte)(key & 0x1F);
|
||||||
|
|
||||||
|
var entry = EntryTypes[type]();
|
||||||
|
entry.FromStream(stream);
|
||||||
|
entry.Index = index;
|
||||||
|
|
||||||
|
value[index] = entry;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteTo(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
foreach (var entry in entries)
|
||||||
|
entry.Value.WriteTo(stream, entry.Key);
|
||||||
|
stream.WriteUInt8(0x7F);
|
||||||
|
}
|
||||||
|
|
||||||
|
delegate MetadataEntry CreateEntryInstance();
|
||||||
|
|
||||||
|
private static readonly CreateEntryInstance[] EntryTypes = new CreateEntryInstance[]
|
||||||
|
{
|
||||||
|
() => new MetadataByte(), // 0
|
||||||
|
() => new MetadataShort(), // 1
|
||||||
|
() => new MetadataInt(), // 2
|
||||||
|
() => new MetadataFloat(), // 3
|
||||||
|
() => new MetadataString(), // 4
|
||||||
|
() => new MetadataSlot(), // 5
|
||||||
|
};
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
System.Text.StringBuilder sb = null;
|
||||||
|
|
||||||
|
foreach (var entry in entries.Values)
|
||||||
|
{
|
||||||
|
if (sb != null)
|
||||||
|
sb.Append(", ");
|
||||||
|
else
|
||||||
|
sb = new System.Text.StringBuilder();
|
||||||
|
|
||||||
|
sb.Append(entry.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sb != null)
|
||||||
|
return sb.ToString();
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
63
TrueCraft.API/MetadataEntry.cs
Normal file
63
TrueCraft.API/MetadataEntry.cs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.API
|
||||||
|
{
|
||||||
|
public abstract class MetadataEntry
|
||||||
|
{
|
||||||
|
public abstract byte Identifier { get; }
|
||||||
|
public abstract string FriendlyName { get; }
|
||||||
|
|
||||||
|
public abstract void FromStream(IMinecraftStream stream);
|
||||||
|
public abstract void WriteTo(IMinecraftStream stream, byte index);
|
||||||
|
|
||||||
|
internal byte Index { get; set; }
|
||||||
|
|
||||||
|
public static implicit operator MetadataEntry(byte value)
|
||||||
|
{
|
||||||
|
return new MetadataByte(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator MetadataEntry(short value)
|
||||||
|
{
|
||||||
|
return new MetadataShort(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator MetadataEntry(int value)
|
||||||
|
{
|
||||||
|
return new MetadataInt(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator MetadataEntry(float value)
|
||||||
|
{
|
||||||
|
return new MetadataFloat(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator MetadataEntry(string value)
|
||||||
|
{
|
||||||
|
return new MetadataString(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator MetadataEntry(ItemStack value)
|
||||||
|
{
|
||||||
|
return new MetadataSlot(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected byte GetKey(byte index)
|
||||||
|
{
|
||||||
|
Index = index; // Cheat to get this for ToString
|
||||||
|
return (byte)((Identifier << 5) | (index & 0x1F));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
Type type = GetType();
|
||||||
|
FieldInfo[] fields = type.GetFields();
|
||||||
|
string result = FriendlyName + "[" + Index + "]: ";
|
||||||
|
if (fields.Length != 0)
|
||||||
|
result += fields[0].GetValue(this).ToString();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
TrueCraft.API/MetadataFloat.cs
Normal file
38
TrueCraft.API/MetadataFloat.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.API
|
||||||
|
{
|
||||||
|
public class MetadataFloat : MetadataEntry
|
||||||
|
{
|
||||||
|
public override byte Identifier { get { return 3; } }
|
||||||
|
public override string FriendlyName { get { return "float"; } }
|
||||||
|
|
||||||
|
public float Value;
|
||||||
|
|
||||||
|
public static implicit operator MetadataFloat(float value)
|
||||||
|
{
|
||||||
|
return new MetadataFloat(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetadataFloat()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetadataFloat(float value)
|
||||||
|
{
|
||||||
|
Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void FromStream(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
Value = stream.ReadSingle();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteTo(IMinecraftStream stream, byte index)
|
||||||
|
{
|
||||||
|
stream.WriteUInt8(GetKey(index));
|
||||||
|
stream.WriteSingle(Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
TrueCraft.API/MetadataInt.cs
Normal file
38
TrueCraft.API/MetadataInt.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.API
|
||||||
|
{
|
||||||
|
public class MetadataInt : MetadataEntry
|
||||||
|
{
|
||||||
|
public override byte Identifier { get { return 2; } }
|
||||||
|
public override string FriendlyName { get { return "int"; } }
|
||||||
|
|
||||||
|
public int Value;
|
||||||
|
|
||||||
|
public static implicit operator MetadataInt(int value)
|
||||||
|
{
|
||||||
|
return new MetadataInt(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetadataInt()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetadataInt(int value)
|
||||||
|
{
|
||||||
|
Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void FromStream(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
Value = stream.ReadInt32();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteTo(IMinecraftStream stream, byte index)
|
||||||
|
{
|
||||||
|
stream.WriteUInt8(GetKey(index));
|
||||||
|
stream.WriteInt32(Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
TrueCraft.API/MetadataShort.cs
Normal file
38
TrueCraft.API/MetadataShort.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.API
|
||||||
|
{
|
||||||
|
public class MetadataShort : MetadataEntry
|
||||||
|
{
|
||||||
|
public override byte Identifier { get { return 1; } }
|
||||||
|
public override string FriendlyName { get { return "short"; } }
|
||||||
|
|
||||||
|
public short Value;
|
||||||
|
|
||||||
|
public static implicit operator MetadataShort(short value)
|
||||||
|
{
|
||||||
|
return new MetadataShort(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetadataShort()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetadataShort(short value)
|
||||||
|
{
|
||||||
|
Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void FromStream(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
Value = stream.ReadInt16();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteTo(IMinecraftStream stream, byte index)
|
||||||
|
{
|
||||||
|
stream.WriteUInt8(GetKey(index));
|
||||||
|
stream.WriteInt16(Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
54
TrueCraft.API/MetadataSlot.cs
Normal file
54
TrueCraft.API/MetadataSlot.cs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using fNbt;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.API
|
||||||
|
{
|
||||||
|
public class MetadataSlot : MetadataEntry
|
||||||
|
{
|
||||||
|
public override byte Identifier { get { return 5; } }
|
||||||
|
public override string FriendlyName { get { return "slot"; } }
|
||||||
|
|
||||||
|
public ItemStack Value;
|
||||||
|
|
||||||
|
public static implicit operator MetadataSlot(ItemStack value)
|
||||||
|
{
|
||||||
|
return new MetadataSlot(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetadataSlot()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetadataSlot(ItemStack value)
|
||||||
|
{
|
||||||
|
Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void FromStream(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
Value = ItemStack.FromStream(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteTo(IMinecraftStream stream, byte index)
|
||||||
|
{
|
||||||
|
stream.WriteUInt8(GetKey(index));
|
||||||
|
stream.WriteInt16(Value.Id);
|
||||||
|
if (Value.Id != -1)
|
||||||
|
{
|
||||||
|
stream.WriteInt8(Value.Count);
|
||||||
|
stream.WriteInt16(Value.Metadata);
|
||||||
|
if (Value.Nbt != null)
|
||||||
|
{
|
||||||
|
var file = new NbtFile(Value.Nbt);
|
||||||
|
var data = file.SaveToBuffer(NbtCompression.GZip);
|
||||||
|
stream.WriteInt16((short)data.Length);
|
||||||
|
stream.WriteUInt8Array(data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
stream.WriteInt16(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
43
TrueCraft.API/MetadataString.cs
Normal file
43
TrueCraft.API/MetadataString.cs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.API
|
||||||
|
{
|
||||||
|
public class MetadataString : MetadataEntry
|
||||||
|
{
|
||||||
|
public override byte Identifier { get { return 4; } }
|
||||||
|
public override string FriendlyName { get { return "string"; } }
|
||||||
|
|
||||||
|
public string Value;
|
||||||
|
|
||||||
|
public static implicit operator MetadataString(string value)
|
||||||
|
{
|
||||||
|
return new MetadataString(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetadataString()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetadataString(string value)
|
||||||
|
{
|
||||||
|
if (value.Length > 16)
|
||||||
|
throw new ArgumentOutOfRangeException("value", "Maximum string length is 16 characters");
|
||||||
|
while (value.Length < 16)
|
||||||
|
value = value + "\0";
|
||||||
|
Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void FromStream(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
Value = stream.ReadString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteTo(IMinecraftStream stream, byte index)
|
||||||
|
{
|
||||||
|
stream.WriteUInt8(GetKey(index));
|
||||||
|
stream.WriteString(Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
TrueCraft.API/Networking/IMinecraftStream.cs
Normal file
60
TrueCraft.API/Networking/IMinecraftStream.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace TrueCraft.API.Networking
|
||||||
|
{
|
||||||
|
public interface IMinecraftStream
|
||||||
|
{
|
||||||
|
byte ReadUInt8();
|
||||||
|
sbyte ReadInt8();
|
||||||
|
void WriteUInt8(byte value);
|
||||||
|
void WriteInt8(sbyte value);
|
||||||
|
|
||||||
|
ushort ReadUInt16();
|
||||||
|
short ReadInt16();
|
||||||
|
void WriteUInt16(ushort value);
|
||||||
|
void WriteInt16(short value);
|
||||||
|
|
||||||
|
uint ReadUInt32();
|
||||||
|
int ReadInt32();
|
||||||
|
void WriteUInt32(uint value);
|
||||||
|
void WriteInt32(int value);
|
||||||
|
|
||||||
|
ulong ReadUInt64();
|
||||||
|
long ReadInt64();
|
||||||
|
void WriteUInt64(ulong value);
|
||||||
|
void WriteInt64(long value);
|
||||||
|
|
||||||
|
float ReadSingle();
|
||||||
|
void WriteSingle(float value);
|
||||||
|
|
||||||
|
double ReadDouble();
|
||||||
|
void WriteDouble(double value);
|
||||||
|
|
||||||
|
string ReadString();
|
||||||
|
void WriteString(string value);
|
||||||
|
|
||||||
|
bool ReadBoolean();
|
||||||
|
void WriteBoolean(bool value);
|
||||||
|
|
||||||
|
byte[] ReadUInt8Array(int length);
|
||||||
|
void WriteUInt8Array(byte[] value);
|
||||||
|
sbyte[] ReadInt8Array(int length);
|
||||||
|
void WriteInt8Array(sbyte[] value);
|
||||||
|
|
||||||
|
ushort[] ReadUInt16Array(int length);
|
||||||
|
void WriteUInt16Array(ushort[] value);
|
||||||
|
short[] ReadInt16Array(int length);
|
||||||
|
void WriteInt16Array(short[] value);
|
||||||
|
|
||||||
|
uint[] ReadUInt32Array(int length);
|
||||||
|
void WriteUInt32Array(uint[] value);
|
||||||
|
int[] ReadInt32Array(int length);
|
||||||
|
void WriteInt32Array(int[] value);
|
||||||
|
|
||||||
|
ulong[] ReadUInt64Array(int length);
|
||||||
|
void WriteUInt64Array(ulong[] value);
|
||||||
|
long[] ReadInt64Array(int length);
|
||||||
|
void WriteInt64Array(long[] value);
|
||||||
|
}
|
||||||
|
}
|
11
TrueCraft.API/Networking/IPacket.cs
Normal file
11
TrueCraft.API/Networking/IPacket.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace TrueCraft.API.Networking
|
||||||
|
{
|
||||||
|
public interface IPacket
|
||||||
|
{
|
||||||
|
byte ID { get; }
|
||||||
|
void ReadPacket(IMinecraftStream stream);
|
||||||
|
void WritePacket(IMinecraftStream stream);
|
||||||
|
}
|
||||||
|
}
|
11
TrueCraft.API/Networking/IPacketReader.cs
Normal file
11
TrueCraft.API/Networking/IPacketReader.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace TrueCraft.API.Networking
|
||||||
|
{
|
||||||
|
public interface IPacketReader
|
||||||
|
{
|
||||||
|
void RegisterPacketType<T>(bool clientbound = true, bool serverbound = true) where T : IPacket;
|
||||||
|
IPacket ReadPacket(IMinecraftStream stream, bool serverbound = true);
|
||||||
|
void WritePacket(IMinecraftStream stream, IPacket packet);
|
||||||
|
}
|
||||||
|
}
|
12
TrueCraft.API/Networking/IRemoteClient.cs
Normal file
12
TrueCraft.API/Networking/IRemoteClient.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace TrueCraft.API.Networking
|
||||||
|
{
|
||||||
|
public interface IRemoteClient
|
||||||
|
{
|
||||||
|
IMinecraftStream MinecraftStream { get; }
|
||||||
|
bool DataAvailable { get; }
|
||||||
|
|
||||||
|
void QueuePacket(IPacket packet);
|
||||||
|
}
|
||||||
|
}
|
27
TrueCraft.API/Properties/AssemblyInfo.cs
Normal file
27
TrueCraft.API/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
// Information about this assembly is defined by the following attributes.
|
||||||
|
// Change them to the values specific to your project.
|
||||||
|
|
||||||
|
[assembly: AssemblyTitle("TrueCraft.API")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("")]
|
||||||
|
[assembly: AssemblyCopyright("sircmpwn")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||||
|
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||||
|
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||||
|
|
||||||
|
[assembly: AssemblyVersion("1.0.*")]
|
||||||
|
|
||||||
|
// The following attributes are used to specify the signing key for the assembly,
|
||||||
|
// if desired. See the Mono documentation for more information about signing.
|
||||||
|
|
||||||
|
//[assembly: AssemblyDelaySign(false)]
|
||||||
|
//[assembly: AssemblyKeyFile("")]
|
||||||
|
|
139
TrueCraft.API/Ray.cs
Normal file
139
TrueCraft.API/Ray.cs
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace TrueCraft.API
|
||||||
|
{
|
||||||
|
// Mostly taken from the MonoXna project, which is licensed under the MIT license
|
||||||
|
public struct Ray : IEquatable<Ray>
|
||||||
|
{
|
||||||
|
#region Public Fields
|
||||||
|
|
||||||
|
public readonly Vector3 Direction;
|
||||||
|
public readonly Vector3 Position;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public Ray(Vector3 position, Vector3 direction)
|
||||||
|
{
|
||||||
|
this.Position = position;
|
||||||
|
this.Direction = direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
return (obj is Ray) && Equals((Ray)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public bool Equals(Ray other)
|
||||||
|
{
|
||||||
|
return Position.Equals(other.Position) && Direction.Equals(other.Direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return Position.GetHashCode() ^ Direction.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double? Intersects(BoundingBox box)
|
||||||
|
{
|
||||||
|
//first test if start in box
|
||||||
|
if (Position.X >= box.Min.X
|
||||||
|
&& Position.X <= box.Max.X
|
||||||
|
&& Position.Y >= box.Min.Y
|
||||||
|
&& Position.Y <= box.Max.Y
|
||||||
|
&& Position.Z >= box.Min.Z
|
||||||
|
&& Position.Z <= box.Max.Z)
|
||||||
|
return 0.0f;// here we concidere cube is full and origine is in cube so intersect at origine
|
||||||
|
|
||||||
|
//Second we check each face
|
||||||
|
Vector3 maxT = new Vector3(-1.0f);
|
||||||
|
//Vector3 minT = new Vector3(-1.0f);
|
||||||
|
//calcul intersection with each faces
|
||||||
|
if (Position.X < box.Min.X && Direction.X != 0.0f)
|
||||||
|
maxT.X = (box.Min.X - Position.X) / Direction.X;
|
||||||
|
else if (Position.X > box.Max.X && Direction.X != 0.0f)
|
||||||
|
maxT.X = (box.Max.X - Position.X) / Direction.X;
|
||||||
|
if (Position.Y < box.Min.Y && Direction.Y != 0.0f)
|
||||||
|
maxT.Y = (box.Min.Y - Position.Y) / Direction.Y;
|
||||||
|
else if (Position.Y > box.Max.Y && Direction.Y != 0.0f)
|
||||||
|
maxT.Y = (box.Max.Y - Position.Y) / Direction.Y;
|
||||||
|
if (Position.Z < box.Min.Z && Direction.Z != 0.0f)
|
||||||
|
maxT.Z = (box.Min.Z - Position.Z) / Direction.Z;
|
||||||
|
else if (Position.Z > box.Max.Z && Direction.Z != 0.0f)
|
||||||
|
maxT.Z = (box.Max.Z - Position.Z) / Direction.Z;
|
||||||
|
|
||||||
|
//get the maximum maxT
|
||||||
|
if (maxT.X > maxT.Y && maxT.X > maxT.Z)
|
||||||
|
{
|
||||||
|
if (maxT.X < 0.0f)
|
||||||
|
return null;// ray go on opposite of face
|
||||||
|
//coordonate of hit point of face of cube
|
||||||
|
double coord = Position.Z + maxT.X * Direction.Z;
|
||||||
|
// if hit point coord ( intersect face with ray) is out of other plane coord it miss
|
||||||
|
if (coord < box.Min.Z || coord > box.Max.Z)
|
||||||
|
return null;
|
||||||
|
coord = Position.Y + maxT.X * Direction.Y;
|
||||||
|
if (coord < box.Min.Y || coord > box.Max.Y)
|
||||||
|
return null;
|
||||||
|
return maxT.X;
|
||||||
|
}
|
||||||
|
if (maxT.Y > maxT.X && maxT.Y > maxT.Z)
|
||||||
|
{
|
||||||
|
if (maxT.Y < 0.0f)
|
||||||
|
return null;// ray go on opposite of face
|
||||||
|
//coordonate of hit point of face of cube
|
||||||
|
double coord = Position.Z + maxT.Y * Direction.Z;
|
||||||
|
// if hit point coord ( intersect face with ray) is out of other plane coord it miss
|
||||||
|
if (coord < box.Min.Z || coord > box.Max.Z)
|
||||||
|
return null;
|
||||||
|
coord = Position.X + maxT.Y * Direction.X;
|
||||||
|
if (coord < box.Min.X || coord > box.Max.X)
|
||||||
|
return null;
|
||||||
|
return maxT.Y;
|
||||||
|
}
|
||||||
|
else //Z
|
||||||
|
{
|
||||||
|
if (maxT.Z < 0.0f)
|
||||||
|
return null;// ray go on opposite of face
|
||||||
|
//coordonate of hit point of face of cube
|
||||||
|
double coord = Position.X + maxT.Z * Direction.X;
|
||||||
|
// if hit point coord ( intersect face with ray) is out of other plane coord it miss
|
||||||
|
if (coord < box.Min.X || coord > box.Max.X)
|
||||||
|
return null;
|
||||||
|
coord = Position.Y + maxT.Z * Direction.Y;
|
||||||
|
if (coord < box.Min.Y || coord > box.Max.Y)
|
||||||
|
return null;
|
||||||
|
return maxT.Z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(Ray a, Ray b)
|
||||||
|
{
|
||||||
|
return !a.Equals(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(Ray a, Ray b)
|
||||||
|
{
|
||||||
|
return a.Equals(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return string.Format("{{Position:{0} Direction:{1}}}", Position.ToString(), Direction.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
22
TrueCraft.API/Server/IMultiplayerServer.cs
Normal file
22
TrueCraft.API/Server/IMultiplayerServer.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
using System.Net;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace TrueCraft.API.Server
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the given packet comes in from a remote client. Return false to cease communication
|
||||||
|
/// with that client.
|
||||||
|
/// </summary>
|
||||||
|
public delegate void PacketHandler(IPacket packet, IRemoteClient client, IMultiplayerServer server);
|
||||||
|
|
||||||
|
public interface IMultiplayerServer
|
||||||
|
{
|
||||||
|
IPacketReader PacketReader { get; }
|
||||||
|
IList<IRemoteClient> Clients { get; }
|
||||||
|
|
||||||
|
void Start(IPEndPoint endPoint);
|
||||||
|
void RegisterPacketHandler(byte packetId, PacketHandler handler);
|
||||||
|
}
|
||||||
|
}
|
32
TrueCraft.API/Size.cs
Normal file
32
TrueCraft.API/Size.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
namespace TrueCraft.API
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the size of an object in 3D space.
|
||||||
|
/// </summary>
|
||||||
|
public struct Size
|
||||||
|
{
|
||||||
|
public double Depth;
|
||||||
|
public double Height;
|
||||||
|
public double Width;
|
||||||
|
|
||||||
|
public Size(double width, double height, double depth)
|
||||||
|
{
|
||||||
|
this.Width = width;
|
||||||
|
this.Height = height;
|
||||||
|
this.Depth = depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Size(Size s)
|
||||||
|
{
|
||||||
|
this.Width = s.Width;
|
||||||
|
this.Height = s.Height;
|
||||||
|
this.Depth = s.Depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: More operators
|
||||||
|
public static Size operator /(Size a, double b)
|
||||||
|
{
|
||||||
|
return new Size(a.Width / b, a.Height / b, a.Depth / b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
68
TrueCraft.API/TrueCraft.API.csproj
Normal file
68
TrueCraft.API/TrueCraft.API.csproj
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{FEE55B54-91B0-4325-A2C3-D576C0B7A81F}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<RootNamespace>TrueCraft.API</RootNamespace>
|
||||||
|
<AssemblyName>TrueCraft.API</AssemblyName>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<ConsolePause>false</ConsolePause>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release</OutputPath>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<ConsolePause>false</ConsolePause>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Networking\IPacket.cs" />
|
||||||
|
<Compile Include="Networking\IPacketReader.cs" />
|
||||||
|
<Compile Include="Networking\IMinecraftStream.cs" />
|
||||||
|
<Compile Include="GameMode.cs" />
|
||||||
|
<Compile Include="Difficulty.cs" />
|
||||||
|
<Compile Include="Dimension.cs" />
|
||||||
|
<Compile Include="BoundingBox.cs" />
|
||||||
|
<Compile Include="Coordinates.cs" />
|
||||||
|
<Compile Include="ItemStack.cs" />
|
||||||
|
<Compile Include="MetadataByte.cs" />
|
||||||
|
<Compile Include="MetadataDictionary.cs" />
|
||||||
|
<Compile Include="MetadataEntry.cs" />
|
||||||
|
<Compile Include="MetadataFloat.cs" />
|
||||||
|
<Compile Include="MetadataInt.cs" />
|
||||||
|
<Compile Include="MetadataShort.cs" />
|
||||||
|
<Compile Include="MetadataSlot.cs" />
|
||||||
|
<Compile Include="MetadataString.cs" />
|
||||||
|
<Compile Include="Ray.cs" />
|
||||||
|
<Compile Include="Size.cs" />
|
||||||
|
<Compile Include="Vector3.cs" />
|
||||||
|
<Compile Include="Server\IMultiplayerServer.cs" />
|
||||||
|
<Compile Include="Networking\IRemoteClient.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Networking\" />
|
||||||
|
<Folder Include="Server\" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\externals\fNbt\fNbt\fNbt.csproj">
|
||||||
|
<Project>{4488498D-976D-4DA3-BF72-109531AF0488}</Project>
|
||||||
|
<Name>fNbt</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
297
TrueCraft.API/Vector3.cs
Normal file
297
TrueCraft.API/Vector3.cs
Normal file
@ -0,0 +1,297 @@
|
|||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace TrueCraft.API
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the location of an object in 3D space.
|
||||||
|
/// </summary>
|
||||||
|
[StructLayout(LayoutKind.Explicit)]
|
||||||
|
public struct Vector3 : IEquatable<Vector3>
|
||||||
|
{
|
||||||
|
[FieldOffset(0)]
|
||||||
|
public double X;
|
||||||
|
[FieldOffset(8)]
|
||||||
|
public double Y;
|
||||||
|
[FieldOffset(16)]
|
||||||
|
public double Z;
|
||||||
|
|
||||||
|
public Vector3(double value)
|
||||||
|
{
|
||||||
|
X = Y = Z = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector3(double x, double y, double z)
|
||||||
|
{
|
||||||
|
X = x;
|
||||||
|
Y = y;
|
||||||
|
Z = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector3(Vector3 v)
|
||||||
|
{
|
||||||
|
X = v.X;
|
||||||
|
Y = v.Y;
|
||||||
|
Z = v.Z;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts this Vector3 to a string in the format <x, y, z>.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return string.Format("<{0},{1},{2}>", X, Y, Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Math
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Truncates the decimal component of each part of this Vector3.
|
||||||
|
/// </summary>
|
||||||
|
public Vector3 Floor()
|
||||||
|
{
|
||||||
|
return new Vector3(Math.Floor(X), Math.Floor(Y), Math.Floor(Z));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the distance between two Vector3 objects.
|
||||||
|
/// </summary>
|
||||||
|
public double DistanceTo(Vector3 other)
|
||||||
|
{
|
||||||
|
return Math.Sqrt(Square(other.X - X) +
|
||||||
|
Square(other.Y - Y) +
|
||||||
|
Square(other.Z - Z));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the square of a num.
|
||||||
|
/// </summary>
|
||||||
|
private double Square(double num)
|
||||||
|
{
|
||||||
|
return num * num;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Finds the distance of this vector from Vector3.Zero
|
||||||
|
/// </summary>
|
||||||
|
public double Distance
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return DistanceTo(Zero);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 Min(Vector3 value1, Vector3 value2)
|
||||||
|
{
|
||||||
|
return new Vector3(
|
||||||
|
Math.Min(value1.X, value2.X),
|
||||||
|
Math.Min(value1.Y, value2.Y),
|
||||||
|
Math.Min(value1.Z, value2.Z)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 Max(Vector3 value1, Vector3 value2)
|
||||||
|
{
|
||||||
|
return new Vector3(
|
||||||
|
Math.Max(value1.X, value2.X),
|
||||||
|
Math.Max(value1.Y, value2.Y),
|
||||||
|
Math.Max(value1.Z, value2.Z)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Operators
|
||||||
|
|
||||||
|
public static bool operator !=(Vector3 a, Vector3 b)
|
||||||
|
{
|
||||||
|
return !a.Equals(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(Vector3 a, Vector3 b)
|
||||||
|
{
|
||||||
|
return a.Equals(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 operator +(Vector3 a, Vector3 b)
|
||||||
|
{
|
||||||
|
return new Vector3(
|
||||||
|
a.X + b.X,
|
||||||
|
a.Y + b.Y,
|
||||||
|
a.Z + b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 operator -(Vector3 a, Vector3 b)
|
||||||
|
{
|
||||||
|
return new Vector3(
|
||||||
|
a.X - b.X,
|
||||||
|
a.Y - b.Y,
|
||||||
|
a.Z - b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 operator +(Vector3 a, Size b)
|
||||||
|
{
|
||||||
|
return new Vector3(
|
||||||
|
a.X + b.Width,
|
||||||
|
a.Y + b.Height,
|
||||||
|
a.Z + b.Depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 operator -(Vector3 a, Size b)
|
||||||
|
{
|
||||||
|
return new Vector3(
|
||||||
|
a.X - b.Width,
|
||||||
|
a.Y - b.Height,
|
||||||
|
a.Z - b.Depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 operator -(Vector3 a)
|
||||||
|
{
|
||||||
|
return new Vector3(
|
||||||
|
-a.X,
|
||||||
|
-a.Y,
|
||||||
|
-a.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 operator *(Vector3 a, Vector3 b)
|
||||||
|
{
|
||||||
|
return new Vector3(
|
||||||
|
a.X * b.X,
|
||||||
|
a.Y * b.Y,
|
||||||
|
a.Z * b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 operator /(Vector3 a, Vector3 b)
|
||||||
|
{
|
||||||
|
return new Vector3(
|
||||||
|
a.X / b.X,
|
||||||
|
a.Y / b.Y,
|
||||||
|
a.Z / b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 operator %(Vector3 a, Vector3 b)
|
||||||
|
{
|
||||||
|
return new Vector3(a.X % b.X, a.Y % b.Y, a.Z % b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 operator +(Vector3 a, double b)
|
||||||
|
{
|
||||||
|
return new Vector3(
|
||||||
|
a.X + b,
|
||||||
|
a.Y + b,
|
||||||
|
a.Z + b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 operator -(Vector3 a, double b)
|
||||||
|
{
|
||||||
|
return new Vector3(
|
||||||
|
a.X - b,
|
||||||
|
a.Y - b,
|
||||||
|
a.Z - b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 operator *(Vector3 a, double b)
|
||||||
|
{
|
||||||
|
return new Vector3(
|
||||||
|
a.X * b,
|
||||||
|
a.Y * b,
|
||||||
|
a.Z * b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 operator /(Vector3 a, double b)
|
||||||
|
{
|
||||||
|
return new Vector3(
|
||||||
|
a.X / b,
|
||||||
|
a.Y / b,
|
||||||
|
a.Z / b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 operator %(Vector3 a, double b)
|
||||||
|
{
|
||||||
|
return new Vector3(a.X % b, a.Y % b, a.Y % b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 operator +(double a, Vector3 b)
|
||||||
|
{
|
||||||
|
return new Vector3(
|
||||||
|
a + b.X,
|
||||||
|
a + b.Y,
|
||||||
|
a + b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 operator -(double a, Vector3 b)
|
||||||
|
{
|
||||||
|
return new Vector3(
|
||||||
|
a - b.X,
|
||||||
|
a - b.Y,
|
||||||
|
a - b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 operator *(double a, Vector3 b)
|
||||||
|
{
|
||||||
|
return new Vector3(
|
||||||
|
a * b.X,
|
||||||
|
a * b.Y,
|
||||||
|
a * b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 operator /(double a, Vector3 b)
|
||||||
|
{
|
||||||
|
return new Vector3(
|
||||||
|
a / b.X,
|
||||||
|
a / b.Y,
|
||||||
|
a / b.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 operator %(double a, Vector3 b)
|
||||||
|
{
|
||||||
|
return new Vector3(a % b.X, a % b.Y, a % b.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constants
|
||||||
|
|
||||||
|
public static readonly Vector3 Zero = new Vector3(0);
|
||||||
|
public static readonly Vector3 One = new Vector3(1);
|
||||||
|
|
||||||
|
public static readonly Vector3 Up = new Vector3(0, 1, 0);
|
||||||
|
public static readonly Vector3 Down = new Vector3(0, -1, 0);
|
||||||
|
public static readonly Vector3 Left = new Vector3(-1, 0, 0);
|
||||||
|
public static readonly Vector3 Right = new Vector3(1, 0, 0);
|
||||||
|
public static readonly Vector3 Backwards = new Vector3(0, 0, -1);
|
||||||
|
public static readonly Vector3 Forwards = new Vector3(0, 0, 1);
|
||||||
|
|
||||||
|
public static readonly Vector3 East = new Vector3(1, 0, 0);
|
||||||
|
public static readonly Vector3 West = new Vector3(-1, 0, 0);
|
||||||
|
public static readonly Vector3 North = new Vector3(0, 0, -1);
|
||||||
|
public static readonly Vector3 South = new Vector3(0, 0, 1);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public bool Equals(Vector3 other)
|
||||||
|
{
|
||||||
|
return other.X.Equals(X) && other.Y.Equals(Y) && other.Z.Equals(Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(null, obj)) return false;
|
||||||
|
if (obj.GetType() != typeof(Vector3)) return false;
|
||||||
|
return Equals((Vector3)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
int result = X.GetHashCode();
|
||||||
|
result = (result * 397) ^ Y.GetHashCode();
|
||||||
|
result = (result * 397) ^ Z.GetHashCode();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
350
TrueCraft.Core/Networking/MinecraftStream.cs
Normal file
350
TrueCraft.Core/Networking/MinecraftStream.cs
Normal file
@ -0,0 +1,350 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking
|
||||||
|
{
|
||||||
|
public class MinecraftStream : Stream, IMinecraftStream
|
||||||
|
{
|
||||||
|
public Stream BaseStream { get; set; }
|
||||||
|
public Encoding StringEncoding { get; set; }
|
||||||
|
|
||||||
|
public MinecraftStream(Stream baseStream)
|
||||||
|
{
|
||||||
|
BaseStream = baseStream;
|
||||||
|
StringEncoding = Encoding.BigEndianUnicode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanRead { get { return BaseStream.CanRead; } }
|
||||||
|
|
||||||
|
public override bool CanSeek { get { return BaseStream.CanSeek; } }
|
||||||
|
|
||||||
|
public override bool CanWrite { get { return BaseStream.CanWrite; } }
|
||||||
|
|
||||||
|
public override void Flush()
|
||||||
|
{
|
||||||
|
BaseStream.Flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override long Length
|
||||||
|
{
|
||||||
|
get { return BaseStream.Length; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override long Position
|
||||||
|
{
|
||||||
|
get { return BaseStream.Position; }
|
||||||
|
set { BaseStream.Position = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int Read(byte[] buffer, int offset, int count)
|
||||||
|
{
|
||||||
|
return BaseStream.Read(buffer, offset, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override long Seek(long offset, SeekOrigin origin)
|
||||||
|
{
|
||||||
|
return BaseStream.Seek(offset, origin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetLength(long value)
|
||||||
|
{
|
||||||
|
BaseStream.SetLength(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Write(byte[] buffer, int offset, int count)
|
||||||
|
{
|
||||||
|
BaseStream.Write(buffer, offset, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte ReadUInt8()
|
||||||
|
{
|
||||||
|
int value = BaseStream.ReadByte();
|
||||||
|
if (value == -1)
|
||||||
|
throw new EndOfStreamException();
|
||||||
|
return (byte)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteUInt8(byte value)
|
||||||
|
{
|
||||||
|
WriteByte(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public sbyte ReadInt8()
|
||||||
|
{
|
||||||
|
return (sbyte)ReadUInt8();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteInt8(sbyte value)
|
||||||
|
{
|
||||||
|
WriteUInt8((byte)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ushort ReadUInt16()
|
||||||
|
{
|
||||||
|
return (ushort)(
|
||||||
|
(ReadUInt8() << 8) |
|
||||||
|
ReadUInt8());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteUInt16(ushort value)
|
||||||
|
{
|
||||||
|
Write(new[]
|
||||||
|
{
|
||||||
|
(byte)((value & 0xFF00) >> 8),
|
||||||
|
(byte)(value & 0xFF)
|
||||||
|
}, 0, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public short ReadInt16()
|
||||||
|
{
|
||||||
|
return (short)ReadUInt16();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteInt16(short value)
|
||||||
|
{
|
||||||
|
WriteUInt16((ushort)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public uint ReadUInt32()
|
||||||
|
{
|
||||||
|
return (uint)(
|
||||||
|
(ReadUInt8() << 24) |
|
||||||
|
(ReadUInt8() << 16) |
|
||||||
|
(ReadUInt8() << 8 ) |
|
||||||
|
ReadUInt8());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteUInt32(uint value)
|
||||||
|
{
|
||||||
|
Write(new[]
|
||||||
|
{
|
||||||
|
(byte)((value & 0xFF000000) >> 24),
|
||||||
|
(byte)((value & 0xFF0000) >> 16),
|
||||||
|
(byte)((value & 0xFF00) >> 8),
|
||||||
|
(byte)(value & 0xFF)
|
||||||
|
}, 0, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ReadInt32()
|
||||||
|
{
|
||||||
|
return (int)ReadUInt32();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteInt32(int value)
|
||||||
|
{
|
||||||
|
WriteUInt32((uint)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ulong ReadUInt64()
|
||||||
|
{
|
||||||
|
return unchecked(
|
||||||
|
((ulong)ReadUInt8() << 56) |
|
||||||
|
((ulong)ReadUInt8() << 48) |
|
||||||
|
((ulong)ReadUInt8() << 40) |
|
||||||
|
((ulong)ReadUInt8() << 32) |
|
||||||
|
((ulong)ReadUInt8() << 24) |
|
||||||
|
((ulong)ReadUInt8() << 16) |
|
||||||
|
((ulong)ReadUInt8() << 8) |
|
||||||
|
(ulong)ReadUInt8());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteUInt64(ulong value)
|
||||||
|
{
|
||||||
|
Write(new[]
|
||||||
|
{
|
||||||
|
(byte)((value & 0xFF00000000000000) >> 56),
|
||||||
|
(byte)((value & 0xFF000000000000) >> 48),
|
||||||
|
(byte)((value & 0xFF0000000000) >> 40),
|
||||||
|
(byte)((value & 0xFF00000000) >> 32),
|
||||||
|
(byte)((value & 0xFF000000) >> 24),
|
||||||
|
(byte)((value & 0xFF0000) >> 16),
|
||||||
|
(byte)((value & 0xFF00) >> 8),
|
||||||
|
(byte)(value & 0xFF)
|
||||||
|
}, 0, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long ReadInt64()
|
||||||
|
{
|
||||||
|
return (long)ReadUInt64();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteInt64(long value)
|
||||||
|
{
|
||||||
|
WriteUInt64((ulong)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] ReadUInt8Array(int length)
|
||||||
|
{
|
||||||
|
var result = new byte[length];
|
||||||
|
if (length == 0) return result;
|
||||||
|
int n = length;
|
||||||
|
while (true) {
|
||||||
|
n -= Read(result, length - n, n);
|
||||||
|
if (n == 0)
|
||||||
|
break;
|
||||||
|
System.Threading.Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteUInt8Array(byte[] value)
|
||||||
|
{
|
||||||
|
Write(value, 0, value.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteUInt8Array(byte[] value, int offset, int count)
|
||||||
|
{
|
||||||
|
Write(value, offset, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
public sbyte[] ReadInt8Array(int length)
|
||||||
|
{
|
||||||
|
return (sbyte[])(Array)ReadUInt8Array(length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteInt8Array(sbyte[] value)
|
||||||
|
{
|
||||||
|
Write((byte[])(Array)value, 0, value.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ushort[] ReadUInt16Array(int length)
|
||||||
|
{
|
||||||
|
var result = new ushort[length];
|
||||||
|
if (length == 0) return result;
|
||||||
|
for (int i = 0; i < length; i++)
|
||||||
|
result[i] = ReadUInt16();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteUInt16Array(ushort[] value)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < value.Length; i++)
|
||||||
|
WriteUInt16(value[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public short[] ReadInt16Array(int length)
|
||||||
|
{
|
||||||
|
return (short[])(Array)ReadUInt16Array(length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteInt16Array(short[] value)
|
||||||
|
{
|
||||||
|
WriteUInt16Array((ushort[])(Array)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public uint[] ReadUInt32Array(int length)
|
||||||
|
{
|
||||||
|
var result = new uint[length];
|
||||||
|
if (length == 0) return result;
|
||||||
|
for (int i = 0; i < length; i++)
|
||||||
|
result[i] = ReadUInt32();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteUInt32Array(uint[] value)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < value.Length; i++)
|
||||||
|
WriteUInt32(value[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] ReadInt32Array(int length)
|
||||||
|
{
|
||||||
|
return (int[])(Array)ReadUInt32Array(length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteInt32Array(int[] value)
|
||||||
|
{
|
||||||
|
WriteUInt32Array((uint[])(Array)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ulong[] ReadUInt64Array(int length)
|
||||||
|
{
|
||||||
|
var result = new ulong[length];
|
||||||
|
if (length == 0) return result;
|
||||||
|
for (int i = 0; i < length; i++)
|
||||||
|
result[i] = ReadUInt64();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteUInt64Array(ulong[] value)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < value.Length; i++)
|
||||||
|
WriteUInt64(value[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long[] ReadInt64Array(int length)
|
||||||
|
{
|
||||||
|
return (long[])(Array)ReadUInt64Array(length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteInt64Array(long[] value)
|
||||||
|
{
|
||||||
|
WriteUInt64Array((ulong[])(Array)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public unsafe float ReadSingle()
|
||||||
|
{
|
||||||
|
uint value = ReadUInt32();
|
||||||
|
return *(float*)&value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public unsafe void WriteSingle(float value)
|
||||||
|
{
|
||||||
|
WriteUInt32(*(uint*)&value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public unsafe double ReadDouble()
|
||||||
|
{
|
||||||
|
ulong value = ReadUInt64();
|
||||||
|
return *(double*)&value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public unsafe void WriteDouble(double value)
|
||||||
|
{
|
||||||
|
WriteUInt64(*(ulong*)&value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ReadBoolean()
|
||||||
|
{
|
||||||
|
return ReadUInt8() != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteBoolean(bool value)
|
||||||
|
{
|
||||||
|
WriteUInt8(value ? (byte)1 : (byte)0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ReadString()
|
||||||
|
{
|
||||||
|
short length = ReadInt16();
|
||||||
|
if (length == 0) return string.Empty;
|
||||||
|
var data = ReadUInt8Array(length * 2);
|
||||||
|
return StringEncoding.GetString(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteString(string value)
|
||||||
|
{
|
||||||
|
WriteInt16((short)value.Length);
|
||||||
|
if (value.Length > 0)
|
||||||
|
WriteUInt8Array(StringEncoding.GetBytes(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: string8 is modified UTF-8, which has a special representation of the NULL character
|
||||||
|
public string ReadString8()
|
||||||
|
{
|
||||||
|
short length = ReadInt16();
|
||||||
|
if (length == 0) return string.Empty;
|
||||||
|
var data = ReadUInt8Array((int)length);
|
||||||
|
return Encoding.UTF8.GetString(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteString8(string value)
|
||||||
|
{
|
||||||
|
WriteInt16((short)value.Length);
|
||||||
|
if (value.Length > 0)
|
||||||
|
WriteUInt8Array(Encoding.UTF8.GetBytes(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
TrueCraft.Core/Networking/NetworkBlockFace.cs
Normal file
15
TrueCraft.Core/Networking/NetworkBlockFace.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking
|
||||||
|
{
|
||||||
|
public enum NetworkBlockFace
|
||||||
|
{
|
||||||
|
NegativeY = 0,
|
||||||
|
PositiveY = 1,
|
||||||
|
NegativeZ = 2,
|
||||||
|
PositiveZ = 3,
|
||||||
|
NegativeX = 4,
|
||||||
|
PositiveX = 5,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
118
TrueCraft.Core/Networking/PacketReader.cs
Normal file
118
TrueCraft.Core/Networking/PacketReader.cs
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
using TrueCraft.Core.Networking.Packets;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking
|
||||||
|
{
|
||||||
|
public class PacketReader : IPacketReader
|
||||||
|
{
|
||||||
|
public static readonly int ProtocolVersion = 18;
|
||||||
|
|
||||||
|
private Type[] ClientboundPackets = new Type[0x100];
|
||||||
|
private Type[] ServerboundPackets = new Type[0x100];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Registers TrueCraft.Core implementations of all packets used by vanilla Minecraft.
|
||||||
|
/// </summary>
|
||||||
|
public void RegisterCorePackets()
|
||||||
|
{
|
||||||
|
RegisterPacketType<KeepAlivePacket>(); // 0x00
|
||||||
|
RegisterPacketType<LoginRequestPacket>(serverbound: true, clientbound: false); // 0x01
|
||||||
|
RegisterPacketType<LoginResponsePacket>(serverbound: false, clientbound: true); // 0x01
|
||||||
|
RegisterPacketType<HandshakePacket>(serverbound: true, clientbound: false); // 0x02
|
||||||
|
RegisterPacketType<HandshakeResponsePacket>(serverbound: false, clientbound: true); // 0x02
|
||||||
|
RegisterPacketType<ChatMessagePacket>(); // 0x03
|
||||||
|
RegisterPacketType<TimeUpdatePacket>(serverbound: false, clientbound: true); // 0x04
|
||||||
|
RegisterPacketType<EntityEquipmentPacket>(serverbound: false, clientbound: true); // 0x05 // NOTE: serverbound not confirmed
|
||||||
|
RegisterPacketType<SpawnPositionPacket>(serverbound: true, clientbound: false); // 0x06
|
||||||
|
RegisterPacketType<UseEntityPacket>(serverbound: false, clientbound: true); // 0x07
|
||||||
|
RegisterPacketType<UpdateHealthPacket>(serverbound: false, clientbound: true); // 0x08
|
||||||
|
RegisterPacketType<RespawnPacket>(); // 0x09
|
||||||
|
RegisterPacketType<PlayerGroundedPacket>(serverbound: true, clientbound: false); // 0x0A
|
||||||
|
RegisterPacketType<PlayerPositionPacket>(serverbound: true, clientbound: false); // 0x0B
|
||||||
|
RegisterPacketType<PlayerLookPacket>(serverbound: true, clientbound: false); // 0x0C
|
||||||
|
RegisterPacketType<PlayerPositionPacket>(serverbound: true, clientbound: false); // 0x0D
|
||||||
|
RegisterPacketType<SetPlayerPositionPacket>(serverbound: false, clientbound: true); // 0x0D
|
||||||
|
RegisterPacketType<PlayerDiggingPacket>(serverbound: true, clientbound: false); // 0x0E
|
||||||
|
RegisterPacketType<PlayerBlockPlacementPacket>(serverbound: true, clientbound: false); // 0x0F
|
||||||
|
RegisterPacketType<ChangeHeldItemPacket>(serverbound: true, clientbound: false); // 0x10
|
||||||
|
RegisterPacketType<UseBedPacket>(serverbound: false, clientbound: true); // 0x11
|
||||||
|
RegisterPacketType<AnimationPacket>(serverbound: false, clientbound: true); // 0x12
|
||||||
|
RegisterPacketType<PlayerActionPacket>(serverbound: true, clientbound: false); // 0x13
|
||||||
|
RegisterPacketType<SpawnPlayerPacket>(serverbound: false, clientbound: true); // 0x14
|
||||||
|
RegisterPacketType<SpawnItemPacket>(serverbound: false, clientbound: true); // 0x15
|
||||||
|
RegisterPacketType<CollectItemPacket>(serverbound: false, clientbound: true); // 0x16
|
||||||
|
RegisterPacketType<SpawnGenericEntityPacket>(serverbound: false, clientbound: true); // 0x17
|
||||||
|
RegisterPacketType<SpawnMobPacket>(serverbound: false, clientbound: true); // 0x18
|
||||||
|
RegisterPacketType<SpawnPaintingPacket>(serverbound: false, clientbound: true); // 0x19
|
||||||
|
|
||||||
|
RegisterPacketType<EntityVelocityPacket>(serverbound: false, clientbound: true); // 0x1C
|
||||||
|
|
||||||
|
RegisterPacketType<UselessEntityPacket>(serverbound: false, clientbound: true); // 0x1E
|
||||||
|
RegisterPacketType<EntityRelativeMovePacket>(serverbound: false, clientbound: true); // 0x1F
|
||||||
|
RegisterPacketType<EntityLookPacket>(serverbound: false, clientbound: true); // 0x20
|
||||||
|
RegisterPacketType<EntityLookAndRelativeMovePacket>(serverbound: false, clientbound: true); // 0x21
|
||||||
|
RegisterPacketType<EntityTeleportPacket>(serverbound: false, clientbound: true); // 0x22
|
||||||
|
|
||||||
|
RegisterPacketType<EntityStatusPacket>(serverbound: false, clientbound: true); // 0x26
|
||||||
|
RegisterPacketType<AttachEntityPacket>(serverbound: false, clientbound: true); // 0x27
|
||||||
|
RegisterPacketType<EntityMetadataPacket>(serverbound: false, clientbound: true); // 0x28
|
||||||
|
|
||||||
|
RegisterPacketType<ChunkPreamblePacket>(serverbound: false, clientbound: true); // 0x32
|
||||||
|
RegisterPacketType<ChunkDataPacket>(serverbound: false, clientbound: true); // 0x33
|
||||||
|
RegisterPacketType<BulkBlockChangePacket>(serverbound: false, clientbound: true); // 0x34
|
||||||
|
RegisterPacketType<BlockChangePacket>(serverbound: false, clientbound: true); // 0x35
|
||||||
|
RegisterPacketType<BlockActionPacket>(serverbound: false, clientbound: true); // 0x36
|
||||||
|
|
||||||
|
RegisterPacketType<SoundEffectPacket>(serverbound: false, clientbound: true); // 0x3D
|
||||||
|
|
||||||
|
RegisterPacketType<EnvironmentStatePacket>(serverbound: false, clientbound: true); // 0x46
|
||||||
|
RegisterPacketType<LightningPacket>(serverbound: false, clientbound: true); // 0x47
|
||||||
|
|
||||||
|
RegisterPacketType<OpenWindowPacket>(serverbound: false, clientbound: true); // 0x64
|
||||||
|
RegisterPacketType<CloseWindow>(); // 0x65
|
||||||
|
RegisterPacketType<ClickWindowPacket>(serverbound: true, clientbound: false); // 0x66
|
||||||
|
RegisterPacketType<SetSlotPacket>(serverbound: false, clientbound: true); // 0x67
|
||||||
|
RegisterPacketType<WindowItemsPacket>(serverbound: false, clientbound: true); // 0x68
|
||||||
|
RegisterPacketType<UpdateProgressPacket>(serverbound: false, clientbound: true); // 0x69
|
||||||
|
RegisterPacketType<TransactionStatusPacket>(serverbound: false, clientbound: true); // 0x6A
|
||||||
|
|
||||||
|
RegisterPacketType<UpdateSignPacket>(); // 0x82
|
||||||
|
RegisterPacketType<MapDataPacket>(serverbound: false, clientbound: true); // 0x83
|
||||||
|
|
||||||
|
RegisterPacketType<UpdateStatisticPacket>(serverbound: false, clientbound: true); // 0xC8
|
||||||
|
|
||||||
|
RegisterPacketType<DisconnectPacket>(); // 0xFF
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RegisterPacketType<T>(bool clientbound = true, bool serverbound = true) where T : IPacket
|
||||||
|
{
|
||||||
|
var packet = (IPacket)Activator.CreateInstance(typeof(T));
|
||||||
|
if (clientbound)
|
||||||
|
ClientboundPackets[packet.ID] = typeof(T);
|
||||||
|
if (serverbound)
|
||||||
|
ServerboundPackets[packet.ID] = typeof(T);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IPacket ReadPacket(IMinecraftStream stream, bool serverbound = true)
|
||||||
|
{
|
||||||
|
var id = stream.ReadUInt8();
|
||||||
|
Type type;
|
||||||
|
if (serverbound)
|
||||||
|
type = ServerboundPackets[id];
|
||||||
|
else
|
||||||
|
type = ClientboundPackets[id];
|
||||||
|
if (type == null)
|
||||||
|
throw new NotSupportedException("Unable to read packet type 0x" + id.ToString("X2"));
|
||||||
|
var instance = (IPacket)Activator.CreateInstance(type);
|
||||||
|
instance.ReadPacket(stream);
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream, IPacket packet)
|
||||||
|
{
|
||||||
|
stream.WriteUInt8(packet.ID);
|
||||||
|
packet.WritePacket(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
36
TrueCraft.Core/Networking/Packets/AnimationPacket.cs
Normal file
36
TrueCraft.Core/Networking/Packets/AnimationPacket.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
public struct AnimationPacket : IPacket
|
||||||
|
{
|
||||||
|
public enum PlayerAnimation
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
SwingArm = 1,
|
||||||
|
TakeDamage = 2,
|
||||||
|
LeaveBed = 3,
|
||||||
|
Unknown = 102,
|
||||||
|
Crouch = 104,
|
||||||
|
Uncrouch = 105,
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte ID { get { return 0x12; } }
|
||||||
|
|
||||||
|
public int EntityID;
|
||||||
|
public PlayerAnimation Animation;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
EntityID = stream.ReadInt32();
|
||||||
|
Animation = (PlayerAnimation)stream.ReadInt8();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(EntityID);
|
||||||
|
stream.WriteInt8((sbyte)Animation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
28
TrueCraft.Core/Networking/Packets/AttachEntityPacket.cs
Normal file
28
TrueCraft.Core/Networking/Packets/AttachEntityPacket.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Used to attach entities to other entities, i.e. players to minecarts
|
||||||
|
/// </summary>
|
||||||
|
public struct AttachEntityPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x27; } }
|
||||||
|
|
||||||
|
public int EntityID;
|
||||||
|
public int VehicleID;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
EntityID = stream.ReadInt32();
|
||||||
|
VehicleID = stream.ReadInt32();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(EntityID);
|
||||||
|
stream.WriteInt32(VehicleID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
40
TrueCraft.Core/Networking/Packets/BlockActionPacket.cs
Normal file
40
TrueCraft.Core/Networking/Packets/BlockActionPacket.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Used to indicate that a certain "action" has happened to a block.
|
||||||
|
/// In practice this controls note blocks and pistons.
|
||||||
|
/// </summary>
|
||||||
|
public struct BlockActionPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x36; } }
|
||||||
|
|
||||||
|
public int X;
|
||||||
|
public short Y;
|
||||||
|
public int Z;
|
||||||
|
/// <summary>
|
||||||
|
/// Used for instrument type or piston state.
|
||||||
|
/// </summary>
|
||||||
|
public sbyte State;
|
||||||
|
/// <summary>
|
||||||
|
/// Used for piston direction or note block instrument.
|
||||||
|
/// </summary>
|
||||||
|
public sbyte Data;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
X = stream.ReadInt32();
|
||||||
|
Y = stream.ReadInt16();
|
||||||
|
Z = stream.ReadInt32();
|
||||||
|
State = stream.ReadInt8();
|
||||||
|
Data = stream.ReadInt8();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
34
TrueCraft.Core/Networking/Packets/BlockChangePacket.cs
Normal file
34
TrueCraft.Core/Networking/Packets/BlockChangePacket.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
public struct BlockChangePacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x35; } }
|
||||||
|
|
||||||
|
public int X;
|
||||||
|
public sbyte Y;
|
||||||
|
public int Z;
|
||||||
|
public sbyte BlockID;
|
||||||
|
public sbyte Metadata;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
X = stream.ReadInt32();
|
||||||
|
Y = stream.ReadInt8();
|
||||||
|
Z = stream.ReadInt32();
|
||||||
|
BlockID = stream.ReadInt8();
|
||||||
|
Metadata = stream.ReadInt8();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(X);
|
||||||
|
stream.WriteInt32(Y);
|
||||||
|
stream.WriteInt32(Z);
|
||||||
|
stream.WriteInt8(BlockID);
|
||||||
|
stream.WriteInt8(Metadata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
48
TrueCraft.Core/Networking/Packets/BulkBlockChangePacket.cs
Normal file
48
TrueCraft.Core/Networking/Packets/BulkBlockChangePacket.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
using TrueCraft.API;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
public struct BulkBlockChangePacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x34; } }
|
||||||
|
|
||||||
|
public int ChunkX, ChunkZ;
|
||||||
|
public Coordinates3D[] Coordinates;
|
||||||
|
public sbyte[] BlockIDs;
|
||||||
|
public sbyte[] Metadata;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
ChunkX = stream.ReadInt32();
|
||||||
|
ChunkZ = stream.ReadInt32();
|
||||||
|
short length = stream.ReadInt16();
|
||||||
|
Coordinates = new Coordinates3D[length];
|
||||||
|
for (int i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
ushort value = stream.ReadUInt16();
|
||||||
|
Coordinates[i] = new Coordinates3D(
|
||||||
|
value >> 12 & 0xF,
|
||||||
|
value & 0xFF,
|
||||||
|
value >> 8 & 0xF);
|
||||||
|
}
|
||||||
|
BlockIDs = stream.ReadInt8Array(length);
|
||||||
|
Metadata = stream.ReadInt8Array(length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(ChunkX);
|
||||||
|
stream.WriteInt32(ChunkZ);
|
||||||
|
stream.WriteInt16((short)Coordinates.Length);
|
||||||
|
for (int i = 0; i < Coordinates.Length; i++)
|
||||||
|
{
|
||||||
|
var coord = Coordinates[i];
|
||||||
|
stream.WriteUInt16((ushort)((coord.X << 12 & 0xF) | (coord.Z << 8 & 0xF) | (coord.Y & 0xFF)));
|
||||||
|
}
|
||||||
|
stream.WriteInt8Array(BlockIDs);
|
||||||
|
stream.WriteInt8Array(Metadata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
TrueCraft.Core/Networking/Packets/ChangeHeldItemPacket.cs
Normal file
22
TrueCraft.Core/Networking/Packets/ChangeHeldItemPacket.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
public struct ChangeHeldItemPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x10; } }
|
||||||
|
|
||||||
|
public short Slot;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
Slot = stream.ReadInt16();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt16(Slot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
TrueCraft.Core/Networking/Packets/ChatMessagePacket.cs
Normal file
27
TrueCraft.Core/Networking/Packets/ChatMessagePacket.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Used by clients to send messages and by servers to propegate messages to clients.
|
||||||
|
/// Note that the server is expected to include the username, i.e. <User> message, but the
|
||||||
|
/// client is not given the same expectation.
|
||||||
|
/// </summary>
|
||||||
|
public struct ChatMessagePacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x03; } }
|
||||||
|
|
||||||
|
public string Message;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
Message = stream.ReadString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteString(Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
43
TrueCraft.Core/Networking/Packets/ChunkDataPacket.cs
Normal file
43
TrueCraft.Core/Networking/Packets/ChunkDataPacket.cs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sends actual blocks to populate chunks with.
|
||||||
|
/// </summary>
|
||||||
|
public struct ChunkDataPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x33; } }
|
||||||
|
|
||||||
|
public int X;
|
||||||
|
public short Y;
|
||||||
|
public int Z;
|
||||||
|
public short Width, Height, Depth;
|
||||||
|
public byte[] CompressedData;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
X = stream.ReadInt32();
|
||||||
|
Y = stream.ReadInt16();
|
||||||
|
Z = stream.ReadInt32();
|
||||||
|
Width = (short)(stream.ReadInt8() + 1);
|
||||||
|
Height = (short)(stream.ReadInt8() + 1);
|
||||||
|
Depth = (short)(stream.ReadInt8() + 1);
|
||||||
|
int len = stream.ReadInt32();
|
||||||
|
CompressedData = stream.ReadUInt8Array(len);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(X);
|
||||||
|
stream.WriteInt16(Y);
|
||||||
|
stream.WriteInt32(Z);
|
||||||
|
stream.WriteInt8((sbyte)(Width - 1));
|
||||||
|
stream.WriteInt8((sbyte)(Height - 1));
|
||||||
|
stream.WriteInt8((sbyte)(Depth - 1));
|
||||||
|
stream.WriteInt32(CompressedData.Length);
|
||||||
|
stream.WriteUInt8Array(CompressedData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
TrueCraft.Core/Networking/Packets/ChunkPreamblePacket.cs
Normal file
33
TrueCraft.Core/Networking/Packets/ChunkPreamblePacket.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Used to allocate or unload chunks.
|
||||||
|
/// </summary>
|
||||||
|
public struct ChunkPreamblePacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x32; } }
|
||||||
|
|
||||||
|
public int X, Z;
|
||||||
|
/// <summary>
|
||||||
|
/// If false, free the chunk. If true, allocate it.
|
||||||
|
/// </summary>
|
||||||
|
public bool Load;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
X = stream.ReadInt32();
|
||||||
|
Z = stream.ReadInt32();
|
||||||
|
Load = stream.ReadBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(X);
|
||||||
|
stream.WriteInt32(Z);
|
||||||
|
stream.WriteBoolean(Load);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
55
TrueCraft.Core/Networking/Packets/ClickWindowPacket.cs
Normal file
55
TrueCraft.Core/Networking/Packets/ClickWindowPacket.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent by clients when clicking on an inventory window.
|
||||||
|
/// </summary>
|
||||||
|
public struct ClickWindowPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x66; } }
|
||||||
|
|
||||||
|
public sbyte WindowID;
|
||||||
|
public short SlotIndex;
|
||||||
|
public bool RightClick;
|
||||||
|
public short TransactionID;
|
||||||
|
public bool Shift;
|
||||||
|
/// <summary>
|
||||||
|
/// You should probably ignore this.
|
||||||
|
/// </summary>
|
||||||
|
public short ItemID;
|
||||||
|
/// <summary>
|
||||||
|
/// You should probably ignore this.
|
||||||
|
/// </summary>
|
||||||
|
public sbyte Count;
|
||||||
|
/// <summary>
|
||||||
|
/// You should probably ignore this.
|
||||||
|
/// </summary>
|
||||||
|
public sbyte Metadata;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
WindowID = stream.ReadInt8();
|
||||||
|
SlotIndex = stream.ReadInt16();
|
||||||
|
RightClick = stream.ReadBoolean();
|
||||||
|
TransactionID = stream.ReadInt16();
|
||||||
|
Shift = stream.ReadBoolean();
|
||||||
|
ItemID = stream.ReadInt16();
|
||||||
|
Count = stream.ReadInt8();
|
||||||
|
Metadata = stream.ReadInt8();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt8(WindowID);
|
||||||
|
stream.WriteInt16(SlotIndex);
|
||||||
|
stream.WriteBoolean(RightClick);
|
||||||
|
stream.WriteInt16(TransactionID);
|
||||||
|
stream.WriteBoolean(Shift);
|
||||||
|
stream.WriteInt16(ItemID);
|
||||||
|
stream.WriteInt8(Count);
|
||||||
|
stream.WriteInt8(Metadata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
25
TrueCraft.Core/Networking/Packets/CloseWindow.cs
Normal file
25
TrueCraft.Core/Networking/Packets/CloseWindow.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent by the server to forcibly close an inventory window, or from the client when naturally closed.
|
||||||
|
/// </summary>
|
||||||
|
public struct CloseWindow : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x65; } }
|
||||||
|
|
||||||
|
public sbyte WindowID;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
WindowID = stream.ReadInt8();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt8(WindowID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
28
TrueCraft.Core/Networking/Packets/CollectItemPacket.cs
Normal file
28
TrueCraft.Core/Networking/Packets/CollectItemPacket.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent by servers to show the animation of an item entity being collected by a player.
|
||||||
|
/// </summary>
|
||||||
|
public struct CollectItemPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x16; } }
|
||||||
|
|
||||||
|
public int CollectedItemID;
|
||||||
|
public int CollectorID;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
CollectedItemID = stream.ReadInt32();
|
||||||
|
CollectorID = stream.ReadInt32();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(CollectedItemID);
|
||||||
|
stream.WriteInt32(CollectorID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
TrueCraft.Core/Networking/Packets/DisconnectPacket.cs
Normal file
30
TrueCraft.Core/Networking/Packets/DisconnectPacket.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Disconnects from a server or kicks a player. This is the last packet sent.
|
||||||
|
/// </summary>
|
||||||
|
public struct DisconnectPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0xFF; } }
|
||||||
|
|
||||||
|
public DisconnectPacket(string reason)
|
||||||
|
{
|
||||||
|
Reason = reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Reason;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
Reason = stream.ReadString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteString(Reason);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
45
TrueCraft.Core/Networking/Packets/EntityEquipmentPacket.cs
Normal file
45
TrueCraft.Core/Networking/Packets/EntityEquipmentPacket.cs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the equipment visible on player entities (i.e. armor).
|
||||||
|
/// </summary>
|
||||||
|
public struct EntityEquipmentPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x05; } }
|
||||||
|
|
||||||
|
public EntityEquipmentPacket(int entityID, short slot, short itemID, short metadata)
|
||||||
|
{
|
||||||
|
EntityID = entityID;
|
||||||
|
Slot = slot;
|
||||||
|
ItemID = itemID;
|
||||||
|
Metadata = metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int EntityID;
|
||||||
|
public short Slot;
|
||||||
|
/// <summary>
|
||||||
|
/// The ID of the item to show on this player. Set to -1 for nothing.
|
||||||
|
/// </summary>
|
||||||
|
public short ItemID;
|
||||||
|
public short Metadata;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
EntityID = stream.ReadInt32();
|
||||||
|
Slot = stream.ReadInt16();
|
||||||
|
ItemID = stream.ReadInt16();
|
||||||
|
Metadata = stream.ReadInt16();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(EntityID);
|
||||||
|
stream.WriteInt16(Slot);
|
||||||
|
stream.WriteInt16(ItemID);
|
||||||
|
stream.WriteInt16(Metadata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
public struct EntityLookAndRelativeMovePacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x21; } }
|
||||||
|
|
||||||
|
public int EntityID;
|
||||||
|
public sbyte DeltaX, DeltaY, DeltaZ;
|
||||||
|
public sbyte Yaw, Pitch;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
EntityID = stream.ReadInt32();
|
||||||
|
DeltaX = stream.ReadInt8();
|
||||||
|
DeltaY = stream.ReadInt8();
|
||||||
|
DeltaZ = stream.ReadInt8();
|
||||||
|
Yaw = stream.ReadInt8();
|
||||||
|
Pitch = stream.ReadInt8();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(EntityID);
|
||||||
|
stream.WriteInt8(DeltaX);
|
||||||
|
stream.WriteInt8(DeltaY);
|
||||||
|
stream.WriteInt8(DeltaZ);
|
||||||
|
stream.WriteInt8(Yaw);
|
||||||
|
stream.WriteInt8(Pitch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
TrueCraft.Core/Networking/Packets/EntityLookPacket.cs
Normal file
30
TrueCraft.Core/Networking/Packets/EntityLookPacket.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent by servers to update the direction an entity is looking in.
|
||||||
|
/// </summary>
|
||||||
|
public struct EntityLookPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x20; } }
|
||||||
|
|
||||||
|
public int EntityID;
|
||||||
|
public sbyte Yaw, Pitch;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
EntityID = stream.ReadInt32();
|
||||||
|
Yaw = stream.ReadInt8();
|
||||||
|
Pitch = stream.ReadInt8();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(EntityID);
|
||||||
|
stream.WriteInt8(Yaw);
|
||||||
|
stream.WriteInt8(Pitch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
26
TrueCraft.Core/Networking/Packets/EntityMetadataPacket.cs
Normal file
26
TrueCraft.Core/Networking/Packets/EntityMetadataPacket.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
using TrueCraft.API;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
public struct EntityMetadataPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x28; } }
|
||||||
|
|
||||||
|
public int EntityID;
|
||||||
|
public MetadataDictionary Metadata;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
EntityID = stream.ReadInt32();
|
||||||
|
Metadata = MetadataDictionary.FromStream(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(EntityID);
|
||||||
|
Metadata.WriteTo(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
public struct EntityRelativeMovePacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x1F; } }
|
||||||
|
|
||||||
|
public int EntityID;
|
||||||
|
public sbyte DeltaX, DeltaY, DeltaZ;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
EntityID = stream.ReadInt32();
|
||||||
|
DeltaX = stream.ReadInt8();
|
||||||
|
DeltaY = stream.ReadInt8();
|
||||||
|
DeltaZ = stream.ReadInt8();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(EntityID);
|
||||||
|
stream.WriteInt8(DeltaX);
|
||||||
|
stream.WriteInt8(DeltaY);
|
||||||
|
stream.WriteInt8(DeltaZ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
TrueCraft.Core/Networking/Packets/EntityStatusPacket.cs
Normal file
38
TrueCraft.Core/Networking/Packets/EntityStatusPacket.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gives updates to what entities are doing.
|
||||||
|
/// </summary>
|
||||||
|
public struct EntityStatusPacket : IPacket
|
||||||
|
{
|
||||||
|
public enum EntityStatus
|
||||||
|
{
|
||||||
|
EntityHurt = 2,
|
||||||
|
EntityKilled = 3,
|
||||||
|
WolfTaming = 6,
|
||||||
|
WolfTamed = 7,
|
||||||
|
WolfShaking = 8,
|
||||||
|
EatingAccepted = 9 // what
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte ID { get { return 0x22; } }
|
||||||
|
|
||||||
|
public int EntityID;
|
||||||
|
public EntityStatus Status;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
EntityID = stream.ReadInt32();
|
||||||
|
Status = (EntityStatus)stream.ReadInt8();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(EntityID);
|
||||||
|
stream.WriteInt8((sbyte)Status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
TrueCraft.Core/Networking/Packets/EntityTeleportPacket.cs
Normal file
38
TrueCraft.Core/Networking/Packets/EntityTeleportPacket.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Used to teleport entities to arbitrary locations.
|
||||||
|
/// </summary>
|
||||||
|
public struct EntityTeleportPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x22; } }
|
||||||
|
|
||||||
|
public int EntityID;
|
||||||
|
public int X, Y, Z;
|
||||||
|
public sbyte Yaw, Pitch;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
EntityID = stream.ReadInt32();
|
||||||
|
X = stream.ReadInt32();
|
||||||
|
Y = stream.ReadInt32();
|
||||||
|
Z = stream.ReadInt32();
|
||||||
|
Yaw = stream.ReadInt8();
|
||||||
|
Pitch = stream.ReadInt8();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(EntityID);
|
||||||
|
stream.WriteInt32(X);
|
||||||
|
stream.WriteInt32(Y);
|
||||||
|
stream.WriteInt32(Z);
|
||||||
|
stream.WriteInt8(Yaw);
|
||||||
|
stream.WriteInt8(Pitch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
35
TrueCraft.Core/Networking/Packets/EntityVelocityPacket.cs
Normal file
35
TrueCraft.Core/Networking/Packets/EntityVelocityPacket.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent by servers to inform players of changes to the velocity of entities.
|
||||||
|
/// Not sure exactly how all of that works, but I know it's going to be a pain in the ass.
|
||||||
|
/// </summary>
|
||||||
|
public struct EntityVelocityPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x1C; } }
|
||||||
|
|
||||||
|
public int EntityID;
|
||||||
|
public short XVelocity;
|
||||||
|
public short YVelocity;
|
||||||
|
public short ZVelocity;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
EntityID = stream.ReadInt32();
|
||||||
|
XVelocity = stream.ReadInt16();
|
||||||
|
YVelocity = stream.ReadInt16();
|
||||||
|
ZVelocity = stream.ReadInt16();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(EntityID);
|
||||||
|
stream.WriteInt16(XVelocity);
|
||||||
|
stream.WriteInt16(YVelocity);
|
||||||
|
stream.WriteInt16(ZVelocity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
32
TrueCraft.Core/Networking/Packets/EnvironmentStatePacket.cs
Normal file
32
TrueCraft.Core/Networking/Packets/EnvironmentStatePacket.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the player on changes to or status of the environment.
|
||||||
|
/// </summary>
|
||||||
|
public struct EnvironmentStatePacket : IPacket
|
||||||
|
{
|
||||||
|
public enum EnvironmentState
|
||||||
|
{
|
||||||
|
InvalidBed = 0,
|
||||||
|
BeginRaining = 1,
|
||||||
|
EndRaining = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte ID { get { return 0x46; } }
|
||||||
|
|
||||||
|
public EnvironmentState State;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
State = (EnvironmentState)stream.ReadInt8();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt8((sbyte)State);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
TrueCraft.Core/Networking/Packets/HandshakePacket.cs
Normal file
30
TrueCraft.Core/Networking/Packets/HandshakePacket.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent from clients to begin a new connection.
|
||||||
|
/// </summary>
|
||||||
|
public struct HandshakePacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x02; } }
|
||||||
|
|
||||||
|
public HandshakePacket(string username)
|
||||||
|
{
|
||||||
|
Username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Username;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
Username = stream.ReadString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteString(Username);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
TrueCraft.Core/Networking/Packets/HandshakeResponsePacket.cs
Normal file
33
TrueCraft.Core/Networking/Packets/HandshakeResponsePacket.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent from servers to continue with a connection. A kick is sent instead if the connection is refused.
|
||||||
|
/// </summary>
|
||||||
|
public struct HandshakeResponsePacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x02; } }
|
||||||
|
|
||||||
|
public HandshakeResponsePacket(string connectionHash)
|
||||||
|
{
|
||||||
|
ConnectionHash = connectionHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set to "-" for offline mode servers. Online mode beta servers are obsolete.
|
||||||
|
/// </summary>
|
||||||
|
public string ConnectionHash;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
ConnectionHash = stream.ReadString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteString(ConnectionHash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
TrueCraft.Core/Networking/Packets/KeepAlivePacket.cs
Normal file
24
TrueCraft.Core/Networking/Packets/KeepAlivePacket.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent periodically to confirm that the connection is still active. Send the same packet back
|
||||||
|
/// to confirm it. Connection is dropped if no keep alive is received within one minute.
|
||||||
|
/// </summary>
|
||||||
|
public struct KeepAlivePacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x00; } }
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
// This space intentionally left blank
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
// This space intentionally left blank
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
34
TrueCraft.Core/Networking/Packets/LightningPacket.cs
Normal file
34
TrueCraft.Core/Networking/Packets/LightningPacket.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Spawns lightning at the given coordinates.
|
||||||
|
/// </summary>
|
||||||
|
public struct LightningPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x47; } }
|
||||||
|
|
||||||
|
public int EntityID;
|
||||||
|
public int X, Y, Z;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
EntityID = stream.ReadInt32();
|
||||||
|
stream.ReadBoolean(); // Unknown
|
||||||
|
X = stream.ReadInt32();
|
||||||
|
Y = stream.ReadInt32();
|
||||||
|
Z = stream.ReadInt32();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(EntityID);
|
||||||
|
stream.WriteBoolean(true); // Unknown
|
||||||
|
stream.WriteInt32(X);
|
||||||
|
stream.WriteInt32(Y);
|
||||||
|
stream.WriteInt32(Z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
TrueCraft.Core/Networking/Packets/LoginRequestPacket.cs
Normal file
38
TrueCraft.Core/Networking/Packets/LoginRequestPacket.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent by clients after the handshake to request logging into the world.
|
||||||
|
/// </summary>
|
||||||
|
public struct LoginRequestPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x01; } }
|
||||||
|
|
||||||
|
public LoginRequestPacket(int protocolVersion, string username)
|
||||||
|
{
|
||||||
|
ProtocolVersion = protocolVersion;
|
||||||
|
Username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ProtocolVersion;
|
||||||
|
public string Username;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
ProtocolVersion = stream.ReadInt32();
|
||||||
|
Username = stream.ReadString();
|
||||||
|
stream.ReadInt64(); // Unused
|
||||||
|
stream.ReadInt8(); // Unused
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(ProtocolVersion);
|
||||||
|
stream.WriteString(Username);
|
||||||
|
stream.WriteInt64(0); // Unused
|
||||||
|
stream.WriteInt8(0); // Unused
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
41
TrueCraft.Core/Networking/Packets/LoginResponsePacket.cs
Normal file
41
TrueCraft.Core/Networking/Packets/LoginResponsePacket.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
using TrueCraft.API;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent by the server to allow the player to spawn, with information about the world being spawned into.
|
||||||
|
/// </summary>
|
||||||
|
public struct LoginResponsePacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x01; } }
|
||||||
|
|
||||||
|
public LoginResponsePacket(int entityID, long seed, Dimension dimension)
|
||||||
|
{
|
||||||
|
EntityID = entityID;
|
||||||
|
Seed = seed;
|
||||||
|
Dimension = dimension;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int EntityID;
|
||||||
|
public long Seed;
|
||||||
|
public Dimension Dimension;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
EntityID = stream.ReadInt32();
|
||||||
|
stream.ReadString(); // Unused
|
||||||
|
Seed = stream.ReadInt64();
|
||||||
|
Dimension = (Dimension)stream.ReadInt8();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(EntityID);
|
||||||
|
stream.WriteString(""); // Unused
|
||||||
|
stream.WriteInt64(Seed);
|
||||||
|
stream.WriteInt8((sbyte)Dimension);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
TrueCraft.Core/Networking/Packets/MapDataPacket.cs
Normal file
30
TrueCraft.Core/Networking/Packets/MapDataPacket.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
public struct MapDataPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x83; } }
|
||||||
|
|
||||||
|
public short ItemID;
|
||||||
|
public short Metadata;
|
||||||
|
public byte[] Data;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
ItemID = stream.ReadInt16();
|
||||||
|
Metadata = stream.ReadInt16();
|
||||||
|
byte length = stream.ReadUInt8();
|
||||||
|
Data = stream.ReadUInt8Array(length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt16(ItemID);
|
||||||
|
stream.WriteInt16(Metadata);
|
||||||
|
stream.WriteUInt8((byte)Data.Length);
|
||||||
|
stream.WriteUInt8Array(Data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
42
TrueCraft.Core/Networking/Packets/OpenWindowPacket.cs
Normal file
42
TrueCraft.Core/Networking/Packets/OpenWindowPacket.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Instructs the client to open an inventory window.
|
||||||
|
/// </summary>
|
||||||
|
public struct OpenWindowPacket : IPacket
|
||||||
|
{
|
||||||
|
public enum WindowType
|
||||||
|
{
|
||||||
|
Chest = 0,
|
||||||
|
Workbench = 1,
|
||||||
|
Furnace = 2,
|
||||||
|
Dispenser = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte ID { get { return 0x64; } }
|
||||||
|
|
||||||
|
public sbyte WindowID;
|
||||||
|
public WindowType Type;
|
||||||
|
public string Title;
|
||||||
|
public sbyte TotalSlots;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
WindowID = stream.ReadInt8();
|
||||||
|
Type = (WindowType)stream.ReadInt8();
|
||||||
|
Title = stream.ReadString();
|
||||||
|
TotalSlots = stream.ReadInt8();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt8(WindowID);
|
||||||
|
stream.WriteInt8((sbyte)Type);
|
||||||
|
stream.WriteString(Title);
|
||||||
|
stream.WriteInt8(TotalSlots);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
32
TrueCraft.Core/Networking/Packets/PlayerActionPacket.cs
Normal file
32
TrueCraft.Core/Networking/Packets/PlayerActionPacket.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
public struct PlayerActionPacket : IPacket
|
||||||
|
{
|
||||||
|
public enum PlayerAction
|
||||||
|
{
|
||||||
|
Crouch = 1,
|
||||||
|
Uncrouch = 2,
|
||||||
|
LeaveBed = 3,
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte ID { get { return 0x13; } }
|
||||||
|
|
||||||
|
public int EntityID;
|
||||||
|
public PlayerAction Action;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
EntityID = stream.ReadInt32();
|
||||||
|
Action = (PlayerAction)stream.ReadInt8();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(EntityID);
|
||||||
|
stream.WriteInt8((sbyte)Action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent when the player interacts with a block (generally via right clicking).
|
||||||
|
/// This is also used for items that don't interact with blocks (i.e. food) with the coordinates set to -1.
|
||||||
|
/// </summary>
|
||||||
|
public struct PlayerBlockPlacementPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x0F; } }
|
||||||
|
|
||||||
|
public int X;
|
||||||
|
public sbyte Y;
|
||||||
|
public int Z;
|
||||||
|
public NetworkBlockFace Direction;
|
||||||
|
/// <summary>
|
||||||
|
/// The block or item ID. You should probably ignore this and use a server-side inventory.
|
||||||
|
/// </summary>
|
||||||
|
public short ItemID;
|
||||||
|
/// <summary>
|
||||||
|
/// The amount in the player's hand. Who cares?
|
||||||
|
/// </summary>
|
||||||
|
public sbyte? Amount;
|
||||||
|
/// <summary>
|
||||||
|
/// The block metadata. You should probably ignore this and use a server-side inventory.
|
||||||
|
/// </summary>
|
||||||
|
public short? Metadata;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
X = stream.ReadInt32();
|
||||||
|
Y = stream.ReadInt8();
|
||||||
|
Z = stream.ReadInt32();
|
||||||
|
Direction = (NetworkBlockFace)stream.ReadInt8();
|
||||||
|
ItemID = stream.ReadInt16();
|
||||||
|
if (ItemID != 0)
|
||||||
|
{
|
||||||
|
Amount = stream.ReadInt8();
|
||||||
|
Metadata = stream.ReadInt16();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(X);
|
||||||
|
stream.WriteInt32(Y);
|
||||||
|
stream.WriteInt32(Z);
|
||||||
|
stream.WriteInt8((sbyte)Direction);
|
||||||
|
stream.WriteInt16(ItemID);
|
||||||
|
if (ItemID != 0)
|
||||||
|
{
|
||||||
|
stream.WriteInt8(Amount.Value);
|
||||||
|
stream.WriteInt16(Metadata.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
45
TrueCraft.Core/Networking/Packets/PlayerDiggingPacket.cs
Normal file
45
TrueCraft.Core/Networking/Packets/PlayerDiggingPacket.cs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent by clients when they start or stop digging. Also used to throw items.
|
||||||
|
/// Also sent with action set to StartDigging when clicking to open a door.
|
||||||
|
/// </summary>
|
||||||
|
public struct PlayerDiggingPacket : IPacket
|
||||||
|
{
|
||||||
|
public enum Action
|
||||||
|
{
|
||||||
|
StartDigging = 0,
|
||||||
|
StopDigging = 2,
|
||||||
|
DropItem = 4
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte ID { get { return 0x0E; } }
|
||||||
|
|
||||||
|
public Action PlayerAction;
|
||||||
|
public int X;
|
||||||
|
public sbyte Y;
|
||||||
|
public int Z;
|
||||||
|
public NetworkBlockFace BlockFace;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
PlayerAction = (Action)stream.ReadInt8();
|
||||||
|
X = stream.ReadInt32();
|
||||||
|
Y = stream.ReadInt8();
|
||||||
|
Z = stream.ReadInt32();
|
||||||
|
BlockFace = (NetworkBlockFace)stream.ReadInt8();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt8((sbyte)PlayerAction);
|
||||||
|
stream.WriteInt32(X);
|
||||||
|
stream.WriteInt8(Y);
|
||||||
|
stream.WriteInt32(Z);
|
||||||
|
stream.WriteInt8((sbyte)BlockFace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
26
TrueCraft.Core/Networking/Packets/PlayerGroundedPacket.cs
Normal file
26
TrueCraft.Core/Networking/Packets/PlayerGroundedPacket.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent by clients to update whether or not the player is on the ground.
|
||||||
|
/// Probably best to just ignore this.
|
||||||
|
/// </summary>
|
||||||
|
public struct PlayerGroundedPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x0A; }}
|
||||||
|
|
||||||
|
public bool OnGround;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
OnGround = stream.ReadBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteBoolean(OnGround);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
TrueCraft.Core/Networking/Packets/PlayerLookPacket.cs
Normal file
30
TrueCraft.Core/Networking/Packets/PlayerLookPacket.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent to update the rotation of the player's head and body.
|
||||||
|
/// </summary>
|
||||||
|
public struct PlayerLookPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x0C; } }
|
||||||
|
|
||||||
|
public float Yaw, Pitch;
|
||||||
|
public bool OnGround;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
Yaw = stream.ReadSingle();
|
||||||
|
Pitch = stream.ReadSingle();
|
||||||
|
OnGround = stream.ReadBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteDouble(Yaw);
|
||||||
|
stream.WriteDouble(Pitch);
|
||||||
|
stream.WriteBoolean(OnGround);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent by clients to inform the server of updates to their position and look direction.
|
||||||
|
/// A combination of the PlayerPosition and PlayerLook packets.
|
||||||
|
/// </summary>
|
||||||
|
public struct PlayerPositionAndLookPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x0D; } }
|
||||||
|
|
||||||
|
public double X, Y, Z;
|
||||||
|
public double Stance;
|
||||||
|
public float Yaw, Pitch;
|
||||||
|
public bool OnGround;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
X = stream.ReadDouble();
|
||||||
|
Y = stream.ReadDouble();
|
||||||
|
Stance = stream.ReadDouble();
|
||||||
|
Z = stream.ReadDouble();
|
||||||
|
Yaw = stream.ReadSingle();
|
||||||
|
Pitch = stream.ReadSingle();
|
||||||
|
OnGround = stream.ReadBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteDouble(X);
|
||||||
|
stream.WriteDouble(Y);
|
||||||
|
stream.WriteDouble(Stance);
|
||||||
|
stream.WriteDouble(Z);
|
||||||
|
stream.WriteDouble(Yaw);
|
||||||
|
stream.WriteDouble(Pitch);
|
||||||
|
stream.WriteBoolean(OnGround);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
TrueCraft.Core/Networking/Packets/PlayerPositionPacket.cs
Normal file
38
TrueCraft.Core/Networking/Packets/PlayerPositionPacket.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent by clients to inform the server of updates to their position.
|
||||||
|
/// </summary>
|
||||||
|
public struct PlayerPositionPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x0B; } }
|
||||||
|
|
||||||
|
public double X, Y, Z;
|
||||||
|
/// <summary>
|
||||||
|
/// The Y position of the player's eyes. This changes when crouching.
|
||||||
|
/// </summary>
|
||||||
|
public double Stance;
|
||||||
|
public bool OnGround;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
X = stream.ReadDouble();
|
||||||
|
Y = stream.ReadDouble();
|
||||||
|
Stance = stream.ReadDouble();
|
||||||
|
Z = stream.ReadDouble();
|
||||||
|
OnGround = stream.ReadBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteDouble(X);
|
||||||
|
stream.WriteDouble(Y);
|
||||||
|
stream.WriteDouble(Stance);
|
||||||
|
stream.WriteDouble(Z);
|
||||||
|
stream.WriteBoolean(OnGround);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
TrueCraft.Core/Networking/Packets/RespawnPacket.cs
Normal file
27
TrueCraft.Core/Networking/Packets/RespawnPacket.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
using TrueCraft.API;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent by clients when the player clicks "Respawn" after death. Sent by servers to confirm
|
||||||
|
/// the respawn, and to respawn players in different dimensions (i.e. when using a portal).
|
||||||
|
/// </summary>
|
||||||
|
public struct RespawnPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x09; } }
|
||||||
|
|
||||||
|
public Dimension Dimension;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
Dimension = (Dimension)stream.ReadInt8();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt8((sbyte)Dimension);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
40
TrueCraft.Core/Networking/Packets/SetPlayerPositionPacket.cs
Normal file
40
TrueCraft.Core/Networking/Packets/SetPlayerPositionPacket.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent by servers to set the position and look of the player. Can be used to teleport players.
|
||||||
|
/// </summary>
|
||||||
|
public struct SetPlayerPositionPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x0D; } }
|
||||||
|
|
||||||
|
public double X, Y, Z;
|
||||||
|
public double Stance;
|
||||||
|
public float Yaw, Pitch;
|
||||||
|
public bool OnGround;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
X = stream.ReadDouble();
|
||||||
|
Stance = stream.ReadDouble();
|
||||||
|
Y = stream.ReadDouble();
|
||||||
|
Z = stream.ReadDouble();
|
||||||
|
Yaw = stream.ReadSingle();
|
||||||
|
Pitch = stream.ReadSingle();
|
||||||
|
OnGround = stream.ReadBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteDouble(X);
|
||||||
|
stream.WriteDouble(Stance);
|
||||||
|
stream.WriteDouble(Y);
|
||||||
|
stream.WriteDouble(Z);
|
||||||
|
stream.WriteDouble(Yaw);
|
||||||
|
stream.WriteDouble(Pitch);
|
||||||
|
stream.WriteBoolean(OnGround);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
37
TrueCraft.Core/Networking/Packets/SetSlotPacket.cs
Normal file
37
TrueCraft.Core/Networking/Packets/SetSlotPacket.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the contents of an item slot on an inventory window.
|
||||||
|
/// </summary>
|
||||||
|
public struct SetSlotPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x67; } }
|
||||||
|
|
||||||
|
public sbyte WindowID;
|
||||||
|
public short SlotIndex;
|
||||||
|
public short ItemID;
|
||||||
|
public sbyte Count;
|
||||||
|
public short Metadata;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
WindowID = stream.ReadInt8();
|
||||||
|
SlotIndex = stream.ReadInt16();
|
||||||
|
ItemID = stream.ReadInt16();
|
||||||
|
Count = stream.ReadInt8();
|
||||||
|
Metadata = stream.ReadInt16();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt8(WindowID);
|
||||||
|
stream.WriteInt16(SlotIndex);
|
||||||
|
stream.WriteInt16(ItemID);
|
||||||
|
stream.WriteInt8(Count);
|
||||||
|
stream.WriteInt16(Metadata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
52
TrueCraft.Core/Networking/Packets/SoundEffectPacket.cs
Normal file
52
TrueCraft.Core/Networking/Packets/SoundEffectPacket.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Plays a sound effect (or special case: generates smoke particles)
|
||||||
|
/// </summary>
|
||||||
|
public struct SoundEffectPacket : IPacket
|
||||||
|
{
|
||||||
|
public enum EffectType
|
||||||
|
{
|
||||||
|
Click2 = 1000,
|
||||||
|
Click1 = 1001,
|
||||||
|
FireBow = 1002,
|
||||||
|
ToggleDoor = 1003,
|
||||||
|
Extinguish = 1004,
|
||||||
|
PlayRecord = 1005,
|
||||||
|
Smoke = 1006,
|
||||||
|
BreakBlock = 1007,
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte ID { get { return 0x3D; } }
|
||||||
|
|
||||||
|
public EffectType Effect;
|
||||||
|
public int X;
|
||||||
|
public sbyte Y;
|
||||||
|
public int Z;
|
||||||
|
/// <summary>
|
||||||
|
/// For record play, the record ID. For smoke, the direction. For break block, the block ID.
|
||||||
|
/// </summary>
|
||||||
|
public int Data;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
Effect = (EffectType)stream.ReadInt32();
|
||||||
|
X = stream.ReadInt32();
|
||||||
|
Y = stream.ReadInt8();
|
||||||
|
Z = stream.ReadInt32();
|
||||||
|
Data = stream.ReadInt32();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32((int)Effect);
|
||||||
|
stream.WriteInt32(X);
|
||||||
|
stream.WriteInt8(Y);
|
||||||
|
stream.WriteInt32(Z);
|
||||||
|
stream.WriteInt32(Data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Spawns entities that don't fit into any other bucket of entities.
|
||||||
|
/// </summary>
|
||||||
|
public struct SpawnGenericEntityPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x17; } }
|
||||||
|
|
||||||
|
public int EntityID;
|
||||||
|
public sbyte EntityType; // TODO: Enum? Maybe a lookup would be better.
|
||||||
|
public int X, Y, Z;
|
||||||
|
public int Data;
|
||||||
|
public short? XVelocity, YVelocity, ZVelocity;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
EntityID = stream.ReadInt32();
|
||||||
|
EntityType = stream.ReadInt8();
|
||||||
|
X = stream.ReadInt32();
|
||||||
|
Y = stream.ReadInt32();
|
||||||
|
Z = stream.ReadInt32();
|
||||||
|
Data = stream.ReadInt32();
|
||||||
|
if (Data > 0)
|
||||||
|
{
|
||||||
|
XVelocity = stream.ReadInt16();
|
||||||
|
YVelocity = stream.ReadInt16();
|
||||||
|
ZVelocity = stream.ReadInt16();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(EntityID);
|
||||||
|
stream.WriteInt8(EntityType);
|
||||||
|
stream.WriteInt32(X);
|
||||||
|
stream.WriteInt32(Y);
|
||||||
|
stream.WriteInt32(Z);
|
||||||
|
stream.WriteInt32(Data);
|
||||||
|
if (Data > 0)
|
||||||
|
{
|
||||||
|
stream.WriteInt16(XVelocity.Value);
|
||||||
|
stream.WriteInt16(YVelocity.Value);
|
||||||
|
stream.WriteInt16(ZVelocity.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
50
TrueCraft.Core/Networking/Packets/SpawnItemPacket.cs
Normal file
50
TrueCraft.Core/Networking/Packets/SpawnItemPacket.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent by servers to spawn item entities, I think.
|
||||||
|
/// </summary>
|
||||||
|
public struct SpawnItemPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x15; } }
|
||||||
|
|
||||||
|
public int EntityID;
|
||||||
|
public short ItemID;
|
||||||
|
public sbyte Count;
|
||||||
|
public short Metadata;
|
||||||
|
public int X, Y, Z;
|
||||||
|
public sbyte Yaw;
|
||||||
|
public sbyte Pitch;
|
||||||
|
public sbyte Roll;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
EntityID = stream.ReadInt32();
|
||||||
|
ItemID = stream.ReadInt16();
|
||||||
|
Count = stream.ReadInt8();
|
||||||
|
Metadata = stream.ReadInt16();
|
||||||
|
X = stream.ReadInt32();
|
||||||
|
Y = stream.ReadInt32();
|
||||||
|
Z = stream.ReadInt32();
|
||||||
|
Yaw = stream.ReadInt8();
|
||||||
|
Pitch = stream.ReadInt8();
|
||||||
|
Roll = stream.ReadInt8();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(EntityID);
|
||||||
|
stream.WriteInt16(ItemID);
|
||||||
|
stream.WriteInt8(Count);
|
||||||
|
stream.WriteInt16(Metadata);
|
||||||
|
stream.WriteInt32(X);
|
||||||
|
stream.WriteInt32(Y);
|
||||||
|
stream.WriteInt32(Z);
|
||||||
|
stream.WriteInt8(Yaw);
|
||||||
|
stream.WriteInt8(Pitch);
|
||||||
|
stream.WriteInt8(Roll);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
44
TrueCraft.Core/Networking/Packets/SpawnMobPacket.cs
Normal file
44
TrueCraft.Core/Networking/Packets/SpawnMobPacket.cs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
using TrueCraft.API;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Does what it says on the tin.
|
||||||
|
/// </summary>
|
||||||
|
public struct SpawnMobPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x18; } }
|
||||||
|
|
||||||
|
public int EntityID;
|
||||||
|
public sbyte MobType;
|
||||||
|
public int X, Y, Z;
|
||||||
|
public sbyte Yaw, Pitch;
|
||||||
|
public MetadataDictionary Metadata; // TODO: Import metadata implementation from Craft.Net
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
EntityID = stream.ReadInt32();
|
||||||
|
MobType = stream.ReadInt8();
|
||||||
|
X = stream.ReadInt32();
|
||||||
|
Y = stream.ReadInt32();
|
||||||
|
Z = stream.ReadInt32();
|
||||||
|
Yaw = stream.ReadInt8();
|
||||||
|
Pitch = stream.ReadInt8();
|
||||||
|
Metadata = MetadataDictionary.FromStream(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(EntityID);
|
||||||
|
stream.WriteInt8(MobType);
|
||||||
|
stream.WriteInt32(X);
|
||||||
|
stream.WriteInt32(Y);
|
||||||
|
stream.WriteInt32(Z);
|
||||||
|
stream.WriteInt8(Yaw);
|
||||||
|
stream.WriteInt8(Pitch);
|
||||||
|
Metadata.WriteTo(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
46
TrueCraft.Core/Networking/Packets/SpawnPaintingPacket.cs
Normal file
46
TrueCraft.Core/Networking/Packets/SpawnPaintingPacket.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Does what it says on the tin.
|
||||||
|
/// </summary>
|
||||||
|
public struct SpawnPaintingPacket : IPacket
|
||||||
|
{
|
||||||
|
public enum PaintingDirection
|
||||||
|
{
|
||||||
|
NegativeZ = 0,
|
||||||
|
NegativeX = 1,
|
||||||
|
PositiveZ = 2,
|
||||||
|
PositiveX = 3,
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte ID { get { return 0x19; } }
|
||||||
|
|
||||||
|
public int EntityID;
|
||||||
|
public string PaintingName;
|
||||||
|
public int X, Y, Z;
|
||||||
|
public PaintingDirection Direction;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
EntityID = stream.ReadInt32();
|
||||||
|
PaintingName = stream.ReadString();
|
||||||
|
X = stream.ReadInt32();
|
||||||
|
Y = stream.ReadInt32();
|
||||||
|
Z = stream.ReadInt32();
|
||||||
|
Direction = (PaintingDirection)stream.ReadInt32();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(EntityID);
|
||||||
|
stream.WriteString(PaintingName);
|
||||||
|
stream.WriteInt32(X);
|
||||||
|
stream.WriteInt32(Y);
|
||||||
|
stream.WriteInt32(Z);
|
||||||
|
stream.WriteInt32((int)Direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
43
TrueCraft.Core/Networking/Packets/SpawnPlayerPacket.cs
Normal file
43
TrueCraft.Core/Networking/Packets/SpawnPlayerPacket.cs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
public struct SpawnPlayerPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x14; } }
|
||||||
|
|
||||||
|
public int EntityID;
|
||||||
|
public string PlayerName;
|
||||||
|
public int X, Y, Z;
|
||||||
|
public sbyte Yaw, Pitch;
|
||||||
|
/// <summary>
|
||||||
|
/// Note that this should be 0 for "no item".
|
||||||
|
/// </summary>
|
||||||
|
public short CurrentItem;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
EntityID = stream.ReadInt32();
|
||||||
|
PlayerName = stream.ReadString();
|
||||||
|
X = stream.ReadInt32();
|
||||||
|
Y = stream.ReadInt32();
|
||||||
|
Z = stream.ReadInt32();
|
||||||
|
Yaw = stream.ReadInt8();
|
||||||
|
Pitch = stream.ReadInt8();
|
||||||
|
CurrentItem = stream.ReadInt16();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(EntityID);
|
||||||
|
stream.WriteString(PlayerName);
|
||||||
|
stream.WriteInt32(X);
|
||||||
|
stream.WriteInt32(Y);
|
||||||
|
stream.WriteInt32(Z);
|
||||||
|
stream.WriteInt8(Yaw);
|
||||||
|
stream.WriteInt8(Pitch);
|
||||||
|
stream.WriteInt16(CurrentItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
37
TrueCraft.Core/Networking/Packets/SpawnPositionPacket.cs
Normal file
37
TrueCraft.Core/Networking/Packets/SpawnPositionPacket.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent by the server to specify the coordinates of the spawn point. This only affects what the
|
||||||
|
/// compass item points to.
|
||||||
|
/// </summary>
|
||||||
|
public struct SpawnPositionPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x06; } }
|
||||||
|
|
||||||
|
public SpawnPositionPacket(int x, int y, int z)
|
||||||
|
{
|
||||||
|
X = x;
|
||||||
|
Y = y;
|
||||||
|
Z = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int X, Y, Z;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
X = stream.ReadInt32();
|
||||||
|
Y = stream.ReadInt32();
|
||||||
|
Z = stream.ReadInt32();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(X);
|
||||||
|
stream.WriteInt32(Y);
|
||||||
|
stream.WriteInt32(Z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
31
TrueCraft.Core/Networking/Packets/TimeUpdatePacket.cs
Normal file
31
TrueCraft.Core/Networking/Packets/TimeUpdatePacket.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent from the server to inform the client of the in-game time of day.
|
||||||
|
/// The number sent is in 1/20th of a second increments, where 24000 ticks are in each day.
|
||||||
|
/// </summary>
|
||||||
|
public struct TimeUpdatePacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x04; } }
|
||||||
|
|
||||||
|
public TimeUpdatePacket(long time)
|
||||||
|
{
|
||||||
|
Time = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long Time;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
Time = stream.ReadInt64();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt64(Time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
31
TrueCraft.Core/Networking/Packets/TransactionStatusPacket.cs
Normal file
31
TrueCraft.Core/Networking/Packets/TransactionStatusPacket.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent by the server to inform the client if an inventory transaction was successful.
|
||||||
|
/// </summary>
|
||||||
|
public struct TransactionStatusPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x6A; } }
|
||||||
|
|
||||||
|
public sbyte WindowID;
|
||||||
|
public short TransactionID;
|
||||||
|
public bool Accepted;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
WindowID = stream.ReadInt8();
|
||||||
|
TransactionID = stream.ReadInt16();
|
||||||
|
Accepted = stream.ReadBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt8(WindowID);
|
||||||
|
stream.WriteInt16(TransactionID);
|
||||||
|
stream.WriteBoolean(Accepted);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
25
TrueCraft.Core/Networking/Packets/UpdateHealthPacket.cs
Normal file
25
TrueCraft.Core/Networking/Packets/UpdateHealthPacket.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent by servers to inform clients of their current health.
|
||||||
|
/// </summary>
|
||||||
|
public struct UpdateHealthPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x08; } }
|
||||||
|
|
||||||
|
public short Health;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
Health = stream.ReadInt16();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt16(Health);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
40
TrueCraft.Core/Networking/Packets/UpdateProgressPacket.cs
Normal file
40
TrueCraft.Core/Networking/Packets/UpdateProgressPacket.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the progress on the furnace UI.
|
||||||
|
/// </summary>
|
||||||
|
public struct UpdateProgressPacket : IPacket
|
||||||
|
{
|
||||||
|
public enum ProgressTarget
|
||||||
|
{
|
||||||
|
ItemCompletion = 0,
|
||||||
|
AvailableHeat = 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte ID { get { return 0x69; } }
|
||||||
|
|
||||||
|
public sbyte WindowID;
|
||||||
|
public ProgressTarget Target;
|
||||||
|
/// <summary>
|
||||||
|
/// For the item completion, about 180 is full. For the available heat, about 250 is full.
|
||||||
|
/// </summary>
|
||||||
|
public short Value;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
WindowID = stream.ReadInt8();
|
||||||
|
Target = (ProgressTarget)stream.ReadInt16();
|
||||||
|
Value = stream.ReadInt16();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt8(WindowID);
|
||||||
|
stream.WriteInt16((short)Target);
|
||||||
|
stream.WriteInt16(Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
41
TrueCraft.Core/Networking/Packets/UpdateSignPacket.cs
Normal file
41
TrueCraft.Core/Networking/Packets/UpdateSignPacket.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent by clients to update signs and by servers to notify clients of the change.
|
||||||
|
/// </summary>
|
||||||
|
public struct UpdateSignPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x82; } }
|
||||||
|
|
||||||
|
public int X;
|
||||||
|
public short Y;
|
||||||
|
public int Z;
|
||||||
|
public string[] Text;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
X = stream.ReadInt32();
|
||||||
|
Y = stream.ReadInt16();
|
||||||
|
Z = stream.ReadInt32();
|
||||||
|
Text = new string[4];
|
||||||
|
Text[0] = stream.ReadString();
|
||||||
|
Text[1] = stream.ReadString();
|
||||||
|
Text[2] = stream.ReadString();
|
||||||
|
Text[3] = stream.ReadString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(X);
|
||||||
|
stream.WriteInt32(Y);
|
||||||
|
stream.WriteInt32(Z);
|
||||||
|
stream.WriteString(Text[0]);
|
||||||
|
stream.WriteString(Text[1]);
|
||||||
|
stream.WriteString(Text[2]);
|
||||||
|
stream.WriteString(Text[3]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
28
TrueCraft.Core/Networking/Packets/UpdateStatisticPacket.cs
Normal file
28
TrueCraft.Core/Networking/Packets/UpdateStatisticPacket.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent to update the client's list of player statistics.
|
||||||
|
/// </summary>
|
||||||
|
public struct UpdateStatisticPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0xC8; } }
|
||||||
|
|
||||||
|
public int StatisticID;
|
||||||
|
public sbyte Delta;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
StatisticID = stream.ReadInt32();
|
||||||
|
Delta = stream.ReadInt8();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(StatisticID);
|
||||||
|
stream.WriteInt8(Delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
37
TrueCraft.Core/Networking/Packets/UseBedPacket.cs
Normal file
37
TrueCraft.Core/Networking/Packets/UseBedPacket.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent by servers to indicate that a player is using a bed. More research required on this packet.
|
||||||
|
/// </summary>
|
||||||
|
public struct UseBedPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x11; } }
|
||||||
|
|
||||||
|
public int EntityID;
|
||||||
|
public bool InBed;
|
||||||
|
public int X;
|
||||||
|
public sbyte Y;
|
||||||
|
public int Z;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
EntityID = stream.ReadInt32();
|
||||||
|
InBed = stream.ReadBoolean();
|
||||||
|
X = stream.ReadInt32();
|
||||||
|
Y = stream.ReadInt8();
|
||||||
|
Z = stream.ReadInt32();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(EntityID);
|
||||||
|
stream.WriteBoolean(InBed);
|
||||||
|
stream.WriteInt32(X);
|
||||||
|
stream.WriteInt8(Y);
|
||||||
|
stream.WriteInt32(Z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
31
TrueCraft.Core/Networking/Packets/UseEntityPacket.cs
Normal file
31
TrueCraft.Core/Networking/Packets/UseEntityPacket.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sent by clients upon clicking an entity.
|
||||||
|
/// </summary>
|
||||||
|
public struct UseEntityPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x07; } }
|
||||||
|
|
||||||
|
public int UserID;
|
||||||
|
public int TargetID;
|
||||||
|
public bool LeftClick;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
UserID = stream.ReadInt32();
|
||||||
|
TargetID = stream.ReadInt32();
|
||||||
|
LeftClick = stream.ReadBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(UserID);
|
||||||
|
stream.WriteInt32(TargetID);
|
||||||
|
stream.WriteBoolean(LeftClick);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
TrueCraft.Core/Networking/Packets/UselessEntityPacket.cs
Normal file
22
TrueCraft.Core/Networking/Packets/UselessEntityPacket.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
public struct UselessEntityPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x1E; } }
|
||||||
|
|
||||||
|
public int EntityID;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
EntityID = stream.ReadInt16();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt32(EntityID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
51
TrueCraft.Core/Networking/Packets/WindowItemsPacket.cs
Normal file
51
TrueCraft.Core/Networking/Packets/WindowItemsPacket.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
using TrueCraft.API;
|
||||||
|
|
||||||
|
namespace TrueCraft.Core.Networking.Packets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the items in an inventory window on the client.
|
||||||
|
/// </summary>
|
||||||
|
public struct WindowItemsPacket : IPacket
|
||||||
|
{
|
||||||
|
public byte ID { get { return 0x68; } }
|
||||||
|
|
||||||
|
public sbyte WindowID;
|
||||||
|
public ItemStack[] Items;
|
||||||
|
|
||||||
|
public void ReadPacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
WindowID = stream.ReadInt8();
|
||||||
|
short length = stream.ReadInt16();
|
||||||
|
Items = new ItemStack[length];
|
||||||
|
for (int i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
short id = stream.ReadInt16();
|
||||||
|
if (id != -1)
|
||||||
|
{
|
||||||
|
sbyte count = stream.ReadInt8();
|
||||||
|
short metadata = stream.ReadInt16();
|
||||||
|
Items[i] = new ItemStack(id, count, metadata);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Items[i] = ItemStack.EmptyStack;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePacket(IMinecraftStream stream)
|
||||||
|
{
|
||||||
|
stream.WriteInt8(WindowID);
|
||||||
|
stream.WriteInt16((short)Items.Length);
|
||||||
|
for (int i = 0; i < Items.Length; i++)
|
||||||
|
{
|
||||||
|
stream.WriteInt16(Items[i].Id);
|
||||||
|
if (!Items[i].Empty)
|
||||||
|
{
|
||||||
|
stream.WriteInt8(Items[i].Count);
|
||||||
|
stream.WriteInt16(Items[i].Metadata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
TrueCraft.Core/Properties/AssemblyInfo.cs
Normal file
27
TrueCraft.Core/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
// Information about this assembly is defined by the following attributes.
|
||||||
|
// Change them to the values specific to your project.
|
||||||
|
|
||||||
|
[assembly: AssemblyTitle("TrueCraft.Core")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("")]
|
||||||
|
[assembly: AssemblyCopyright("sircmpwn")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||||
|
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||||
|
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||||
|
|
||||||
|
[assembly: AssemblyVersion("1.0.*")]
|
||||||
|
|
||||||
|
// The following attributes are used to specify the signing key for the assembly,
|
||||||
|
// if desired. See the Mono documentation for more information about signing.
|
||||||
|
|
||||||
|
//[assembly: AssemblyDelaySign(false)]
|
||||||
|
//[assembly: AssemblyKeyFile("")]
|
||||||
|
|
107
TrueCraft.Core/TrueCraft.Core.csproj
Normal file
107
TrueCraft.Core/TrueCraft.Core.csproj
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{FA4BE9A3-DBF0-4380-BA2B-FFAA71C4706D}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<RootNamespace>TrueCraft.Core</RootNamespace>
|
||||||
|
<AssemblyName>TrueCraft.Core</AssemblyName>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<ConsolePause>false</ConsolePause>
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release</OutputPath>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<ConsolePause>false</ConsolePause>
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Networking\MinecraftStream.cs" />
|
||||||
|
<Compile Include="Networking\PacketReader.cs" />
|
||||||
|
<Compile Include="Networking\Packets\HandshakePacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\HandshakeResponsePacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\KeepAlivePacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\LoginRequestPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\LoginResponsePacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\ChatMessagePacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\TimeUpdatePacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\EntityEquipmentPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\SpawnPositionPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\UseEntityPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\UpdateHealthPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\RespawnPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\PlayerGroundedPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\PlayerPositionPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\PlayerLookPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\PlayerPositionAndLookPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\SetPlayerPositionPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\PlayerDiggingPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\PlayerBlockPlacementPacket.cs" />
|
||||||
|
<Compile Include="Networking\NetworkBlockFace.cs" />
|
||||||
|
<Compile Include="Networking\Packets\ChangeHeldItemPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\UseBedPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\AnimationPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\PlayerActionPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\SpawnPlayerPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\SpawnItemPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\CollectItemPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\SpawnGenericEntityPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\SpawnMobPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\SpawnPaintingPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\EntityVelocityPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\UselessEntityPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\EntityRelativeMovePacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\EntityLookPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\EntityLookAndRelativeMovePacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\EntityTeleportPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\EntityStatusPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\AttachEntityPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\EntityMetadataPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\ChunkPreamblePacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\ChunkDataPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\BulkBlockChangePacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\BlockChangePacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\BlockActionPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\SoundEffectPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\EnvironmentStatePacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\LightningPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\OpenWindowPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\CloseWindow.cs" />
|
||||||
|
<Compile Include="Networking\Packets\ClickWindowPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\SetSlotPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\WindowItemsPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\UpdateProgressPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\TransactionStatusPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\UpdateSignPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\MapDataPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\UpdateStatisticPacket.cs" />
|
||||||
|
<Compile Include="Networking\Packets\DisconnectPacket.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TrueCraft.API\TrueCraft.API.csproj">
|
||||||
|
<Project>{FEE55B54-91B0-4325-A2C3-D576C0B7A81F}</Project>
|
||||||
|
<Name>TrueCraft.API</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Networking\Packets\" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
56
TrueCraft.sln
Normal file
56
TrueCraft.sln
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 2012
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrueCraft", "TrueCraft\TrueCraft.csproj", "{C1C47EF5-2D8A-4231-AAA8-F651F52F480E}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrueCraft.API", "TrueCraft.API\TrueCraft.API.csproj", "{FEE55B54-91B0-4325-A2C3-D576C0B7A81F}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrueCraft.Core", "TrueCraft.Core\TrueCraft.Core.csproj", "{FA4BE9A3-DBF0-4380-BA2B-FFAA71C4706D}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "fNbt", "externals\fNbt\fNbt\fNbt.csproj", "{4488498D-976D-4DA3-BF72-109531AF0488}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{4488498D-976D-4DA3-BF72-109531AF0488}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{4488498D-976D-4DA3-BF72-109531AF0488}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{4488498D-976D-4DA3-BF72-109531AF0488}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{4488498D-976D-4DA3-BF72-109531AF0488}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{4488498D-976D-4DA3-BF72-109531AF0488}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{4488498D-976D-4DA3-BF72-109531AF0488}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{4488498D-976D-4DA3-BF72-109531AF0488}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{4488498D-976D-4DA3-BF72-109531AF0488}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{C1C47EF5-2D8A-4231-AAA8-F651F52F480E}.Debug|x64.ActiveCfg = Debug|x86
|
||||||
|
{C1C47EF5-2D8A-4231-AAA8-F651F52F480E}.Debug|x64.Build.0 = Debug|x86
|
||||||
|
{C1C47EF5-2D8A-4231-AAA8-F651F52F480E}.Debug|x86.ActiveCfg = Debug|x86
|
||||||
|
{C1C47EF5-2D8A-4231-AAA8-F651F52F480E}.Debug|x86.Build.0 = Debug|x86
|
||||||
|
{C1C47EF5-2D8A-4231-AAA8-F651F52F480E}.Release|x64.ActiveCfg = Release|x86
|
||||||
|
{C1C47EF5-2D8A-4231-AAA8-F651F52F480E}.Release|x64.Build.0 = Release|x86
|
||||||
|
{C1C47EF5-2D8A-4231-AAA8-F651F52F480E}.Release|x86.ActiveCfg = Release|x86
|
||||||
|
{C1C47EF5-2D8A-4231-AAA8-F651F52F480E}.Release|x86.Build.0 = Release|x86
|
||||||
|
{FA4BE9A3-DBF0-4380-BA2B-FFAA71C4706D}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{FA4BE9A3-DBF0-4380-BA2B-FFAA71C4706D}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{FA4BE9A3-DBF0-4380-BA2B-FFAA71C4706D}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{FA4BE9A3-DBF0-4380-BA2B-FFAA71C4706D}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{FA4BE9A3-DBF0-4380-BA2B-FFAA71C4706D}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{FA4BE9A3-DBF0-4380-BA2B-FFAA71C4706D}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{FA4BE9A3-DBF0-4380-BA2B-FFAA71C4706D}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{FA4BE9A3-DBF0-4380-BA2B-FFAA71C4706D}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{FEE55B54-91B0-4325-A2C3-D576C0B7A81F}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{FEE55B54-91B0-4325-A2C3-D576C0B7A81F}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{FEE55B54-91B0-4325-A2C3-D576C0B7A81F}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{FEE55B54-91B0-4325-A2C3-D576C0B7A81F}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{FEE55B54-91B0-4325-A2C3-D576C0B7A81F}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{FEE55B54-91B0-4325-A2C3-D576C0B7A81F}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{FEE55B54-91B0-4325-A2C3-D576C0B7A81F}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{FEE55B54-91B0-4325-A2C3-D576C0B7A81F}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(MonoDevelopProperties) = preSolution
|
||||||
|
StartupItem = TrueCraft\TrueCraft.csproj
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
25
TrueCraft/Handlers/LoginHandlers.cs
Normal file
25
TrueCraft/Handlers/LoginHandlers.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Server;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
using TrueCraft.Core.Networking.Packets;
|
||||||
|
|
||||||
|
namespace TrueCraft.Handlers
|
||||||
|
{
|
||||||
|
internal static class LoginHandlers
|
||||||
|
{
|
||||||
|
public static void HandleHandshakePacket(IPacket _packet, IRemoteClient _client, IMultiplayerServer server)
|
||||||
|
{
|
||||||
|
var packet = (HandshakePacket)_packet;
|
||||||
|
var client = (RemoteClient)_client;
|
||||||
|
client.Username = packet.Username;
|
||||||
|
client.QueuePacket(new HandshakeResponsePacket("-")); // TODO: Implement some form of authentication
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void HandleLoginRequestPacket(IPacket _packet, IRemoteClient _client, IMultiplayerServer server)
|
||||||
|
{
|
||||||
|
var packet = (LoginRequestPacket)_packet;
|
||||||
|
var client = (RemoteClient)_client;
|
||||||
|
client.QueuePacket(new DisconnectPacket("It works!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
TrueCraft/Handlers/PacketHandlers.cs
Normal file
15
TrueCraft/Handlers/PacketHandlers.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Server;
|
||||||
|
using TrueCraft.Core.Networking.Packets;
|
||||||
|
|
||||||
|
namespace TrueCraft.Handlers
|
||||||
|
{
|
||||||
|
public static class PacketHandlers
|
||||||
|
{
|
||||||
|
public static void RegisterHandlers(IMultiplayerServer server)
|
||||||
|
{
|
||||||
|
server.RegisterPacketHandler(new HandshakePacket().ID, LoginHandlers.HandleHandshakePacket);
|
||||||
|
server.RegisterPacketHandler(new LoginRequestPacket().ID, LoginHandlers.HandleLoginRequestPacket);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
90
TrueCraft/MultiplayerServer.cs
Normal file
90
TrueCraft/MultiplayerServer.cs
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Server;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
using TrueCraft.Core.Networking;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using System.Net;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace TrueCraft
|
||||||
|
{
|
||||||
|
public class MultiplayerServer : IMultiplayerServer
|
||||||
|
{
|
||||||
|
public IPacketReader PacketReader { get; private set; }
|
||||||
|
public IList<IRemoteClient> Clients { get; private set; }
|
||||||
|
|
||||||
|
private Timer NetworkWorker;
|
||||||
|
private TcpListener Listener;
|
||||||
|
private PacketHandler[] PacketHandlers;
|
||||||
|
|
||||||
|
public MultiplayerServer()
|
||||||
|
{
|
||||||
|
var reader = new PacketReader();
|
||||||
|
PacketReader = reader;
|
||||||
|
Clients = new List<IRemoteClient>();
|
||||||
|
NetworkWorker = new Timer(DoNetwork);
|
||||||
|
PacketHandlers = new PacketHandler[0x100];
|
||||||
|
|
||||||
|
reader.RegisterCorePackets();
|
||||||
|
Handlers.PacketHandlers.RegisterHandlers(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RegisterPacketHandler(byte packetId, PacketHandler handler)
|
||||||
|
{
|
||||||
|
PacketHandlers[packetId] = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Start(IPEndPoint endPoint)
|
||||||
|
{
|
||||||
|
Listener = new TcpListener(endPoint);
|
||||||
|
Listener.Start();
|
||||||
|
Listener.BeginAcceptTcpClient(AcceptClient, null);
|
||||||
|
NetworkWorker.Change(100, 1000 / 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AcceptClient(IAsyncResult result)
|
||||||
|
{
|
||||||
|
var tcpClient = Listener.EndAcceptTcpClient(result);
|
||||||
|
var client = new RemoteClient(tcpClient.GetStream());
|
||||||
|
Clients.Add(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DoNetwork(object discarded)
|
||||||
|
{
|
||||||
|
for (int i = 0, ClientsCount = Clients.Count; i < ClientsCount; i++)
|
||||||
|
{
|
||||||
|
var client = Clients[i] as RemoteClient;
|
||||||
|
if (client.PacketQueue.Count != 0)
|
||||||
|
{
|
||||||
|
IPacket packet;
|
||||||
|
while (!client.PacketQueue.TryDequeue(out packet)) { }
|
||||||
|
Console.WriteLine("Sending packet 0x{0:X2}: {1}", packet.ID, packet.GetType().Name);
|
||||||
|
PacketReader.WritePacket(client.MinecraftStream, packet);
|
||||||
|
}
|
||||||
|
if (client.DataAvailable)
|
||||||
|
{
|
||||||
|
var packet = PacketReader.ReadPacket(client.MinecraftStream);
|
||||||
|
if (PacketHandlers[packet.ID] != null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Got packet 0x{0:X2}: {1}", packet.ID, packet.GetType().Name);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PacketHandlers[packet.ID](packet, client, this);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
// TODO: Something else
|
||||||
|
Clients.Remove(client);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("WARNING: Got unhandled packet 0x{0:X2}: {1}", packet.ID, packet.GetType().Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
18
TrueCraft/Program.cs
Normal file
18
TrueCraft/Program.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Net;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace TrueCraft
|
||||||
|
{
|
||||||
|
class MainClass
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
// TODO: Make this more flexible
|
||||||
|
var server = new MultiplayerServer();
|
||||||
|
server.Start(new IPEndPoint(IPAddress.Any, 25565));
|
||||||
|
while (true)
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
TrueCraft/Properties/AssemblyInfo.cs
Normal file
27
TrueCraft/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
// Information about this assembly is defined by the following attributes.
|
||||||
|
// Change them to the values specific to your project.
|
||||||
|
|
||||||
|
[assembly: AssemblyTitle("TrueCraft")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("")]
|
||||||
|
[assembly: AssemblyCopyright("sircmpwn")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||||
|
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||||
|
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||||
|
|
||||||
|
[assembly: AssemblyVersion("1.0.*")]
|
||||||
|
|
||||||
|
// The following attributes are used to specify the signing key for the assembly,
|
||||||
|
// if desired. See the Mono documentation for more information about signing.
|
||||||
|
|
||||||
|
//[assembly: AssemblyDelaySign(false)]
|
||||||
|
//[assembly: AssemblyKeyFile("")]
|
||||||
|
|
36
TrueCraft/RemoteClient.cs
Normal file
36
TrueCraft/RemoteClient.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using TrueCraft.Core.Networking;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
|
namespace TrueCraft
|
||||||
|
{
|
||||||
|
public class RemoteClient : IRemoteClient
|
||||||
|
{
|
||||||
|
public RemoteClient(NetworkStream stream)
|
||||||
|
{
|
||||||
|
NetworkStream = stream;
|
||||||
|
MinecraftStream = new MinecraftStream(NetworkStream);
|
||||||
|
PacketQueue = new ConcurrentQueue<IPacket>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public NetworkStream NetworkStream { get; set; }
|
||||||
|
public IMinecraftStream MinecraftStream { get; internal set; }
|
||||||
|
public ConcurrentQueue<IPacket> PacketQueue { get; private set; }
|
||||||
|
public string Username { get; internal set; }
|
||||||
|
|
||||||
|
public bool DataAvailable
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return NetworkStream.DataAvailable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void QueuePacket(IPacket packet)
|
||||||
|
{
|
||||||
|
PacketQueue.Enqueue(packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
56
TrueCraft/TrueCraft.csproj
Normal file
56
TrueCraft/TrueCraft.csproj
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||||
|
<ProjectGuid>{C1C47EF5-2D8A-4231-AAA8-F651F52F480E}</ProjectGuid>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<RootNamespace>TrueCraft</RootNamespace>
|
||||||
|
<AssemblyName>TrueCraft</AssemblyName>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<Externalconsole>true</Externalconsole>
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release</OutputPath>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<Externalconsole>true</Externalconsole>
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Program.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="MultiplayerServer.cs" />
|
||||||
|
<Compile Include="RemoteClient.cs" />
|
||||||
|
<Compile Include="Handlers\PacketHandlers.cs" />
|
||||||
|
<Compile Include="Handlers\LoginHandlers.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TrueCraft.API\TrueCraft.API.csproj">
|
||||||
|
<Project>{FEE55B54-91B0-4325-A2C3-D576C0B7A81F}</Project>
|
||||||
|
<Name>TrueCraft.API</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\TrueCraft.Core\TrueCraft.Core.csproj">
|
||||||
|
<Project>{FA4BE9A3-DBF0-4380-BA2B-FFAA71C4706D}</Project>
|
||||||
|
<Name>TrueCraft.Core</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Handlers\" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
1
externals/fNbt
vendored
Submodule
1
externals/fNbt
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit bf33aec3f01ba86358e837a5345da6c25feccf7f
|
Loading…
x
Reference in New Issue
Block a user