Skip to content

Commit 7c2f473

Browse files
Reduce IL size of CenterCallback by 436 bytes
1 parent 8d45e1a commit 7c2f473

File tree

1 file changed

+28
-57
lines changed

1 file changed

+28
-57
lines changed

fCraft/Commands/BuildingCommands.cs

Lines changed: 28 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,8 @@ private static void DisPlace(Player player, CommandReader cmd) {
768768
if (cmd.CountRemaining < 2) {
769769
CdDisPlace.PrintUsage(player);
770770
return;
771-
}
772-
771+
}
772+
773773
Block block;
774774
if (!cmd.NextBlock(player, false, out block)) return;
775775
int dis;
@@ -925,74 +925,45 @@ private static void CenterCallback(Player player, Vector3I[] marks, object tag)
925925
player.Message("&WCannot deduce desired block. Click a block or type out the block name.");
926926
return;
927927
}
928-
int sx = Math.Min(marks[0].X, marks[1].X), ex = Math.Max(marks[0].X, marks[1].X),
929-
sy = Math.Min(marks[0].Y, marks[1].Y), ey = Math.Max(marks[0].Y, marks[1].Y),
930-
sz = Math.Min(marks[0].Z, marks[1].Z), ez = Math.Max(marks[0].Z, marks[1].Z);
931-
932-
BoundingBox bounds = new BoundingBox(sx, sy, sz, ex, ey, ez);
933-
int blocksDrawn = 0,
934-
blocksSkipped = 0;
928+
929+
BoundingBox bounds = new BoundingBox(marks[0], marks[1]);
930+
int blocksDrawn = 0, blocksSkipped = 0;
935931
UndoState undoState = player.DrawBegin(null);
936932

937933
World playerWorld = player.World;
938934
if (playerWorld == null)
939935
PlayerOpException.ThrowNoWorld(player);
940936

941-
Map map = player.WorldMap;
942-
if (((bounds.XMin + bounds.XMax) % 2) == 1)
943-
{
944-
Vector3I cPos = new Vector3I(bounds.XCentre + 1, bounds.YCentre, bounds.ZCentre);
945-
DrawOneBlock(player, player.World.Map, player.LastUsedBlockType, cPos,
946-
BlockChangeContext.Drawn,
947-
ref blocksDrawn, ref blocksSkipped, undoState);
948-
}
949-
if (((bounds.XMin + bounds.XMax) % 2) == 1 && ((bounds.YMin + bounds.YMax) % 2) == 1)
950-
{
951-
Vector3I cPos = new Vector3I(bounds.XCentre + 1, bounds.YCentre + 1, bounds.ZCentre);
952-
DrawOneBlock(player, player.World.Map, player.LastUsedBlockType, cPos,
953-
BlockChangeContext.Drawn,
954-
ref blocksDrawn, ref blocksSkipped, undoState);
937+
Vector3I[] coords = new Vector3I[8];
938+
int count = 0, cenX = bounds.XCentre, cenY = bounds.YCentre, cenZ = bounds.ZCentre;
939+
940+
if ((bounds.Width % 2) == 0) {
941+
coords[count] = new Vector3I(cenX + 1, cenY, cenZ); count++;
955942
}
956-
if (((bounds.XMin + bounds.XMax) % 2) == 1 && ((bounds.ZMin + bounds.ZMax) % 2) == 1)
957-
{
958-
Vector3I cPos = new Vector3I(bounds.XCentre + 1, bounds.YCentre, bounds.ZCentre + 1);
959-
DrawOneBlock(player, player.World.Map, player.LastUsedBlockType, cPos,
960-
BlockChangeContext.Drawn,
961-
ref blocksDrawn, ref blocksSkipped, undoState);
943+
if ((bounds.Width % 2) == 0 && (bounds.Length % 2) == 0) {
944+
coords[count] = new Vector3I(cenX + 1, cenY + 1, cenZ); count++;
962945
}
963-
if (((bounds.XMin + bounds.XMax) % 2) == 1 && ((bounds.YMin + bounds.YMax) % 2) == 1 && ((bounds.ZMin + bounds.ZMax) % 2) == 1)
964-
{
965-
Vector3I cPos = new Vector3I(bounds.XCentre + 1, bounds.YCentre + 1, bounds.ZCentre + 1);
966-
DrawOneBlock(player, player.World.Map, player.LastUsedBlockType, cPos,
967-
BlockChangeContext.Drawn,
968-
ref blocksDrawn, ref blocksSkipped, undoState);
946+
if ((bounds.Width % 2) == 0 && (bounds.Height % 2) == 0) {
947+
coords[count] = new Vector3I(cenX + 1, cenY, cenZ + 1); count++;
969948
}
970-
if (((bounds.YMin + bounds.YMax) % 2) == 1)
971-
{
972-
Vector3I cPos = new Vector3I(bounds.XCentre, bounds.YCentre + 1, bounds.ZCentre);
973-
DrawOneBlock(player, player.World.Map, player.LastUsedBlockType, cPos,
974-
BlockChangeContext.Drawn,
975-
ref blocksDrawn, ref blocksSkipped, undoState);
949+
if ((bounds.Width % 2) == 0 && (bounds.Length % 2) == 0 && (bounds.Height % 2) == 0) {
950+
coords[count] = new Vector3I(cenX + 1, cenY + 1, cenZ + 1); count++;
976951
}
977-
if (((bounds.YMin + bounds.YMax) % 2) == 1 && ((bounds.ZMin + bounds.ZMax) % 2) == 1)
978-
{
979-
Vector3I cPos = new Vector3I(bounds.XCentre, bounds.YCentre + 1, bounds.ZCentre + 1);
980-
DrawOneBlock(player, player.World.Map, player.LastUsedBlockType, cPos,
981-
BlockChangeContext.Drawn,
982-
ref blocksDrawn, ref blocksSkipped, undoState);
952+
if ((bounds.Length % 2) == 0) {
953+
coords[count] = new Vector3I(cenX, cenY + 1, cenZ); count++;
983954
}
984-
if (((bounds.ZMin + bounds.ZMax) % 2) == 1)
985-
{
986-
Vector3I cPos = new Vector3I(bounds.XCentre, bounds.YCentre, bounds.ZCentre + 1);
987-
DrawOneBlock(player, player.World.Map, player.LastUsedBlockType, cPos,
988-
BlockChangeContext.Drawn,
989-
ref blocksDrawn, ref blocksSkipped, undoState);
955+
if ((bounds.Length % 2) == 0 && (bounds.Height % 2) == 0) {
956+
coords[count] = new Vector3I(cenX, cenY + 1, cenZ + 1); count++;
990957
}
958+
if ((bounds.Height % 2) == 0) {
959+
coords[count] = new Vector3I(cenX, cenY, cenZ + 1); count++;
960+
}
961+
coords[count] = new Vector3I(cenX, cenY, cenZ); count++;
991962

992-
Vector3I cPoso = new Vector3I(bounds.XCentre, bounds.YCentre, bounds.ZCentre);
993-
DrawOneBlock(player, player.World.Map, player.LastUsedBlockType, cPoso,
994-
BlockChangeContext.Drawn,
995-
ref blocksDrawn, ref blocksSkipped, undoState);
963+
for (int i = 0; i < count; i++) {
964+
DrawOneBlock(player, player.World.Map, player.LastUsedBlockType, coords[i],
965+
BlockChangeContext.Drawn, ref blocksDrawn, ref blocksSkipped, undoState);
966+
}
996967
DrawingFinished(player, "Placed", blocksDrawn, blocksSkipped);
997968
}
998969
#endregion

0 commit comments

Comments
 (0)