diff --git a/MCGalaxy/Commands/building/CmdImageprint.cs b/MCGalaxy/Commands/building/CmdImageprint.cs index a9116682a..136900488 100644 --- a/MCGalaxy/Commands/building/CmdImageprint.cs +++ b/MCGalaxy/Commands/building/CmdImageprint.cs @@ -158,11 +158,7 @@ namespace MCGalaxy.Commands.Building { } static int LargestDelta(Level lvl, Vec3S32 point) { - Vec3S32 clamped; - clamped.X = Math.Max(0, Math.Min(point.X, lvl.Width - 1)); - clamped.Y = Math.Max(0, Math.Min(point.Y, lvl.Height - 1)); - clamped.Z = Math.Max(0, Math.Min(point.Z, lvl.Length - 1)); - + Vec3S32 clamped = lvl.ClampPos(point); int dx = Math.Abs(point.X - clamped.X); int dy = Math.Abs(point.Y - clamped.Y); int dz = Math.Abs(point.Z - clamped.Z); diff --git a/MCGalaxy/Commands/building/CmdMark.cs b/MCGalaxy/Commands/building/CmdMark.cs index e68208589..fc06deb73 100644 --- a/MCGalaxy/Commands/building/CmdMark.cs +++ b/MCGalaxy/Commands/building/CmdMark.cs @@ -45,9 +45,7 @@ namespace MCGalaxy.Commands.Building { P.Y = (p.Pos.Y - 32) / 32; if (message.Length > 0 && !ParseCoords(message, p, ref P)) return; - P.X = Clamp(P.X, p.level.Width); - P.Y = Clamp(P.Y, p.level.Height); - P.Z = Clamp(P.Z, p.level.Length); + P = p.level.ClampPos(P); if (DoMark(p, P.X, P.Y, P.Z)) return; Vec3U16 mark = (Vec3U16)P; @@ -80,12 +78,6 @@ namespace MCGalaxy.Commands.Building { return CommandParser.GetCoords(p, args, 0, ref P); } - static int Clamp(int value, int axisLen) { - if (value < 0) return 0; - if (value >= axisLen) return axisLen - 1; - return value; - } - internal static bool DoMark(Player p, int x, int y, int z) { if (!p.HasBlockChange()) return false; if (!p.Ignores.DrawOutput) { diff --git a/MCGalaxy/Commands/building/CmdPlace.cs b/MCGalaxy/Commands/building/CmdPlace.cs index 83bfd280f..6c853414e 100644 --- a/MCGalaxy/Commands/building/CmdPlace.cs +++ b/MCGalaxy/Commands/building/CmdPlace.cs @@ -49,9 +49,7 @@ namespace MCGalaxy.Commands.Building { } if (!CommandParser.IsBlockAllowed(p, "place", block)) return; - P.X = Clamp(P.X, p.level.Width); - P.Y = Clamp(P.Y, p.level.Height); - P.Z = Clamp(P.Z, p.level.Length); + P = p.level.ClampPos(P); p.level.UpdateBlock(p, (ushort)P.X, (ushort)P.Y, (ushort)P.Z, block); string blockName = Block.GetName(p, block); @@ -60,12 +58,6 @@ namespace MCGalaxy.Commands.Building { } } - static int Clamp(int value, int axisLen) { - if (value < 0) return 0; - if (value >= axisLen) return axisLen - 1; - return value; - } - public override void Help(Player p) { p.Message("%T/Place "); p.Message("%HPlaces block at your feet."); diff --git a/MCGalaxy/Levels/Level.Blocks.cs b/MCGalaxy/Levels/Level.Blocks.cs index 37a2abfbd..252b80883 100644 --- a/MCGalaxy/Levels/Level.Blocks.cs +++ b/MCGalaxy/Levels/Level.Blocks.cs @@ -441,6 +441,13 @@ namespace MCGalaxy { return x >= 0 && y >= 0 && z >= 0 && x < Width && y < Height && z < Length; } + public Vec3S32 ClampPos(Vec3S32 P) { + P.X = Math.Max(0, Math.Min(P.X, Width - 1)); + P.Y = Math.Max(0, Math.Min(P.Y, Height - 1)); + P.Z = Math.Max(0, Math.Min(P.Z, Length - 1)); + return P; + } + public void UpdateBlock(Player p, ushort x, ushort y, ushort z, BlockID block, ushort flags = BlockDBFlags.ManualPlace, bool buffered = false) { int index;