This commit is contained in:
libraryaddict 2020-11-26 18:36:30 +13:00
parent 8fbeb2a4f7
commit 3f7d824e73

@ -74,8 +74,7 @@ public class ReflectionManager {
private static Enum[] enumGamemode;
private static Method getNmsEntityMethod;
private static Enum[] enumItemSlots;
private static Enum[] craftSounds;
private static Field craftSound;
private static Method soundGetMethod;
private static Constructor vector3FConstructor;
private static Method enumDirectionFrom;
private static Constructor villagerDataConstructor;
@ -138,9 +137,7 @@ public class ReflectionManager {
enumGamemode = (Enum[]) getNmsClass("EnumGamemode").getEnumConstants();
getNmsEntityMethod = getCraftMethod("entity.CraftEntity", "getHandle");
enumItemSlots = (Enum[]) getNmsClass("EnumItemSlot").getEnumConstants();
craftSounds = (Enum[]) getCraftClass("CraftSound").getEnumConstants();
craftSound = getCraftClass("CraftSound").getDeclaredField("minecraftKey");
craftSound.setAccessible(true);
soundGetMethod = getCraftMethod("CraftSound", "getSound", Sound.class);
vector3FConstructor = getNmsConstructor("Vector3f", float.class, float.class, float.class);
enumDirectionFrom = getNmsMethod("EnumDirection", "fromType1", int.class);
getBlockData = getNmsMethod(getNmsClass("Block"), "getBlockData");
@ -1060,15 +1057,9 @@ public class ReflectionManager {
public static Object getSoundString(Sound sound) {
try {
for (Enum e : craftSounds) {
if (!e.name().equals(sound.name())) {
continue;
}
return craftSound.get(e);
}
} catch (IllegalAccessException illegalAccessException) {
illegalAccessException.printStackTrace();
return soundGetMethod.invoke(null, sound);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
return null;