Skip to content

Commit dc4217e

Browse files
Cleanup /snake
1 parent e86fcf1 commit dc4217e

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

fCraft/Commands/BuildingCommands.cs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2779,16 +2779,13 @@ static void StaticHandler( Player player, CommandReader cmd ) {
27792779
};
27802780

27812781
private static void SnakeHandler(Player player, CommandReader cmd) {
2782-
string slength = cmd.Next();
27832782
int length;
2784-
if (slength == null) {
2785-
CdSnake.PrintUsage(player);
2786-
return;
2787-
}
2788-
if (!int.TryParse(slength, out length)) {
2789-
player.Message("Invalid Integer: ({0})", slength);
2783+
if (!cmd.NextInt(out length)) return;
2784+
if (length > 100000) {
2785+
player.Message("Snake cannot be more than 100,000 blocks in length");
27902786
return;
27912787
}
2788+
27922789
string sblock = cmd.Next();
27932790
Block newBlock;
27942791
if (sblock == null) {
@@ -2811,23 +2808,24 @@ private static void SnakeHandler(Player player, CommandReader cmd) {
28112808
}
28122809
}
28132810
Random dir = new Random();
2814-
Vector3I posStart = new Vector3I(player.Position.BlockX, player.Position.BlockY, player.Position.BlockZ);
2811+
Vector3I pos = new Vector3I(player.Position.BlockX, player.Position.BlockY, player.Position.BlockZ);
28152812

28162813
if (player.World != null && player.World.Map != null) {
28172814
int blocksDrawn = 0, blocksSkipped = 0;
28182815
UndoState undoState = player.DrawBegin(null);
28192816
for (int i = 1; i <= length; i++) {
2820-
Vector3I posx = new Vector3I(posStart.X + dir.Next(0, 2) * 2 - 1, posStart.Y, posStart.Z);
2821-
Vector3I posy = new Vector3I(posStart.X, posStart.Y + dir.Next(0, 2) * 2 - 1, posStart.Z);
2822-
Vector3I posz = new Vector3I(posStart.X, posStart.Y, posStart.Z + dir.Next(0, 2) * 2 - 1);
2823-
posStart = new Vector3I(posx.X, posy.Y, posz.Z);
2824-
DrawOneBlock(player, player.World.Map, newBlock, posx,
2817+
Vector3I nextX = pos; nextX.X += dir.Next(0, 2) * 2 - 1;
2818+
Vector3I nextY = pos; nextY.Y += dir.Next(0, 2) * 2 - 1;
2819+
Vector3I nextZ = pos; nextZ.Z += dir.Next(0, 2) * 2 - 1;
2820+
pos = new Vector3I(nextX.X, nextY.Y, nextZ.Z);
2821+
2822+
DrawOneBlock(player, player.World.Map, newBlock, nextX,
28252823
BlockChangeContext.Drawn,
28262824
ref blocksDrawn, ref blocksSkipped, undoState);
2827-
DrawOneBlock(player, player.World.Map, newBlock, posy,
2825+
DrawOneBlock(player, player.World.Map, newBlock, nextY,
28282826
BlockChangeContext.Drawn,
28292827
ref blocksDrawn, ref blocksSkipped, undoState);
2830-
DrawOneBlock(player, player.World.Map, newBlock, posz,
2828+
DrawOneBlock(player, player.World.Map, newBlock, nextZ,
28312829
BlockChangeContext.Drawn,
28322830
ref blocksDrawn, ref blocksSkipped, undoState);
28332831
}

0 commit comments

Comments
 (0)