当前位置: 首页>>代码示例>>Java>>正文


Java ReflectionHelper.findMethod方法代码示例

本文整理汇总了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);
}
 
开发者ID:Xilef11,项目名称:runesofwizardry-classics,代码行数:20,代码来源:RuneResurrection.java

示例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;
}
 
开发者ID:Xilef11,项目名称:runesofwizardry-classics,代码行数:25,代码来源:RuneResurrection.java

示例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();
    }
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:13,代码来源:AdvancementTriggers.java

示例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");
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:9,代码来源:Reflections.java

示例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);
}
 
开发者ID:stuebz88,项目名称:modName,代码行数:32,代码来源:GrassColours.java

示例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();}
}
 
开发者ID:Alec-WAM,项目名称:CrystalMod,代码行数:13,代码来源:EntityUtil.java

示例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;
	}
}
 
开发者ID:hea3ven,项目名称:CommonUtils,代码行数:11,代码来源:ResourceScannerClient.java

示例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");
	}
}
 
开发者ID:hea3ven,项目名称:CommonUtils,代码行数:9,代码来源:SlotUtil.java

示例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;
}
 
开发者ID:CenturionFox,项目名称:wolfarmor,代码行数:49,代码来源:ReflectionCache.java

示例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);
    }
}
 
开发者ID:droidicus,项目名称:AquaRegia,代码行数:18,代码来源:ReflectionUtil.java


注:本文中的net.minecraftforge.fml.relauncher.ReflectionHelper.findMethod方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。