cpw.mods.fml.common.ModContainer Java Examples
The following examples show how to use
cpw.mods.fml.common.ModContainer.
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: IGWSupportNotifier.java From PneumaticCraft with GNU General Public License v3.0 | 6 votes |
/** * Needs to be instantiated somewhere in your mod's loading stage. */ public IGWSupportNotifier(){ if(FMLCommonHandler.instance().getSide() == Side.CLIENT && !Loader.isModLoaded("IGWMod")) { File dir = new File(".", "config"); Configuration config = new Configuration(new File(dir, "IGWMod.cfg")); config.load(); if(config.get(Configuration.CATEGORY_GENERAL, "enable_missing_notification", true, "When enabled, this will notify players when IGW-Mod is not installed even though mods add support.").getBoolean()) { ModContainer mc = Loader.instance().activeModContainer(); String modid = mc.getModId(); List<ModContainer> loadedMods = Loader.instance().getActiveModList(); for(ModContainer container : loadedMods) { if(container.getModId().equals(modid)) { supportingMod = container.getName(); FMLCommonHandler.instance().bus().register(this); ClientCommandHandler.instance.registerCommand(new CommandDownloadIGW()); break; } } } config.save(); } }
Example #2
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 #3
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 #4
Source File: GuiModIdConfig.java From ehacks-pro with GNU General Public License v3.0 | 6 votes |
@Override public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_) { this.drawDefaultBackground(); this.drawCenteredString(this.fontRendererObj, "ModID configuration", this.width / 2, 15, 16777215); this.modId.drawTextBox(); this.modVersion.drawTextBox(); boolean nameOk = true; for (ModContainer container : Loader.instance().getActiveModList()) { if ((container.getModId() == null ? this.modId.getText() == null : container.getModId().equals(this.modId.getText())) && container.getMod() != INSTANCE) { nameOk = false; break; } } this.saveButton.enabled = "".equals(this.modId.getText()) || nameOk; this.drawString(this.fontRendererObj, "Mod ID (empty - no mod)", this.width / 2 - 100, this.height / 6 + 66 - 13, 16777215); this.drawString(this.fontRendererObj, "Mod Version", this.width / 2 - 100, this.height / 6 + 66 + 36 - 13, 16777215); super.drawScreen(p_73863_1_, p_73863_2_, p_73863_3_); }
Example #5
Source File: AdvancedGolemProvider.java From Gadomancy with GNU Lesser General Public License v3.0 | 6 votes |
@Override public List<String> getWailaTail(Entity paramEntity, List<String> strings, IWailaEntityAccessor data, IWailaConfigHandler config) { if(data.getEntity() instanceof EntityGolemBase) { AdditionalGolemType type = GadomancyApi.getAdditionalGolemType(((EntityGolemBase) data.getEntity()).getGolemType()); if(type != null && strings.size() > 0) { String oldMod = strings.get(strings.size() - 1); ModContainer container = Loader.instance().getIndexedModList().get(type.getModId()); if(container != null) { String mod = ColorHelper.extractColors(oldMod) + container.getName(); strings.remove(strings.size() - 1); strings.add(mod); } } } return strings; }
Example #6
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 5 votes |
private static void loadModChunks() throws IOException { for (Entry<Object, ModContainer> entry : mods.entrySet()) { File saveFile = new File(saveDir, entry.getValue().getModId() + ".dat"); if (!saveFile.exists()) return; DataInputStream datain = new DataInputStream(new FileInputStream(saveFile)); ModOrganiser organiser = getModOrganiser(entry.getKey()); ReviveChange.ModRevive.list.add(organiser); organiser.load(datain); datain.close(); } }
Example #7
Source File: Protection.java From MyTown2 with The Unlicense | 5 votes |
private static boolean isModLoaded(String modid, String name, String version) { if ("Minecraft".equals(modid)) { return true; } for(ModContainer mod : Loader.instance().getModList()) { if(mod.getModId().equals(modid) && (name.length() == 0 || mod.getName().equals(name)) && mod.getVersion().startsWith(version)) { return true; } } return false; }
Example #8
Source File: FuelManager.java From NEI-Integration with MIT License | 5 votes |
/** * Register the amount of heat in a bucket of liquid fuel. * * @param fluid * @param heatValuePerBucket */ public static void addBoilerFuel(Fluid fluid, int heatValuePerBucket) { ModContainer mod = Loader.instance().activeModContainer(); String modName = mod != null ? mod.getName() : "An Unknown Mod"; if (fluid == null) { FMLLog.log("Railcraft", Level.WARN, String.format("An error occured while %s was registering a Boiler fuel source", modName)); return; } boilerFuel.put(fluid, heatValuePerBucket); FMLLog.log("Railcraft", Level.DEBUG, String.format("%s registered \"%s\" as a valid Boiler fuel source with %d heat.", modName, fluid.getName(), heatValuePerBucket)); }
Example #9
Source File: Utils.java From NEI-Integration with MIT License | 5 votes |
public static boolean isModLoaded(String modid, String versionRangeString) { if (!isModLoaded(modid)) { return false; } ModContainer mod = Loader.instance().getIndexedModList().get(modid); VersionRange versionRange = VersionParser.parseRange(versionRangeString); DefaultArtifactVersion required = new DefaultArtifactVersion(modid, versionRange); return required.containsVersion(mod.getProcessedVersion()); }
Example #10
Source File: LoadedModDumper.java From NEI-Integration with MIT License | 5 votes |
@Override public Iterable<String[]> dump(int mode) { List<String[]> list = new LinkedList<String[]>(); for (ModContainer mod : Loader.instance().getModList()) { list.add(new String[] { mod.getModId(), mod.getName(), mod.getVersion(), String.valueOf(!(mod instanceof FMLModContainer)), String.valueOf(mod.canBeDisabled()), mod.getDependencies().toString() }); } return list; }
Example #11
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 #12
Source File: OpenPeripheralIntegration.java From OpenPeripheral-Integration with MIT License | 5 votes |
private static boolean sameOrNewerVersion(String modid, String version) { final ModContainer modContainer = Loader.instance().getIndexedModList().get(modid); if (modContainer == null) return true; final ArtifactVersion targetVersion = new DefaultArtifactVersion(version); final ArtifactVersion actualVersion = modContainer.getProcessedVersion(); return actualVersion.compareTo(targetVersion) >= 0; }
Example #13
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 5 votes |
private static ModOrganiser getModOrganiser(Object mod) { ModOrganiser organiser = modOrganisers.get(mod); if (organiser == null) { ModContainer container = mods.get(mod); if (container == null) throw new NullPointerException("Mod not registered with chickenchunks: " + mod); modOrganisers.put(mod, organiser = new ModOrganiser(mod, container)); } return organiser; }
Example #14
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 5 votes |
/** * By doing this you are delegating all chunks from your mod to be handled by yours truly. */ public static void registerMod(Object mod) { ModContainer container = Loader.instance().getModObjectList().inverse().get(mod); if (container == null) throw new NullPointerException("Mod container not found for: " + mod); mods.put(mod, container); ForgeChunkManager.setForcedChunkLoadingCallback(mod, new DummyLoadingCallback()); }
Example #15
Source File: TileArcaneHand.java From Gadomancy with GNU Lesser General Public License v3.0 | 5 votes |
public void openGui(Object mod, int modGuiId, World world, int x, int y, int z) { ModContainer mc = FMLCommonHandler.instance().findContainerFor(mod); tile.container = NetworkRegistry.INSTANCE.getRemoteGuiContainer(mc, this, modGuiId, world, x, y, z); if (tile.container != null) { tile.slots = new ArrayList<Slot>(); for (Slot slot : (List<Slot>) tile.container.inventorySlots) { if(!inventory.equals(slot.inventory)) { tile.slots.add(slot); } } } }
Example #16
Source File: RadioHatchCompat.java From bartworks with MIT License | 4 votes |
public static void run() { DebugLog.log("Starting Generation of missing GT++ rods/longrods"); try { Class rodclass = Class.forName("gtPlusPlus.core.item.base.rods.BaseItemRod"); Class longrodclass = Class.forName("gtPlusPlus.core.item.base.rods.BaseItemRodLong"); Constructor<? extends Item> c1 = rodclass.getConstructor(RadioHatchCompat.materialClass); Constructor<? extends Item> c2 = longrodclass.getConstructor(RadioHatchCompat.materialClass); Field cOwners = GameData.class.getDeclaredField("customOwners"); cOwners.setAccessible(true); Field map = RegistryNamespaced.class.getDeclaredField("field_148758_b"); map.setAccessible(true); Map<Item,String> UniqueIdentifierMap = (Map<Item, String>) map.get(GameData.getItemRegistry()); Map<GameRegistry.UniqueIdentifier, ModContainer> ownerItems = (Map<GameRegistry.UniqueIdentifier, ModContainer>) cOwners.get(null); ModContainer gtpp = null; ModContainer bartworks = null; for (ModContainer container : Loader.instance().getModList()){ if (gtpp != null && bartworks != null) break; else if (container.getModId().equalsIgnoreCase(BartWorksCrossmod.MOD_ID)) bartworks=container; else if (container.getModId().equalsIgnoreCase("miscutils")) gtpp=container; } for (Object mats : (Set) RadioHatchCompat.materialClass.getField("mMaterialMap").get(null)) { if (RadioHatchCompat.isRadioactive.getBoolean(mats)) { if (OreDictionary.getOres("stick" + RadioHatchCompat.unlocalizedName.get(mats)).isEmpty()) { Item it = c1.newInstance(mats); UniqueIdentifierMap.replace(it,"miscutils:"+it.getUnlocalizedName()); GameRegistry.UniqueIdentifier ui = GameRegistry.findUniqueIdentifierFor(it); ownerItems.replace(ui,bartworks,gtpp); String tanslate = it.getUnlocalizedName()+".name="+RadioHatchCompat.localizedName.get(mats)+" Rod"; RadioHatchCompat.TranslateSet.add(tanslate); DebugLog.log(tanslate); DebugLog.log("Generate: " + RadioHatchCompat.rod + RadioHatchCompat.unlocalizedName.get(mats)); } if (OreDictionary.getOres("stickLong" + RadioHatchCompat.unlocalizedName.get(mats)).isEmpty()) { Item it2 = c2.newInstance(mats); UniqueIdentifierMap.replace(it2,"miscutils:"+it2.getUnlocalizedName()); GameRegistry.UniqueIdentifier ui2 = GameRegistry.findUniqueIdentifierFor(it2); ownerItems.replace(ui2,bartworks,gtpp); DebugLog.log("Generate: " + RadioHatchCompat.longRod + RadioHatchCompat.unlocalizedName.get(mats)); } } } } catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { e.printStackTrace(); } }
Example #17
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 4 votes |
public ModOrganiser(Object mod, ModContainer container) { this.mod = mod; this.container = container; }
Example #18
Source File: TooltipEventHandler.java From bartworks with MIT License | 4 votes |
@SideOnly(Side.CLIENT) @SubscribeEvent(priority = EventPriority.HIGHEST) public void getTooltip(ItemTooltipEvent event) { if (event == null || event.itemStack == null || event.itemStack.getItem() == null) return; if (TooltipCache.getTooltip(event.itemStack).isEmpty()) { ItemStack tmp = event.itemStack.copy(); Pair<Integer,Short> abstractedStack = new Pair<>(Item.getIdFromItem(tmp.getItem()), (short) tmp.getItemDamage()); List<String> tooAdd = new ArrayList<>(); if (OreDictHandler.getNonBWCache().contains(abstractedStack)) { for (Pair<Integer,Short> pair : OreDictHandler.getNonBWCache()) { if (pair.equals(abstractedStack)) { GameRegistry.UniqueIdentifier UI = GameRegistry.findUniqueIdentifierFor(tmp.getItem()); if (UI == null) UI = GameRegistry.findUniqueIdentifierFor(Block.getBlockFromItem(tmp.getItem())); if (UI != null) { for (ModContainer modContainer : Loader.instance().getModList()) { if (UI.modId.equals(MainMod.MOD_ID) || UI.modId.equals(BartWorksCrossmod.MOD_ID) || UI.modId.equals("BWCore")) break; if (UI.modId.equals(modContainer.getModId())) { tooAdd.add("Shared ItemStack between " + ChatColorHelper.DARKGREEN + "BartWorks" + ChatColorHelper.GRAY + " and " + ChatColorHelper.RED + modContainer.getName()); } } } else tooAdd.add("Shared ItemStack between " + ChatColorHelper.DARKGREEN + "BartWorks" + ChatColorHelper.GRAY + " and another Mod, that doesn't use the ModContainer propperly!"); } } } Block BLOCK = Block.getBlockFromItem(event.itemStack.getItem()); if (BLOCK != null && BLOCK != Blocks.air) { if (BLOCK instanceof BW_Blocks) { TooltipCache.put(event.itemStack, tooAdd); return; } BioVatLogicAdder.BlockMetaPair PAIR = new BioVatLogicAdder.BlockMetaPair(BLOCK, (byte) event.itemStack.getItemDamage()); HashMap<BioVatLogicAdder.BlockMetaPair, Byte> GLASSMAP = BioVatLogicAdder.BioVatGlass.getGlassMap(); if (GLASSMAP.containsKey(PAIR)) { int tier = GLASSMAP.get(PAIR); tooAdd.add( StatCollector.translateToLocal("tooltip.glas.0.name") + " " + BW_ColorUtil.getColorForTier(tier) + GT_Values.VN[tier] + ChatColorHelper.RESET); } else if (BLOCK.getMaterial().equals(Material.glass)) { tooAdd.add(StatCollector.translateToLocal("tooltip.glas.0.name") + " " + BW_ColorUtil.getColorForTier(3) + GT_Values.VN[3] + ChatColorHelper.RESET); } } TooltipCache.put(event.itemStack, tooAdd); event.toolTip.addAll(tooAdd); } else { event.toolTip.addAll(TooltipCache.getTooltip(event.itemStack)); } }