nus-yam/ex-repair huggingface dataset:
Program: 734
Project: 734
Buggy source:
@ReceiveEvent public void onHeldItemChanged(OnChangedComponent event,EntityRef character,CharacterHeldItemComponent heldItemComponent,CharacterComponent characterComponents){
  EntityRef oldHeldItem=currentHeldItem;
  currentHeldItem=heldItemComponent.selectedItem;
  linkHeldItemLocationForLocalPlayer(character,currentHeldItem,oldHeldItem);
}

Fixed version (ground truth):
@ReceiveEvent public void onHeldItemChanged(OnChangedComponent event,EntityRef character,CharacterHeldItemComponent heldItemComponent,CharacterComponent characterComponents){
  if (localPlayer.getCharacterEntity().equals(character)) {
    EntityRef oldHeldItem=currentHeldItem;
    currentHeldItem=heldItemComponent.selectedItem;
    linkHeldItemLocationForLocalPlayer(character,currentHeldItem,oldHeldItem);
  }
}
Program: 735
Project: 735
Buggy source:
@ReceiveEvent public void onHeldItemActivated(OnActivatedComponent event,EntityRef character,CharacterHeldItemComponent heldItemComponent,CharacterComponent characterComponents){
  EntityRef oldHeldItem=currentHeldItem;
  currentHeldItem=heldItemComponent.selectedItem;
  linkHeldItemLocationForLocalPlayer(character,currentHeldItem,oldHeldItem);
}

Fixed version (ground truth):
@ReceiveEvent public void onHeldItemActivated(OnActivatedComponent event,EntityRef character,CharacterHeldItemComponent heldItemComponent,CharacterComponent characterComponents){
  if (localPlayer.getCharacterEntity().equals(character)) {
    EntityRef oldHeldItem=currentHeldItem;
    currentHeldItem=heldItemComponent.selectedItem;
    linkHeldItemLocationForLocalPlayer(character,currentHeldItem,oldHeldItem);
  }
}
Program: 736
Project: 736
Buggy source:
void linkHeldItemLocationForLocalPlayer(EntityRef character,EntityRef newItem,EntityRef oldItem){
  if (character.equals(localPlayer.getCharacterEntity()) && !newItem.equals(oldItem)) {
    EntityRef camera=localPlayer.getCameraEntity();
    FirstPersonHeldItemMountPointComponent mountPointComponent=camera.getComponent(FirstPersonHeldItemMountPointComponent.class);
    if (mountPointComponent != null) {
      if (oldItem != null && oldItem.exists()) {
        Location.removeChild(mountPointComponent.mountPointEntity,oldItem);
        oldItem.removeComponent(LocationComponent.class);
      }
 else {
        Location.removeChild(mountPointComponent.mountPointEntity,getHandEntity());
        getHandEntity().removeComponent(LocationComponent.class);
      }
      EntityRef heldItem=newItem;
      if (!heldItem.exists()) {
        heldItem=getHandEntity();
      }
      heldItem.addOrSaveComponent(new LocationComponent());
      FirstPersonHeldItemTransformComponent heldItemTransformComponent=heldItem.getComponent(FirstPersonHeldItemTransformComponent.class);
      if (heldItemTransformComponent == null) {
        heldItemTransformComponent=new FirstPersonHeldItemTransformComponent();
      }
      Location.attachChild(mountPointComponent.mountPointEntity,heldItem,heldItemTransformComponent.translate,new Quat4f(TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.y,TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.x,TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.z),heldItemTransformComponent.scale);
    }
  }
}

Fixed version (ground truth):
void linkHeldItemLocationForLocalPlayer(EntityRef character,EntityRef newItem,EntityRef oldItem){
  if (!newItem.equals(oldItem)) {
    EntityRef camera=localPlayer.getCameraEntity();
    FirstPersonHeldItemMountPointComponent mountPointComponent=camera.getComponent(FirstPersonHeldItemMountPointComponent.class);
    if (mountPointComponent != null) {
      if (oldItem != null && oldItem.exists()) {
        Location.removeChild(mountPointComponent.mountPointEntity,oldItem);
        oldItem.removeComponent(LocationComponent.class);
      }
 else {
        Location.removeChild(mountPointComponent.mountPointEntity,getHandEntity());
        getHandEntity().removeComponent(LocationComponent.class);
      }
      EntityRef heldItem=newItem;
      if (!heldItem.exists()) {
        heldItem=getHandEntity();
      }
      heldItem.addOrSaveComponent(new LocationComponent());
      FirstPersonHeldItemTransformComponent heldItemTransformComponent=heldItem.getComponent(FirstPersonHeldItemTransformComponent.class);
      if (heldItemTransformComponent == null) {
        heldItemTransformComponent=new FirstPersonHeldItemTransformComponent();
      }
      Location.attachChild(mountPointComponent.mountPointEntity,heldItem,heldItemTransformComponent.translate,new Quat4f(TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.y,TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.x,TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.z),heldItemTransformComponent.scale);
    }
  }
}
Program: 737
Project: 737
Buggy source:
@ReceiveEvent public void onItemDropped(ItemDroppedEvent event,EntityRef itemEntity,MeshComponent meshComponent){
  EntityBuilder builder=event.getPickup();
  if (itemEntity.hasComponent(MeshComponent.class)) {
    builder.addOrSaveComponent(meshComponent);
  }
}

Fixed version (ground truth):
@ReceiveEvent public void onItemDropped(ItemDroppedEvent event,EntityRef itemEntity,MeshComponent meshComponent){
  EntityBuilder builder=event.getPickup();
  MeshComponent builderMeshComponent=builder.getComponent(MeshComponent.class);
  if (builderMeshComponent != null) {
    builderMeshComponent.mesh=meshComponent.mesh;
    builderMeshComponent.material=meshComponent.material;
    builderMeshComponent.color=meshComponent.color;
    builderMeshComponent.hideFromOwner=meshComponent.hideFromOwner;
    builderMeshComponent.translucent=meshComponent.translucent;
    builder.saveComponent(builderMeshComponent);
  }
}
Program: 738
Project: 738
Buggy source:
@Command("String_Node_Str") public void setFirstPersonheldItemMountPointRotation(@CommandParam("String_Node_Str") float x,@CommandParam("String_Node_Str") float y,@CommandParam("String_Node_Str") float z){
  FirstPersonHeldItemMountPointComponent newComponent=localPlayer.getCameraEntity().getComponent(FirstPersonHeldItemMountPointComponent.class);
  if (newComponent != null) {
    newComponent.rotateDegrees=new Vector3f(x,y,z);
    ensureClientSideEntityOnHeldItemMountPoint(OnActivatedComponent.newInstance(),localPlayer.getCameraEntity(),newComponent);
  }
}

