diff --git a/Commands/World/CmdNewLvl.cs b/Commands/World/CmdNewLvl.cs index 47c8874fc..d693d2158 100644 --- a/Commands/World/CmdNewLvl.cs +++ b/Commands/World/CmdNewLvl.cs @@ -93,8 +93,9 @@ namespace MCGalaxy.Commands.World { Player.Message(p, " %HType %T/help newlvl themes %Hto see a list of themes."); Player.Message(p, "%HSeed is optional, and controls how the level is generated."); Player.Message(p, " %HFlat theme: Seed specifies the grass height."); - Player.Message(p, " %HOther themes: Seed affects how terrain is generated."); - Player.Message(p, "%HIf the seed is the same, the generated level will be the same."); + Player.Message(p, " %HHeightmap theme: Seed specifies url of heightmap image."); + Player.Message(p, " %HOther themes: Seed affects how terrain is generated. " + + "If seed is the same, the generated level will be the same."); } public override void Help(Player p, string message) { diff --git a/Commands/building/CmdBrush.cs b/Commands/building/CmdBrush.cs index fbcd007a9..9e4a830cf 100644 --- a/Commands/building/CmdBrush.cs +++ b/Commands/building/CmdBrush.cs @@ -68,8 +68,10 @@ namespace MCGalaxy.Commands.Building { Player.Message(p, "%T/help brush [name]"); Player.Message(p, "%HOutputs the help for the brush with the given name."); Player.Message(p, "%HAvailable brushes: %S" + AvailableBrushes); - Player.Message(p, "%HThe default brush simply takes one argument specifying the block to draw with. " + - "If no arguments are given, your currently held block is used instead."); + Player.Message(p, "%H The default brush takes one argument specifying the block to draw with. " + + "If no arguments are given, draws with your currently held block."); + Player.Message(p, "%H If \"skip\" is used for a block name, " + + "existing blocks in the map will not be replaced by this block."); } public override void Help(Player p, string message) { diff --git a/Commands/building/CmdOutline.cs b/Commands/building/CmdOutline.cs index 707ecef2a..f9422761e 100644 --- a/Commands/building/CmdOutline.cs +++ b/Commands/building/CmdOutline.cs @@ -32,10 +32,13 @@ namespace MCGalaxy.Commands.Building { if (args.Length != 2) { Help(p); return; } DrawArgs dArgs = default(DrawArgs); - dArgs.type = DrawCmd.GetBlock(p, args[0], out dArgs.extType); - if (dArgs.type == Block.Zero) return; - dArgs.newType = DrawCmd.GetBlock(p, args[1], out dArgs.newExtType); - if (dArgs.newType == Block.Zero) return; + int block = DrawCmd.GetBlock(p, args[0], out dArgs.extBlock); + if (block == -1) return; + dArgs.block = (byte)block; + + int newBlock = DrawCmd.GetBlock(p, args[1], out dArgs.newExtBlock); + if (newBlock == -1) return; + dArgs.newBlock = (byte)block; Player.Message(p, "Place two blocks to determine the edges."); p.MakeSelection(2, dArgs, DoOutline); @@ -44,11 +47,11 @@ namespace MCGalaxy.Commands.Building { bool DoOutline(Player p, Vec3S32[] marks, object state, byte type, byte extType) { DrawArgs dArgs = (DrawArgs)state; OutlineDrawOp op = new OutlineDrawOp(); - op.Type = dArgs.type; op.ExtType = dArgs.extType; - op.NewType = dArgs.newType; op.NewExtType = dArgs.newExtType; + op.Block = dArgs.block; op.ExtBlock = dArgs.extBlock; + op.NewBlock = dArgs.newBlock; op.NewExtBlock = dArgs.newExtBlock; return DrawOp.DoDrawOp(op, null, p, marks); } - struct DrawArgs { public byte type, extType, newType, newExtType; } + struct DrawArgs { public byte block, extBlock, newBlock, newExtBlock; } public override void Help(Player p) { Player.Message(p, "%T/outline [type] [type2]"); diff --git a/Commands/building/CmdPaste.cs b/Commands/building/CmdPaste.cs index ca3871bfa..3cdaa8e8d 100644 --- a/Commands/building/CmdPaste.cs +++ b/Commands/building/CmdPaste.cs @@ -20,15 +20,15 @@ using MCGalaxy.Drawing; using MCGalaxy.Drawing.Brushes; using MCGalaxy.Drawing.Ops; -namespace MCGalaxy.Commands.Building { - public sealed class CmdPaste : Command { +namespace MCGalaxy.Commands.Building { + public sealed class CmdPaste : Command { public override string name { get { return "paste"; } } public override string shortcut { get { return "v"; } } public override string type { get { return CommandTypes.Building; } } public override bool museumUsable { get { return false; } } public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } public override CommandAlias[] Aliases { - get { return new[] { new CommandAlias("pastenot", "not"), new CommandAlias("pn", "not") }; } + get { return new[] { new CommandAlias("pastenot", "not"), new CommandAlias("pn", "not") }; } } public override void Use(Player p, string message) { @@ -38,25 +38,29 @@ namespace MCGalaxy.Commands.Building { } bool DoPaste(Player p, Vec3S32[] m, object state, byte type, byte extType) { - string message = (string)state; - m[0] += p.copyoffset; + string message = (string)state; + m[0] += p.copyoffset; CopyState cState = p.CopyBuffer; if (cState.X != cState.OriginX) m[0].X -= (cState.Width - 1); if (cState.Y != cState.OriginY) m[0].Y -= (cState.Height - 1); if (cState.Z != cState.OriginZ) m[0].Z -= (cState.Length - 1); - DrawOp op; if (message == "") { - op = new SimplePasteDrawOp(); - ((SimplePasteDrawOp)op).CopyState = p.CopyBuffer; + SimplePasteDrawOp simpleOp = new SimplePasteDrawOp(); + simpleOp.CopyState = p.CopyBuffer; + return DrawOp.DoDrawOp(simpleOp, null, p, m); + } + + PasteDrawOp op = new PasteDrawOp(); + op.CopyState = p.CopyBuffer; + string[] args = message.Split(' '); + + if (args[0].CaselessEq("not")) { + op.Exclude = ReplaceBrush.GetBlocks(p, 1, args.Length, args); + if (op.Exclude == null) return false; } else { - op = new PasteDrawOp(); - ((PasteDrawOp)op).CopyState = p.CopyBuffer; - string[] args = message.Split(' '); - if (args[0].CaselessEq("not")) - ((PasteDrawOp)op).Exclude = ReplaceBrush.GetBlocks(p, 1, args.Length, args); - else - ((PasteDrawOp)op).Include = ReplaceBrush.GetBlocks(p, 0, args.Length, args); + op.Include = ReplaceBrush.GetBlocks(p, 0, args.Length, args); + if (op.Include == null) return false; } return DrawOp.DoDrawOp(op, null, p, m); } diff --git a/Commands/building/CmdPlace.cs b/Commands/building/CmdPlace.cs index 532e986b2..235325d07 100644 --- a/Commands/building/CmdPlace.cs +++ b/Commands/building/CmdPlace.cs @@ -27,7 +27,8 @@ namespace MCGalaxy.Commands.Building { public CmdPlace() { } public override void Use(Player p, string message) { - byte type = Block.Zero, extType = 0; + int type = -1; + byte extType = 0; ushort x = p.pos[0], y = (ushort)(p.pos[1] - 32), z = p.pos[2]; try { @@ -53,12 +54,12 @@ namespace MCGalaxy.Commands.Building { Player.Message(p, "Invalid parameters"); return; } - if (type == Block.Zero) return; - if (!Block.canPlace(p, type)) { Player.Message(p, "Cannot place that block type."); return; } + if (type == -1 || type == Block.Zero) return; + if (!Block.canPlace(p, (byte)type)) { Player.Message(p, "Cannot place that block type."); return; } Vec3U16 P = Vec3U16.ClampPos(x, y, z, p.level); P.X /= 32; P.Y /= 32; P.Z /= 32; - p.level.UpdateBlock(p, P.X, P.Y, P.Z, type, extType); + p.level.UpdateBlock(p, P.X, P.Y, P.Z, (byte)type, extType); Player.Message(p, "A block was placed at (" + P.X + ", " + P.Y + ", " + P.Z + ")."); } diff --git a/Commands/building/CmdReplaceBrush.cs b/Commands/building/CmdReplaceBrush.cs index cb2438dcd..3c64a1955 100644 --- a/Commands/building/CmdReplaceBrush.cs +++ b/Commands/building/CmdReplaceBrush.cs @@ -44,9 +44,10 @@ namespace MCGalaxy.Commands.Building { string[] parts = ((string)state).SplitSpaces(3); if (parts.Length < 2) { Help(p); return false; } - byte extTile = 0; - byte tile = DrawCmd.GetBlock(p, parts[0], out extTile); - if (tile == Block.Zero) return false; + byte extBlock = 0; + int block = DrawCmd.GetBlock(p, parts[0], out extBlock); + if (block == -1) return false; + string brushName = CmdBrush.FindBrush(parts[1]); if (brushName == null) { Player.Message(p, "No brush found with name \"" + parts[1] + "\"."); @@ -60,8 +61,8 @@ namespace MCGalaxy.Commands.Building { if (brush == null) return false; DrawOp drawOp = null; - if (ReplaceNot) drawOp = new ReplaceNotDrawOp(tile, extTile); - else drawOp = new ReplaceDrawOp(tile, extTile); + if (ReplaceNot) drawOp = new ReplaceNotDrawOp((byte)block, extBlock); + else drawOp = new ReplaceDrawOp((byte)block, extBlock); return DrawOp.DoDrawOp(drawOp, brush, p, marks); } diff --git a/Commands/building/DrawCmd.cs b/Commands/building/DrawCmd.cs index cf3008535..a7c69cf62 100644 --- a/Commands/building/DrawCmd.cs +++ b/Commands/building/DrawCmd.cs @@ -50,23 +50,25 @@ namespace MCGalaxy.Commands.Building { return message == "" ? DrawMode.normal : ParseMode(parts[parts.Length - 1]); } - internal static byte GetBlock(Player p, string msg, out byte extType, bool checkPlacePerm = true) { + internal static int GetBlock(Player p, string msg, out byte extType, bool checkPlacePerm = true) { byte type = Block.Byte(msg); extType = 0; + if (msg.CaselessEq("skip") || msg.CaselessEq("none")) return Block.Zero; + if (type == Block.Zero) { // try treat as a block definition id. type = BlockDefinition.GetBlock(msg, p); if (type == Block.Zero) { - Player.Message(p, "There is no block \"" + msg + "\"."); - return Block.Zero; + Player.Message(p, "There is no block \"{0}\".", msg); + return -1; } extType = type; return Block.custom_block; } if (checkPlacePerm && !Block.canPlace(p, type)) { - Player.Message(p, "Cannot place the block \"" + msg + "\"."); - return Block.Zero; + Player.Message(p, "Cannot place the block \"{0}\".", msg); + return -1; } return type; } diff --git a/Drawing/Brushes/CheckeredBrush.cs b/Drawing/Brushes/CheckeredBrush.cs index fdbdd9d41..9906a23ca 100644 --- a/Drawing/Brushes/CheckeredBrush.cs +++ b/Drawing/Brushes/CheckeredBrush.cs @@ -45,16 +45,17 @@ namespace MCGalaxy.Drawing.Brushes { if (args.Message == "") return new CheckeredBrush(args.Type, args.ExtType, 0, 0); string[] parts = args.Message.Split(' '); - byte extType1; - byte type1 = DrawCmd.GetBlock(args.Player, parts[0], out extType1); - if (type1 == Block.Zero) return null; - if (parts.Length == 1) - return new CheckeredBrush(type1, extType1, Block.Zero, 0); - byte extType2; - byte type2 = DrawCmd.GetBlock(args.Player, parts[1], out extType2); - if (type2 == Block.Zero) return null; - return new CheckeredBrush(type1, extType1, type2, extType2); + byte extBlock1; + int block1 = DrawCmd.GetBlock(args.Player, parts[0], out extBlock1); + if (block1 == -1) return null; + if (parts.Length == 1) + return new CheckeredBrush((byte)block1, extBlock1, Block.Zero, 0); + + byte extBlock2; + int block2 = DrawCmd.GetBlock(args.Player, parts[1], out extBlock2); + if (block2 == -1) return null; + return new CheckeredBrush((byte)block1, extBlock1, (byte)block2, extBlock2); } public override byte NextBlock(DrawOp op) { diff --git a/Drawing/Brushes/FrequencyBrush.cs b/Drawing/Brushes/FrequencyBrush.cs index 8b4033e6d..78a8ffd9a 100644 --- a/Drawing/Brushes/FrequencyBrush.cs +++ b/Drawing/Brushes/FrequencyBrush.cs @@ -43,10 +43,10 @@ namespace MCGalaxy.Drawing.Brushes { byte extType = 0; int sepIndex = parts[i].IndexOf('/'); string block = sepIndex >= 0 ? parts[i].Substring(0, sepIndex) : parts[i]; - byte type = DrawCmd.GetBlock(p, block, out extType); - if (type == Block.Zero) return null; + int type = DrawCmd.GetBlock(p, block, out extType); + if (type == -1) return null; - blocks[j].Type = type; blocks[j].ExtType = extType; + blocks[j].Type = (byte)type; blocks[j].ExtType = extType; if (sepIndex < 0) { j++; continue; } int chance; diff --git a/Drawing/Brushes/ReplaceBrush.cs b/Drawing/Brushes/ReplaceBrush.cs index e71177f70..6f05b9aad 100644 --- a/Drawing/Brushes/ReplaceBrush.cs +++ b/Drawing/Brushes/ReplaceBrush.cs @@ -41,16 +41,24 @@ namespace MCGalaxy.Drawing.Brushes { }; public static Brush Process(BrushArgs args) { - string[] parts = args.Message.Split(' '); + return ProcessReplace(args, false); + } + + internal static Brush ProcessReplace(BrushArgs args, bool not) { + string[] parts = args.Message.Split(' '); if (parts.Length < 2) { args.Player.SendMessage("You need to provide a target block, and at least one block to replace."); return null; } - ExtBlock[] toAffect = GetBlocks(args.Player, 0, parts.Length - 1, parts); + if (toAffect == null) return null; + ExtBlock target; - target.Type = DrawCmd.GetBlock(args.Player, parts[parts.Length - 1], out target.ExtType); - if (target.Type == Block.Zero) return null; - return target.Type == Block.Zero ? null : new ReplaceBrush(toAffect, target); + int block = DrawCmd.GetBlock(args.Player, parts[parts.Length - 1], out target.ExtType); + if (block == -1) return null; + + target.Type = (byte)block; + if (not) return new ReplaceNotBrush(toAffect, target); + return new ReplaceBrush(toAffect, target); } internal static ExtBlock[] GetBlocks(Player p, int start, int max, string[] parts) { @@ -58,10 +66,10 @@ namespace MCGalaxy.Drawing.Brushes { for (int i = 0; i < blocks.Length; i++) blocks[i].Type = Block.Zero; for (int i = 0; start < max; start++, i++ ) { - byte extType = 0; - byte type = DrawCmd.GetBlock(p, parts[start], out extType); - if (type == Block.Zero) continue; - blocks[i].Type = type; blocks[i].ExtType = extType; + byte extBlock = 0; + int block = DrawCmd.GetBlock(p, parts[start], out extBlock); + if (block == -1) return null; + blocks[i].Type = (byte)block; blocks[i].ExtType = extBlock; } return blocks; } @@ -103,16 +111,7 @@ namespace MCGalaxy.Drawing.Brushes { }; public static Brush Process(BrushArgs args) { - string[] parts = args.Message.Split(' '); - if (parts.Length < 2) { - args.Player.SendMessage("You need to provide a target block, and at least one block to replace."); return null; - } - - ExtBlock[] toAffect = ReplaceBrush.GetBlocks(args.Player, 0, parts.Length - 1, parts); - ExtBlock target; - target.Type = DrawCmd.GetBlock(args.Player, parts[parts.Length - 1], out target.ExtType); - if (target.Type == Block.Zero) return null; - return target.Type == Block.Zero ? null : new ReplaceNotBrush(toAffect, target); + return ReplaceBrush.ProcessReplace(args, true); } public override byte NextBlock(DrawOp op) { diff --git a/Drawing/Brushes/SolidBrush.cs b/Drawing/Brushes/SolidBrush.cs index 4add730df..c2ac290d3 100644 --- a/Drawing/Brushes/SolidBrush.cs +++ b/Drawing/Brushes/SolidBrush.cs @@ -42,10 +42,10 @@ namespace MCGalaxy.Drawing.Brushes { public static Brush Process(BrushArgs args) { if (args.Message == "") return new SolidBrush(args.Type, args.ExtType); - byte extType; - byte type = DrawCmd.GetBlock(args.Player, args.Message, out extType); - if (type == Block.Zero) return null; - return new SolidBrush(type, extType); + byte extBlock; + int block = DrawCmd.GetBlock(args.Player, args.Message, out extBlock); + if (block == -1) return null; + return new SolidBrush((byte)block, extBlock); } public override byte NextBlock(DrawOp op) { return type; } diff --git a/Drawing/Brushes/StripedBrush.cs b/Drawing/Brushes/StripedBrush.cs index 7b32559ab..dd37c11b8 100644 --- a/Drawing/Brushes/StripedBrush.cs +++ b/Drawing/Brushes/StripedBrush.cs @@ -45,16 +45,17 @@ namespace MCGalaxy.Drawing.Brushes { if (args.Message == "") return new StripedBrush(args.Type, args.ExtType, 0, 0); string[] parts = args.Message.Split(' '); - byte extType1; - byte type1 = DrawCmd.GetBlock(args.Player, parts[0], out extType1); - if (type1 == Block.Zero) return null; - if (parts.Length == 1) - return new StripedBrush(type1, extType1, 0, 0); - byte extType2; - byte type2 = DrawCmd.GetBlock(args.Player, parts[1], out extType2); - if (type2 == Block.Zero) return null; - return new StripedBrush(type1, extType1, type2, extType2); + byte extBlock1; + int block1 = DrawCmd.GetBlock(args.Player, parts[0], out extBlock1); + if (block1 == -1) return null; + if (parts.Length == 1) + return new StripedBrush((byte)block1, extBlock1, 0, 0); + + byte extBlock2; + int block2 = DrawCmd.GetBlock(args.Player, parts[1], out extBlock2); + if (block2 == -1) return null; + return new StripedBrush((byte)block1, extBlock1, (byte)block2, extBlock2); } public override byte NextBlock(DrawOp op) { diff --git a/Drawing/DrawOps/CuboidDrawOps.cs b/Drawing/DrawOps/CuboidDrawOps.cs index 46c870ebf..a4c0be1d6 100644 --- a/Drawing/DrawOps/CuboidDrawOps.cs +++ b/Drawing/DrawOps/CuboidDrawOps.cs @@ -59,7 +59,7 @@ namespace MCGalaxy.Drawing.Ops { public class OutlineDrawOp : CuboidDrawOp { public override string Name { get { return "Outline"; } } - public byte Type, ExtType, NewType, NewExtType; + public byte Block, ExtBlock, NewBlock, NewExtBlock; public override IEnumerable Perform(Vec3S32[] marks, Player p, Level lvl, Brush brush) { Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max); @@ -76,14 +76,14 @@ namespace MCGalaxy.Drawing.Ops { outline |= Check(lvl, x, (ushort)(y + 1), z); if (outline && !Check(lvl, x, y, z)) - yield return Place(x, y, z, NewType, NewExtType); + yield return Place(x, y, z, NewBlock, NewExtBlock); } } bool Check(Level lvl, ushort x, ushort y, ushort z) { byte tile = lvl.GetTile(x, y, z); - if (tile != Type) return false; - return tile != Block.custom_block || lvl.GetExtTile(x, y, z) == ExtType; + if (tile != Block) return false; + return tile != MCGalaxy.Block.custom_block || lvl.GetExtTile(x, y, z) == ExtBlock; } } diff --git a/Generator/HeightmapGen.cs b/Generator/HeightmapGen.cs index 448428161..e921e0768 100644 --- a/Generator/HeightmapGen.cs +++ b/Generator/HeightmapGen.cs @@ -84,7 +84,7 @@ namespace MCGalaxy.Generator { for (int y = 0; y < height - 1; y++) lvl.blocks[index + oneY * y] = Block.dirt; if (height > 0) - lvl.blocks[index + oneY * (height -1)] = Block.grass; + lvl.blocks[index + oneY * (height - 1)] = Block.grass; index++; } } diff --git a/Levels/LevelEnv.cs b/Levels/LevelEnv.cs index b1d2b1a0c..1ee5352ee 100644 --- a/Levels/LevelEnv.cs +++ b/Levels/LevelEnv.cs @@ -95,8 +95,8 @@ namespace MCGalaxy { static bool CheckBlock(Player p, string value, string variable, ref byte modify) { byte extBlock = 0; - byte block = DrawCmd.GetBlock(p, value, out extBlock, false); - if (block == Block.Zero) return false; + int block = DrawCmd.GetBlock(p, value, out extBlock, false); + if (block == -1 || block == Block.Zero) return false; if (block >= Block.CpeCount && block != Block.custom_block) { Player.Message(p, "Cannot use physics block ids for /env."); return false; } @@ -105,7 +105,7 @@ namespace MCGalaxy { block == Block.mushroom || block == Block.redmushroom || block == Block.rope || block == Block.fire) { Player.Message(p, "Env: Cannot use {0} for {1}.", block, variable); } else { - modify = block == Block.custom_block ? extBlock : block; + modify = block == Block.custom_block ? extBlock : (byte)block; Player.Message(p, "Set {0} for {1}%S to {2}", variable, p.level.name, modify); return true; }