Merge branch 'master' of github.com:UnknownShadow200/ClassicalSharp

This commit is contained in:
UnknownShadow200 2016-12-15 21:17:37 +11:00
commit 699c16826e
10 changed files with 135 additions and 9 deletions

View file

@ -104,10 +104,10 @@ namespace ClassicalSharp.Gui.Screens {
base.Init();
left = new KeyBind[3];
left[0] = KeyBind.ExtInput; left[1] = KeyBind.HideFps; left[2] = KeyBind.HideGui;
right = new KeyBind[3];
right[0] = KeyBind.Screenshot; right[1] = KeyBind.Fullscreen; right[2] = KeyBind.AxisLines;
right = new KeyBind[4];
right[0] = KeyBind.Screenshot; right[1] = KeyBind.Fullscreen; right[2] = KeyBind.AxisLines; right[3] = KeyBind.Autorotate;
leftDesc = new string[] { "Show ext input", "Hide FPS", "Hide gui" };
rightDesc = new string[] { "Screenshot", "Fullscreen", "Show axis lines" };
rightDesc = new string[] { "Screenshot", "Fullscreen", "Show axis lines", "Toggle auto-rotate" };
widgets = new Widget[left.Length + right.Length + 4];
title = "Other controls";

View file

@ -0,0 +1,96 @@
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
using System;
using OpenTK;
namespace ClassicalSharp {
/// <summary> Performs automatic rotation of directional blocks. </summary>
public static class AutoRotate {
public static byte RotateBlock(Game game, byte block) {
string name = game.BlockInfo.Name[block];
int dirIndex = name.LastIndexOf('-');
if (dirIndex == -1) return block; // not a directional block
string dir = name.Substring(dirIndex + 1);
name = name.Substring(0, dirIndex);
Vector3 offset = game.SelectedPos.Intersect - (Vector3)game.SelectedPos.TranslatedPos;
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(dir, "u") || Utils.CaselessEquals(dir, "d")) {
return RotateVertical(game, block, name, offset);
} 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(dir, "UD") || Utils.CaselessEquals(dir, "WE") ||
Utils.CaselessEquals(dir, "NS")) {
return RotatePillar(game, block, name, offset);
}
return block;
}
static byte RotateCorner(Game game, byte block, string name, Vector3 offset) {
if (offset.X < 0.5f && offset.Z < 0.5f) {
return Find(game, block, name + "-NW");
} else if (offset.X >= 0.5f && offset.Z < 0.5f) {
return Find(game, block, name + "-NE");
} else if (offset.X < 0.5f && offset.Z >= 0.5f) {
return Find(game, block, name + "-SW");
} else if (offset.X >= 0.5f && offset.Z >= 0.5f) {
return Find(game, block, name + "-SE");
}
return block;
}
static byte RotateVertical(Game game, byte block, string name, Vector3 offset) {
string height = offset.Y >= 0.5f ? "-U" : "-D";
return Find(game, block, name + height);
}
static byte RotatePillar(Game game, byte block, string name, Vector3 offset) {
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) {
Vector3 southEast = new Vector3 (1, 0, 1);
Vector3 southWest = new Vector3 (-1, 0, 1);
Vector3I pos = game.SelectedPos.TranslatedPos;
Vector3 posExact = game.SelectedPos.Intersect;
Vector3 posExactFlat = posExact; posExactFlat.Y = 0;
Vector3 southEastToPoint = posExactFlat - new Vector3 (pos.X, 0, pos.Z);
Vector3 southWestToPoint = posExactFlat - new Vector3 (pos.X +1, 0, pos.Z);
float dotSouthEast = Vector3.Dot(southEastToPoint, southWest);
float dotSouthWest= Vector3.Dot(southWestToPoint, southEast);
if (dotSouthEast <= 0) { // NorthEast
if (dotSouthWest <= 0) { //NorthWest
return Find(game, block, name + "-N");
} else { //SouthEast
return Find(game, block, name + "-E");
}
} else { //SouthWest
if (dotSouthWest <= 0) { //NorthWest
return Find(game, block, name + "-W");
} else { //SouthEast
return Find(game, block, name + "-S");
}
}
}
static byte Find(Game game, byte block, string name) {
int rotated = game.BlockInfo.FindID(name);
if (rotated != -1) return (byte)rotated;
return block;
}
}
}

View file