Fixed version (ground truth):
@Command(shortDescription="String_Node_Str") public void setFirstPersonheldItemMountPointRotation(@CommandParam("String_Node_Str") float x,@CommandParam("String_Node_Str") float y,@CommandParam("String_Node_Str") float z){
  FirstPersonHeldItemMountPointComponent newComponent=localPlayer.getCameraEntity().getComponent(FirstPersonHeldItemMountPointComponent.class);
  if (newComponent != null) {
    newComponent.rotateDegrees=new Vector3f(x,y,z);
    ensureClientSideEntityOnHeldItemMountPoint(OnActivatedComponent.newInstance(),localPlayer.getCameraEntity(),newComponent);
  }
}
Program: 739
Project: 739
Buggy source:
@Command("String_Node_Str") public void setFirstPersonheldItemMountPointTranslation(@CommandParam("String_Node_Str") float x,@CommandParam("String_Node_Str") float y,@CommandParam("String_Node_Str") float z){
  FirstPersonHeldItemMountPointComponent newComponent=localPlayer.getCameraEntity().getComponent(FirstPersonHeldItemMountPointComponent.class);
  if (newComponent != null) {
    newComponent.translate=new Vector3f(x,y,z);
    ensureClientSideEntityOnHeldItemMountPoint(OnActivatedComponent.newInstance(),localPlayer.getCameraEntity(),newComponent);
  }
}

Fixed version (ground truth):
@Command(shortDescription="String_Node_Str") public void setFirstPersonheldItemMountPointTranslation(@CommandParam("String_Node_Str") float x,@CommandParam("String_Node_Str") float y,@CommandParam("String_Node_Str") float z){
  FirstPersonHeldItemMountPointComponent newComponent=localPlayer.getCameraEntity().getComponent(FirstPersonHeldItemMountPointComponent.class);
  if (newComponent != null) {
    newComponent.translate=new Vector3f(x,y,z);
    ensureClientSideEntityOnHeldItemMountPoint(OnActivatedComponent.newInstance(),localPlayer.getCameraEntity(),newComponent);
  }
}
Program: 740
Project: 740
Buggy source:
void linkHeldItemLocationForLocalPlayer(EntityRef character,EntityRef newItem,EntityRef oldItem){
  if (character.equals(localPlayer.getCharacterEntity()) && !newItem.equals(oldItem)) {
    EntityRef camera=localPlayer.getCameraEntity();
    FirstPersonHeldItemMountPointComponent mountPointComponent=camera.getComponent(FirstPersonHeldItemMountPointComponent.class);
    if (mountPointComponent != null) {
      EntityRef heldItem=newItem;
      if (!heldItem.exists()) {
        heldItem=handEntity;
      }
      FirstPersonHeldItemTransformComponent heldItemTransformComponent=heldItem.getComponent(FirstPersonHeldItemTransformComponent.class);
      heldItem.addOrSaveComponent(new LocationComponent());
      if (oldItem.exists()) {
        Location.removeChild(mountPointComponent.mountPointEntity,oldItem);
        oldItem.removeComponent(LocationComponent.class);
      }
 else {
        Location.removeChild(mountPointComponent.mountPointEntity,handEntity);
        handEntity.removeComponent(LocationComponent.class);
      }
      Location.attachChild(mountPointComponent.mountPointEntity,heldItem,heldItemTransformComponent.translate,new Quat4f(TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.y,TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.x,TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.z),heldItemTransformComponent.scale);
    }
  }
}

Fixed version (ground truth):
void linkHeldItemLocationForLocalPlayer(EntityRef character,EntityRef newItem,EntityRef oldItem){
  if (character.equals(localPlayer.getCharacterEntity()) && !newItem.equals(oldItem)) {
    EntityRef camera=localPlayer.getCameraEntity();
    FirstPersonHeldItemMountPointComponent mountPointComponent=camera.getComponent(FirstPersonHeldItemMountPointComponent.class);
    if (mountPointComponent != null) {
      if (oldItem != null && oldItem.exists()) {
        Location.removeChild(mountPointComponent.mountPointEntity,oldItem);
        oldItem.removeComponent(LocationComponent.class);
      }
 else {
        Location.removeChild(mountPointComponent.mountPointEntity,getHandEntity());
        getHandEntity().removeComponent(LocationComponent.class);
      }
      EntityRef heldItem=newItem;
      if (!heldItem.exists()) {
        heldItem=getHandEntity();
      }
      heldItem.addOrSaveComponent(new LocationComponent());
      FirstPersonHeldItemTransformComponent heldItemTransformComponent=heldItem.getComponent(FirstPersonHeldItemTransformComponent.class);
      if (heldItemTransformComponent == null) {
        heldItemTransformComponent=new FirstPersonHeldItemTransformComponent();
      }
      Location.attachChild(mountPointComponent.mountPointEntity,heldItem,heldItemTransformComponent.translate,new Quat4f(TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.y,TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.x,TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.z),heldItemTransformComponent.scale);
    }
  }
}
Program: 741
Project: 741
Buggy source:
private int regenerateHealth(HealthComponent health,int healAmount){
  while (time.getGameTimeInMs() >= health.nextRegenTick) {
    healAmount++;
    health.nextRegenTick=health.nextRegenTick + (long)(1000 / health.regenRate);
  }
  return healAmount;
}

Fixed version (ground truth):
private int regenerateHealth(HealthComponent health,int healAmount){
  int newHeal=healAmount;
  while (time.getGameTimeInMs() >= health.nextRegenTick) {
    newHeal++;
    health.nextRegenTick=health.nextRegenTick + (long)(1000 / health.regenRate);
  }
  return newHeal;
}
Program: 742
Project: 742
Buggy source:
/** 
 * @param type
 * @param < T >
 * @return The system fulfilling the given interface
 */
public static <T>T get(Class<T> type){
  if (context == null)   return null;
  if (type == Context.class) {
    return type.cast(context);
  }
  return context.get(type);
}

