mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-24 05:10:42 -04:00
core: /client cuboid now takes block names
This commit is contained in:
parent
d4a50ef33f
commit
b785c3e2b7
@ -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";
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 + ".");
|
||||
|
@ -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));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user