diff --git a/Commands/building/CmdClick.cs b/Commands/building/CmdClick.cs
index 526173056..06d4e1905 100644
--- a/Commands/building/CmdClick.cs
+++ b/Commands/building/CmdClick.cs
@@ -28,7 +28,8 @@ namespace MCGalaxy.Commands {
public override void Use(Player p, string message) {
if (p == null) { MessageInGameOnly(p); return; }
- ushort[] click = p.lastClick;
+ Vec3U16 click = p.lastClick;
+ ushort value;
if (message.IndexOf(' ') != -1) {
string[] args = message.ToLower().Split(' ');
@@ -36,28 +37,20 @@ namespace MCGalaxy.Commands {
for (int i = 0; i < 3; i++) {
if (args[i] == "x" || args[i] == "y" || args[i] == "z") {
- click[i] = p.lastClick[i];
- } else if (IsValid(p, i, args[i])) {
- click[i] = ushort.Parse(args[i]);
+ // use the last value
+ } else if (ushort.TryParse(args[i], out value)) {
+ if (i == 0) click.X = value;
+ else if (i == 1) click.Y = value;
+ else click.Z = value;
} else {
- Player.SendMessage(p, "\"" + args[i] + "\" was not valid"); return;
+ Player.SendMessage(p, "\"" + args[i] + "\" was not valid"); return;
}
}
}
-
- p.lastCMD = "click";
- p.ManualChange(click[0], click[1], click[2], 0, Block.rock);
- Player.SendMessage(p, "Clicked &b(" + click[0] + ", " + click[1] + ", " + click[2] + ")");
- }
-
- bool IsValid(Player p, int axis, string message) {
- ushort value;
- if (!ushort.TryParse(message, out value)) return false;
-
- if (value >= p.level.Width && axis == 0) return false;
- else if (value >= p.level.Height && axis == 1) return false;
- else if (value >= p.level.Length && axis == 2) return false;
- return true;
+
+ click = Vec3U16.ClampToBounds(click.X, click.Y, click.Z, p.level);
+ p.ManualChange(click.X, click.Y, click.Z, 0, Block.rock);
+ Player.SendMessage(p, "Clicked &b(" + click.X + ", " + click.Y + ", " + click.Z + ")");
}
public override void Help(Player p) {
diff --git a/Commands/building/CmdMark.cs b/Commands/building/CmdMark.cs
index 2f5f7156b..653c1ae5d 100644
--- a/Commands/building/CmdMark.cs
+++ b/Commands/building/CmdMark.cs
@@ -26,8 +26,7 @@ namespace MCGalaxy.Commands
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
public CmdMark() { }
- public override void Use(Player p, string message)
- {
+ public override void Use(Player p, string message) {
if (p == null) { MessageInGameOnly(p); return; }
int x = (ushort)(p.pos[0] / 32);
@@ -35,8 +34,8 @@ namespace MCGalaxy.Commands
int z = (ushort)(p.pos[2] / 32);
Command.all.Find("click").Use(p, x + " " + y + " " + z);
}
- public override void Help(Player p)
- {
+
+ public override void Help(Player p) {
Player.SendMessage(p, "/mark - Clicks where you are standing.");
Player.SendMessage(p, "Use this to place a marker at your position when making a selection or cuboid.");
}
diff --git a/Commands/building/CmdPlace.cs b/Commands/building/CmdPlace.cs
index f2dd2c82a..d4b3cdd90 100644
--- a/Commands/building/CmdPlace.cs
+++ b/Commands/building/CmdPlace.cs
@@ -58,10 +58,9 @@ namespace MCGalaxy.Commands {
if (type == Block.Zero) return;
if (!Block.canPlace(p, type)) { Player.SendMessage(p, "Cannot place that block type."); return; }
- if (y >= p.level.Height) y = (ushort)(p.level.Height - 1);
-
- p.level.UpdateBlock(p, x, y, z, type, extType);
- Player.SendMessage(p, "A block was placed at (" + x + ", " + y + ", " + z + ").");
+ Vec3U16 P = Vec3U16.ClampToBounds(x, y, z, p.level);
+ p.level.UpdateBlock(p, P.X, P.Y, P.Z, type, extType);
+ Player.SendMessage(p, "A block was placed at (" + P.X + ", " + P.Y + ", " + P.Z + ").");
}
public override void Help(Player p) {
diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj
index b60ae3dbd..aff7ffaa3 100644
--- a/MCGalaxy_.csproj
+++ b/MCGalaxy_.csproj
@@ -426,7 +426,6 @@
-
@@ -615,6 +614,7 @@
+
EcoLevelWindow.cs
diff --git a/Player/Player.Handlers.cs b/Player/Player.Handlers.cs
index 2341f03ad..27d70bf41 100644
--- a/Player/Player.Handlers.cs
+++ b/Player/Player.Handlers.cs
@@ -71,7 +71,7 @@ namespace MCGalaxy {
bP.index = level.PosToInt(x, y, z);
bP.SetData(type, extType, false);
- lastClick[0] = x; lastClick[1] = y; lastClick[2] = z;
+ lastClick.X = x; lastClick.Y = y; lastClick.Z = z;
if ( Blockchange != null ) {
if ( Blockchange.Method.ToString().IndexOf("AboutBlockchange") == -1 && !level.IsMuseum ) {
bP.flags |= 1;
diff --git a/Player/Player.cs b/Player/Player.cs
index 99376b545..aebc2dca6 100644
--- a/Player/Player.cs
+++ b/Player/Player.cs
@@ -265,7 +265,7 @@ namespace MCGalaxy {
public Level level = Server.mainLevel;
public bool Loading = true; //True if player is loading a map.
internal bool usingGoto = false;
- public ushort[] lastClick = new ushort[] { 0, 0, 0 };
+ public Vec3U16 lastClick = Vec3U16.Zero;
public ushort[] beforeTeleportPos = new ushort[] { 0, 0, 0 };
public string beforeTeleportMap = "";
public ushort[] pos = new ushort[] { 0, 0, 0 };
diff --git a/Drawing/Vectors.cs b/util/Vectors.cs
similarity index 88%
rename from Drawing/Vectors.cs
rename to util/Vectors.cs
index 2a11b33c7..e0337e52a 100644
--- a/Drawing/Vectors.cs
+++ b/util/Vectors.cs
@@ -17,11 +17,12 @@
*/
using System;
-namespace MCGalaxy.Drawing {
+namespace MCGalaxy {
public struct Vec3U16 {
public ushort X, Y, Z;
+ public static Vec3U16 Zero = new Vec3U16(0);
public static Vec3U16 MinVal = new Vec3U16(ushort.MinValue);
public static Vec3U16 MaxVal = new Vec3U16(ushort.MaxValue);
@@ -75,6 +76,18 @@ namespace MCGalaxy.Drawing {
return new Vec3U16(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y), Math.Min(a.Z, b.Z));
}
+ public static Vec3U16 ClampToBounds(ushort x, ushort y, ushort z, Level lvl) {
+ Vec3U16 P = new Vec3U16(x, y, z);
+ if (P.X >= 32768) P.X = 0;
+ if (P.Y >= 32768) P.Y = 0;
+ if (P.Z >= 32768) P.Z = 0;
+
+ if (P.X >= lvl.Width) P.X = (ushort)(lvl.Width - 1);
+ if (P.Y >= lvl.Height) P.Y = (ushort)(lvl.Height - 1);
+ if (P.Z >= lvl.Length) P.Z = (ushort)(lvl.Length - 1);
+ return P;
+ }
+
public static bool operator == (Vec3U16 a, Vec3U16 b) {
return a.X == b.X && a.Y == b.Y && a.Z == b.Z;
}
@@ -95,8 +108,8 @@ namespace MCGalaxy.Drawing {
return X + "," + Y + "," + Z;
}
}
-
- public struct Vec3S16 {
+
+ public struct Vec3S16 {
public short X, Y, Z;