Fixed version (ground truth):
/** 
 * @param type
 * @param < T >
 * @return The system fulfilling the given interface
 */
public static <T>T get(Class<T> type){
  if (context == null) {
    return null;
  }
  if (type == Context.class) {
    return type.cast(context);
  }
  return context.get(type);
}
Program: 743
Project: 743
Buggy source:
/** 
 * Registers an object. These objects will be removed when CoreRegistry.clear() is called (typically when game state changes)
 * @param type   The interface which the system fulfils
 * @param object The system itself
 * @param < T >
 */
public static <T,U extends T>U put(Class<T> type,U object){
  if (context == null)   return null;
  context.put(type,object);
  return object;
}

Fixed version (ground truth):
/** 
 * Registers an object. These objects will be removed when CoreRegistry.clear() is called (typically when game state changes)
 * @param type   The interface which the system fulfils
 * @param object The system itself
 * @param < T >
 */
public static <T,U extends T>U put(Class<T> type,U object){
  if (context == null) {
    return null;
  }
  context.put(type,object);
  return object;
}
Program: 745
Project: 745
Buggy source:
@Override public void update(float delta){
  super.update(delta);
  if (!updateComplete) {
    if (downloader.isDone()) {
      updateComplete=true;
    }
    Predicate<ServerInfo> onlyActive=server -> server.isActive();
    customServers.clear();
    customServers.addAll(Collections2.filter(config.getNetwork().getServers(),onlyActive));
    listedServers.clear();
    listedServers.addAll(Collections2.filter(downloader.getServers(),onlyActive));
  }
}

Fixed version (ground truth):
@Override public void update(float delta){
  super.update(delta);
  if (!updateComplete) {
    if (downloader.isDone()) {
      updateComplete=true;
    }
    listedServers.clear();
    listedServers.addAll(Collections2.filter(downloader.getServers(),activeServersOnly));
  }
}
Program: 746
Project: 746
Buggy source:
private void configureServerList(final UIList<ServerInfo> serverList,List<ServerInfo> servers){
  serverList.bindList(new DefaultBinding<List<ServerInfo>>(servers));
  serverList.subscribe(new ItemActivateEventListener<ServerInfo>(){
    @Override public void onItemActivated(    UIWidget widget,    ServerInfo item){
      join(item.getAddress(),item.getPort());
    }
  }
);
  serverList.subscribeSelection(new ItemSelectEventListener<ServerInfo>(){
    @Override public void onItemSelected(    UIWidget widget,    ServerInfo item){
      if (item != null && !extInfo.containsKey(item)) {
        extInfo.put(item,infoService.requestInfo(item.getAddress(),item.getPort()));
      }
    }
  }
);
  serverList.setItemRenderer(new StringTextRenderer<ServerInfo>(){
    @Override public String getString(    ServerInfo value){
      return value.getName();
    }
  }
);
}

Fixed version (ground truth):
private void configureServerList(final UIList<ServerInfo> serverList){
  serverList.subscribe(new ItemActivateEventListener<ServerInfo>(){
    @Override public void onItemActivated(    UIWidget widget,    ServerInfo item){
      join(item.getAddress(),item.getPort());
    }
  }
);
  serverList.subscribeSelection(new ItemSelectEventListener<ServerInfo>(){
    @Override public void onItemSelected(    UIWidget widget,    ServerInfo item){
      if (item != null && !extInfo.containsKey(item)) {
        extInfo.put(item,infoService.requestInfo(item.getAddress(),item.getPort()));
      }
    }
  }
);
  serverList.setItemRenderer(new StringTextRenderer<ServerInfo>(){
    @Override public String getString(    ServerInfo value){
      return value.getName();
    }
  }
);
}
Program: 747
Project: 747
Buggy source:
private void bindCustomButtons(){
  UIButton add=find("String_Node_Str",UIButton.class);
  if (add != null) {
    add.subscribe(button -> {
      AddServerPopup popup=getManager().pushScreen(AddServerPopup.ASSET_URI,AddServerPopup.class);
      popup.onSuccess(item -> visibleList.setSelection(item));
    }
);
  }
  UIButton edit=find("String_Node_Str",UIButton.class);
  if (edit != null) {
    edit.subscribe(button -> {
      AddServerPopup popup=getManager().pushScreen(AddServerPopup.ASSET_URI,AddServerPopup.class);
      ServerInfo info=visibleList.getSelection();
      popup.setServerInfo(info);
      popup.onSuccess(item -> extInfo.put(item,infoService.requestInfo(item.getAddress(),item.getPort())));
    }
);
  }
  UIButton removeButton=find("String_Node_Str",UIButton.class);
  if (removeButton != null) {
    removeButton.subscribe(button -> {
      ServerInfo info=visibleList.getSelection();
      if (info != null) {
        config.getNetwork().remove(info);
        extInfo.remove(info);
        visibleList.setSelection(null);
      }
    }
);
  }
  UILabel downloadLabel=find("String_Node_Str",UILabel.class);
  if (downloadLabel != null) {
    downloadLabel.bindText(new ReadOnlyBinding<String>(){
      @Override public String get(){
        return downloader.getStatus();
      }
    }
);
  }
}

