Page 1 of 1

Skip block

Posted: July 16th, 2012, 12:50 pm
by Hellenion
Imitates the skip block behaviour from 0.700

It may not be as sophisticated as f's implementation but this was the easiest way for modders to copy it.

Patch:
Show
Manual implementation:
Show

Re: Skip block

Posted: July 16th, 2012, 8:05 pm
by fragmer
The official skip-block support was added in r1458-r1459. Here's the diff (won't be applicable to 0.6xx).

The most notable change was rewroting CommandReader.NextBlock(), CommandReader.NextBlockWithParam(), and Map.GetBlockByName(). Previously they just took a string and a player name, and returned Block. Now they write result into an "out" variable, and return a bool. This allows me to distinguish between cases where "skip" block was given and when an unrecognized block name was given.

Code: Select all

/// <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.None 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 ) {...
So a typical usage before was...

Code: Select all

Block block = cmd.NextBlock( Player );
if( block == Block.Undefined ){
    // unrecognized block name
}else{
    // normal blocktype given
}
...and now it became...

Code: Select all

Block block;
if( !cmd.NextBlock( Player, true, out block ) ){
    // unrecognized block name
}else if( block == Block.None ){
    // "none" blocktype given
}else{
    // normal blocktype given
}

Re: Skip block

Posted: August 14th, 2012, 4:55 am
by fragmer
I merged the official "skip" block implementation with fCraft 0.630:
SVN wrote:fcraft: fragmer * r1646 /branch-0.60x/fCraft/ (34 files in 9 dirs):
Added support for "none" block in brushes - http://forum.fcraft.net/viewtopic.php?p=18087
Rewrote CommandReader.NextBlock, CommandReader.NextBlockWithParam, and Map.GetBlockByName to accommodate the change.
Renamed Block.Undefined to Block.None