Java Code Examples for cpw.mods.fml.relauncher.ReflectionHelper#getPrivateValue()

The following examples show how to use cpw.mods.fml.relauncher.ReflectionHelper#getPrivateValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Nan0EventRegistar.java    From ehacks-pro with GNU General Public License v3.0 6 votes vote down vote up
public static void register(EventBus bus, Object target) {
    ConcurrentHashMap<Object, ArrayList<IEventListener>> listeners = ReflectionHelper.getPrivateValue(EventBus.class, bus, "listeners");
    Map<Object, ModContainer> listenerOwners = ReflectionHelper.getPrivateValue(EventBus.class, bus, "listenerOwners");
    if (listeners.containsKey(target)) {
        return;
    }
    ModContainer activeModContainer = Loader.instance().getMinecraftModContainer();
    listenerOwners.put(target, activeModContainer);
    ReflectionHelper.setPrivateValue(EventBus.class, bus, listenerOwners, "listenerOwners");
    Set<? extends Class<?>> supers = TypeToken.of(target.getClass()).getTypes().rawTypes();
    for (Method method : target.getClass().getMethods()) {
        for (Class<?> cls : supers) {
            try {
                Method real = cls.getDeclaredMethod(method.getName(), method.getParameterTypes());
                if (real.isAnnotationPresent(SubscribeEvent.class)) {
                    Class<?>[] parameterTypes = method.getParameterTypes();
                    Class<?> eventType = parameterTypes[0];
                    register(bus, eventType, target, method, activeModContainer);
                    break;
                }
            } catch (NoSuchMethodException ignored) {
            }
        }
    }
}
 
Example 2
Source File: Nan0EventRegistar.java    From ehacks-pro with GNU General Public License v3.0 6 votes vote down vote up
private static void register(EventBus bus, Class<?> eventType, Object target, Method method, ModContainer owner) {
    try {
        int busID = ReflectionHelper.getPrivateValue(EventBus.class, bus, "busID");
        ConcurrentHashMap<Object, ArrayList<IEventListener>> listeners = ReflectionHelper.getPrivateValue(EventBus.class, bus, "listeners");
        Constructor<?> ctr = eventType.getConstructor();
        ctr.setAccessible(true);
        Event event = (Event) ctr.newInstance();
        ASMEventHandler listener = new ASMEventHandler(target, method, owner);
        event.getListenerList().register(busID, listener.getPriority(), listener);
        ArrayList<IEventListener> others = listeners.get(target);
        if (others == null) {
            others = new ArrayList<>();
            listeners.put(target, others);
            ReflectionHelper.setPrivateValue(EventBus.class, bus, listeners, "listeners");
        }
        others.add(listener);
    } catch (Exception e) {
    }
}
 
Example 3
Source File: TileEntityDumper.java    From NEI-Integration with MIT License 6 votes vote down vote up
@Override
public Iterable<String[]> dump(int mode) {
    List<String[]> list = new LinkedList<String[]>();
    
    Map<Class, String> classToNameMap = ReflectionHelper.getPrivateValue(TileEntity.class, null, "field_145853_j", "classToNameMap");
    List<Class> classes = new ArrayList<Class>();
    classes.addAll(classToNameMap.keySet());
    Collections.sort(classes, new Comparator<Class>() {
        @Override
        public int compare(Class o1, Class o2) {
            if (o1 == null || o2 == null) {
                return 0;
            }
            return o1.getName().compareTo(o2.getName());
        }
    });
    
    for (Class clazz : classes) {
        if (clazz != null) {
            list.add(new String[] { clazz.getName(), classToNameMap.get(clazz) });
        }
    }
    
    return list;
}
 
Example 4
Source File: ChestLootDumper.java    From NEI-Integration with MIT License 6 votes vote down vote up
@Override
public Iterable<String[]> dump(int mode) {
    List<String[]> list = new LinkedList<String[]>();
    
    Map<String, ChestGenHooks> lootTables = ReflectionHelper.getPrivateValue(ChestGenHooks.class, null, "chestInfo");
    List<String> names = new ArrayList<String>();
    names.addAll(lootTables.keySet());
    Collections.sort(names);
    
    for (String name : names) {
        List<WeightedRandomChestContent> contents = ReflectionHelper.getPrivateValue(ChestGenHooks.class, lootTables.get(name), "contents");
        
        for (WeightedRandomChestContent w : contents) {
            String displayName;
            try {
                displayName = w.theItemId.getDisplayName();
            } catch (Exception ex) {
                displayName = "-";
            }
            list.add(new String[] { name, w.theItemId.toString(), displayName, Item.itemRegistry.getNameForObject(w.theItemId.getItem()), String.valueOf(w.itemWeight) });
        }
    }
    
    return list;
}
 