Fixed version (ground truth):
private void bindCustomButtons(){
  UIList<?> customServerList=find("String_Node_Str",UIList.class);
  ReadOnlyBinding<Boolean> localSelectedServerOnly=new ReadOnlyBinding<Boolean>(){
    @Override public Boolean get(){
      return customServerList.getSelection() != null;
    }
  }
;
  UIButton add=find("String_Node_Str",UIButton.class);
  if (add != null) {
    add.subscribe(button -> {
      AddServerPopup popup=getManager().pushScreen(AddServerPopup.ASSET_URI,AddServerPopup.class);
      popup.onSuccess(item -> {
        config.getNetwork().addServerInfo(item);
        visibleList.setSelection(item);
      }
);
    }
);
  }
  UIButton edit=find("String_Node_Str",UIButton.class);
  if (edit != null) {
    edit.bindEnabled(localSelectedServerOnly);
    edit.subscribe(button -> {
      AddServerPopup popup=getManager().pushScreen(AddServerPopup.ASSET_URI,AddServerPopup.class);
      ServerInfo info=visibleList.getSelection();
      popup.setServerInfo(info);
      popup.onSuccess(item -> extInfo.put(item,infoService.requestInfo(item.getAddress(),item.getPort())));
    }
);
  }
  UIButton removeButton=find("String_Node_Str",UIButton.class);
  if (removeButton != null) {
    removeButton.bindEnabled(localSelectedServerOnly);
    removeButton.subscribe(button -> {
      ServerInfo info=visibleList.getSelection();
      if (info != null) {
        config.getNetwork().removeServerInfo(info);
        extInfo.remove(info);
        visibleList.setSelection(null);
      }
    }
);
  }
  UILabel downloadLabel=find("String_Node_Str",UILabel.class);
  if (downloadLabel != null) {
    downloadLabel.bindText(new ReadOnlyBinding<String>(){
      @Override public String get(){
        return downloader.getStatus();
      }
    }
);
  }
}
Program: 748
Project: 748
Buggy source:
@Override public void initialise(){
  downloader=new ServerListDownloader(config.getNetwork().getMasterServer());
  CardLayout cards=find("String_Node_Str",CardLayout.class);
  UIList<ServerInfo> customServerList=find("String_Node_Str",UIList.class);
  if (customServerList != null) {
    configureServerList(customServerList,customServers);
  }
  UIList<ServerInfo> onlineServerList=find("String_Node_Str",UIList.class);
  if (onlineServerList != null) {
    configureServerList(onlineServerList,listedServers);
  }
  ActivateEventListener activateCustom=e -> {
    cards.setDisplayedCard("String_Node_Str");
    find("String_Node_Str",UIButton.class).setFamily("String_Node_Str");
    find("String_Node_Str",UIButton.class).setFamily("String_Node_Str");
    visibleList=customServerList;
  }
;
  WidgetUtil.trySubscribe(this,"String_Node_Str",activateCustom);
  ActivateEventListener activateOnline=e -> {
    cards.setDisplayedCard("String_Node_Str");
    find("String_Node_Str",UIButton.class).setFamily("String_Node_Str");
    find("String_Node_Str",UIButton.class).setFamily("String_Node_Str");
    visibleList=onlineServerList;
  }
;
  WidgetUtil.trySubscribe(this,"String_Node_Str",activateOnline);
  bindCustomButtons();
  bindInfoLabels();
  WidgetUtil.trySubscribe(this,"String_Node_Str",new ActivateEventListener(){
    @Override public void onActivated(    UIWidget button){
      config.save();
      getManager().popScreen();
    }
  }
);
  activateOnline.onActivated(null);
}

Fixed version (ground truth):
@Override public void initialise(){
  downloader=new ServerListDownloader(config.getNetwork().getMasterServer());
  CardLayout cards=find("String_Node_Str",CardLayout.class);
  UIList<ServerInfo> customServerList=find("String_Node_Str",UIList.class);
  if (customServerList != null) {
    customServerList.setList(config.getNetwork().getServerInfos());
    configureServerList(customServerList);
  }
  UIList<ServerInfo> onlineServerList=find("String_Node_Str",UIList.class);
  if (onlineServerList != null) {
    onlineServerList.setList(listedServers);
    configureServerList(onlineServerList);
  }
  ActivateEventListener activateCustom=e -> {
    cards.setDisplayedCard("String_Node_Str");
    find("String_Node_Str",UIButton.class).setFamily("String_Node_Str");
    find("String_Node_Str",UIButton.class).setFamily("String_Node_Str");
    visibleList=customServerList;
  }
;
  WidgetUtil.trySubscribe(this,"String_Node_Str",activateCustom);
  ActivateEventListener activateOnline=e -> {
    cards.setDisplayedCard("String_Node_Str");
    find("String_Node_Str",UIButton.class).setFamily("String_Node_Str");
    find("String_Node_Str",UIButton.class).setFamily("String_Node_Str");
    visibleList=onlineServerList;
  }
;
  WidgetUtil.trySubscribe(this,"String_Node_Str",activateOnline);
  bindCustomButtons();
  bindInfoLabels();
  WidgetUtil.trySubscribe(this,"String_Node_Str",new ActivateEventListener(){
    @Override public void onActivated(    UIWidget button){
      config.save();
      getManager().popScreen();
    }
  }
);
  activateOnline.onActivated(null);
}
Program: 749
Project: 749
Buggy source:
@Override public void onClosed(){
  CoreRegistry.setContext(context);
  if (environment != null) {
    EnvironmentSwitchHandler environmentSwitchHandler=context.get(EnvironmentSwitchHandler.class);
    environmentSwitchHandler.handleSwitchBackFromPreviewEnivronment(context);
    environment.close();
    environment=null;
  }
  ensurePreviewUnloaded();
  WorldConfigurator worldConfig=worldGenerator.getConfigurator();
  Map<String,Component> params=worldConfig.getProperties();
  if (params != null) {
    config.setModuleConfigs(worldGenerator.getUri(),params);
  }
  super.onClosed();
}

Fixed version (ground truth):
@Override public void onClosed(){
  CoreRegistry.setContext(context);
  if (environment != null) {
    EnvironmentSwitchHandler environmentSwitchHandler=context.get(EnvironmentSwitchHandler.class);
    environmentSwitchHandler.handleSwitchBackFromPreviewEnvironment(subContext);
    environment.close();
    environment=null;
  }
  previewGen.close();
  WorldConfigurator worldConfig=worldGenerator.getConfigurator();
  Map<String,Component> params=worldConfig.getProperties();
  if (params != null) {
    config.setModuleConfigs(worldGenerator.getUri(),params);
  }
  super.onClosed();
}
Program: 750
Project: 750
Buggy source:
private void updatePreview(){
  ensurePreviewAvailable();
  final NUIManager manager=context.get(NUIManager.class);
  final WaitPopup<TextureData> popup=manager.pushScreen(WaitPopup.ASSET_URI,WaitPopup.class);
  popup.setMessage("String_Node_Str","String_Node_Str");
  ProgressListener progressListener=progress -> popup.setMessage("String_Node_Str",String.format("String_Node_Str",(int)(progress * 100f)));
  Callable<TextureData> operation=() -> {
    if (seed != null) {
      worldGenerator.setWorldSeed(seed.getText());
    }
    int zoom=TeraMath.floorToInt(zoomSlider.getValue());
    TextureData data=texture.getData();
    previewGen.render(data,zoom,progressListener);
    return data;
  }
;
  popup.onSuccess(texture::reload);
  popup.startOperation(operation,true);
}

