Program: 8273
Project: 8273
Buggy source:
@Override public ItemStack onItemRightClick(ItemStack stack,World world,EntityPlayer player){
  if (!world.isRemote) {
    MovingObjectPosition mop=this.getMovingObjectPositionFromPlayer(world,player,false);
    if (mop == null || mop.typeOfHit != MovingObjectPosition.MovingObjectType.BLOCK) {
      return stack;
    }
    ItemStack[] inventory=getInventory(stack);
    if (inventory[0] == null || inventory[1] == null) {
      return stack;
    }
    Block newBlock=Block.getBlockFromItem(inventory[1].getItem());
    if (newBlock == Blocks.air) {
      return stack;
    }
    int newMeta=inventory[1].getItemDamage();
    double kleinEmc=ItemPE.getEmc(inventory[0]);
    int reqEmc=EMCHelper.getEmcValue(inventory[1]);
    byte charge=getCharge(stack);
    byte mode=this.getMode(stack);
    int facing=MathHelper.floor_double((double)((player.rotationYaw * 4F) / 360F) + 0.5D) & 3;
    ForgeDirection dir=ForgeDirection.getOrientation(mop.sideHit);
    Vec3 look=player.getLookVec();
    AxisAlignedBB box=AxisAlignedBB.getBoundingBox(mop.blockX,mop.blockY,mop.blockZ,mop.blockX,mop.blockY,mop.blockZ);
    int dX=0, dY=0, dZ=0;
    boolean lookingDown=look.yCoord >= -1 && look.yCoord <= -WALL_MODE;
    boolean lookingUp=look.yCoord <= 1 && look.yCoord >= WALL_MODE;
    boolean lookingAlongZ=facing == 0 || facing == 2;
switch (dir) {
case UP:
      if (lookingDown || mode == TRANSMUTATION_MODE) {
        box=box.expand(charge,0,charge);
        dY=1;
      }
 else       if (lookingAlongZ)       box=box.expand(charge,charge * 2,0).offset(0,charge,0);
 else       box=box.expand(0,charge * 2,charge).offset(0,charge,0);
    break;
case DOWN:
  if (lookingUp || mode == TRANSMUTATION_MODE) {
    box=box.expand(charge,0,charge);
    dY=-1;
  }
 else   if (lookingAlongZ)   box=box.expand(charge,charge * 2,0).offset(0,-charge,0);
 else   box=box.expand(0,charge * 2,charge).offset(0,-charge,0);
break;
case EAST:
box=box.expand(0,charge,charge);
dX=1;
break;
case WEST:
box=box.expand(0,charge,charge);
dX=-1;
break;
case SOUTH:
box=box.expand(charge,charge,0);
dZ=1;
break;
case NORTH:
box=box.expand(charge,charge,0);
dZ=-1;
break;
}
if (NORMAL_MODE == mode) box=box.offset(dX,dY,dZ);
if (box != null) {
for (int x=(int)box.minX; x <= (int)box.maxX; x++) {
for (int y=(int)box.minY; y <= (int)box.maxY; y++) {
for (int z=(int)box.minZ; z <= (int)box.maxZ; z++) {
Block oldBlock=world.getBlock(x,y,z);
int oldMeta=oldBlock.getDamageValue(world,x,y,z);
if (mode == NORMAL_MODE && oldBlock == Blocks.air) {
if (kleinEmc < reqEmc) break;
if (PlayerHelper.checkedPlaceBlock(((EntityPlayerMP)player),x,y,z,newBlock,newMeta)) {
removeKleinEMC(stack,reqEmc);
kleinEmc-=reqEmc;
}
}
 else if (mode == TRANSMUTATION_MODE) {
if ((oldBlock == newBlock && oldMeta == newMeta) || oldBlock == Blocks.air || world.getTileEntity(x,y,z) != null || !EMCHelper.doesItemHaveEmc(new ItemStack(oldBlock,1,oldMeta))) {
continue;
}
int emc=EMCHelper.getEmcValue(new ItemStack(oldBlock,1,oldMeta));
if (emc > reqEmc) {
if (PlayerHelper.checkedPlaceBlock(((EntityPlayerMP)player),x,y,z,newBlock,newMeta)) {
int difference=emc - reqEmc;
kleinEmc+=MathHelper.clamp_double(kleinEmc,0,EMCHelper.getKleinStarMaxEmc(inventory[0]));
addKleinEMC(stack,difference);
}
}
 else if (emc < reqEmc) {
int difference=reqEmc - emc;
if (kleinEmc >= difference) {
if (PlayerHelper.checkedPlaceBlock(((EntityPlayerMP)player),x,y,z,newBlock,newMeta)) {
kleinEmc-=difference;
removeKleinEMC(stack,difference);
}
}
}
 else {
PlayerHelper.checkedPlaceBlock(((EntityPlayerMP)player),x,y,z,newBlock,newMeta);
}
}
}
}
}
player.worldObj.playSoundAtEntity(player,"String_Node_Str",1.0F,0.80F + ((0.20F / (float)numCharges) * charge));
}
}
return stack;
}

