Program: 177306
Project: 177306
Buggy source:
private boolean setBlockMaterial(int x,int y,int z,BlockMaterial material,short data,Cause<?> cause,boolean event){
  int bx=x & BLOCKS.MASK;
  int by=y & BLOCKS.MASK;
  int bz=z & BLOCKS.MASK;
  checkChunkLoaded();
  checkBlockStoreUpdateAllowed();
  if (event) {
    Block block=getBlock(bx,by,bz);
    BlockChangeEvent blockEvent=new BlockChangeEvent(block,new BlockSnapshot(block,material,data),cause);
    Spout.getEngine().getEventManager().callEvent(blockEvent);
    if (blockEvent.isCancelled()) {
      return false;
    }
    material=blockEvent.getSnapshot().getMaterial();
    data=blockEvent.getSnapshot().getData();
  }
  short newId=material.getId();
  short newData=data;
  int newState=BlockFullState.getPacked(newId,newData);
  int oldState;
  BlockMaterial oldMaterial;
  if (material instanceof ComplexMaterial) {
    oldState=getAndSetBlockLocked(bx,by,bz,newId,newData);
    oldMaterial=(BlockMaterial)MaterialRegistry.get(oldState);
  }
 else {
    boolean success=false;
    do {
      oldState=blockStore.getFullData(bx,by,bz);
      oldMaterial=(BlockMaterial)MaterialRegistry.get(oldState);
      if (oldMaterial instanceof ComplexMaterial) {
        oldState=getAndSetBlockLocked(bx,by,bz,newId,newData);
        success=true;
      }
 else {
        short oldId=BlockFullState.getId(oldState);
        short oldData=BlockFullState.getData(oldState);
        success=blockStore.compareAndSetBlock(bx,by,bz,oldId,oldData,newId,newData);
      }
    }
 while (!success);
  }
  short oldData=BlockFullState.getData(oldState);
  int oldheight=column.getSurfaceHeight(bx,bz);
  int wy=by + this.getBlockY();
  column.notifyBlockChange(bx,wy,bz);
  int wx=bx + this.getBlockX();
  int wz=bz + this.getBlockZ();
  int newheight=column.getSurfaceHeight(bx,bz);
  if (this.isPopulated()) {
    SpoutWorld world=this.getWorld();
    if (!this.setBlockLight(wx,wy,wz,material.getLightLevel(data),cause)) {
      addBlockLightOperation(wx,wy,wz,SpoutWorldLighting.REFRESH);
    }
    if (newheight > oldheight) {
      for (y=oldheight; y < newheight; y++) {
        world.setBlockSkyLight(wx,wy + 1,wz,(byte)0,cause);
      }
    }
 else     if (newheight < oldheight) {
      for (y=newheight; y < oldheight; y++) {
        world.setBlockSkyLight(wx,wy + 1,wz,(byte)15,cause);
      }
    }
 else {
      byte old=this.getBlockSkyLight(wx,wy,wz);
      if (old == 0) {
        addSkyLightOperation(wx,wy,wz,SpoutWorldLighting.REFRESH);
      }
 else       if (old < 15) {
        this.setBlockSkyLight(wx,wy,wz,(byte)0,cause);
      }
    }
  }
  if (newState != oldState) {
    blockChanged(bx,by,bz,material,newData,oldMaterial,oldData,cause);
    return true;
  }
  return false;
}

Fixed version (ground truth):
private boolean setBlockMaterial(int x,int y,int z,BlockMaterial material,short data,Cause<?> cause,boolean event){
  int bx=x & BLOCKS.MASK;
  int by=y & BLOCKS.MASK;
  int bz=z & BLOCKS.MASK;
  checkChunkLoaded();
  checkBlockStoreUpdateAllowed();
  if (event) {
    Block block=getBlock(bx,by,bz);
    BlockChangeEvent blockEvent=new BlockChangeEvent(block,new BlockSnapshot(block,material,data),cause);
    Spout.getEngine().getEventManager().callEvent(blockEvent);
    if (blockEvent.isCancelled()) {
      return false;
    }
    material=blockEvent.getSnapshot().getMaterial();
    data=blockEvent.getSnapshot().getData();
  }
  short newId=material.getId();
  short newData=data;
  int newState=BlockFullState.getPacked(newId,newData);
  int oldState;
  BlockMaterial oldMaterial;
  if (material instanceof ComplexMaterial) {
    oldState=getAndSetBlockLocked(bx,by,bz,newId,newData);
    oldMaterial=(BlockMaterial)MaterialRegistry.get(oldState);
  }
 else {
    boolean success=false;
    do {
      oldState=blockStore.getFullData(bx,by,bz);
      oldMaterial=(BlockMaterial)MaterialRegistry.get(oldState);
      if (oldMaterial instanceof ComplexMaterial) {
        oldState=getAndSetBlockLocked(bx,by,bz,newId,newData);
        success=true;
      }
 else {
        short oldId=BlockFullState.getId(oldState);
        short oldData=BlockFullState.getData(oldState);
        success=blockStore.compareAndSetBlock(bx,by,bz,oldId,oldData,newId,newData);
      }
    }
 while (!success);
  }
  short oldData=BlockFullState.getData(oldState);
  int oldheight=column.getSurfaceHeight(bx,bz);
  int wy=by + this.getBlockY();
  column.notifyBlockChange(bx,wy,bz);
  int wx=bx + this.getBlockX();
  int wz=bz + this.getBlockZ();
  int newheight=column.getSurfaceHeight(bx,bz);
  if (this.isPopulated()) {
    SpoutWorld world=this.getWorld();
    if (!this.setBlockLight(wx,wy,wz,material.getLightLevel(data),cause)) {
      addBlockLightOperation(wx,wy,wz,SpoutWorldLighting.REFRESH);
    }
    if (newheight > oldheight) {
      for (y=oldheight; y < newheight; y++) {
        world.setBlockSkyLight(wx,y + 1,wz,(byte)0,cause);
      }
    }
 else     if (newheight < oldheight) {
      for (y=newheight; y < oldheight; y++) {
        world.setBlockSkyLight(wx,y + 1,wz,(byte)15,cause);
      }
    }
 else {
      this.setBlockSkyLight(wx,wy,wz,(byte)0,cause);
      addSkyLightOperation(wx,wy,wz,SpoutWorldLighting.REFRESH);
    }
  }
  if (newState != oldState) {
    blockChanged(bx,by,bz,material,newData,oldMaterial,oldData,cause);
    return true;
  }
  return false;
}