Fixed version (ground truth):
private void updatePreview(){
  final NUIManager manager=context.get(NUIManager.class);
  final WaitPopup<TextureData> popup=manager.pushScreen(WaitPopup.ASSET_URI,WaitPopup.class);
  popup.setMessage("String_Node_Str","String_Node_Str");
  ProgressListener progressListener=progress -> popup.setMessage("String_Node_Str",String.format("String_Node_Str",(int)(progress * 100f)));
  Callable<TextureData> operation=() -> {
    if (seed != null) {
      worldGenerator.setWorldSeed(seed.getText());
    }
    int zoom=TeraMath.floorToInt(zoomSlider.getValue());
    TextureData data=texture.getData();
    previewGen.render(data,zoom,progressListener);
    return data;
  }
;
  popup.onSuccess(texture::reload);
  popup.startOperation(operation,true);
}
Program: 751
Project: 751
Buggy source:
WorldConfigNumberBinding(WorldConfigurator config,String label,FieldMetadata<Object,Float> field){
  super(config,label,field);
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") protected WorldConfigNumberBinding(WorldConfigurator config,String label,ComponentLibrary compLib,FieldMetadata<Object,?> field){
  Class<?> type=field.getType();
  if (type == Integer.TYPE || type == Integer.class) {
    this.binding=new WorldConfigBinding<Integer>(config,label,compLib,(FieldMetadata<Object,Integer>)field);
  }
 else   if (type == Float.TYPE || type == Float.class) {
    this.binding=new WorldConfigBinding<Float>(config,label,compLib,(FieldMetadata<Object,Float>)field);
  }
}
Program: 752
Project: 752
Buggy source:
@Override public void set(T value){
  T old=get();
  if (!Objects.equals(old,value)) {
    notifyObservers(label,fieldMetadata.getName(),value);
  }
}

Fixed version (ground truth):
@Override @SuppressWarnings("String_Node_Str") public void set(Float value){
  Class<? extends Number> type=binding.fieldMetadata.getType();
  if (type == Integer.TYPE || type == Integer.class) {
    ((Binding<Integer>)binding).set(Integer.valueOf(value.intValue()));
  }
 else   if (type == Float.TYPE || type == Float.class) {
    ((Binding<Float>)binding).set(value);
  }
}
Program: 753
Project: 753
Buggy source:
@Override protected <T>Binding<T> createTextBinding(Object target,FieldMetadata<Object,T> fieldMetadata){
  Binding<T> wrap=new WorldConfigBinding<T>(worldConfig,label,fieldMetadata);
  return wrap;
}

Fixed version (ground truth):
@Override protected <T>Binding<T> createTextBinding(Object target,FieldMetadata<Object,T> fieldMetadata){
  return new WorldConfigBinding<T>(worldConfig,label,compLib,fieldMetadata);
}
Program: 754
Project: 754
Buggy source:
private void configureProperties(){
  PropertyLayout propLayout=find("String_Node_Str",PropertyLayout.class);
  propLayout.setOrdering(PropertyOrdering.byLabel());
  propLayout.clear();
  WorldConfigurator worldConfig=worldGenerator.getConfigurator();
  Map<String,Component> params=worldConfig.getProperties();
  for (  String key : params.keySet()) {
    Class<? extends Component> clazz=params.get(key).getClass();
    Component comp=config.getModuleConfig(worldGenerator.getUri(),key,clazz);
    if (comp != null) {
      worldConfig.setProperty(key,comp);
    }
  }
  for (  String label : params.keySet()) {
    PropertyProvider provider=new PropertyProvider(){
      @Override protected <T>Binding<T> createTextBinding(      Object target,      FieldMetadata<Object,T> fieldMetadata){
        Binding<T> wrap=new WorldConfigBinding<T>(worldConfig,label,fieldMetadata);
        return wrap;
      }
      @Override protected Binding<Float> createFloatBinding(      Object target,      FieldMetadata<Object,?> fieldMetadata){
        Binding<Float> wrap=new WorldConfigNumberBinding(worldConfig,label,(FieldMetadata<Object,Float>)fieldMetadata);
        return wrap;
      }
    }
;
    Component target=params.get(label);
    List<Property<?,?>> properties=provider.createProperties(target);
    propLayout.addProperties(label,properties);
  }
}

Fixed version (ground truth):
private void configureProperties(){
  PropertyLayout propLayout=find("String_Node_Str",PropertyLayout.class);
  propLayout.setOrdering(PropertyOrdering.byLabel());
  propLayout.clear();
  WorldConfigurator worldConfig=worldGenerator.getConfigurator();
  Map<String,Component> params=worldConfig.getProperties();
  for (  String key : params.keySet()) {
    Class<? extends Component> clazz=params.get(key).getClass();
    Component comp=config.getModuleConfig(worldGenerator.getUri(),key,clazz);
    if (comp != null) {
      worldConfig.setProperty(key,comp);
    }
  }
  ComponentLibrary compLib=subContext.get(ComponentLibrary.class);
  for (  String label : params.keySet()) {
    PropertyProvider provider=new PropertyProvider(){
      @Override protected <T>Binding<T> createTextBinding(      Object target,      FieldMetadata<Object,T> fieldMetadata){
        return new WorldConfigBinding<T>(worldConfig,label,compLib,fieldMetadata);
      }
      @Override protected Binding<Float> createFloatBinding(      Object target,      FieldMetadata<Object,?> fieldMetadata){
        return new WorldConfigNumberBinding(worldConfig,label,compLib,fieldMetadata);
      }
    }
;
    Component target=params.get(label);
    List<Property<?,?>> properties=provider.createProperties(target);
    propLayout.addProperties(label,properties);
  }
}
Program: 755
Project: 755
Buggy source:
@Override public void onOpened(){
  super.onOpened();
  SimpleUri worldGenUri=config.getWorldGeneration().getDefaultGenerator();
  Name moduleName=worldGenUri.getModuleName();
  try {
    DependencyResolver resolver=new DependencyResolver(moduleManager.getRegistry());
    ResolutionResult result=resolver.resolve(moduleName);
    if (result.isSuccess()) {
      subContext=new ContextImpl(context);
      CoreRegistry.setContext(subContext);
      environment=moduleManager.loadEnvironment(result.getModules(),false);
      subContext.put(WorldGeneratorPluginLibrary.class,new TempWorldGeneratorPluginLibrary(environment,subContext));
      worldGenerator=worldGeneratorManager.createWorldGenerator(worldGenUri,subContext,environment);
      worldGenerator.setWorldSeed(seed.getText());
      configureProperties();
    }
 else {
      logger.error("String_Node_Str",worldGenUri);
    }
  }
 catch (  Exception e) {
    worldGenerator=null;
    logger.error("String_Node_Str" + worldGenUri + "String_Node_Str",e);
  }
}

