Skip to content
Permalink
Browse files

get rid of minor code duplication

  • Loading branch information...
UnknownShadow200 committed Feb 18, 2018
1 parent 32f8262 commit 72fecbe1b37226b0ce6ec7fc246fd9b3b61fa13e
Showing with 15 additions and 22 deletions.
  1. +7 −19 fCraft/Commands/BuildingCommands.cs
  2. +1 −3 fCraft/Commands/WorldCommands.cs
  3. +7 −0 fCraft/System/Utils/BoundingBox.cs
@@ -782,10 +782,7 @@ private static void WallsHandler(Player player, CommandReader cmd)
Vector3I dir = Vector3I.FlatDirection(yaw, pitch);
pos += dir * length;

pos.X = Math.Min(player.WorldMap.Width - 1, Math.Max(0, pos.X));
pos.Y = Math.Min(player.WorldMap.Length - 1, Math.Max(0, pos.Y));
pos.Z = Math.Min(player.WorldMap.Height - 1, Math.Max(0, pos.Z));

pos = player.WorldMap.Bounds.Clamp(pos);
if (player.CanPlace(player.World.Map, pos, block, BlockChangeContext.Drawn) != CanPlaceResult.Allowed) {
player.Message("&WYou are not allowed to build here");
return;
@@ -852,9 +849,7 @@ private static void WallsHandler(Player player, CommandReader cmd)
world.LoadMap();
unLoad = true;
}
coords.X = Math.Min(world.map.Width - 1, Math.Max(0, coords.X));
coords.Y = Math.Min(world.map.Length - 1, Math.Max(0, coords.Y));
coords.Z = Math.Min(world.map.Height - 1, Math.Max(0, coords.Z));
coords = world.map.Bounds.Clamp(coords);

if (player == Player.Console) {
BlockUpdate blockUpdate = new BlockUpdate(player, coords, block);
@@ -2080,9 +2075,7 @@ static void LavaHandler([NotNull] Player player, [NotNull] CommandReader cmd)
} else {
coords = player.Position.ToBlockCoords();
}
coords.X = Math.Min( map.Width - 1, Math.Max( 0, coords.X ) );
coords.Y = Math.Min( map.Length - 1, Math.Max( 0, coords.Y ) );
coords.Z = Math.Min( map.Height - 1, Math.Max( 0, coords.Z ) );
coords = map.Bounds.Clamp(coords);

if( player.SelectionMarksExpected > 0 ) {
player.SelectionAddMark( coords, true, true );
@@ -2099,16 +2092,11 @@ static void LavaHandler([NotNull] Player player, [NotNull] CommandReader cmd)
Handler = MarkAllHandler
};

private static void MarkAllHandler(Player player, CommandReader cmd) {
static void MarkAllHandler(Player player, CommandReader cmd) {
Map map = player.WorldMap;
Vector3I coordsMin;
Vector3I coordsMax;
coordsMin.X = 0;
coordsMin.Y = 0;
coordsMin.Z = 0;
coordsMax.X = map.Width - 1;
coordsMax.Y = map.Length - 1;
coordsMax.Z = map.Height - 1;
Vector3I coordsMin = map.Bounds.MinVertex;
Vector3I coordsMax = map.Bounds.MaxVertex;

if (player.IsMakingSelection) {
player.SelectionResetMarks();
player.SelectionAddMark(coordsMin, false, false);
@@ -451,9 +451,7 @@ static class WorldCommands {
}
Vector3I coords = new Vector3I( x, y, z );
Map map = player.WorldMap;
coords.X = Math.Min( map.Width - 1, Math.Max( 0, coords.X ) );
coords.Y = Math.Min( map.Length - 1, Math.Max( 0, coords.Y ) );
coords.Z = Math.Min( map.Height - 1, Math.Max( 0, coords.Z ) );
coords = map.Bounds.Clamp( coords );
BlockInfoSelectionCallback( player, new[] { coords }, null );

} else {
@@ -226,6 +226,13 @@ public BoundingBox(Vector3I origin, int width, int length, int height)
}

#endregion

public Vector3I Clamp(Vector3I coords) {
coords.X = Math.Min(XMax, Math.Max(XMin, coords.X));
coords.Y = Math.Min(YMax, Math.Max(YMin, coords.Y));
coords.Z = Math.Min(ZMax, Math.Max(ZMin, coords.Z));
return coords;
}

public bool Equals([NotNull] BoundingBox other) {
return XMin == other.XMin && XMax == other.XMax &&

0 comments on commit 72fecbe

Please sign in to comment.
You can’t perform that action at this time.