项目作者: MeGysssTaa

项目描述 :
Runtime Forge/FML mod controller — toggle mods without restarting
高级语言: Java
项目地址: git://github.com/MeGysssTaa/rfmc.git
创建时间: 2019-03-11T14:44:19Z
项目社区:https://github.com/MeGysssTaa/rfmc

开源协议:Apache License 2.0

下载


RFMC

Runtime Forge Mod Control

An easy-to-use and lightweight library (not a mod!) that allows one to control Minecraft Forge/FML mods right at runtime. There is no proper API in Forge to do so, and thus RFMC uses nothing but black magic (reflections) to do its job.

Usage

Just copy the src/me/... directory and clone it into your project’s source folder. The only dependency is Forge. I personally used 1.8.9-11.15.1.2318, but hope RFMC also works for other versions, or at least for the newer ones.

Done? Now you can use code like this to control Forge mods:

  1. private static final String KEYSTROKES_MOD_ID = "keystrokesmod";
  2. public void toogleKeystrokesMod() {
  3. if (ModControl.isModEnabled(KEYSTROKES_MOD_ID)) {
  4. // Since now, the mod will be displayed as disabled in the Forge mods list,
  5. // and all its event handlers are unregistered.
  6. System.out.println("The mod was enabled. Disabling it!");
  7. ModControl.disableMod(KEYSTROKES_MOD_ID);
  8. } else {
  9. // Since now, the mod will be displayed as enabled in the Forge mods list,
  10. // and all its event handlers that were disabled previously are registered again.
  11. System.out.println("The mod was disabled. Enabling it!");
  12. ModControl.enableMod(KEYSTROKES_MOD_ID);
  13. }
  14. }

The default implementation disables mods by switching their state to DISABLED and unregistering all their MinecraftForge.EVENT_BUS event handlers. The process of enabling simply does the opposite things, with new mod state being set to AVAILABLE.

If one or more of your mods require something more to be disabled, or are even courteous enough to provide some API for runtime control, you can always add mod-specific controllers as follows:

  1. public class CustomModController implements ModController {
  2. public CustomModController() {
  3. ModControl.registerModSpecificController("custom-mod-id", this);
  4. }
  5. public void enableMod() {
  6. CustomModAPI.enableProperlyKThx();
  7. }
  8. public void disableMod() {
  9. CustomModAPI.disableProperlyKThx();
  10. }
  11. }

Mod-specific controllers are called right before the basic implementation which was described above.

Contributing

Any pull requests are always welcome, for example, if you want to add a publicly available mod-specific controller or do something else which may be cool for people using RFMC.

Issues and bugs are not really welcome, obviously. However, if you believe something is wrong with the code and want me to fix it, please open a proper issue describing your problem in details.

Have fun using RFMC!

License

Apache License 2.0