Fixed version (ground truth):
@Override public void onOpened(){
  super.onOpened();
  SimpleUri worldGenUri=config.getWorldGeneration().getDefaultGenerator();
  Name moduleName=worldGenUri.getModuleName();
  try {
    DependencyResolver resolver=new DependencyResolver(moduleManager.getRegistry());
    ResolutionResult result=resolver.resolve(moduleName);
    if (result.isSuccess()) {
      subContext=new ContextImpl(context);
      CoreRegistry.setContext(subContext);
      environment=moduleManager.loadEnvironment(result.getModules(),false);
      subContext.put(WorldGeneratorPluginLibrary.class,new TempWorldGeneratorPluginLibrary(environment,subContext));
      EnvironmentSwitchHandler environmentSwitchHandler=context.get(EnvironmentSwitchHandler.class);
      environmentSwitchHandler.handleSwitchToPreviewEnvironment(subContext,environment);
      genTexture();
      worldGenerator=worldGeneratorManager.createWorldGenerator(worldGenUri,subContext,environment);
      worldGenerator.setWorldSeed(seed.getText());
      previewGen=new FacetLayerPreview(environment,worldGenerator);
      configureProperties();
    }
 else {
      logger.error("String_Node_Str",worldGenUri);
    }
  }
 catch (  Exception e) {
    worldGenerator=null;
    logger.error("String_Node_Str" + worldGenUri + "String_Node_Str",e);
  }
}
Program: 756
Project: 756
Buggy source:
@Override protected Binding<Float> createFloatBinding(Object target,FieldMetadata<Object,?> fieldMetadata){
  Binding<Float> wrap=new WorldConfigNumberBinding(worldConfig,label,(FieldMetadata<Object,Float>)fieldMetadata);
  return wrap;
}

Fixed version (ground truth):
@Override protected Binding<Float> createFloatBinding(Object target,FieldMetadata<Object,?> fieldMetadata){
  return new WorldConfigNumberBinding(worldConfig,label,compLib,fieldMetadata);
}
Program: 757
Project: 757
Buggy source:
@Override public Float get(){
  Number val=super.get();
  if (val instanceof Float) {
    return (Float)val;
  }
  return (val).floatValue();
}

Fixed version (ground truth):
@Override public Float get(){
  Number val=binding.get();
  if (val instanceof Float) {
    return (Float)val;
  }
  return Float.valueOf(val.floatValue());
}
Program: 758
Project: 758
Buggy source:
WorldConfigBinding(WorldConfigurator config,String label,FieldMetadata<Object,T> fieldMetadata){
  this.worldConfig=config;
  this.label=label;
  this.fieldMetadata=fieldMetadata;
}

Fixed version (ground truth):
protected WorldConfigBinding(WorldConfigurator config,String label,ComponentLibrary compLib,FieldMetadata<Object,T> fieldMetadata){
  this.worldConfig=config;
  this.label=label;
  this.compLib=compLib;
  this.fieldMetadata=fieldMetadata;
}
Program: 759
Project: 759
Buggy source:
private static Component cloneAndSet(Component object,String field,Object value){
  Gson gson=new Gson();
  JsonObject json=(JsonObject)gson.toJsonTree(object);
  JsonElement jsonValue=gson.toJsonTree(value);
  json.add(field,jsonValue);
  Component clone=gson.fromJson(json,object.getClass());
  return clone;
}

Fixed version (ground truth):
private void cloneAndSet(String group,Object value){
  Component comp=worldConfig.getProperties().get(group);
  Component clone=compLib.copy(comp);
  fieldMetadata.setValue(clone,value);
  worldConfig.setProperty(label,clone);
}
Program: 760
Project: 760
Buggy source:
private <T>TextMapper<T> createTextMapping(Class<?> type){
  TextMapper<?> textBinding=null;
  if (type == String.class) {
    textBinding=new StringTextBinding();
  }
 else   if (type == Integer.TYPE || type == Integer.class) {
    textBinding=new IntegerTextBinding();
  }
 else   if (type == Float.TYPE || type == Float.class) {
    textBinding=new FloatTextBinding();
  }
 else   if (type == Vector3f.class) {
    textBinding=new Vector3fTextBinding();
  }
 else {
    throw new IllegalArgumentException("String_Node_Str" + type);
  }
  return (TextMapper<T>)textBinding;
}

Fixed version (ground truth):
private <T>TextMapper<T> createTextMapping(Class<?> type){
  TextMapper<?> textBinding=null;
  if (type == String.class) {
    textBinding=new StringTextBinding();
  }
 else   if (type == Boolean.TYPE || type == Boolean.class) {
    textBinding=new BooleanTextBinding();
  }
 else   if (type == Integer.TYPE || type == Integer.class) {
    textBinding=new IntegerTextBinding();
  }
 else   if (type == Float.TYPE || type == Float.class) {
    textBinding=new FloatTextBinding();
  }
 else   if (type == Vector3f.class) {
    textBinding=new Vector3fTextBinding();
  }
 else {
    throw new IllegalArgumentException("String_Node_Str" + type);
  }
  return (TextMapper<T>)textBinding;
}
Program: 761
Project: 761
Buggy source:
private void download(String address) throws IOException {
  status="String_Node_Str";
  URL url=new URL("String_Node_Str",address,"String_Node_Str");
  try (JsonReader reader=new JsonReader(new InputStreamReader(url.openStream(),TerasologyConstants.CHARSET))){
    status="String_Node_Str";
    reader.beginArray();
    while (reader.hasNext()) {
      ModuleMetadata meta=metaReader.read(reader);
      logger.debug("String_Node_Str",meta.getId(),meta.getVersion());
      RemoteModule remoteModule=new RemoteModule(meta);
      modules.add(remoteModule);
      int count=modules.size();
      status=String.format("String_Node_Str",count,(count == 1) ? "String_Node_Str" : "String_Node_Str");
    }
    reader.endArray();
  }
 }

