cpw.mods.fml.relauncher.ReflectionHelper Java Examples
The following examples show how to use
cpw.mods.fml.relauncher.ReflectionHelper.
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 |
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: RabbitFoot.java From Et-Futurum with The Unlicense | 6 votes |
@SuppressWarnings("unchecked") public RabbitFoot() { setTextureName("rabbit_foot"); setUnlocalizedName(Utils.getUnlocalisedName("rabbit_foot")); setCreativeTab(EtFuturum.enableRabbit ? EtFuturum.creativeTab : null); if (EtFuturum.enableRabbit) try { Field f = ReflectionHelper.findField(PotionHelper.class, "potionRequirements", "field_77927_l"); f.setAccessible(true); HashMap<Integer, String> potionRequirements = (HashMap<Integer, String>) f.get(null); potionRequirements.put(Potion.jump.getId(), "0 & 1 & !2 & 3"); Field f2 = ReflectionHelper.findField(PotionHelper.class, "potionAmplifiers", "field_77928_m"); f2.setAccessible(true); HashMap<Integer, String> potionAmplifiers = (HashMap<Integer, String>) f2.get(null); potionAmplifiers.put(Potion.jump.getId(), "5"); Field f3 = ReflectionHelper.findField(Potion.class, "liquidColor", "field_76414_N"); f3.setAccessible(true); f3.set(Potion.jump, 0x22FF4C); } catch (Exception e) { } }
Example #3
Source File: ChestLootDumper.java From NEI-Integration with MIT License | 6 votes |
@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 #4
Source File: TileEntityDumper.java From NEI-Integration with MIT License | 6 votes |
@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 #5
Source File: EntityTippedArrow.java From Et-Futurum with The Unlicense | 6 votes |
@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: EntityRabbit.java From Et-Futurum with The Unlicense | 6 votes |
public EntityRabbit(World world) { super(world); moveType = EntityRabbit.EnumMoveType.HOP; carrotTicks = 0; setSize(0.4F, 0.5F); ReflectionHelper.setPrivateValue(EntityLiving.class, this, new EntityRabbit.RabbitJumpHelper(this), "jumpHelper", "field_70767_i"); ReflectionHelper.setPrivateValue(EntityLiving.class, this, new EntityRabbit.RabbitMoveHelper(), "moveHelper", "field_70765_h"); getNavigator().setAvoidsWater(true); // navigator.func_179678_a(2.5F); tasks.addTask(1, new EntityAISwimming(this)); tasks.addTask(1, new EntityRabbit.AIPanic(1.33D)); tasks.addTask(2, new EntityAIMate(this, 0.8D)); tasks.addTask(3, new EntityAITempt(this, 1.0D, Items.carrot, false)); tasks.addTask(5, new EntityRabbit.AIRaidFarm()); tasks.addTask(5, new EntityAIWander(this, 0.6D)); tasks.addTask(11, new EntityAIWatchClosest(this, EntityPlayer.class, 10.0F)); tasks.addTask(4, new EntityAIAvoidEntity(this, EntityWolf.class, 16.0F, 1.33D, 1.33D)); tasks.addTask(4, new EntityAIAvoidEntity(this, EntityPlayer.class, 16.0F, 0.8D, 1.33D)); setMovementSpeed(0.0D); }
Example #7
Source File: DimensionDumper.java From NEI-Integration with MIT License | 6 votes |
@Override public Iterable<String[]> dump(int mode) { List<String[]> list = new LinkedList<String[]>(); List<Integer> ids = new ArrayList<Integer>(); ids.addAll(Arrays.asList(DimensionManager.getStaticDimensionIDs())); Collections.sort(ids); for (int id : ids) { int providerId = DimensionManager.getProviderType(id); Map<Integer, Class> providers = ReflectionHelper.getPrivateValue(DimensionManager.class, null, "providers"); Class providerClass = providers.get(providerId); list.add(new String[] { String.valueOf(id), String.valueOf(providerId), providerClass.getName() }); } return list; }
Example #8
Source File: BlockTrackEntryInventory.java From PneumaticCraft with GNU General Public License v3.0 | 6 votes |
@Override public boolean shouldTrackWithThisEntry(IBlockAccess world, int x, int y, int z, Block block, TileEntity te){ if(tileEntityClassToNameMapping == null) { try { tileEntityClassToNameMapping = (Map)ReflectionHelper.findField(TileEntity.class, "field_145853_j", "classToNameMap").get(null); } catch(Exception e) { Log.error("[BlockTrackEntryInventory.class] Uhm reflection failed here!"); e.printStackTrace(); } } if(te instanceof TileEntityChest) { TileEntityChest chest = (TileEntityChest)te; if(chest.adjacentChestXNeg != null || chest.adjacentChestZNeg != null) return false; } return te != null && !invBlackList.contains(tileEntityClassToNameMapping.get(te.getClass())) && te instanceof IInventory && ((IInventory)te).getSizeInventory() > 0 && !MinecraftForge.EVENT_BUS.post(new InventoryTrackEvent(te)); }
Example #9
Source File: Nan0EventRegistar.java From ehacks-pro with GNU General Public License v3.0 | 6 votes |
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 #10
Source File: DramaSplash.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
@Override public void run(){ try { if(getAsieSplashMethod == null) { Class okuTickHandler = Class.forName("okushama.drama.TickHandlerClient"); okuTickHandlerInstance = okuTickHandler.newInstance(); getAsieSplashMethod = ReflectionHelper.findMethod(okuTickHandler, okuTickHandlerInstance, new String[]{"asieSplash"}); } cachedLine = (String)getAsieSplashMethod.invoke(okuTickHandlerInstance); } catch(Exception e) { Log.warning("Reflection failed on the Drama Splash getter!"); e.printStackTrace(); failed = true; } }
Example #11
Source File: EntityDrone.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
public EntityDrone(World world){ super(world); setSize(0.7F, 0.35F); ReflectionHelper.setPrivateValue(EntityLiving.class, this, new EntityPathNavigateDrone(this, world), "navigator", "field_70699_by"); ReflectionHelper.setPrivateValue(EntityLiving.class, this, new DroneMoveHelper(this), "moveHelper", "field_70765_h"); tasks.addTask(1, chargeAI = new DroneGoToChargingStation(this)); }
Example #12
Source File: IGWMod.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
@Override public void preInit(){ try { int minorVersion = Integer.parseInt((String)ReflectionHelper.getPrivateValue(Constants.class, null, "MINOR")); if(minorVersion < 7) FMLCommonHandler.instance().bus().register(this); } catch(Throwable e) { e.printStackTrace(); } }
Example #13
Source File: HackableWitch.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
@Override public boolean afterHackTick(Entity entity){ if(attackTimer == null) attackTimer = ReflectionHelper.findField(EntityWitch.class, "field_82200_e", "witchAttackTimer"); try { attackTimer.set(entity, 20); ((EntityWitch)entity).setAggressive(true); return true; } catch(Exception e) { Log.warning("Reflection failed on HackableWitch:"); e.printStackTrace(); return false; } }
Example #14
Source File: BlockSaplingTainted.java From ForbiddenMagic with Do What The F*ck You Want To Public License | 5 votes |
public BlockSaplingTainted() { super(); setCreativeTab(Forbidden.tab); setStepSound(ConfigBlocks.blockTaint.stepSound); try { Field mat = ReflectionHelper.findField(Block.class, "blockMaterial", "field_149764_J"); mat.set(this, Config.taintMaterial); } catch (Exception e){ e.printStackTrace(); } }
Example #15
Source File: BlockLeavesTainted.java From ForbiddenMagic with Do What The F*ck You Want To Public License | 5 votes |
public BlockLeavesTainted() { super(); setCreativeTab(Forbidden.tab); setLightOpacity(0); setHardness(0.2F); setStepSound(ConfigBlocks.blockTaint.stepSound); try { Field mat = ReflectionHelper.findField(Block.class, "blockMaterial", "field_149764_J"); mat.set(this, Config.taintMaterial); } catch (Exception e){ e.printStackTrace(); } }
Example #16
Source File: BlockLogTainted.java From ForbiddenMagic with Do What The F*ck You Want To Public License | 5 votes |
public BlockLogTainted() { super(); setCreativeTab(Forbidden.tab); setStepSound(ConfigBlocks.blockTaint.stepSound); try { Field mat = ReflectionHelper.findField(Block.class, "blockMaterial", "field_149764_J"); mat.set(this, Config.taintMaterial); } catch (Exception e){ e.printStackTrace(); } this.setHarvestLevel("axe", 0); }
Example #17
Source File: AdvancedModEventHandler.java From AdvancedMod with GNU General Public License v3.0 | 5 votes |
@SubscribeEvent public void onCreeperSpawn(EntityJoinWorldEvent event){ if(event.entity instanceof EntityCreeper) { ((EntityCreeper)event.entity).explosionRadius = 0; try { Field field = ReflectionHelper.findField(EntityCreeper.class, "field_82225_f", "fuseTime"); field.set(event.entity, 80); } catch(Throwable e) { Log.warn("Reflection on Creeper fuseTime failed!"); e.printStackTrace(); } } }
Example #18
Source File: FakePlayerItemInWorldManager.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
public boolean isDigging(){ if(isDigging == null) isDigging = ReflectionHelper.findField(ItemInWorldManager.class, "field_73088_d", "isDestroyingBlock"); try { return isDigging.getBoolean(this); } catch(Exception e) { Log.error("Drone FakePlayerItemInWorldManager failed with reflection (Digging)!"); e.printStackTrace(); return true; } }
Example #19
Source File: FakePlayerItemInWorldManager.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
public boolean isAcknowledged(){ if(acknowledged == null) acknowledged = ReflectionHelper.findField(ItemInWorldManager.class, "field_73097_j", "receivedFinishDiggingPacket"); try { return acknowledged.getBoolean(this); } catch(Exception e) { Log.error("Drone FakePlayerItemInWorldManager failed with reflection (Acknowledge get)!"); e.printStackTrace(); return true; } }
Example #20
Source File: Util.java From ExtraCells1 with MIT License | 5 votes |
/** * All future API calls should be made via this method. * @return */ public static IAppEngApi getAppEngApi() { try { Class c = ReflectionHelper.getClass( Util.class.getClassLoader(), "appeng.common.AppEngApi" ); api = (IAppEngApi) c.getMethod( "getInstance" ).invoke( c ); } catch ( Throwable e) { return null; } return api; }
Example #21
Source File: EntityDumper.java From NEI-Integration with MIT License | 5 votes |
@Override public Iterable<String[]> dump(int mode) { List<String[]> list = new LinkedList<String[]>(); List<Integer> ids = new ArrayList<Integer>(); ids.addAll(EntityList.IDtoClassMapping.keySet()); Collections.sort(ids); for (int id : ids) { list.add(new String[] { GLOBAL, String.valueOf(id), EntityList.getStringFromID(id), EntityList.getClassFromID(id).getName() }); } ListMultimap<ModContainer, EntityRegistration> modEntities = ReflectionHelper.getPrivateValue(EntityRegistry.class, EntityRegistry.instance(), "entityRegistrations"); for (Entry<ModContainer, EntityRegistration> e : modEntities.entries()) { EntityRegistration er = e.getValue(); list.add(new String[] { e.getKey().getModId(), String.valueOf(er.getModEntityId()), e.getKey().getModId() + "." + er.getEntityName(), er.getEntityClass().getName() }); } Collections.sort(list, new Comparator<String[]>() { @Override public int compare(String[] s1, String[] s2) { if (s1[0].equals(GLOBAL) && !s1[0].equals(s2[0])) { return -1; } int i = s1[0].compareTo(s2[0]); if (i != 0) { return i; } return Integer.compare(Integer.valueOf(s1[1]), Integer.valueOf(s2[1])); } }); return list; }
Example #22
Source File: Debug.java From ehacks-pro with GNU General Public License v3.0 | 5 votes |
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 #23
Source File: LegacyJavaFixer.java From LegacyJavaFixer with MIT License | 5 votes |
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 #24
Source File: ParticleUtils.java From Artifacts with MIT License | 5 votes |
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 #25
Source File: EtFuturum.java From Et-Futurum with The Unlicense | 5 votes |
private void setFinalField(Class<?> cls, Object obj, Object newValue, String... fieldNames) { try { Field field = ReflectionHelper.findField(cls, fieldNames); field.setAccessible(true); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); field.set(obj, newValue); } catch (Exception e) { e.printStackTrace(); } }
Example #26
Source File: NoLimitClear.java From ehacks-pro with GNU General Public License v3.0 | 5 votes |
@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 #27
Source File: FastClick.java From ehacks-pro with GNU General Public License v3.0 | 5 votes |
@Override public void onTicks() { if (Wrapper.INSTANCE.mcSettings().keyBindAttack.getIsKeyPressed()) { try { Method m = ReflectionHelper.findMethod(Minecraft.class, Wrapper.INSTANCE.mc(), new String[]{"func_147116_af"}, (Class[]) null); m.invoke(Wrapper.INSTANCE.mc()); } catch (Exception e) { } } }
Example #28
Source File: FastPlace.java From ehacks-pro with GNU General Public License v3.0 | 5 votes |
@Override public void onTicks() { if (Wrapper.INSTANCE.mcSettings().keyBindUseItem.getIsKeyPressed()) { try { Method m = ReflectionHelper.findMethod(Minecraft.class, Wrapper.INSTANCE.mc(), new String[]{"func_147121_ag"}, (Class[]) null); m.invoke(Wrapper.INSTANCE.mc()); } catch (Exception e) { } } }
Example #29
Source File: Mappings.java From ehacks-pro with GNU General Public License v3.0 | 5 votes |
public static boolean isMCP() { try { return ReflectionHelper.findField(Minecraft.class, new String[]{"theMinecraft"}) != null; } catch (Exception ex) { return false; } }
Example #30
Source File: ClientProxy.java From Et-Futurum with The Unlicense | 5 votes |
@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()); }