Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow using ReplaceBrush as a /brush (Thanks 123DMWM)
- Loading branch information
1 parent
2152efb
commit 74e5ea3
Showing
7 changed files
with
176 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
Copyright 2015 MCGalaxy | ||
Dual-licensed under the Educational Community License, Version 2.0 and | ||
the GNU General Public License, Version 3 (the "Licenses"); you may | ||
not use this file except in compliance with the Licenses. You may | ||
obtain a copy of the Licenses at | ||
http://www.opensource.org/licenses/ecl2.php | ||
http://www.gnu.org/licenses/gpl-3.0.html | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the Licenses are distributed on an "AS IS" | ||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
or implied. See the Licenses for the specific language governing | ||
permissions and limitations under the Licenses. | ||
*/ | ||
using System; | ||
using MCGalaxy.Drawing.Brushes; | ||
using MCGalaxy.Commands; | ||
using MCGalaxy.Commands.Building; | ||
using BlockID = System.UInt16; | ||
|
||
namespace MCGalaxy.Drawing.Brushes | ||
{ | ||
public class ReplaceBrushBrushFactory : BrushFactory | ||
{ | ||
public override string Name { get { return "ReplaceBrush"; } } | ||
public override string[] Help { get { return HelpString; } } | ||
|
||
static string[] HelpString = new string[] { | ||
"&TArguments: [block] [brush name] <brush args>", | ||
"&HDraws by replacing existing blocks that are the given [block] with the output of the given brush" | ||
}; | ||
|
||
public override Brush Construct(BrushArgs args) { | ||
BlockID include = 0; | ||
Brush brush = ParseArguments(args, ref include); | ||
|
||
if (brush == null) return null; | ||
return new ReplaceBrushBrush(include, brush); | ||
} | ||
|
||
protected Brush ParseArguments(BrushArgs args, ref BlockID target) { | ||
string[] parts = args.Message.SplitSpaces(3); | ||
Player p = args.Player; | ||
|
||
if (parts.Length < 2) { p.MessageLines(Help); return null; } | ||
if (!CommandParser.GetBlockIfAllowed(p, parts[0], "replace", out target)) return null; | ||
|
||
BrushFactory factory = BrushFactory.Find(parts[1]); | ||
if (factory == null) { | ||
p.Message("No brush found with name \"{0}\".", parts[1]); | ||
CmdBrush.List(p); return null; | ||
} | ||
|
||
args.Message = parts.Length > 2 ? parts[2] : ""; | ||
return factory.Construct(args); | ||
} | ||
} | ||
|
||
public class ReplaceNotBrushBrushFactory : ReplaceBrushBrushFactory | ||
{ | ||
public override string Name { get { return "ReplaceNotBrush"; } } | ||
public override string[] Help { get { return HelpString; } } | ||
|
||
static string[] HelpString = new string[] { | ||
"&TArguments: [block] [brush name] <brush args>", | ||
"&HDraws by replacing existing blocks that not the given [block] with the output of the given brush" | ||
}; | ||
|
||
public override Brush Construct(BrushArgs args) { | ||
BlockID exclude = 0; | ||
Brush brush = ParseArguments(args, ref exclude); | ||
|
||
if (brush == null) return null; | ||
return new ReplaceNotBrushBrush(exclude, brush); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
Copyright 2015 MCGalaxy | ||
Dual-licensed under the Educational Community License, Version 2.0 and | ||
the GNU General Public License, Version 3 (the "Licenses"); you may | ||
not use this file except in compliance with the Licenses. You may | ||
obtain a copy of the Licenses at | ||
http://www.opensource.org/licenses/ecl2.php | ||
http://www.gnu.org/licenses/gpl-3.0.html | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the Licenses are distributed on an "AS IS" | ||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
or implied. See the Licenses for the specific language governing | ||
permissions and limitations under the Licenses. | ||
*/ | ||
using System; | ||
using MCGalaxy.DB; | ||
using MCGalaxy.Drawing.Ops; | ||
using BlockID = System.UInt16; | ||
|
||
namespace MCGalaxy.Drawing.Brushes | ||
{ | ||
public sealed class ReplaceBrushBrush : Brush | ||
{ | ||
readonly BlockID include; | ||
readonly Brush replacement; | ||
|
||
public ReplaceBrushBrush(BlockID include, Brush replacement) { | ||
this.include = include; this.replacement = replacement; | ||
} | ||
|
||
public override string Name { get { return "ReplaceBrush"; } } | ||
|
||
public override void Configure(DrawOp op, Player p) { | ||
op.Flags = BlockDBFlags.Replaced; | ||
} | ||
|
||
public override BlockID NextBlock(DrawOp op) { | ||
ushort x = op.Coords.X, y = op.Coords.Y, z = op.Coords.Z; | ||
BlockID block = op.Level.GetBlock(x, y, z); // TODO FastGetBlock | ||
|
||
if (block != include) return Block.Invalid; | ||
return replacement.NextBlock(op); | ||
} | ||
} | ||
|
||
public sealed class ReplaceNotBrushBrush : Brush | ||
{ | ||
readonly BlockID exclude; | ||
readonly Brush replacement; | ||
|
||
public ReplaceNotBrushBrush(BlockID exclude, Brush replacement) { | ||
this.exclude = exclude; this.replacement = replacement; | ||
} | ||
|
||
public override string Name { get { return "ReplaceNotBrush"; } } | ||
|
||
public override void Configure(DrawOp op, Player p) { | ||
op.Flags = BlockDBFlags.Replaced; | ||
} | ||
|
||
public override BlockID NextBlock(DrawOp op) { | ||
ushort x = op.Coords.X, y = op.Coords.Y, z = op.Coords.Z; | ||
BlockID block = op.Level.GetBlock(x, y, z); // TODO FastGetBlock | ||
|
||
if (block == exclude) return Block.Invalid; | ||
return replacement.NextBlock(op); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters