Skip block

For all mod-related questions and custom code.
Post Reply
User avatar
Hellenion
Offline
Posts: 220
Joined: October 20th, 2011, 9:20 am
Location: Subnet
Contact:

Skip block

Post 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
A = {x ∈ P(U) | x ∉ x}
Mods:
  1. /Su - Allows players to temporarily become a different rank
  2. /Snap - Like /Line but only draws straight or diagonal lines.
  3. pre-0.630 skip/none block

User avatar
fragmer
fCraft Developer
Offline
Posts: 1386
Joined: May 21st, 2011, 10:53 pm

Re: Skip block

Post 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
}

User avatar
fragmer
fCraft Developer
Offline
Posts: 1386
Joined: May 21st, 2011, 10:53 pm

Re: Skip block

Post 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

Post Reply