mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-10 15:52:11 -04:00
Show server version in heartbeat, add AABB struct
This commit is contained in:
parent
077f181084
commit
c5876ee307
@ -623,6 +623,7 @@
|
||||
<Compile Include="util\Formatting\MultiPageOutput.cs" />
|
||||
<Compile Include="util\IO\BufferedBlockSender.cs" />
|
||||
<Compile Include="util\IO\Paths.cs" />
|
||||
<Compile Include="util\Math\AABB.cs" />
|
||||
<Compile Include="util\Math\DirUtils.cs" />
|
||||
<Compile Include="util\Math\Vectors.cs" />
|
||||
<Compile Include="util\NET_20.cs" />
|
||||
|
@ -71,7 +71,7 @@ namespace MCGalaxy {
|
||||
"&version=7" +
|
||||
"&salt=" + Server.salt +
|
||||
"&users=" + PlayerCount() +
|
||||
"&software=MCGalaxy";
|
||||
"&software=" + Uri.EscapeDataString("MCGalaxy " + Server.VersionString);
|
||||
}
|
||||
|
||||
static int PlayerCount() {
|
||||
|
@ -58,10 +58,19 @@ namespace MCGalaxy {
|
||||
public static PlayerMetaList Notes = new PlayerMetaList("text/notes.txt");
|
||||
public static Version Version { get { return System.Reflection.Assembly.GetAssembly(typeof(Server)).GetName().Version; } }
|
||||
|
||||
static string versionString = null;
|
||||
static object versionLock = new object();
|
||||
|
||||
// Cache getting the version
|
||||
public static string VersionString {
|
||||
get {
|
||||
lock (versionLock) {
|
||||
if (versionString == null) {
|
||||
Version v = Version;
|
||||
return v.Major + "." + v.Minor + "." + v.Build + "." + v.Revision;
|
||||
versionString = v.Major + "." + v.Minor + "." + v.Build + "." + v.Revision;
|
||||
}
|
||||
return versionString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,21 +103,25 @@ namespace MCGalaxy {
|
||||
if (itemName.IndexOf(name, comp) < 0) continue;
|
||||
|
||||
match = item; matches++;
|
||||
if (matches <= limit)
|
||||
if (matches <= limit) {
|
||||
nameMatches.Append(itemName).Append(", ");
|
||||
else if (matches == limit + 1)
|
||||
} else if (matches == limit + 1) {
|
||||
nameMatches.Append("(and more)").Append(", ");
|
||||
}
|
||||
}
|
||||
|
||||
if (matches == 0) {
|
||||
Player.Message(pl, "No " + group + " match \"" + name + "\"."); return default(T);
|
||||
Player.Message(pl, "No " + group + " match \"" + name + "\".");
|
||||
return default(T);
|
||||
} else if (matches == 1) {
|
||||
return match;
|
||||
} else {
|
||||
string count = matches > limit ? limit + "+ " : matches + " ";
|
||||
string names = nameMatches.ToString(0, nameMatches.Length - 2);
|
||||
|
||||
Player.Message(pl, count + group + " match \"" + name + "\":");
|
||||
Player.Message(pl, names); return default(T);
|
||||
Player.Message(pl, names);
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
88
MCGalaxy/util/Math/AABB.cs
Normal file
88
MCGalaxy/util/Math/AABB.cs
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
Copyright 2015 MCGalaxy
|
||||
|
||||
Dual-licensed under the Educational Community License, Version 2.0 and
|
||||
the GNU General Public License, Version 3 (the "Licenses"); you may
|
||||
not use this file except in compliance with the Licenses. You may
|
||||
obtain a copy of the Licenses at
|
||||
|
||||
http://www.opensource.org/licenses/ecl2.php
|
||||
http://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the Licenses are distributed on an "AS IS"
|
||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
or implied. See the Licenses for the specific language governing
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
|
||||
namespace MCGalaxy {
|
||||
|
||||
public struct AABB {
|
||||
|
||||
/// <summary> Fixed-point min coordinate of this bounding box. </summary>
|
||||
public Vec3S32 Min;
|
||||
|
||||
/// <summary> Fixed-point max coordinate of this bounding box. </summary>
|
||||
public Vec3S32 Max;
|
||||
|
||||
/// <summary> World/block coordinate of the min coordinate of this bounding box. </summary>
|
||||
public Vec3S32 BlockMin { get { return new Vec3S32(Min.X >> 5, Min.Y >> 5, Min.Z >> 5); } }
|
||||
|
||||
/// <summary> World/block coordinate of the max coordinate of this bounding box. </summary>
|
||||
public Vec3S32 BlockMax { get { return new Vec3S32(Max.X >> 5, Max.Y >> 5, Max.Z >> 5); } }
|
||||
|
||||
|
||||
public AABB(int x1, int y1, int z1, int x2, int y2, int z2) {
|
||||
Min.X = x1; Min.Y = y1; Min.Z = z1;
|
||||
Max.X = x2; Max.Y = y2; Max.Z = z2;
|
||||
}
|
||||
|
||||
public AABB(Vec3S32 min, Vec3S32 max) {
|
||||
Min = min;
|
||||
Max = max;
|
||||
}
|
||||
|
||||
public static AABB Make(Vec3S32 pos, Vec3S32 size) {
|
||||
return new AABB(pos.X - size.X / 2, pos.Y, pos.Z - size.Z / 2,
|
||||
pos.X + size.X / 2, pos.Y + size.Y, pos.Z + size.Z / 2);
|
||||
}
|
||||
|
||||
/// <summary> Returns a new bounding box, with the minimum and maximum coordinates
|
||||
/// of the original bounding box scaled away from origin the given value. </summary>
|
||||
public AABB Scale(float scale) {
|
||||
return new AABB(Min * scale, Max * scale);
|
||||
}
|
||||
|
||||
/// <summary> Determines whether this bounding box intersects
|
||||
/// the given bounding box on any axes. </summary>
|
||||
public bool Intersects(AABB other) {
|
||||
if (Max.X >= other.Min.X && Min.X <= other.Max.X) {
|
||||
if (Max.Y < other.Min.Y || Min.Y > other.Max.Y) {
|
||||
return false;
|
||||
}
|
||||
return Max.Z >= other.Min.Z && Min.Z <= other.Max.Z;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary> Determines whether this bounding box entirely contains
|
||||
/// the given bounding box on all axes. </summary>
|
||||
public bool Contains(AABB other) {
|
||||
return other.Min.X >= Min.X && other.Min.Y >= Min.Y && other.Min.Z >= Min.Z &&
|
||||
other.Max.X <= Max.X && other.Max.Y <= Max.Y && other.Max.Z <= Max.Z;
|
||||
}
|
||||
|
||||
/// <summary> Determines whether this bounding box entirely contains
|
||||
/// the coordinates on all axes. </summary>
|
||||
public bool Contains(Vec3S32 P) {
|
||||
return P.X >= Min.X && P.Y >= Min.Y && P.Z >= Min.Z &&
|
||||
P.X <= Max.X && P.Y <= Max.Y && P.Z <= Max.Z;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return Min + " : " + Max;
|
||||
}
|
||||
}
|
||||
}
|
@ -165,6 +165,10 @@ namespace MCGalaxy {
|
||||
return new Vec3S32(a.X / b, a.Y / b, a.Z / b);
|
||||
}
|
||||
|
||||
public static Vec3S32 operator * (Vec3S32 a, float b) {
|
||||
return new Vec3S32((int)(a.X * b), (int)(a.Y * b), (int)(a.Z * b));
|
||||
}
|
||||
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
return (obj is Vec3S32) && Equals((Vec3S32)obj);
|
||||
|
Loading…
x
Reference in New Issue
Block a user