net.minecraftforge.fml.common.Loader.getModClassLoader()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(2.7k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中net.minecraftforge.fml.common.Loader.getModClassLoader()方法的一些代码示例,展示了Loader.getModClassLoader()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Loader.getModClassLoader()方法的具体详情如下:
包路径:net.minecraftforge.fml.common.Loader
类名称:Loader
方法名:getModClassLoader

Loader.getModClassLoader介绍

暂无

代码示例

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

public InventoryTweaksModule()
{
  try
  {
    this.api = (InvTweaksAPI) Class.forName( "invtweaks.forge.InvTweaksMod", true, Loader.instance().getModClassLoader() )
        .getField( "instance" )
        .get( null );
  }
  catch( Exception ex )
  {
  }
}

代码示例来源:origin: raoulvdberge/refinedstorage

public GridSorterInventoryTweaks() {
  try {
    api = (InvTweaksAPI) Class.forName("invtweaks.forge.InvTweaksMod", true, Loader.instance().getModClassLoader()).getField("instance").get(null);
  } catch (Exception e) {
    // NO OP
  }
}

代码示例来源:origin: iLexiconn/LLibrary

public void injectConfig(ModContainer mod, ASMDataTable data) {
  SetMultimap<String, ASMDataTable.ASMData> annotations = data.getAnnotationsFor(mod);
  if (annotations != null) {
    Set<ASMDataTable.ASMData> targetList = annotations.get(Config.class.getName());
    ClassLoader classLoader = Loader.instance().getModClassLoader();
    for (ASMDataTable.ASMData target : targetList) {
      try {
        Class<?> targetClass = Class.forName(target.getClassName(), true, classLoader);
        Field field = targetClass.getDeclaredField(target.getObjectName());
        field.setAccessible(true);
        Class<?> configClass = field.getType();
        File configFile = new File(".", "config" + File.separator + mod.getModId() + ".cfg");
        field.set(null, this.registerConfig(mod, configFile, configClass.newInstance()));
      } catch (Exception e) {
        LLibrary.LOGGER.fatal("Failed to inject config for mod container " + mod, e);
      }
    }
  }
}

代码示例来源:origin: iLexiconn/LLibrary

public void injectNetworkWrapper(ModContainer mod, ASMDataTable data) {
    SetMultimap<String, ASMDataTable.ASMData> annotations = data.getAnnotationsFor(mod);
    if (annotations != null) {
      Set<ASMDataTable.ASMData> targetList = annotations.get(NetworkWrapper.class.getName());
      ClassLoader classLoader = Loader.instance().getModClassLoader();
      for (ASMDataTable.ASMData target : targetList) {
        try {
          Class<?> targetClass = Class.forName(target.getClassName(), true, classLoader);
          Field field = targetClass.getDeclaredField(target.getObjectName());
          field.setAccessible(true);
          NetworkWrapper annotation = field.getAnnotation(NetworkWrapper.class);
          SimpleNetworkWrapper networkWrapper = NetworkRegistry.INSTANCE.newSimpleChannel(mod.getModId());
          field.set(null, networkWrapper);
          for (Class messageClass : annotation.value()) {
            this.registerMessage(networkWrapper, messageClass);
          }
        } catch (Exception e) {
          LLibrary.LOGGER.fatal("Failed to inject network wrapper for mod container " + mod, e);
        }
      }
    }
  }
}

相关文章