當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。