Example 5
Source File: EntityTippedArrow.java    From Et-Futurum with The Unlicense 6 votes vote down vote up
@Override
public void onCollideWithPlayer(EntityPlayer player) {
	boolean inGround = false;
	try {
		inGround = ReflectionHelper.getPrivateValue(EntityArrow.class, this, "inGround", "field_70254_i");
	} catch (Exception e) {
	}

	if (!worldObj.isRemote && inGround && arrowShake <= 0 && isEffectValid()) {
		boolean flag = canBePickedUp == 1 || canBePickedUp == 2 && player.capabilities.isCreativeMode;

		ItemStack stack = new ItemStack(ModItems.tipped_arrow);
		TippedArrow.setEffect(stack, Potion.potionTypes[effect.getPotionID()], effect.getDuration());

		if (canBePickedUp == 1 && !player.inventory.addItemStackToInventory(stack))
			flag = false;

		if (flag) {
			playSound("random.pop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
			player.onItemPickup(this, 1);
			setDead();
		}
	}
}
 
Example 6
Source File: ClientProxy.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void registerEntityRenderers() {
	if (EtFuturum.enableArmourStand)
		RenderingRegistry.registerEntityRenderingHandler(EntityArmourStand.class, new ArmourStandRenderer());
	if (EtFuturum.enableEndermite)
		RenderingRegistry.registerEntityRenderingHandler(EntityEndermite.class, new EndermiteRenderer());
	if (EtFuturum.enableRabbit)
		RenderingRegistry.registerEntityRenderingHandler(EntityRabbit.class, new RabbitRenderer());
	if (EtFuturum.enableLingeringPotions) {
		RenderingRegistry.registerEntityRenderingHandler(EntityLingeringPotion.class, new LingeringPotionRenderer());
		RenderingRegistry.registerEntityRenderingHandler(EntityLingeringEffect.class, new LingeringEffectRenderer());
	}
	if (EtFuturum.enableVillagerZombies)
		RenderingRegistry.registerEntityRenderingHandler(EntityZombieVillager.class, new VillagerZombieRenderer());
	if (EtFuturum.enableDragonRespawn)
		RenderingRegistry.registerEntityRenderingHandler(EntityPlacedEndCrystal.class, new PlacedEndCrystalRenderer());
	if (EtFuturum.enablePlayerSkinOverlay) {
		TextureManager texManager = Minecraft.getMinecraft().renderEngine;
		File fileAssets = ReflectionHelper.getPrivateValue(Minecraft.class, Minecraft.getMinecraft(), "fileAssets", "field_110446_Y", " field_110607_c");
		File skinFolder = new File(fileAssets, "skins");
		MinecraftSessionService sessionService = Minecraft.getMinecraft().func_152347_ac();
		ReflectionHelper.setPrivateValue(Minecraft.class, Minecraft.getMinecraft(), new NewSkinManager(Minecraft.getMinecraft().func_152342_ad(), texManager, skinFolder, sessionService), "field_152350_aA");

		RenderManager.instance.entityRenderMap.put(EntityPlayer.class, new NewRenderPlayer());
	}
	if (EtFuturum.enableShearableGolems)
		RenderingRegistry.registerEntityRenderingHandler(EntityNewSnowGolem.class, new NewSnowGolemRenderer());
}
 
Example 7
Source File: ParticleUtils.java    From Artifacts with MIT License 5 votes vote down vote up
public static ResourceLocation getParticleTexture()
{
	try
	{
		return (ResourceLocation)ReflectionHelper.getPrivateValue(EffectRenderer.class, null, new String[] { "particleTextures", "b", "field_110737_b" }); } catch (Exception e) {
		}
	return null;
}
 
Example 8
Source File: LegacyJavaFixer.java    From LegacyJavaFixer with MIT License 5 votes vote down vote up
SortReplacement()
{
    try 
    {
        wrapperCls = Class.forName("cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper", false, SortReplacement.class.getClassLoader());
        wrapperField = wrapperCls.getDeclaredField("sortIndex");
        wrapperField.setAccessible(true);
        tweakSorting = ReflectionHelper.getPrivateValue(CoreModManager.class, null, "tweakSorting");
    }
    catch (Exception e)
    {
        e.printStackTrace();
        Throwables.propagate(e);
    }
}
 
Example 9
Source File: Debug.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
public static List<TileEntity> getNearTileEntities() {
    ArrayList<TileEntity> out = new ArrayList<>();
    IChunkProvider chunkProvider = getWorld().getChunkProvider();
    if (chunkProvider instanceof ChunkProviderClient) {
        List<Chunk> chunks = ReflectionHelper.getPrivateValue(ChunkProviderClient.class, (ChunkProviderClient) chunkProvider, Mappings.chunkListing);
        chunks.forEach((chunk) -> {
            chunk.chunkTileEntityMap.values().stream().filter((entityObj) -> !(!(entityObj instanceof TileEntity))).forEachOrdered((entityObj) -> {
                out.add((TileEntity) entityObj);
            });
        });
    }
    return out;
}
 
Example 10
Source File: ContainerAnvil.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
public ContainerAnvil(EntityPlayer player, World world, int x, int y, int z) {
	super(player.inventory, world, x, y, z, player);
	this.player = player;
	this.x = x;
	this.y = y;
	this.z = z;
	this.world = world;

	inputSlots = ReflectionHelper.getPrivateValue(ContainerRepair.class, this, "inputSlots", "field_82853_g");
	outputSlot = ReflectionHelper.getPrivateValue(ContainerRepair.class, this, "outputSlot", "field_82852_f");
}
 
Example 11
Source File: NoLimitClear.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onModuleEnabled() {
    try {
        Class.forName("powercrystals.minefactoryreloaded.net.ServerPacketHandler");
        int count = 0;
        IChunkProvider chunkProvider = Wrapper.INSTANCE.world().getChunkProvider();
        if (chunkProvider instanceof ChunkProviderClient) {
            ChunkProviderClient clientProvider = (ChunkProviderClient) chunkProvider;
            List<Chunk> chunks = ReflectionHelper.getPrivateValue(ChunkProviderClient.class, clientProvider, Mappings.chunkListing);
            for (Chunk chunk : chunks) {
                for (Object entityObj : chunk.chunkTileEntityMap.values()) {
                    if (!(entityObj instanceof TileEntity)) {
                        return;
                    }
                    TileEntity entity = (TileEntity) entityObj;
                    if (entity instanceof IInventory) {
                        IInventory inv = (IInventory) entity;
                        TileEntity ent = entity;
                        for (int i = 0; i < inv.getSizeInventory(); i++) {
                            setSlot(i, ent.xCoord, ent.yCoord, ent.zCoord);
                        }
                        count++;
                    }
                }
            }
        }
        InteropUtils.log("Cleared " + String.valueOf(count) + " containers", this);
        this.off();
    } catch (Exception ex) {
        this.off();
    }
}
 
Example 12
Source File: NBTHelper.java    From ehacks-pro with GNU General Public License v3.0 4 votes vote down vote up
public static NBTBase getTagAt(NBTTagList tag, int index) {
    List list = (List) ReflectionHelper.getPrivateValue(NBTTagList.class, tag, 0);
    return (NBTBase) list.get(index);
}
 
Example 13
Source File: NBTHelper.java    From ehacks-pro with GNU General Public License v3.0 4 votes vote down vote up
public static Map<String, NBTBase> getMap(NBTTagCompound tag) {
    return (Map) ReflectionHelper.getPrivateValue(NBTTagCompound.class, tag, 1);
}
 
Example 14
Source File: Speed.java    From ehacks-pro with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onModuleDisabled() {
    Timer timer = (Timer) ReflectionHelper.getPrivateValue(Minecraft.class, Wrapper.INSTANCE.mc(), new String[]{Mappings.timer});
    timer.timerSpeed = 1.0f;
}
 
Example 15
Source File: Speed.java    From ehacks-pro with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onTicks() {
    Timer timer = (Timer) ReflectionHelper.getPrivateValue(Minecraft.class, Wrapper.INSTANCE.mc(), new String[]{Mappings.timer});
    timer.timerSpeed = (float) CheatConfiguration.config.speedhack;
}
 
Example 16
Source File: NameUtils.java    From OpenPeripheral with MIT License 4 votes vote down vote up
public static Map<String, Class<? extends TileEntity>> getNameToClassMap() {
	if (teNameToClass == null) teNameToClass = ReflectionHelper.getPrivateValue(TileEntity.class, null, "nameToClassMap", "field_145855_i");
	return teNameToClass;
}
 
Example 17
Source File: RecipeHandlerCyaniteReprocessor.java    From NEI-Integration with MIT License 4 votes vote down vote up
@Override
public void prepare() {
    solidToReactant = ReflectionHelper.getPrivateValue(Reactants.class, null, "_solidToReactant");
    API.setGuiOffset(GuiCyaniteReprocessor.class, 8, 17);
}
 
Example 18
Source File: NBTHelper.java    From NBTEdit with GNU General Public License v3.0 4 votes vote down vote up
public static Map<String,NBTBase> getMap(NBTTagCompound tag){
	return ReflectionHelper.getPrivateValue(NBTTagCompound.class, tag, 1);
}
 
Example 19
Source File: NBTHelper.java    From NBTEdit with GNU General Public License v3.0 4 votes vote down vote up
public static NBTBase getTagAt(NBTTagList tag, int index) {
	List<NBTBase> list = ReflectionHelper.getPrivateValue(NBTTagList.class, tag, 0);
	return list.get(index);
}
 
Example 20
Source File: NameUtils.java    From OpenPeripheral with MIT License 4 votes vote down vote up
public static Map<Class<? extends TileEntity>, String> getClassToNameMap() {
	if (teClassToName == null) teClassToName = ReflectionHelper.getPrivateValue(TileEntity.class, null, "classToNameMap", "field_145853_j");
	return teClassToName;
}