Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fCraft /branch-0.70x/ r1458-r1459 unified diff
Index: C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Commands/BuildingCommands.cs
===================================================================
--- C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Commands/BuildingCommands.cs (revision 1457)
+++ C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Commands/BuildingCommands.cs (revision 1458)
@@ -478,20 +478,16 @@
};
static void BindHandler( Player player, CommandReader cmd ) {
- string originalBlockName = cmd.Next();
- if( originalBlockName == null ) {
+ if( !cmd.HasNext ) {
player.Message( "All bindings have been reset." );
player.ResetAllBinds();
return;
}
- Block originalBlock = Map.GetBlockByName( originalBlockName );
- if( originalBlock == Block.Undefined ) {
- player.Message( "Bind: Unrecognized block name: {0}", originalBlockName );
- return;
- }
- string replacementBlockName = cmd.Next();
- if( replacementBlockName == null ) {
+ Block originalBlock;
+ if( !cmd.NextBlock( player, false, out originalBlock ) ) return;
+
+ if( !cmd.HasNext ) {
if( player.GetBind( originalBlock ) != originalBlock ) {
player.Message( "{0} is no longer bound to {1}",
originalBlock,
@@ -504,36 +500,34 @@
return;
}
+ Block replacementBlock;
+ if( !cmd.NextBlock( player, false, out replacementBlock ) ) return;
+
if( cmd.HasNext ) {
CdBind.PrintUsage( player );
return;
}
- Block replacementBlock = Map.GetBlockByName( replacementBlockName );
- if( replacementBlock == Block.Undefined ) {
- player.Message( "Bind: Unrecognized block name: {0}", replacementBlockName );
+ Permission permission = Permission.Build;
+ switch( replacementBlock ) {
+ case Block.Grass:
+ permission = Permission.PlaceGrass;
+ break;
+ case Block.Admincrete:
+ permission = Permission.PlaceAdmincrete;
+ break;
+ case Block.Water:
+ permission = Permission.PlaceWater;
+ break;
+ case Block.Lava:
+ permission = Permission.PlaceLava;
+ break;
+ }
+ if( player.Can( permission ) ) {
+ player.Bind( originalBlock, replacementBlock );
+ player.Message( "{0} is now replaced with {1}", originalBlock, replacementBlock );
} else {
- Permission permission = Permission.Build;
- switch( replacementBlock ) {
- case Block.Grass:
- permission = Permission.PlaceGrass;
- break;
- case Block.Admincrete:
- permission = Permission.PlaceAdmincrete;
- break;
- case Block.Water:
- permission = Permission.PlaceWater;
- break;
- case Block.Lava:
- permission = Permission.PlaceLava;
- break;
- }
- if( player.Can( permission ) ) {
- player.Bind( originalBlock, replacementBlock );
- player.Message( "{0} is now replaced with {1}", originalBlock, replacementBlock );
- } else {
- player.Message( "&WYou do not have {0} permission.", permission );
- }
+ player.Message( "&WYou do not have {0} permission.", permission );
}
}
@@ -905,8 +899,7 @@
static void CutHandler( Player player, CommandReader cmd ) {
Block fillBlock = Block.Air;
if( cmd.HasNext ) {
- fillBlock = cmd.NextBlock( player );
- if( fillBlock == Block.Undefined ) return;
+ if( !cmd.NextBlock( player, false, out fillBlock ) ) return;
if( cmd.HasNext ) {
CdCut.PrintUsage( player );
return;
Index: C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Commands/CommandReader.cs
===================================================================
--- C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Commands/CommandReader.cs (revision 1457)
+++ C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Commands/CommandReader.cs (revision 1458)
@@ -184,52 +184,69 @@
[DebuggerStepThrough]
- public Block NextBlock( [NotNull] Player player ) {
+ public bool NextBlock( [NotNull] Player player, bool allowNone, out Block block ) {
if( player == null ) throw new ArgumentNullException( "player" );
string blockName = Next();
- Block targetBlock = Block.Undefined;
+ block = Block.None;
if( blockName != null ) {
- targetBlock = Map.GetBlockByName( blockName );
- if( targetBlock == Block.Undefined ) {
+ if( Map.GetBlockByName( blockName, true, out block ) ) {
+ if( block == Block.None && !allowNone ) {
+ player.Message( "The \"none\" block is not allowed here" );
+ return false;
+ } else {
+ return true;
+ }
+ } else {
player.Message( "Unrecognized blocktype \"{0}\"", blockName );
+ return false;
}
+
+ } else {
+ return false;
}
- return targetBlock;
}
- public Block NextBlockWithParam( [NotNull] Player player, ref int param ) {
+ public bool NextBlockWithParam( [NotNull] Player player, bool allowNoneBlock, out Block block, out int param ) {
if( player == null ) throw new ArgumentNullException( "player" );
+ block = Block.None;
+ param = 1;
+
string jointString = Next();
if( jointString == null ) {
- return Block.Undefined;
+ return false;
}
- Block targetBlock;
int slashIndex = jointString.IndexOf( '/' );
if( slashIndex != -1 ) {
string blockName = jointString.Substring( 0, slashIndex );
string paramString = jointString.Substring( slashIndex + 1 );
- targetBlock = Map.GetBlockByName( blockName );
- if( targetBlock == Block.Undefined ) {
+ if( Map.GetBlockByName( blockName, true, out block ) ) {
+ if( block == Block.None && !allowNoneBlock ) {
+ player.Message( "The \"none\" block is not allowed here" );
+ } else {
+ if( Int32.TryParse( paramString, out param ) ) {
+ return true;
+ }
+ player.Message( "Could not parse \"{0}\" as an integer.", paramString );
+ }
+ } else {
player.Message( "Unrecognized blocktype \"{0}\"", blockName );
}
- int tempParam;
- if( Int32.TryParse( paramString, out tempParam ) ) {
- param = tempParam;
+ } else {
+ if( Map.GetBlockByName( jointString, true, out block ) ) {
+ if( block == Block.None && !allowNoneBlock ) {
+ player.Message( "The \"none\" block is not allowed here" );
+ } else {
+ return true;
+ }
} else {
- player.Message( "Could not parse \"{0}\" as an integer.", paramString );
- }
-
- } else {
- targetBlock = Map.GetBlockByName( jointString );
- if( targetBlock == Block.Undefined ) {
player.Message( "Unrecognized blocktype \"{0}\"", jointString );
}
}
- return targetBlock;
+ return false;
}
Index: C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Commands/WorldCommands.cs
===================================================================
--- C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Commands/WorldCommands.cs (revision 1457)
+++ C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Commands/WorldCommands.cs (revision 1458)
@@ -650,8 +650,8 @@
break;
case "edge":
- Block block = Map.GetBlockByName( valueText );
- if( block == Block.Undefined ) {
+ Block block;
+ if( !Map.GetBlockByName( valueText, false, out block ) ) {
CdEnv.PrintUsage( player );
return;
}
Index: C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/World/Map.cs
===================================================================
--- C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/World/Map.cs (revision 1457)
+++ C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/World/Map.cs (revision 1458)
@@ -232,7 +232,7 @@
public Block GetBlock( int x, int y, int z ) {
if( x < Width && y < Length && z < Height && x >= 0 && y >= 0 && z >= 0 )
return (Block)Blocks[Index( x, y, z )];
- return Block.Undefined;
+ return Block.None;
}
@@ -242,7 +242,7 @@
public Block GetBlock( Vector3I coords ) {
if( coords.X < Width && coords.Y < Length && coords.Z < Height && coords.X >= 0 && coords.Y >= 0 && coords.Z >= 0 )
return (Block)Blocks[Index( coords )];
- return Block.Undefined;
+ return Block.None;
}
@@ -608,14 +608,15 @@
static Map() {
// add default names for blocks, and their numeric codes
foreach( Block block in Enum.GetValues( typeof( Block ) ) ) {
- if( block != Block.Undefined ) {
- BlockNames.Add( block.ToString().ToLower(), block );
+ BlockNames.Add( block.ToString().ToLower(), block );
+ if( block != Block.None ) {
BlockNames.Add( ((int)block).ToString( CultureInfo.InvariantCulture ), block );
}
}
// alternative names for blocks
- BlockNames["none"] = Block.Undefined;
+ BlockNames["skip"] = Block.None;
BlockNames["a"] = Block.Air; // common typo
BlockNames["nothing"] = Block.Air;
@@ -843,19 +844,28 @@
}
- /// <summary> Tries to find a blocktype by name. </summary>
- /// <param name="blockName"> Name of the block. </param>
- /// <returns> Described Block, or Block.Undefined if name could not be recognized. </returns>
- public static Block GetBlockByName( [NotNull] string blockName ) {
+ /// <summary> Finds Block corresponding to given blockName. </summary>
+ /// <param name="blockName"> Given block name to parse. </param>
+ /// <param name="allowNoneBlock"> Whether "none" block type is acceptible. </param>
+ /// <param name="block"> Block corresponding to given blockName;
+ /// Block.Undefined if value could not be parsed. </param>
+ /// <returns> True if given blockName was parsed as an acceptible block type. </returns>
+ /// <exception cref="ArgumentNullException"> If blockName is null. </exception>
+ public static bool GetBlockByName( [NotNull] string blockName, bool allowNoneBlock, out Block block ) {
if( blockName == null ) throw new ArgumentNullException( "blockName" );
- Block result;
- if( BlockNames.TryGetValue( blockName.ToLower(), out result ) ) {
- return result;
+ if( BlockNames.TryGetValue( blockName.ToLower(), out block ) ) {
+ if( block == Block.None ) {
+ return allowNoneBlock;
+ } else {
+ return true;
+ }
} else {
- return Block.Undefined;
+ block = Block.None;
+ return false;
}
}
+
/// <summary> Tries to find WoM file hashes for edge textures. </summary>
/// <param name="block"> Blocktype to find edge texture hash for. </param>
/// <returns> Hash string if found, or null if not found. </returns>
Index: C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/World/World.cs
===================================================================
--- C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/World/World.cs (revision 1457)
+++ C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/World/World.cs (revision 1458)
@@ -909,9 +909,9 @@
Name );
}
}
- if( (tempAttr = envEl.Attribute( "edge" )) != null ) {
- Block block = Map.GetBlockByName( tempAttr.Value );
- if( block == Block.Undefined ) {
+ if( ( tempAttr = envEl.Attribute( "edge" ) ) != null ) {
+ Block block;
+ if( !Map.GetBlockByName( tempAttr.Value, false, out block ) ) {
EdgeBlock = Block.Water;
Logger.Log( LogType.Warning,
"WorldManager: Could not parse \"edge\" attribute of Environment settings for world \"{0}\", assuming default (Water).",
Index: C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/World/Block.cs
===================================================================
--- C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/World/Block.cs (revision 1457)
+++ C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/World/Block.cs (revision 1458)
@@ -5,10 +5,8 @@
/// <summary> Enumeration of all standard Minecraft Classic block types. </summary>
#pragma warning disable 1591
public enum Block : byte {
+ None = 255, // for error checking
- Undefined = 255, // for error checking
-
-
Air = 0,
Stone = 1,
Grass = 2,
Index: C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Network/Player.Networking.cs
===================================================================
--- C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Network/Player.Networking.cs (revision 1457)
+++ C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Network/Player.Networking.cs (revision 1458)
@@ -72,7 +72,7 @@
LastActiveTime = DateTime.UtcNow;
LastPatrolTime = DateTime.UtcNow;
LeaveReason = LeaveReason.Unknown;
- LastUsedBlockType = Block.Undefined;
+ LastUsedBlockType = Block.None;
client = tcpClient;
client.SendTimeout = SocketTimeout;
Index: C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/DrawOps/Fill2DDrawOperation.cs
===================================================================
--- C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/DrawOps/Fill2DDrawOperation.cs (revision 1457)
+++ C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/DrawOps/Fill2DDrawOperation.cs (revision 1458)
@@ -18,11 +18,11 @@
public override string Description {
get {
- if( SourceBlock != Block.Undefined ) {
+ if( SourceBlock != Block.None ) {
return String.Format( "{0}({1} -> {2} @{3})",
Name, SourceBlock, ReplacementBlock, Axis );
- } else if( ReplacementBlock != Block.Undefined ) {
+ } else if( ReplacementBlock != Block.None ) {
return String.Format( "{0}({1})",
Name, ReplacementBlock );
@@ -39,15 +39,19 @@
public Fill2DDrawOperation( Player player )
: base( player ) {
- SourceBlock = Block.Undefined;
- ReplacementBlock = Block.Undefined;
+ SourceBlock = Block.None;
+ ReplacementBlock = Block.None;
}
public override bool ReadParams( CommandReader cmd ) {
if( cmd.HasNext ) {
- ReplacementBlock = cmd.NextBlock( Player );
- if( ReplacementBlock == Block.Undefined ) return false;
+ Block replacement;
+ if( cmd.NextBlock( Player, false, out replacement ) ) {
+ ReplacementBlock = replacement;
+ } else {
+ return false;
+ }
}
Brush = this;
return true;
@@ -58,8 +62,8 @@
if( marks == null ) throw new ArgumentNullException( "marks" );
if( marks.Length < 1 ) throw new ArgumentException( "At least one mark needed.", "marks" );
- if( ReplacementBlock == Block.Undefined ) {
- if( Player.LastUsedBlockType == Block.Undefined ) {
+ if( ReplacementBlock == Block.None ) {
+ if( Player.LastUsedBlockType == Block.None ) {
Player.Message( "Cannot deduce desired replacement block. Click a block or type out the block name." );
return false;
} else {
Index: C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/DrawOps/PasteDrawOperation.cs
===================================================================
--- C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/DrawOps/PasteDrawOperation.cs (revision 1457)
+++ C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/DrawOps/PasteDrawOperation.cs (revision 1458)
@@ -120,8 +120,8 @@
}
List<Block> blocks = new List<Block>();
while( cmd.HasNext ) {
- Block block = cmd.NextBlock( Player );
- if( block == Block.Undefined ) return false;
+ Block block;
+ if( !cmd.NextBlock( Player, false, out block ) ) return false;
blocks.Add( block );
}
if( blocks.Count > 0 ) {
@@ -140,14 +140,14 @@
if( Blocks == null ) return block;
if( Not ) {
for( int i = 0; i < Blocks.Length; i++ ) {
- if( block == Blocks[i] ) return Block.Undefined;
+ if( block == Blocks[i] ) return Block.None;
}
return block;
} else {
for( int i = 0; i < Blocks.Length; i++ ) {
if( block == Blocks[i] ) return block;
}
- return Block.Undefined;
+ return Block.None;
}
}
}
Index: C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/DrawOperation.cs
===================================================================
--- C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/DrawOperation.cs (revision 1457)
+++ C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/DrawOperation.cs (revision 1458)
@@ -220,7 +220,7 @@
#endif
Block newBlock = Brush.NextBlock( this );
- if( newBlock == Block.Undefined ) return false;
+ if( newBlock == Block.None ) return false;
int blockIndex = Map.Index( Coords );
Index: C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/NormalBrush.cs
===================================================================
--- C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/NormalBrush.cs (revision 1457)
+++ C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/NormalBrush.cs (revision 1458)
@@ -61,16 +61,13 @@
if( player == null ) throw new ArgumentNullException( "player" );
if( cmd == null ) throw new ArgumentNullException( "cmd" );
if( op == null ) throw new ArgumentNullException( "op" );
- Block block = Block.Undefined,
- altBlock = Block.Undefined;
+ Block block = Block.None,
+ altBlock = Block.None;
if( cmd.HasNext ) {
- block = cmd.NextBlock( player );
- if( block == Block.Undefined ) return null;
-
+ if( !cmd.NextBlock( player, true, out block ) ) return null;
if( cmd.HasNext ) {
- altBlock = cmd.NextBlock( player );
- if( altBlock == Block.Undefined ) return null;
+ if( !cmd.NextBlock( player, true, out altBlock ) ) return null;
}
}
@@ -85,15 +82,15 @@
/// <summary> Whether the brush is capable of providing alternate blocks (e.g. for filling hollow DrawOps).</summary>
public bool HasAlternateBlock {
- get { return AltBlock != Block.Undefined; }
+ get { return AltBlock != Block.None; }
}
/// <summary> A compact readable summary of brush type, configuration, and state. </summary>
public string InstanceDescription {
get {
- if( Block == Block.Undefined ) {
+ if( Block == Block.None ) {
return Brush.Factory.Name;
- } else if( AltBlock == Block.Undefined ) {
+ } else if( AltBlock == Block.None ) {
return String.Format( "{0}({1})", Brush.Factory.Name, Block );
} else {
return String.Format( "{0}({1},{2})", Brush.Factory.Name, Block, AltBlock );
@@ -108,11 +105,11 @@
public NormalBrush( Block block ) {
Block = block;
- AltBlock = Block.Undefined;
+ AltBlock = Block.None;
}
public NormalBrush( Block block, Block altBlock ) {
- if( block == Block.Undefined && altBlock != Block.Undefined ) {
+ if( block == Block.None && altBlock != Block.None ) {
throw new ArgumentException( "Block must not be undefined if altblock is set.", "block" );
}
Block = block;
@@ -129,8 +126,8 @@
public bool Begin( Player player, DrawOperation op ) {
if( player == null ) throw new ArgumentNullException( "player" );
if( op == null ) throw new ArgumentNullException( "op" );
- if( Block == Block.Undefined ) {
- if( player.LastUsedBlockType == Block.Undefined ) {
+ if( Block == Block.None ) {
+ if( player.LastUsedBlockType == Block.None ) {
player.Message( "Cannot deduce desired block. Click a block or type out the block name." );
return false;
} else {
Index: C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/AbstractPerlinNoiseBrush.cs
===================================================================
--- C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/AbstractPerlinNoiseBrush.cs (revision 1457)
+++ C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/AbstractPerlinNoiseBrush.cs (revision 1458)
@@ -36,7 +36,7 @@
protected AbstractPerlinNoiseBrush( Block oneBlock, int ratio )
: this() {
- Blocks = new[] { oneBlock, Block.Undefined };
+ Blocks = new[] { oneBlock, Block.None };
BlockRatios = new[] { ratio, 1 };
}
Index: C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/ReplaceBrush.cs
===================================================================
--- C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/ReplaceBrush.cs (revision 1457)
+++ C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/ReplaceBrush.cs (revision 1458)
@@ -30,15 +30,15 @@
Stack<Block> blocks = new Stack<Block>();
while( cmd.HasNext ) {
- Block block = cmd.NextBlock( player );
- if( block == Block.Undefined ) return null;
+ Block block;
+ if( !cmd.NextBlock( player, false, out block ) ) return null;
blocks.Push( block );
}
switch( blocks.Count ) {
case 0:
return new ReplaceBrush();
case 1:
- return new ReplaceBrush( blocks.ToArray(), Block.Undefined );
+ return new ReplaceBrush( blocks.ToArray(), Block.None );
default: {
Block replacement = blocks.Pop();
return new ReplaceBrush( blocks.ToArray(), replacement );
@@ -78,7 +78,7 @@
get {
if( Blocks == null ) {
return Factory.Name;
- } else if( Replacement == Block.Undefined ) {
+ } else if( Replacement == Block.None ) {
return String.Format( "{0}({1} -> ?)",
Factory.Name,
Blocks.JoinToString() );
@@ -99,8 +99,8 @@
Stack<Block> blocks = new Stack<Block>();
while( cmd.HasNext ) {
- Block block = cmd.NextBlock( player );
- if( block == Block.Undefined ) return null;
+ Block block;
+ if( !cmd.NextBlock( player, false, out block ) ) return null;
blocks.Push( block );
}
@@ -143,8 +143,8 @@
if( Blocks == null || Blocks.Length == 0 ) {
throw new InvalidOperationException( "No blocks given." );
}
- if( Replacement == Block.Undefined ) {
- if( player.LastUsedBlockType == Block.Undefined ) {
+ if( Replacement == Block.None ) {
+ if( player.LastUsedBlockType == Block.None ) {
player.Message( "Cannot deduce desired replacement block. Click a block or type out the block name." );
return false;
} else {
@@ -164,7 +164,7 @@
return Replacement;
}
}
- return Block.Undefined;
+ return Block.None;
}
Index: C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/ReplaceNotBrush.cs
===================================================================
--- C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/ReplaceNotBrush.cs (revision 1457)
+++ C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/ReplaceNotBrush.cs (revision 1458)
@@ -30,15 +30,15 @@
Stack<Block> blocks = new Stack<Block>();
while( cmd.HasNext ) {
- Block block = cmd.NextBlock( player );
- if( block == Block.Undefined ) return null;
+ Block block;
+ if( !cmd.NextBlock( player, false, out block ) ) return null;
blocks.Push( block );
}
switch( blocks.Count ) {
case 0:
return new ReplaceNotBrush();
case 1:
- return new ReplaceNotBrush( blocks.ToArray(), Block.Undefined );
+ return new ReplaceNotBrush( blocks.ToArray(), Block.None );
default: {
Block replacement = blocks.Pop();
return new ReplaceNotBrush( blocks.ToArray(), replacement );
@@ -78,7 +78,7 @@
get {
if( Blocks == null ) {
return Factory.Name;
- } else if( Replacement == Block.Undefined ) {
+ } else if( Replacement == Block.None ) {
return String.Format( "{0}({1} -> ?)",
Factory.Name,
Blocks.JoinToString() );
@@ -99,8 +99,8 @@
Stack<Block> blocks = new Stack<Block>();
while( cmd.HasNext ) {
- Block block = cmd.NextBlock( player );
- if( block == Block.Undefined ) return null;
+ Block block;
+ if( !cmd.NextBlock( player, false, out block ) ) return null;
blocks.Push( block );
}
@@ -143,8 +143,8 @@
if( Blocks == null || Blocks.Length == 0 ) {
throw new InvalidOperationException( "No blocks given." );
}
- if( Replacement == Block.Undefined ) {
- if( player.LastUsedBlockType == Block.Undefined ) {
+ if( Replacement == Block.None ) {
+ if( player.LastUsedBlockType == Block.None ) {
player.Message( "Cannot deduce desired replacement block. Click a block or type out the block name." );
return false;
} else {
@@ -161,7 +161,7 @@
Block block = op.Map.GetBlock( op.Coords );
for( int i = 0; i < Blocks.Length; i++ ) {
if( block == Blocks[i] ) {
- return Block.Undefined;
+ return Block.None;
}
}
return Replacement;
Index: C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/CheckeredBrush.cs
===================================================================
--- C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/CheckeredBrush.cs (revision 1457)
+++ C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/CheckeredBrush.cs (revision 1458)
@@ -26,8 +26,9 @@
public IBrush MakeBrush( Player player, CommandReader cmd ) {
if( player == null ) throw new ArgumentNullException( "player" );
if( cmd == null ) throw new ArgumentNullException( "cmd" );
- Block block = cmd.NextBlock( player );
- Block altBlock = cmd.NextBlock( player );
+ Block block, altBlock;
+ cmd.NextBlock( player, true, out block );
+ cmd.NextBlock( player, true, out altBlock );
return new CheckeredBrush( block, altBlock );
}
}
@@ -60,9 +61,9 @@
public string Description {
get {
- if( Block2 != Block.Undefined ) {
+ if( Block2 != Block.None ) {
return String.Format( "{0}({1},{2})", Factory.Name, Block1, Block2 );
- } else if( Block1 != Block.Undefined ) {
+ } else if( Block1 != Block.None ) {
return String.Format( "{0}({1})", Factory.Name, Block1 );
} else {
return Factory.Name;
@@ -77,14 +78,19 @@
if( op == null ) throw new ArgumentNullException( "op" );
if( cmd.HasNext ) {
- Block block = cmd.NextBlock( player );
- if( block == Block.Undefined ) return null;
- Block altBlock = cmd.NextBlock( player );
+ Block block, altBlock;
+ if( !cmd.NextBlock( player, true, out block ) ) return null;
+ if( cmd.HasNext ) {
+ if( !cmd.NextBlock( player, true, out altBlock ) ) return null;
+ } else {
+ altBlock = Block.None;
+ }
+
Block1 = block;
Block2 = altBlock;
- } else if( Block1 == Block.Undefined ) {
- player.Message( "{0}: Please specify at least one block.", Factory.Name );
+ } else if( Block1 == Block.None ) {
+ player.Message( "{0}: Please specify one or two blocks.", Factory.Name );
return null;
}
Index: C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/CloudyBrush.cs
===================================================================
--- C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/CloudyBrush.cs (revision 1457)
+++ C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/CloudyBrush.cs (revision 1458)
@@ -31,9 +31,9 @@
List<Block> blocks = new List<Block>();
List<int> blockRatios = new List<int>();
while( cmd.HasNext ) {
- int ratio = 1;
- Block block = cmd.NextBlockWithParam( player, ref ratio );
- if( block == Block.Undefined ) return null;
+ int ratio;
+ Block block;
+ if( !cmd.NextBlockWithParam( player, true, out block, out ratio ) ) return null;
if( ratio < 0 || ratio > 1000 ) {
player.Message( "{0} brush: Invalid block ratio ({1}). Must be between 1 and 1000.",
Name, ratio );
@@ -84,7 +84,7 @@
get {
if( Blocks.Length == 0 ) {
return Factory.Name;
- } else if( Blocks.Length == 1 || ( Blocks.Length == 2 && Blocks[1] == Block.Undefined ) ) {
+ } else if( Blocks.Length == 1 || ( Blocks.Length == 2 && Blocks[1] == Block.None ) ) {
return String.Format( "{0}({1})", Factory.Name, Blocks[0] );
} else {
StringBuilder sb = new StringBuilder();
@@ -113,13 +113,14 @@
List<Block> blocks = new List<Block>();
List<int> blockRatios = new List<int>();
while( cmd.HasNext ) {
- int ratio = 1;
- Block block = cmd.NextBlockWithParam( player, ref ratio );
+ int ratio;
+ Block block;
+ if( !cmd.NextBlockWithParam( player, true, out block, out ratio ) ) return null;
if( ratio < 0 || ratio > 1000 ) {
player.Message( "Invalid block ratio ({0}). Must be between 1 and 1000.", ratio );
return null;
}
- if( block == Block.Undefined ) return null;
+ if( block == Block.None ) return null;
blocks.Add( block );
blockRatios.Add( ratio );
}
Index: C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/ReplaceBrushBrush.cs
===================================================================
--- C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/ReplaceBrushBrush.cs (revision 1457)
+++ C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/ReplaceBrushBrush.cs (revision 1458)
@@ -32,8 +32,8 @@
return null;
}
- Block block = cmd.NextBlock( player );
- if( block == Block.Undefined ) return null;
+ Block block;
+ if( !cmd.NextBlock( player, false, out block ) ) return null;
string brushName = cmd.Next();
if( brushName == null || !CommandManager.IsValidCommandName( brushName ) ) {
@@ -98,8 +98,8 @@
if( op == null ) throw new ArgumentNullException( "op" );
if( cmd.HasNext ) {
- Block block = cmd.NextBlock( player );
- if( block == Block.Undefined ) return null;
+ Block block;
+ if( !cmd.NextBlock( player, false, out block ) ) return null;
string brushName = cmd.Next();
if( brushName == null || !CommandManager.IsValidCommandName( brushName ) ) {
@@ -161,7 +161,7 @@
if( block == Block ) {
return ReplacementInstance.NextBlock( op );
} else {
- return Block.Undefined;
+ return Block.None;
}
}
Index: C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/RandomBrush.cs
===================================================================
--- C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/RandomBrush.cs (revision 1457)
+++ C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/RandomBrush.cs (revision 1458)
@@ -33,9 +33,10 @@
List<Block> blocks = new List<Block>();
List<int> blockRatios = new List<int>();
while( cmd.HasNext ) {
- int ratio = 1;
- Block block = cmd.NextBlockWithParam( player, ref ratio );
- if( block == Block.Undefined ) return null;
+ int ratio;
+ Block block;
+ if( !cmd.NextBlockWithParam( player, true, out block, out ratio ) ) return null;
+ if( block == Block.None ) return null;
if( ratio < 0 || ratio > 1000 ) {
player.Message( "{0} brush: Invalid block ratio ({1}). Must be between 1 and 1000.",
Name, ratio );
@@ -69,9 +70,9 @@
}
public RandomBrush( Block oneBlock, int ratio ) {
- Blocks = new[] { oneBlock, Block.Undefined };
+ Blocks = new[] { oneBlock, Block.None };
BlockRatios = new[] { ratio, 1 };
- actualBlocks = new[] { oneBlock, Block.Undefined };
+ actualBlocks = new[] { oneBlock, Block.None };
}
public RandomBrush( Block[] blocks, int[] ratios ) {
@@ -107,7 +108,7 @@
get {
if( Blocks.Length == 0 ) {
return Factory.Name;
- } else if( Blocks.Length == 1 || (Blocks.Length == 2 && Blocks[1] == Block.Undefined) ) {
+ } else if( Blocks.Length == 1 || (Blocks.Length == 2 && Blocks[1] == Block.None) ) {
return String.Format( "{0}({1})", Factory.Name, Blocks[0] );
} else {
StringBuilder sb = new StringBuilder();
@@ -136,13 +137,14 @@
List<Block> blocks = new List<Block>();
List<int> blockRatios = new List<int>();
while( cmd.HasNext ) {
- int ratio = 1;
- Block block = cmd.NextBlockWithParam( player, ref ratio );
+ int ratio;
+ Block block;
+ if( !cmd.NextBlockWithParam( player, true, out block, out ratio ) ) return null;
if( ratio < 0 || ratio > 1000 ) {
player.Message( "Invalid block ratio ({0}). Must be between 1 and 1000.", ratio );
return null;
}
- if( block == Block.Undefined ) return null;
+ if( block == Block.None ) return null;
blocks.Add( block );
blockRatios.Add( ratio );
}
Index: C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/MarbledBrush.cs
===================================================================
--- C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/MarbledBrush.cs (revision 1457)
+++ C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Drawing/Brushes/MarbledBrush.cs (revision 1458)
@@ -31,9 +31,10 @@
List<Block> blocks = new List<Block>();
List<int> blockRatios = new List<int>();
while( cmd.HasNext ) {
- int ratio = 1;
- Block block = cmd.NextBlockWithParam( player, ref ratio );
- if( block == Block.Undefined ) return null;
+ int ratio;
+ Block block;
+ if( !cmd.NextBlockWithParam( player, true, out block, out ratio ) ) return null;
+ if( block == Block.None ) return null;
if( ratio < 0 || ratio > 1000 ) {
player.Message( "{0} brush: Invalid block ratio ({1}). Must be between 1 and 1000.",
Name, ratio );
@@ -88,7 +89,7 @@
get {
if( Blocks.Length == 0 ) {
return Factory.Name;
- } else if( Blocks.Length == 1 || (Blocks.Length == 2 && Blocks[1] == Block.Undefined) ) {
+ } else if( Blocks.Length == 1 || (Blocks.Length == 2 && Blocks[1] == Block.None) ) {
return String.Format( "{0}({1})", Factory.Name, Blocks[0] );
} else {
StringBuilder sb = new StringBuilder();
@@ -117,13 +118,14 @@
List<Block> blocks = new List<Block>();
List<int> blockRatios = new List<int>();
while( cmd.HasNext ) {
- int ratio = 1;
- Block block = cmd.NextBlockWithParam( player, ref ratio );
+ int ratio;
+ Block block;
+ if( !cmd.NextBlockWithParam( player, true, out block, out ratio ) ) return null;
if( ratio < 0 || ratio > 1000 ) {
player.Message( "Invalid block ratio ({0}). Must be between 1 and 1000.", ratio );
return null;
}
- if( block == Block.Undefined ) return null;
+ if( block == Block.None ) return null;
blocks.Add( block );
blockRatios.Add( ratio );
}
Index: C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Player/Player.cs
===================================================================
--- C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Player/Player.cs (revision 1457)
+++ C:/Users/fragmer/Desktop/Minecraft/fCraft/branch-0.70x/fCraft.Core/Player/Player.cs (revision 1458)
@@ -1155,7 +1155,7 @@
// check whether coordinate is in bounds
Block oldBlock = map.GetBlock( coords );
- if( oldBlock == Block.Undefined ) {
+ if( oldBlock == Block.None ) {
result = CanPlaceResult.OutOfBounds;
goto eventCheck;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.