diff --git a/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreens.cs b/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreens.cs
index 8280036a3..79bffb22e 100644
--- a/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreens.cs
+++ b/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreens.cs
@@ -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";
diff --git a/ClassicalSharp/Blocks/BlockInfo.cs b/ClassicalSharp/Blocks/BlockInfo.cs
index 04a5de9a0..e80a2ed7f 100644
--- a/ClassicalSharp/Blocks/BlockInfo.cs
+++ b/ClassicalSharp/Blocks/BlockInfo.cs
@@ -1,5 +1,6 @@
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
using System;
+using System.Collections.Generic;
using ClassicalSharp.Blocks;
using OpenTK;
@@ -28,6 +29,8 @@ namespace ClassicalSharp {
/// Stores various properties about the blocks in Minecraft Classic.
public partial class BlockInfo {
+ public Dictionary dictBlockIDbyName = new Dictionary();
+
/// Gets whether the given block id is a liquid. (water and lava)
public bool IsLiquid(byte block) { return block >= Block.Water && block <= Block.StillLava; }
diff --git a/ClassicalSharp/Game/Game.Properties.cs b/ClassicalSharp/Game/Game.Properties.cs
index d520bc701..eaf5c792f 100644
--- a/ClassicalSharp/Game/Game.Properties.cs
+++ b/ClassicalSharp/Game/Game.Properties.cs
@@ -176,6 +176,8 @@ namespace ClassicalSharp {
public bool SmoothLighting;
+ public bool autoRotate = true;
+
public string FontName = "Arial";
public int ChatLines = 12;
diff --git a/ClassicalSharp/Game/InputHandler.cs b/ClassicalSharp/Game/InputHandler.cs
index f332e1c2b..e5b728508 100644
--- a/ClassicalSharp/Game/InputHandler.cs
+++ b/ClassicalSharp/Game/InputHandler.cs
@@ -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];
diff --git a/ClassicalSharp/Game/KeyMap.cs b/ClassicalSharp/Game/KeyMap.cs
index d095a355a..fe8955c58 100644
--- a/ClassicalSharp/Game/KeyMap.cs
+++ b/ClassicalSharp/Game/KeyMap.cs
@@ -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++)
diff --git a/ClassicalSharp/Game/PickingHandler.cs b/ClassicalSharp/Game/PickingHandler.cs
index f12481f71..253a09311 100644
--- a/ClassicalSharp/Game/PickingHandler.cs
+++ b/ClassicalSharp/Game/PickingHandler.cs
@@ -64,10 +64,133 @@ namespace ClassicalSharp {
game.UserEvents.RaiseBlockChanged(pos, old, 0);
}
} else if (right) {
+ //[1:28:03 PM] well goodlyay you have game.SelectedPos.Intersect
+ //[1:28:17 PM] that's the exact floating point coordinates that the mouse clicked on the block
+ //[1:31:45 PM] e.g. the block clicked on might be (32, 34, 63)
+ //[1:31:55 PM] Intersect might be (33, 34.51049, 63.44751)
Vector3I pos = game.SelectedPos.TranslatedPos;
+ Vector3 posExact = game.SelectedPos.Intersect;
if (!game.World.IsValidPos(pos)) return;
byte old = game.World.GetBlock(pos);
byte block = (byte)inv.HeldBlock;
+ if (game.autoRotate) {
+ string[] blockNameSplit = info.Name[block].ToUpper().Split('-');
+ bool isDirectional = false;
+ bool isHeight = false;
+ bool isCorner = false;
+
+ if (blockNameSplit.Length == 2) {
+ switch (blockNameSplit[1]) {
+ case "N": case "E": case "W": case "S":
+ isDirectional = true;
+ break;
+ }
+ switch (blockNameSplit[1]) {
+ case "U": case "D":
+ isHeight = true;
+ break;
+ }
+ switch (blockNameSplit[1]) {
+ //NW NE
+ //SW SE
+ case "NW": case "NE": case "SW": case "SE":
+ isCorner = true;
+ break;
+ }
+ }
+ if (isDirectional) {
+ Vector3 southEast = new Vector3 (1,0,1);
+ Vector3 southWest = new Vector3 (-1, 0, 1);
+ 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);
+ string direction;
+ if (dotSouthEast <= 0) { // NorthEast
+ if (dotSouthWest <= 0) { //NorthWest
+ //North
+ direction = "N";
+ } else { //SouthEast
+ //East
+ direction = "E";
+ }
+ } else { //SouthWest
+ if (dotSouthWest <= 0) { //NorthWest
+ //West
+ direction = "W";
+ } else { //SouthEast
+ //South
+ direction = "S";
+ }
+ }
+
+ if (direction != blockNameSplit[1]) {
+ string newBlockName = blockNameSplit[0] + "-" + direction;
+ byte newBlockID;
+ if (game.BlockInfo.dictBlockIDbyName.TryGetValue(newBlockName, out newBlockID)) {
+ block = newBlockID;
+ //game.Chat.Add("Substituted " + block + " for " + newBlockID + ".");
+ } else {
+ //game.Chat.Add("could not find " + newBlockName + ".");
+ }
+ }
+ }
+ if (isHeight) {
+ string height = "D";
+ float pickedHeight = posExact.Y - pos.Y;
+ //game.Chat.Add("pickedHeight: " + pickedHeight + ".");
+
+ if (pickedHeight >= 0.5f) {
+ height = "U";
+ }
+
+ if (height != blockNameSplit[1]) {
+ string newBlockName = blockNameSplit[0] + "-" + height;
+ byte newBlockID;
+ if (game.BlockInfo.dictBlockIDbyName.TryGetValue(newBlockName, out newBlockID)) {
+ block = newBlockID;
+ //game.Chat.Add("Substituted " + block + " for " + newBlockID + ".");
+ } else {
+ //game.Chat.Add("could not find " + newBlockName + ".");
+ }
+ }
+ }
+
+ if (isCorner) {
+ string corner = "NW";
+ Vector3 pickedCorner = posExact - (Vector3)pos;
+ //game.Chat.Add("pickedHeight: " + pickedHeight + ".");
+
+ //NW NE
+ //SW SE
+ if (pickedCorner.X < 0.5f && pickedCorner.Z < 0.5f) {
+ corner = "NW";
+ }
+ if (pickedCorner.X >= 0.5f && pickedCorner.Z < 0.5f) {
+ corner = "NE";
+ }
+ if (pickedCorner.X < 0.5f && pickedCorner.Z >= 0.5f) {
+ corner = "SW";
+ }
+ if (pickedCorner.X >= 0.5f && pickedCorner.Z >= 0.5f) {
+ corner = "SE";
+ }
+
+ if (corner != blockNameSplit[1]) {
+ string newBlockName = blockNameSplit[0] + "-" + corner;
+ byte newBlockID;
+ if (game.BlockInfo.dictBlockIDbyName.TryGetValue(newBlockName, out newBlockID)) {
+ block = newBlockID;
+ //game.Chat.Add("Substituted " + block + " for " + newBlockID + ".");
+ } else {
+ //game.Chat.Add("could not find " + newBlockName + ".");
+ }
+ }
+ }
+
+ }
+
if (!game.CanPick(old) && inv.CanPlace[block] && CheckIsFree(game.SelectedPos, block)) {
game.UpdateBlock(pos.X, pos.Y, pos.Z, block);
diff --git a/ClassicalSharp/Network/Protocols/BlockDefs.cs b/ClassicalSharp/Network/Protocols/BlockDefs.cs
index e2007c854..72f5ebcb5 100644
--- a/ClassicalSharp/Network/Protocols/BlockDefs.cs
+++ b/ClassicalSharp/Network/Protocols/BlockDefs.cs
@@ -39,6 +39,8 @@ namespace ClassicalSharp.Network.Protocols {
info.DefinedCustomBlocks[id >> 5] &= ~(1u << (id & 0x1F));
info.ResetBlockProps(id);
info.UpdateCulling(id);
+ //game.Chat.Add("removing block: " + id + ", name: " + info.Name[id] + ".");
+ game.BlockInfo.dictBlockIDbyName.Remove(info.Name[id].ToUpper());
game.Events.RaiseBlockDefinitionChanged();
}
@@ -107,6 +109,9 @@ namespace ClassicalSharp.Network.Protocols {
reader.ReadUInt8(), reader.ReadUInt8(), reader.ReadUInt8());
info.UpdateCulling(id);
+ //game.Chat.Add("adding block: " + id + ", name: " + info.Name[id] + ".");
+ game.BlockInfo.dictBlockIDbyName.Remove(info.Name[id].ToUpper());
+ game.BlockInfo.dictBlockIDbyName.Add(info.Name[id].ToUpper(), id);
game.Events.RaiseBlockDefinitionChanged();
info.DefinedCustomBlocks[id >> 5] |= (1u << (id & 0x1F));
}