@ -1,5 +1,6 @@
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
using System;
using System.Collections.Generic;
using ClassicalSharp.Blocks;
using OpenTK;
@ -132,6 +133,13 @@ namespace ClassicalSharp {
}
}
public int FindID(string name) {
for (int i = 0; i < Block.Count; i++) {
if (Utils.CaselessEquals(Name[i], name)) return i;
}
return -1;
}
static StringBuffer buffer = new StringBuffer(64);
static string DefaultName(byte block) {
if (block >= Block.CpeCount) return "Invalid";

View file

@ -142,6 +142,7 @@
<Compile Include="Audio\AudioPlayer.cs" />
<Compile Include="Audio\AudioPlayer.Sounds.cs" />
<Compile Include="Audio\Soundboard.cs" />
<Compile Include="Blocks\AutoRotate.cs" />
<Compile Include="Blocks\Block.cs" />
<Compile Include="Blocks\BlockInfo.BoundsBox.cs" />
<Compile Include="Blocks\BlockInfo.cs" />

View file

@ -63,10 +63,14 @@ namespace ClassicalSharp.Commands {
if (args.Length == 1) return true;
if (Utils.CaselessEquals(args[1], "yes")) { persist = true; return true; }
int temp = -1;
byte blockID = 0;
if (!byte.TryParse(args[1], out blockID)) {
game.Chat.Add("&eCuboid: &c\"" + args[1] + "\" is not a valid block id."); return false;
if ((temp = game.BlockInfo.FindID(args[1])) != -1) {
blockID = (byte)temp;
} else if (!byte.TryParse(args[1], out blockID)) {
game.Chat.Add("&eCuboid: &c\"" + args[1] + "\" is not a valid block name or id."); return false;
}
if (blockID >= Block.CpeCount && game.BlockInfo.Name[blockID] == "Invalid") {
game.Chat.Add("&eCuboid: &cThere is no block with id \"" + args[1] + "\"."); return false;
}

View file

@ -227,7 +227,7 @@ namespace ClassicalSharp.Entities {
if (!blockBB.Intersects(bounds)) continue;
modifier = Math.Min(modifier, info.SpeedMultiplier[block]);
if (block >= Block.CpeCount && type == CollideType.SwimThrough)
if (!info.IsLiquid(block) && type == CollideType.SwimThrough)
useLiquidGravity = true;
}
return modifier;

View file

@ -176,6 +176,8 @@ namespace ClassicalSharp {
public bool SmoothLighting;
public bool autoRotate = true;
public string FontName = "Arial";
public int ChatLines = 12;

View file

@ -231,6 +231,8 @@ namespace ClassicalSharp {
}
} else if (key == Keys[KeyBind.AxisLines]) {
ToggleAxisLines();
} else if (key == Keys[KeyBind.Autorotate]) {
ToggleAutoRotate();
} else if (key == Keys[KeyBind.ThirdPerson]) {
game.CycleCamera();
} else if (key == Keys[KeyBind.ToggleFog]) {
@ -259,6 +261,16 @@ namespace ClassicalSharp {
}
}
void ToggleAutoRotate() {
game.autoRotate = !game.autoRotate;
Key key = Keys[KeyBind.Autorotate];
if (game.autoRotate) {
game.Chat.Add(" &eAuto rotate is &aenabled. &aPress " + key + " &eto disable.");
} else {
game.Chat.Add(" &eAuto rotate is &cdisabled. &aPress " + key + " &eto re-enable.");
}
}
void CycleDistanceForwards() {
for (int i = 0; i < viewDistances.Length; i++) {
int dist = viewDistances[i];

View file

@ -9,7 +9,7 @@ namespace ClassicalSharp {
Inventory, ToggleFog, SendChat, PauseOrExit, PlayerList,
Speed, NoClip, Fly, FlyUp, FlyDown, ExtInput, HideFps,
Screenshot, Fullscreen, ThirdPerson, HideGui, AxisLines,
ZoomScrolling, HalfSpeed, MouseLeft, MouseMiddle, MouseRight,
ZoomScrolling, HalfSpeed, MouseLeft, MouseMiddle, MouseRight, Autorotate,
}
public class KeyMap {
@ -28,7 +28,7 @@ namespace ClassicalSharp {
public KeyMap() {
// We can't use enum array initaliser because this causes problems when building with mono
// and running on default .NET (https://bugzilla.xamarin.com/show_bug.cgi?id=572)
keys = new Key[30];
keys = new Key[31];
keys[0] = Key.W; keys[1] = Key.S; keys[2] = Key.A; keys[3] = Key.D;
keys[4] = Key.Space; keys[5] = Key.R; keys[6] = Key.Enter; keys[7] = Key.T;
keys[8] = Key.B; keys[9] = Key.F; keys[10] = Key.Enter;
@ -38,7 +38,7 @@ namespace ClassicalSharp {
keys[20] = Key.F12; keys[21] = Key.F11; keys[22] = Key.F5;
keys[23] = Key.F1; keys[24] = Key.F7; keys[25] = Key.C;
keys[26] = Key.ControlLeft;
keys[27] = Key.Unknown; keys[28] = Key.Unknown; keys[29] = Key.Unknown;
keys[27] = Key.Unknown; keys[28] = Key.Unknown; keys[29] = Key.Unknown; keys[30] = Key.F6;
defaultKeys = new Key[keys.Length];
for (int i = 0; i < defaultKeys.Length; i++)

View file

@ -66,8 +66,11 @@ namespace ClassicalSharp {
} else if (right) {
Vector3I pos = game.SelectedPos.TranslatedPos;
if (!game.World.IsValidPos(pos)) return;
byte old = game.World.GetBlock(pos);
byte block = (byte)inv.HeldBlock;
if (game.autoRotate)
block = AutoRotate.RotateBlock(game, block);
if (!game.CanPick(old) && inv.CanPlace[block] && CheckIsFree(game.SelectedPos, block)) {
game.UpdateBlock(pos.X, pos.Y, pos.Z, block);