Permalink
Browse files

Fix accessing biomeName on server

  • Loading branch information...
kenzierocks committed Dec 5, 2018
1 parent 7eafde0 commit 9b996ed27963659894c6cf22908982bb44fc9471
Showing with 25 additions and 2 deletions.
  1. +25 −2 worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeBiomeRegistry.java
@@ -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.
@@ -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;

/**
@@ -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);
}
}
}

0 comments on commit 9b996ed

Please sign in to comment.