From e051a040992be58abcae581d688c6affd0e9614f Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 10 Jan 2018 18:18:36 +1100 Subject: [PATCH] CommandParser.Getblock prefers raw ID, then names of custom blocks on level, then finally default/physics block names. --- MCGalaxy/Commands/CommandParser.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/MCGalaxy/Commands/CommandParser.cs b/MCGalaxy/Commands/CommandParser.cs index 3220c54fe..6e97f07f9 100644 --- a/MCGalaxy/Commands/CommandParser.cs +++ b/MCGalaxy/Commands/CommandParser.cs @@ -180,14 +180,19 @@ namespace MCGalaxy.Commands { /// Attempts to parse the given argument as either a block name or a block ID. /// This does not output any messages to the player. public static ExtBlock RawGetBlock(Player p, string input) { - ExtBlock block = default(ExtBlock); - block.BlockID = Block.Byte(input); - if (!block.IsInvalid) return block; - - // find custom block BlockDefinition[] defs = p == null ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs; + byte id; + // raw ID is treated specially, before names + if (byte.TryParse(input, out id) && (id < Block.CpeCount || defs[id] != null)) { + return ExtBlock.FromRaw(id); + } + int raw = BlockDefinition.GetBlock(input, defs); if (raw != -1) return ExtBlock.FromRaw((byte)raw); + + id = Block.Byte(input); + if (id != Block.Invalid) return new ExtBlock(id, 0); + return ExtBlock.Invalid; }