Skip to content

Commit

Permalink
Cleanup /snake
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Nov 20, 2017
1 parent e86fcf1 commit dc4217e
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions fCraft/Commands/BuildingCommands.cs
Expand Up @@ -2779,16 +2779,13 @@ private static void DrawImageCallback(Player player, Vector3I[] marks, object ta
};

private static void SnakeHandler(Player player, CommandReader cmd) {
string slength = cmd.Next();
int length;
if (slength == null) {
CdSnake.PrintUsage(player);
return;
}
if (!int.TryParse(slength, out length)) {
player.Message("Invalid Integer: ({0})", slength);
if (!cmd.NextInt(out length)) return;
if (length > 100000) {
player.Message("Snake cannot be more than 100,000 blocks in length");
return;
}

string sblock = cmd.Next();
Block newBlock;
if (sblock == null) {
Expand All @@ -2811,23 +2808,24 @@ private static void DrawImageCallback(Player player, Vector3I[] marks, object ta
}
}
Random dir = new Random();
Vector3I posStart = new Vector3I(player.Position.BlockX, player.Position.BlockY, player.Position.BlockZ);
Vector3I pos = new Vector3I(player.Position.BlockX, player.Position.BlockY, player.Position.BlockZ);

if (player.World != null && player.World.Map != null) {
int blocksDrawn = 0, blocksSkipped = 0;
UndoState undoState = player.DrawBegin(null);
for (int i = 1; i <= length; i++) {
Vector3I posx = new Vector3I(posStart.X + dir.Next(0, 2) * 2 - 1, posStart.Y, posStart.Z);
Vector3I posy = new Vector3I(posStart.X, posStart.Y + dir.Next(0, 2) * 2 - 1, posStart.Z);
Vector3I posz = new Vector3I(posStart.X, posStart.Y, posStart.Z + dir.Next(0, 2) * 2 - 1);
posStart = new Vector3I(posx.X, posy.Y, posz.Z);
DrawOneBlock(player, player.World.Map, newBlock, posx,
Vector3I nextX = pos; nextX.X += dir.Next(0, 2) * 2 - 1;
Vector3I nextY = pos; nextY.Y += dir.Next(0, 2) * 2 - 1;
Vector3I nextZ = pos; nextZ.Z += dir.Next(0, 2) * 2 - 1;
pos = new Vector3I(nextX.X, nextY.Y, nextZ.Z);

DrawOneBlock(player, player.World.Map, newBlock, nextX,
BlockChangeContext.Drawn,
ref blocksDrawn, ref blocksSkipped, undoState);
DrawOneBlock(player, player.World.Map, newBlock, posy,
DrawOneBlock(player, player.World.Map, newBlock, nextY,
BlockChangeContext.Drawn,
ref blocksDrawn, ref blocksSkipped, undoState);
DrawOneBlock(player, player.World.Map, newBlock, posz,
DrawOneBlock(player, player.World.Map, newBlock, nextZ,
BlockChangeContext.Drawn,
ref blocksDrawn, ref blocksSkipped, undoState);
}
Expand Down

0 comments on commit dc4217e

Please sign in to comment.