本文整理汇总了Java中net.minecraftforge.fml.relauncher.ReflectionHelper.findMethod方法的典型用法代码示例。如果您正苦于以下问题:Java ReflectionHelper.findMethod方法的具体用法?Java ReflectionHelper.findMethod怎么用?Java ReflectionHelper.findMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.fml.relauncher.ReflectionHelper
的用法示例。
在下文中一共展示了ReflectionHelper.findMethod方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEntityLoot_Table
import net.minecraftforge.fml.relauncher.ReflectionHelper; //导入方法依赖的package包/类
private List<ItemStack> getEntityLoot_Table(EntityLiving el){
ResourceLocation location = (ResourceLocation)ReflectionHelper.getPrivateValue(EntityLiving.class, el, "deathLootTable","field_184659_bA");
if(location==null){
Method getLT = ReflectionHelper.findMethod(EntityLiving.class,"getLootTable","func_184647_J");
try {
location = (ResourceLocation)getLT.invoke(el);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
RunesofWizardry_Classics.log().error("Exception when trying to get LootTable from entity: "+el.getName(),e);
return getEntityLoot_Hacky(el);
}
}
if(location==null){
RunesofWizardry_Classics.log().warn(el.getName()+" does not have a LootTable. falling back to kill method");
return getEntityLoot_Hacky(el);
}
LootTableManager manager = el.world.getLootTableManager();
LootTable table = manager.getLootTableFromLocation(location);
return LootUtils.tableToItemStacks(table);
}
示例2: getEntityLoot_Hacky
import net.minecraftforge.fml.relauncher.ReflectionHelper; //导入方法依赖的package包/类
private List<ItemStack> getEntityLoot_Hacky(EntityLiving ent){
List<ItemStack> result = new LinkedList<>();
ent.captureDrops=true;
Method getdrops = ReflectionHelper.findMethod(EntityLivingBase.class, "dropLoot","func_184610_a",boolean.class,int.class,DamageSource.class);
try {
getdrops.invoke(ent,true, 10,DamageSource.GENERIC);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e1) {
RunesofWizardry_Classics.log().error("Exception when trying to get drops from entity: "+ent,e1);
return result;
}
for(EntityItem item:ent.capturedDrops){
if(item==null){
RunesofWizardry_Classics.log().error("Error - NULL entityItem- while finding drops of entity: "+ent.getName());
continue;
}
ItemStack stack = item.getItem();
if(stack.isEmpty()){
RunesofWizardry_Classics.log().error("Error - Empty ItemStack (in a valid EntityItem) - while finding drops of entity: "+ent.getName());
continue;
}
result.add(stack);
}
return result;
}
示例3: registerTriggers
import net.minecraftforge.fml.relauncher.ReflectionHelper; //导入方法依赖的package包/类
public static void registerTriggers() {
Method method;
try {
method = ReflectionHelper.findMethod(CriteriaTriggers.class, "register", "func_192118_a", ICriterionTrigger.class);
method.setAccessible(true);
for (int i = 0; i < ALL_TRIGGERS.length; i++) {
method.invoke(null, ALL_TRIGGERS[i]);
}
} catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
}
示例4: init
import net.minecraftforge.fml.relauncher.ReflectionHelper; //导入方法依赖的package包/类
public static void init() {
msbl_isActivated = ReflectionHelper.findMethod(MobSpawnerBaseLogic.class, "isActivated", "func_98279_f");
msbl_getEntityId = ReflectionHelper.findMethod(MobSpawnerBaseLogic.class, "getEntityId", "func_190895_g");
// access to non-public entity AI's for hacking purposes
blaze_aiFireballAttack = findEnclosedClass(EntityBlaze.class, "AIFireballAttack", "a");
ghast_aiFireballAttack = findEnclosedClass(EntityGhast.class, "AIFireballAttack", "c");
}
示例5: doImmenseEvil
import net.minecraftforge.fml.relauncher.ReflectionHelper; //导入方法依赖的package包/类
public static void doImmenseEvil() throws Exception {
// de-finalise the grass colour field
Field grass_color = ReflectionHelper.findField(BiomeColorHelper.class, GRASS_COLOR);
grass_color.setAccessible(true);
Field modifiers = Field.class.getDeclaredField("modifiers");
AccessController.doPrivileged((PrivilegedAction) () -> {
modifiers.setAccessible(true);
return null;
});
modifiers.setInt(grass_color, grass_color.getModifiers() & ~Modifier.FINAL);
// get the interface
Class colorResolver = ReflectionHelper.getClass(Minecraft.class.getClassLoader(), COLOR_RESOLVER);
// get what the field was so it can be wrapped
Object wrappedResolver = grass_color.get(null);
// get the version of the method used by the object to be wrapped - avoids exceptions for calling an abstract method
Class wrappedResolverClass = wrappedResolver.getClass();
Method wrappedGetColorAtPos = ReflectionHelper.findMethod(wrappedResolverClass, "getColorAtPos", "func_180283_a", Biome.class, BlockPos.class);
// build a proxy
Method getColorAtPos = ReflectionHelper.findMethod(colorResolver, "getColorAtPos", "func_180283_a", Biome.class, BlockPos.class);
Object proxy = Proxy.newProxyInstance(colorResolver.getClassLoader(), new Class[] { colorResolver }, new GrassHandler(getColorAtPos, wrappedResolver, wrappedGetColorAtPos) );
// set the field
grass_color.set(null, proxy);
}
示例6: setEntitySize
import net.minecraftforge.fml.relauncher.ReflectionHelper; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static void setEntitySize(Entity entity, float width, float height)
{
try
{
if (methodEntitySetSize == null) {
methodEntitySetSize = ReflectionHelper.findMethod(Entity.class, entity, new String[] { "setSize", "func_177725_a"}, new Class[] { Float.TYPE, Float.TYPE });
}
if (methodEntitySetSize != null)methodEntitySetSize.invoke(entity, new Object[] { Float.valueOf(width), Float.valueOf(height) });
}
catch (Exception ex) {ex.printStackTrace();}
}
示例7: getZipFromResPack
import net.minecraftforge.fml.relauncher.ReflectionHelper; //导入方法依赖的package包/类
private static ZipFile getZipFromResPack(FileResourcePack resPack) {
Method mthd = ReflectionHelper.findMethod(FileResourcePack.class, resPack,
new String[] {"getResourcePackZipFile", "func_110599_c"});
try {
return (ZipFile) mthd.invoke(resPack);
} catch (Exception e) {
Throwables.propagate(e);
return null;
}
}
示例8: onSwapCraft
import net.minecraftforge.fml.relauncher.ReflectionHelper; //导入方法依赖的package包/类
public static void onSwapCraft(Slot slot, int count) {
Method mthd = ReflectionHelper.findMethod(Slot.class, "onSwapCraft", "func_190900_b", Integer.class);
try {
mthd.invoke(slot, count);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Could not call onSwapCraft");
}
}
示例9: getMethod
import net.minecraftforge.fml.relauncher.ReflectionHelper; //导入方法依赖的package包/类
/**
* Finds and caches a method.
*
* @param clazz The class
* @param methodName The deobf method name
* @param methodObfName The obf method name
* @param params The method parameter types
* @param <E> The instance or class type
* @return The method
*/
@Future
@Nullable
public static <E> Method getMethod(@Nonnull Class<? super E> clazz,
@Nonnull String methodName,
@Nullable String methodObfName,
@Nullable Class<?>... params) {
Method method = null;
StringBuilder keyParams = new StringBuilder("(");
if(params != null) {
for (int i = 0; i < params.length; i++) {
if (i > 0) {
keyParams.append(", ");
}
keyParams.append(params[i].getName());
}
}
keyParams.append(")");
String key = clazz.getName() + "." + methodObfName + keyParams;
if (CACHED_REFLECTION_METHODS.containsKey(key)) {
method = CACHED_REFLECTION_METHODS.get(key);
}
if (method == null) {
try {
method = ReflectionHelper.findMethod(clazz, methodName, methodObfName, params);
CACHED_REFLECTION_METHODS.put(key, method);
} catch (Exception ex) {
WolfArmorMod.getLogger().error(ex);
setLastError(ex);
}
}
return method;
}
示例10: findMethod
import net.minecraftforge.fml.relauncher.ReflectionHelper; //导入方法依赖的package包/类
/**
* Get a {@link MethodHandle} for a method.
*
* @param clazz The class
* @param methodNames The possible names of the method
* @param methodTypes The argument types of the method
* @param <T> The class
* @return The MethodHandle
*/
public static <T> MethodHandle findMethod(Class<T> clazz, String[] methodNames, Class<?>... methodTypes) {
final Method method = ReflectionHelper.findMethod(clazz, null, methodNames, methodTypes);
try {
return MethodHandles.lookup().unreflect(method);
} catch (IllegalAccessException e) {
throw new ReflectionHelper.UnableToFindMethodException(methodNames, e);
}
}