style: minor cleanup in AutoRotate

This commit is contained in:
UnknownShadow200 2016-12-08 09:45:18 +11:00
parent 9faddef842
commit 683719fb7c

View File

@ -1,7 +1,5 @@
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
using System;
using System.Collections.Generic;
using ClassicalSharp.Blocks;
using OpenTK;
namespace ClassicalSharp {
@ -11,23 +9,23 @@ namespace ClassicalSharp {
public static byte RotateBlock(Game game, byte block) {
string name = game.BlockInfo.Name[block];
int sepIndex = name.LastIndexOf('-');
if (sepIndex == -1) return block; // not a directional block
int dirIndex = name.LastIndexOf('-');
if (dirIndex == -1) return block; // not a directional block
string sep = name.Substring(sepIndex + 1);
name = name.Substring(0, sepIndex);
string dir = name.Substring(dirIndex + 1);
name = name.Substring(0, dirIndex);
Vector3 offset = game.SelectedPos.Intersect - (Vector3)game.SelectedPos.TranslatedPos;
if (Utils.CaselessEquals(sep, "nw") || Utils.CaselessEquals(sep, "ne") ||
Utils.CaselessEquals(sep, "sw") || Utils.CaselessEquals(sep, "se")) {
if (Utils.CaselessEquals(dir, "nw") || Utils.CaselessEquals(dir, "ne") ||
Utils.CaselessEquals(dir, "sw") || Utils.CaselessEquals(dir, "se")) {
return RotateCorner(game, block, name, offset);
} else if (Utils.CaselessEquals(sep, "u") || Utils.CaselessEquals(sep, "d")) {
} else if (Utils.CaselessEquals(dir, "u") || Utils.CaselessEquals(dir, "d")) {
return RotateVertical(game, block, name, offset);
} else if (Utils.CaselessEquals(sep, "n") || Utils.CaselessEquals(sep, "w") ||
Utils.CaselessEquals(sep, "s") || Utils.CaselessEquals(sep, "e")) {
} else if (Utils.CaselessEquals(dir, "n") || Utils.CaselessEquals(dir, "w") ||
Utils.CaselessEquals(dir, "s") || Utils.CaselessEquals(dir, "e")) {
return RotateDirection(game, block, name, offset);
} else if (Utils.CaselessEquals(sep, "UD") || Utils.CaselessEquals(sep, "WE") ||
Utils.CaselessEquals(sep, "NS")) {
} else if (Utils.CaselessEquals(dir, "UD") || Utils.CaselessEquals(dir, "WE") ||
Utils.CaselessEquals(dir, "NS")) {
return RotatePillar(game, block, name, offset);
}
return block;
@ -52,12 +50,14 @@ namespace ClassicalSharp {
}
static byte RotatePillar(Game game, byte block, string name, Vector3 offset) {
BlockFace selectedFace = game.SelectedPos.BlockFace;
string face = "-UD";
if (selectedFace == BlockFace.YMax || selectedFace == BlockFace.YMin) { face = "-UD"; }
else if (selectedFace == BlockFace.XMax || selectedFace == BlockFace.XMin) { face = "-WE"; }
else if (selectedFace == BlockFace.ZMax || selectedFace == BlockFace.ZMin) { face = "-NS"; }
return Find(game, block, name + face);
BlockFace face = game.SelectedPos.BlockFace;
if (face == BlockFace.YMax || face == BlockFace.YMin)
return Find(game, block, name + "-UD");
if (face == BlockFace.XMax || face == BlockFace.XMin)
return Find(game, block, name + "-WE");
if (face == BlockFace.ZMax || face == BlockFace.ZMin)
return Find(game, block, name + "-NS");
return block;
}
static byte RotateDirection(Game game, byte block, string name, Vector3 offset) {