Example #1
0
function getBlockIdAndMeta( b ) { 
  var defaultMeta = 0,
      i = 0,
      bs,
      md,
      sp;
  if (typeof b === 'number' || /^[0-9]+$/.test(b)) {
    // wph 20130414 - use sensible defaults for certain blocks e.g. stairs
    // should face the drone.
    if ( blocks.isStair(b) ) {
      defaultMeta = Drone.PLAYER_STAIRS_FACING[ this.dir % 4 ];
    } else { 
      switch (b) {
      case blocks.sign:
      case blocks.ladder:
	// bug: furnace, chest, dispenser don't always use the right metadata
      case blocks.furnace:  
      case blocks.furnace_burning: 
      case blocks.chest:
      case blocks.enderchest:
      case blocks.dispenser:
	defaultMeta = Drone.PLAYER_SIGN_FACING[ this.dir % 4 ];
	break;
      case blocks.sign_post:
	defaultMeta = ( 12 + ( ( this.dir + 2 ) * 4 ) ) % 16;
	break;
      }
    }
    return [ b, defaultMeta ];
  }
  if ( typeof b === 'string' ) { 
    bs = b;
    sp = bs.indexOf(':' );
    if ( sp == -1 ) { 
      b = parseInt( bs );
      return [ b, defaultMeta ];
    }
    b = parseInt(bs.substring(0,sp ) );
    md = parseInt(bs.substring(sp+1,bs.length ) );
    return [b,md];
  }
  if (b.id){
    // wph 20141230 we are dealing with an object 
    var blockInfo = b;
    var metadata = {};
    for (i in b){
      if (i !== 'id')
	metadata[i] = b[i];
    }
    return [b.id, metadata];
  }
}
Example #2
0
/*
 blocks which have facing
 */
function applyFacing( block, metadata ){
  function face(direction){
    property(block).set('facing', lookup.facing[direction]);
  }
  if ( blocks.isStair(block.typeId) ){
    face( ['east','west','south','north'] [metadata] );
  } else {
    switch( block.typeId ){
    case blocks.sign:
    case blocks.ladder:
      // bug: furnace, chest, dispenser don't always use the right metadata
    case blocks.furnace:  
    case blocks.furnace_burning: 
    case blocks.chest:
    case blocks.enderchest:
    case blocks.dispenser:
      face( [null,null,'north','south','west','east'][metadata] );
      break;
    case blocks.torch:
      face( ['up'/* default */,'east','west','south','north','up'][metadata] );
      break;
    }
  }
}