Core: add support for auto-rotating blocks

based on name
This commit is contained in:
Goodlyay 2016-12-07 00:22:01 -08:00
parent 405fe46544
commit d4a50ef33f
7 changed files with 151 additions and 6 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

@ -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 {
/// <summary> Stores various properties about the blocks in Minecraft Classic. </summary>
public partial class BlockInfo {
public Dictionary<string, byte> dictBlockIDbyName = new Dictionary<string, byte>();
/// <summary> Gets whether the given block id is a liquid. (water and lava) </summary>
public bool IsLiquid(byte block) { return block >= Block.Water && block <= Block.StillLava; }

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

@ -64,10 +64,133 @@ namespace ClassicalSharp {
game.UserEvents.RaiseBlockChanged(pos, old, 0);
}
} else if (right) {
//[1:28:03 PM] <UnknownShadow200+> well goodlyay you have game.SelectedPos.Intersect
//[1:28:17 PM] <UnknownShadow200+> that's the exact floating point coordinates that the mouse clicked on the block
//[1:31:45 PM] <UnknownShadow200+> e.g. the block clicked on might be (32, 34, 63)
//[1:31:55 PM] <UnknownShadow200+> 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);

View File

@ -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));
}