Fixed version (ground truth):
@Override public ItemStack onItemRightClick(ItemStack stack,World world,EntityPlayer player){
  if (!world.isRemote) {
    MovingObjectPosition mop=this.getMovingObjectPositionFromPlayer(world,player,false);
    if (mop == null || mop.typeOfHit != MovingObjectPosition.MovingObjectType.BLOCK) {
      return stack;
    }
    ItemStack[] inventory=getInventory(stack);
    if (inventory[0] == null || inventory[1] == null) {
      return stack;
    }
    Block newBlock=Block.getBlockFromItem(inventory[1].getItem());
    if (newBlock == Blocks.air) {
      return stack;
    }
    int newMeta=inventory[1].getItemDamage();
    double kleinEmc=ItemPE.getEmc(inventory[0]);
    int reqEmc=EMCHelper.getEmcValue(inventory[1]);
    byte charge=getCharge(stack);
    byte mode=this.getMode(stack);
    int facing=MathHelper.floor_double((double)((player.rotationYaw * 4F) / 360F) + 0.5D) & 3;
    ForgeDirection dir=ForgeDirection.getOrientation(mop.sideHit);
    Vec3 look=player.getLookVec();
    AxisAlignedBB box=AxisAlignedBB.getBoundingBox(mop.blockX,mop.blockY,mop.blockZ,mop.blockX,mop.blockY,mop.blockZ);
    int dX=0, dY=0, dZ=0;
    boolean lookingDown=look.yCoord >= -1 && look.yCoord <= -WALL_MODE;
    boolean lookingUp=look.yCoord <= 1 && look.yCoord >= WALL_MODE;
    boolean lookingAlongZ=facing == 0 || facing == 2;
switch (dir) {
case UP:
      if (lookingDown || mode == TRANSMUTATION_MODE) {
        box=box.expand(charge,0,charge);
        dY=1;
      }
 else       if (lookingAlongZ)       box=box.expand(charge,charge * 2,0).offset(0,charge,0);
 else       box=box.expand(0,charge * 2,charge).offset(0,charge,0);
    break;
case DOWN:
  if (lookingUp || mode == TRANSMUTATION_MODE) {
    box=box.expand(charge,0,charge);
    dY=-1;
  }
 else   if (lookingAlongZ)   box=box.expand(charge,charge * 2,0).offset(0,-charge,0);
 else   box=box.expand(0,charge * 2,charge).offset(0,-charge,0);
break;
case EAST:
box=box.expand(0,charge,charge);
dX=1;
break;
case WEST:
box=box.expand(0,charge,charge);
dX=-1;
break;
case SOUTH:
box=box.expand(charge,charge,0);
dZ=1;
break;
case NORTH:
box=box.expand(charge,charge,0);
dZ=-1;
break;
}
if (NORMAL_MODE == mode) box=box.offset(dX,dY,dZ);
if (box != null) {
for (int x=(int)box.minX; x <= (int)box.maxX; x++) {
for (int y=(int)box.minY; y <= (int)box.maxY; y++) {
for (int z=(int)box.minZ; z <= (int)box.maxZ; z++) {
Block oldBlock=world.getBlock(x,y,z);
int oldMeta=oldBlock.getDamageValue(world,x,y,z);
if (mode == NORMAL_MODE && oldBlock == Blocks.air) {
if (kleinEmc < reqEmc) break;
if (PlayerHelper.checkedPlaceBlock(((EntityPlayerMP)player),x,y,z,newBlock,newMeta)) {
removeKleinEMC(stack,reqEmc);
kleinEmc-=reqEmc;
}
}
 else if (mode == TRANSMUTATION_MODE) {
if ((oldBlock == newBlock && oldMeta == newMeta) || oldBlock == Blocks.air || world.getTileEntity(x,y,z) != null || !EMCHelper.doesItemHaveEmc(new ItemStack(oldBlock,1,oldMeta))) {
continue;
}
int emc=EMCHelper.getEmcValue(new ItemStack(oldBlock,1,oldMeta));
if (emc > reqEmc) {
if (PlayerHelper.checkedReplaceBlock(((EntityPlayerMP)player),x,y,z,newBlock,newMeta)) {
int difference=emc - reqEmc;
kleinEmc+=MathHelper.clamp_double(kleinEmc,0,EMCHelper.getKleinStarMaxEmc(inventory[0]));
addKleinEMC(stack,difference);
}
}
 else if (emc < reqEmc) {
int difference=reqEmc - emc;
if (kleinEmc >= difference) {
if (PlayerHelper.checkedReplaceBlock(((EntityPlayerMP)player),x,y,z,newBlock,newMeta)) {
kleinEmc-=difference;
removeKleinEMC(stack,difference);
}
}
}
 else {
PlayerHelper.checkedReplaceBlock(((EntityPlayerMP)player),x,y,z,newBlock,newMeta);
}
}
}
}
}
player.worldObj.playSoundAtEntity(player,"String_Node_Str",1.0F,0.80F + ((0.20F / (float)numCharges) * charge));
}
}
return stack;
}