Fixed version (ground truth):
private void download(String address) throws IOException {
  status="String_Node_Str";
  URL url=new URL("String_Node_Str",address,"String_Node_Str");
  try (JsonReader reader=new JsonReader(new InputStreamReader(url.openStream(),TerasologyConstants.CHARSET))){
    status="String_Node_Str";
    reader.beginArray();
    while (reader.hasNext()) {
      ModuleMetadata meta=metaReader.read(reader);
      logger.debug("String_Node_Str",meta.getId(),meta.getVersion());
      RemoteModule remoteModule=new RemoteModule(meta);
      modules.add(remoteModule);
      int count=modules.size();
      status=String.format("String_Node_Str",count,(count == 1) ? "String_Node_Str" : "String_Node_Str");
      try {
        Thread.sleep(100);
      }
 catch (      InterruptedException e) {
      }
    }
    reader.endArray();
  }
 }
Program: 763
Project: 763
Buggy source:
private void updateModuleInformation(){
  modulesLookup.clear();
  sortedModules.clear();
  for (  Name moduleId : moduleManager.getRegistry().getModuleIds()) {
    Module latestVersion=moduleManager.getRegistry().getLatestModuleVersion(moduleId);
    if (!latestVersion.isOnClasspath()) {
      ModuleSelectionInfo info=ModuleSelectionInfo.local(latestVersion);
      modulesLookup.put(info.getMetadata().getId(),info);
      sortedModules.add(info);
    }
  }
  for (  RemoteModule remote : metaDownloader.getModules()) {
    ModuleSelectionInfo info=modulesLookup.get(remote.getId());
    if (info == null) {
      info=ModuleSelectionInfo.remote(remote);
      modulesLookup.put(remote.getId(),info);
      sortedModules.add(info);
    }
    info.setOnlineVersion(remote);
  }
  Collections.sort(sortedModules,(o1,o2) -> o1.getMetadata().getDisplayName().toString().compareTo(o2.getMetadata().getDisplayName().toString()));
}

Fixed version (ground truth):
private void updateModuleInformation(){
  Set<Name> filtered=ImmutableSet.of(new Name("String_Node_Str"),new Name("String_Node_Str"));
  for (  RemoteModule remote : metaDownloader.getModules()) {
    ModuleSelectionInfo info=modulesLookup.get(remote.getId());
    if (!filtered.contains(remote.getId())) {
      if (info == null) {
        info=ModuleSelectionInfo.remote(remote);
        modulesLookup.put(remote.getId(),info);
        int pos=Collections.binarySearch(sortedModules,info,moduleInfoComparator);
        if (pos < 0) {
          sortedModules.add(-pos - 1,info);
        }
      }
      info.setOnlineVersion(remote);
    }
  }
}
Program: 764
Project: 764
Buggy source:
private void startDownload(ModuleSelectionInfo info){
  final NUIManager manager=context.get(NUIManager.class);
  final WaitPopup<Path> popup=manager.pushScreen(WaitPopup.ASSET_URI,WaitPopup.class);
  popup.setMessage("String_Node_Str","String_Node_Str");
  ProgressListener progressListener=progress -> popup.setMessage("String_Node_Str",String.format("String_Node_Str",(int)(progress * 100f)));
  ModuleMetadata meta=info.getOnlineVersion().getMetadata();
  String version=meta.getVersion().toString();
  String id=meta.getId().toString();
  URL url=RemoteModuleExtension.getDownloadUrl(meta);
  popup.onSuccess(filePath -> {
    ModuleLoader loader=new ModuleLoader(moduleManager.getModuleMetadataReader());
    loader.setModuleInfoPath(TerasologyConstants.MODULE_INFO_FILENAME);
    try {
      Module module=loader.load(filePath);
      info.setLocalVersion(module);
      moduleManager.getRegistry().add(module);
    }
 catch (    IOException e) {
      logger.warn("String_Node_Str",id,version,e);
    }
  }
);
  String fileName=String.format("String_Node_Str",id,version);
  Path folder=PathManager.getInstance().getHomeModPath().normalize();
  Path target=folder.resolve(fileName);
  FileDownloader operation=new FileDownloader(url,target,progressListener);
  popup.startOperation(operation,true);
}

Fixed version (ground truth):
private void startDownload(ModuleSelectionInfo info){
  final NUIManager manager=context.get(NUIManager.class);
  final WaitPopup<Path> popup=manager.pushScreen(WaitPopup.ASSET_URI,WaitPopup.class);
  popup.setMessage("String_Node_Str","String_Node_Str");
  ProgressListener progressListener=progress -> popup.setMessage("String_Node_Str",String.format("String_Node_Str",(int)(progress * 100f)));
  ModuleMetadata meta=info.getOnlineVersion().getMetadata();
  String version=meta.getVersion().toString();
  String id=meta.getId().toString();
  URL url=RemoteModuleExtension.getDownloadUrl(meta);
  popup.onSuccess(filePath -> {
    ModuleLoader loader=new ModuleLoader(moduleManager.getModuleMetadataReader());
    loader.setModuleInfoPath(TerasologyConstants.MODULE_INFO_FILENAME);
    try {
      Module module=loader.load(filePath);
      info.setLocalVersion(module);
      moduleManager.getRegistry().add(module);
      updateValidToSelect();
    }
 catch (    IOException e) {
      logger.warn("String_Node_Str",id,version,e);
    }
  }
);
  String fileName=String.format("String_Node_Str",id,version);
  Path folder=PathManager.getInstance().getHomeModPath().normalize();
  Path target=folder.resolve(fileName);
  FileDownloader operation=new FileDownloader(url,target,progressListener);
  popup.startOperation(operation,true);
}
Program: 765
Project: 765
Buggy source:
@Override public void draw(ModuleSelectionInfo value,Canvas canvas){
  if (isSelectedGameplayModule(value)) {
    canvas.setMode("String_Node_Str");
  }
 else   if (value.isSelected() && value.isExplicitSelection()) {
    canvas.setMode("String_Node_Str");
  }
 else   if (value.isSelected()) {
    canvas.setMode("String_Node_Str");
  }
 else   if (value.isValidToSelect()) {
    canvas.setMode("String_Node_Str");
  }
 else {
    canvas.setMode("String_Node_Str");
  }
  canvas.drawText(getString(value),canvas.getRegion());
}

