Skip to content

Commit

Permalink
Fix accessing biomeName on server
Browse files Browse the repository at this point in the history
  • Loading branch information
octylFractal committed Dec 5, 2018
1 parent 7eafde0 commit 9b996ed
Showing 1 changed file with 25 additions and 2 deletions.
Expand Up @@ -23,9 +23,11 @@
import com.sk89q.worldedit.world.biome.BiomeData;
import com.sk89q.worldedit.world.registry.BiomeRegistry;

import net.minecraft.world.biome.Biome;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.world.biome.Biome;

/**
* Provides access to biome data in Forge.
Expand Down Expand Up @@ -55,6 +57,23 @@ public BiomeData getData(BaseBiome biome) {
* Cached biome data information.
*/
private static class ForgeBiomeData implements BiomeData {

private static final Field biomeNameField;
static {
Field field;
try {
field = Biome.class.getDeclaredField("biomeName");
} catch (NoSuchFieldException e) {
// in live environment, try again:
try {
field = Biome.class.getDeclaredField("field_185412_a");
} catch (NoSuchFieldException e1) {
throw new IllegalStateException("Cannot find biomeName field!", e1);
}
}
field.setAccessible(true);
biomeNameField = field;
}
private final Biome biome;

/**
Expand All @@ -68,7 +87,11 @@ private ForgeBiomeData(Biome biome) {

@Override
public String getName() {
return biome.getBiomeName();
try {
return (String) biomeNameField.get(biome);
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}

Expand Down

0 comments on commit 9b996ed

Please sign in to comment.