From 3f33038e55c0046f5de3f5cd578c23ce5153ce05 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 1 Jun 2017 15:21:20 +1000 Subject: [PATCH] Support custom blocks in /measure and /rp --- MCGalaxy/Commands/building/CmdMeasure.cs | 18 ++++++--------- .../Commands/building/CmdRestartPhysics.cs | 23 +++++++++++-------- MCGalaxy/Levels/Level.Blocks.cs | 7 +++--- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/MCGalaxy/Commands/building/CmdMeasure.cs b/MCGalaxy/Commands/building/CmdMeasure.cs index 4456db2bf..fb1aa0507 100644 --- a/MCGalaxy/Commands/building/CmdMeasure.cs +++ b/MCGalaxy/Commands/building/CmdMeasure.cs @@ -30,20 +30,15 @@ namespace MCGalaxy.Commands.Building { public override void Use(Player p, string message) { if (message.IndexOf(' ') != -1) { Help(p); return; } - byte toIgnore = Block.air; - if (message != "") { - toIgnore = Block.Byte(message); - if (toIgnore == Block.Invalid) { - Player.Message(p, "Could not find block specified"); return; - } - } + ExtBlock skip = ExtBlock.Air; + if (message != "" && !CommandParser.GetBlock(p, message, out skip)) return; Player.Message(p, "Place or break two blocks to determine the edges."); - p.MakeSelection(2, toIgnore, DoMeasure); + p.MakeSelection(2, skip, DoMeasure); } bool DoMeasure(Player p, Vec3S32[] m, object state, ExtBlock block) { - byte toIgnore = (byte)state; + ExtBlock skip = (ExtBlock)state; int minX = Math.Min(m[0].X, m[1].X), maxX = Math.Max(m[0].X, m[1].X); int minY = Math.Min(m[0].Y, m[1].Y), maxY = Math.Max(m[0].Y, m[1].Y); int minZ = Math.Min(m[0].Z, m[1].Z), maxZ = Math.Max(m[0].Z, m[1].Z); @@ -53,7 +48,7 @@ namespace MCGalaxy.Commands.Building { for (int z = minZ; z <= maxZ; z++) for (int x = minX; x <= maxX; x++) { - if (p.level.GetTile((ushort)x, (ushort)y, (ushort)z) != toIgnore) + if (p.level.GetExtBlock((ushort)x, (ushort)y, (ushort)z) != skip) found++; } @@ -62,7 +57,8 @@ namespace MCGalaxy.Commands.Building { minX, minY, minZ, maxX, maxY, maxZ); Player.Message(p, "Area is {0} wide, {1} high, {2} long. Volume is {3} blocks.", width, height, length, width * height * length); - Player.Message(p, "There are {0} {1} blocks in the area.", found, "non-" + Block.Name(toIgnore)); + Player.Message(p, "There are {0} {1} blocks in the area.", found, + "non-" + p.level.BlockName(skip)); return true; } diff --git a/MCGalaxy/Commands/building/CmdRestartPhysics.cs b/MCGalaxy/Commands/building/CmdRestartPhysics.cs index dbabb50e1..89880c19b 100644 --- a/MCGalaxy/Commands/building/CmdRestartPhysics.cs +++ b/MCGalaxy/Commands/building/CmdRestartPhysics.cs @@ -38,33 +38,38 @@ namespace MCGalaxy.Commands.Building { p.MakeSelection(2, extraInfo, DoRestart); } - bool ParseArgs(Player p, string message, ref PhysicsArgs extraInfo) { + bool ParseArgs(Player p, string message, ref PhysicsArgs args) { string[] parts = message.SplitSpaces(); if (parts.Length % 2 == 1) { Player.Message(p, "Number of parameters must be even"); Help(p); return false; } byte type = 0, value = 0; + bool isExt = false; if (parts.Length >= 2) { - if (!Parse(p, parts[0], parts[1], ref type, ref value)) return false; - extraInfo.Type1 = type; extraInfo.Value1 = value; + if (!Parse(p, parts[0], parts[1], ref type, ref value, ref isExt)) return false; + args.Type1 = type; args.Value1 = value; } if (parts.Length >= 4) { - if (!Parse(p, parts[2], parts[3], ref type, ref value)) return false; - extraInfo.Type2 = type; extraInfo.Value2 = value; + if (!Parse(p, parts[2], parts[3], ref type, ref value, ref isExt)) return false; + args.Type2 = type; args.Value2 = value; } if (parts.Length >= 6) { Player.Message(p, "You can only use up to two types of physics."); return false; } + + args.ExtBlock = isExt; return true; } - bool Parse(Player p, string name, string arg, ref byte type, ref byte value) { + bool Parse(Player p, string name, string arg, ref byte type, ref byte value, ref bool isExt) { if (name == "revert") { - byte block = Block.Byte(arg); - if (block == Block.Invalid) { Player.Message(p, "Invalid block type."); return false; } - type = PhysicsArgs.Revert; value = block; + ExtBlock block; + if (!CommandParser.GetBlock(p, arg, out block)) return false; + + type = PhysicsArgs.Revert; value = block.RawID; + isExt = block.BlockID == Block.custom_block; return true; } diff --git a/MCGalaxy/Levels/Level.Blocks.cs b/MCGalaxy/Levels/Level.Blocks.cs index a394a5528..88970c635 100644 --- a/MCGalaxy/Levels/Level.Blocks.cs +++ b/MCGalaxy/Levels/Level.Blocks.cs @@ -48,11 +48,10 @@ namespace MCGalaxy { } public ExtBlock GetExtBlock(ushort x, ushort y, ushort z) { - int index = PosToInt(x, y, z); - if (index < 0 || blocks == null) return ExtBlock.Invalid; - + if (x >= Width || y >= Height || z >= Length || blocks == null) return ExtBlock.Invalid; ExtBlock block; - block.BlockID = blocks[index]; + + block.BlockID = blocks[x + Width * (z + y * Length)]; block.ExtID = block.BlockID == Block.custom_block ? GetExtTileNoCheck(x, y, z) : Block.air; return block;