Fixed version (ground truth):
@Override public void draw(ModuleSelectionInfo value,Canvas canvas){
  if (isSelectedGameplayModule(value)) {
    canvas.setMode("String_Node_Str");
  }
 else   if (value.isSelected() && value.isExplicitSelection()) {
    canvas.setMode("String_Node_Str");
  }
 else   if (value.isSelected()) {
    canvas.setMode("String_Node_Str");
  }
 else   if (!value.isPresent()) {
    canvas.setMode("String_Node_Str");
  }
 else   if (!value.isValidToSelect()) {
    canvas.setMode("String_Node_Str");
  }
 else {
    canvas.setMode("String_Node_Str");
  }
  canvas.drawText(getString(value),canvas.getRegion());
}
Program: 766
Project: 766
Buggy source:
public void setViewDistance(ViewDistance viewDistance){
  this.viewDistance=viewDistance;
}

Fixed version (ground truth):
/** 
 * Sets the view distance and notifies the property change listeners registered via  {@link RenderingConfig#subscribe(PropertyChangeListener)} that listen for the property {@link #VIEW_DISTANCE}.
 * @param viewDistance the new view distance
 */
public void setViewDistance(ViewDistance viewDistance){
  ViewDistance oldValue=this.viewDistance;
  this.viewDistance=viewDistance;
  propertyChangeSupport.firePropertyChange(VIEW_DISTANCE,oldValue,viewDistance);
}
Program: 767
Project: 767
Buggy source:
@ReceiveEvent(components=ClientComponent.class) public void onIncreaseViewDistance(IncreaseViewDistanceButton button,EntityRef entity){
  int viewDistance=config.getRendering().getViewDistance().getIndex();
  int maxViewDistance=ViewDistance.values().length - 1;
  if (viewDistance != maxViewDistance) {
    changeViewDistanceTo(ViewDistance.forIndex((config.getRendering().getViewDistance().getIndex() + 1)));
  }
  button.consume();
}

Fixed version (ground truth):
@ReceiveEvent(components=ClientComponent.class) public void onIncreaseViewDistance(IncreaseViewDistanceButton button,EntityRef entity){
  int viewDistance=config.getRendering().getViewDistance().getIndex();
  int maxViewDistance=ViewDistance.values().length - 1;
  if (viewDistance != maxViewDistance) {
    config.getRendering().setViewDistance(ViewDistance.forIndex((viewDistance + 1)));
  }
  button.consume();
}
Program: 768
Project: 768
Buggy source:
@ReceiveEvent(components=ClientComponent.class) public void onDecreaseViewDistance(DecreaseViewDistanceButton button,EntityRef entity){
  int viewDistance=config.getRendering().getViewDistance().getIndex();
  int minViewDistance=0;
  if (viewDistance != minViewDistance) {
    changeViewDistanceTo(ViewDistance.forIndex((config.getRendering().getViewDistance().getIndex() - 1)));
  }
  button.consume();
}

Fixed version (ground truth):
@ReceiveEvent(components=ClientComponent.class) public void onDecreaseViewDistance(DecreaseViewDistanceButton button,EntityRef entity){
  int viewDistance=config.getRendering().getViewDistance().getIndex();
  int minViewDistance=0;
  if (viewDistance != minViewDistance) {
    config.getRendering().setViewDistance(ViewDistance.forIndex((viewDistance - 1)));
  }
  button.consume();
}
Program: 770
Project: 770
Buggy source:
@Override public void reset(){
  if (reader != null) {
    dispose();
  }
  try {
    reader=new OggReader(stream.openStream());
  }
 catch (  IOException e) {
    throw new RuntimeException("String_Node_Str",e);
  }
}

Fixed version (ground truth):
@Override public void reset(){
  if (reader != null) {
    dispose();
  }
  try {
    reader=AccessController.doPrivileged((PrivilegedExceptionAction<OggReader>)() -> new OggReader(stream.openStream()));
  }
 catch (  PrivilegedActionException e) {
    throw new RuntimeException("String_Node_Str",e);
  }
}
Program: 771
Project: 771
Buggy source:
public OggStreamingSoundData(AssetDataFile stream) throws IOException {
  this.stream=stream;
  reader=new OggReader(stream.openStream());
}

Fixed version (ground truth):
public OggStreamingSoundData(AssetDataFile stream) throws IOException {
  this.stream=stream;
  reset();
}
Program: 772
Project: 772
Buggy source:
private Block getSurfaceBlock(int depth,int height,CoreBiome type){
switch (type) {
case FOREST:
case PLAINS:
case MOUNTAINS:
    if (depth == 0 && height > 32 && height < 128) {
      return grass;
    }
 else     if (depth == 0 && height >= 128) {
      return snow;
    }
 else     if (depth > 32) {
      return stone;
    }
 else {
      return dirt;
    }
case SNOW:
  if (depth == 0 && height > 32) {
    return snow;
  }
 else   if (depth > 32) {
    return stone;
  }
 else {
    return dirt;
  }
case DESERT:
if (depth > 8) {
  return stone;
}
 else {
  return sand;
}
case OCEAN:
if (depth == 0) {
return sand;
}
 else {
return stone;
}
case BEACH:
if (depth < 3) {
return sand;
}
 else {
return stone;
}
}
return dirt;
}

Fixed version (ground truth):
private Block getSurfaceBlock(int depth,int height,CoreBiome type,int seaLevel){
switch (type) {
case FOREST:
case PLAINS:
case MOUNTAINS:
    if (depth == 0 && height > seaLevel && height < seaLevel + 96) {
      return grass;
    }
 else     if (depth == 0 && height >= seaLevel + 96) {
      return snow;
    }
 else     if (depth > 32) {
      return stone;
    }
 else {
      return dirt;
    }
case SNOW:
  if (depth == 0 && height > seaLevel) {
    return snow;
  }
 else   if (depth > 32) {
    return stone;
  }
 else {
    return dirt;
  }
case DESERT:
if (depth > 8) {
  return stone;
}
 else {
  return sand;
}
case OCEAN:
if (depth == 0) {
return sand;
}
 else {
return stone;
}
case BEACH:
if (depth < 3) {
return sand;
}
 else {
return stone;
}
}
return dirt;
}