core: /client cuboid now takes block names

This commit is contained in:
UnknownShadow200 2016-12-07 21:27:12 +11:00
parent d4a50ef33f
commit b785c3e2b7
4 changed files with 22 additions and 18 deletions

View File

@ -29,8 +29,6 @@ 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; }
@ -135,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

@ -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

@ -127,9 +127,9 @@ namespace ClassicalSharp {
if (direction != blockNameSplit[1]) {
string newBlockName = blockNameSplit[0] + "-" + direction;
byte newBlockID;
if (game.BlockInfo.dictBlockIDbyName.TryGetValue(newBlockName, out newBlockID)) {
block = newBlockID;
int newBlockID = game.BlockInfo.FindID(newBlockName);
if (newBlockID != -1) {
block = (byte)newBlockID;
//game.Chat.Add("Substituted " + block + " for " + newBlockID + ".");
} else {
//game.Chat.Add("could not find " + newBlockName + ".");
@ -147,9 +147,9 @@ namespace ClassicalSharp {
if (height != blockNameSplit[1]) {
string newBlockName = blockNameSplit[0] + "-" + height;
byte newBlockID;
if (game.BlockInfo.dictBlockIDbyName.TryGetValue(newBlockName, out newBlockID)) {
block = newBlockID;
int newBlockID = game.BlockInfo.FindID(newBlockName);
if (newBlockID != -1) {
block = (byte)newBlockID;
//game.Chat.Add("Substituted " + block + " for " + newBlockID + ".");
} else {
//game.Chat.Add("could not find " + newBlockName + ".");
@ -179,9 +179,9 @@ namespace ClassicalSharp {
if (corner != blockNameSplit[1]) {
string newBlockName = blockNameSplit[0] + "-" + corner;
byte newBlockID;
if (game.BlockInfo.dictBlockIDbyName.TryGetValue(newBlockName, out newBlockID)) {
block = newBlockID;
int newBlockID = game.BlockInfo.FindID(newBlockName);
if (newBlockID != -1) {
block = (byte)newBlockID;
//game.Chat.Add("Substituted " + block + " for " + newBlockID + ".");
} else {
//game.Chat.Add("could not find " + newBlockName + ".");

View File

@ -39,8 +39,6 @@ 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();
}
@ -109,9 +107,6 @@ 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));
}