Esempio n. 1
0
 private void parseSimpleFieldAnnotation(
     SetMultimap<String, ASMData> annotations,
     String annotationClassName,
     Function<ModContainer, Object> retreiver)
     throws IllegalAccessException {
   String[] annName = annotationClassName.split("\\.");
   String annotationName = annName[annName.length - 1];
   for (ASMData targets : annotations.get(annotationClassName)) {
     String targetMod = (String) targets.getAnnotationInfo().get("value");
     Field f = null;
     Object injectedMod = null;
     ModContainer mc = this;
     boolean isStatic = false;
     Class<?> clz = modInstance.getClass();
     if (!Strings.isNullOrEmpty(targetMod)) {
       if (Loader.isModLoaded(targetMod)) {
         mc = (ModContainer) Loader.instance().getIndexedModList().get(targetMod);
       } else {
         mc = null;
       }
     }
     if (mc != null) {
       try {
         clz = Class.forName(targets.getClassName(), true, Loader.instance().getModClassLoader());
         f = clz.getDeclaredField(targets.getObjectName());
         f.setAccessible(true);
         isStatic = Modifier.isStatic(f.getModifiers());
         injectedMod = retreiver.apply(mc);
       } catch (Exception e) {
         Throwables.propagateIfPossible(e);
         FMLLog.log(
             Level.WARNING,
             e,
             "Attempting to load @%s in class %s for %s and failing",
             annotationName,
             targets.getClassName(),
             mc.getModId());
       }
     }
     if (f != null) {
       Object target = null;
       if (!isStatic) {
         target = modInstance;
         if (!modInstance.getClass().equals(clz)) {
           FMLLog.warning(
               "Unable to inject @%s in non-static field %s.%s for %s as it is NOT the primary mod instance",
               annotationName, targets.getClassName(), targets.getObjectName(), mc.getModId());
           continue;
         }
       }
       f.set(target, injectedMod);
     }
   }
 }
Esempio n. 2
0
  @Override
  public void bindMetadata(MetadataCollection mc) {
    modMetadata = mc.getMetadataForId(getModId(), descriptor);

    if (descriptor.containsKey("useMetadata")) {
      overridesMetadata = !((Boolean) descriptor.get("useMetadata")).booleanValue();
    }

    if (overridesMetadata || !modMetadata.useDependencyInformation) {
      Set<ArtifactVersion> requirements = Sets.newHashSet();
      List<ArtifactVersion> dependencies = Lists.newArrayList();
      List<ArtifactVersion> dependants = Lists.newArrayList();
      annotationDependencies = (String) descriptor.get("dependencies");
      Loader.instance()
          .computeDependencies(annotationDependencies, requirements, dependencies, dependants);
      modMetadata.requiredMods = requirements;
      modMetadata.dependencies = dependencies;
      modMetadata.dependants = dependants;
      FMLLog.finest("Parsed dependency info : %s %s %s", requirements, dependencies, dependants);
    } else {
      FMLLog.finest(
          "Using mcmod dependency info : %s %s %s",
          modMetadata.requiredMods, modMetadata.dependencies, modMetadata.dependants);
    }
    if (Strings.isNullOrEmpty(modMetadata.name)) {
      FMLLog.info(
          "Mod %s is missing the required element 'name'. Substituting %s", getModId(), getModId());
      modMetadata.name = getModId();
    }
    internalVersion = (String) descriptor.get("version");
    if (Strings.isNullOrEmpty(internalVersion)) {
      Properties versionProps = searchForVersionProperties();
      if (versionProps != null) {
        internalVersion = versionProps.getProperty(getModId() + ".version");
        FMLLog.fine(
            "Found version %s for mod %s in version.properties, using",
            internalVersion, getModId());
      }
    }
    if (Strings.isNullOrEmpty(internalVersion) && !Strings.isNullOrEmpty(modMetadata.version)) {
      FMLLog.warning(
          "Mod %s is missing the required element 'version' and a version.properties file could not be found. Falling back to metadata version %s",
          getModId(), modMetadata.version);
      internalVersion = modMetadata.version;
    }
    if (Strings.isNullOrEmpty(internalVersion)) {
      FMLLog.warning(
          "Mod %s is missing the required element 'version' and no fallback can be found. Substituting '1.0'.",
          getModId());
      modMetadata.version = internalVersion = "1.0";
    }

    String mcVersionString = (String) descriptor.get("acceptedMinecraftVersions");
    if (!Strings.isNullOrEmpty(mcVersionString)) {
      minecraftAccepted = VersionParser.parseRange(mcVersionString);
    } else {
      minecraftAccepted = Loader.instance().getMinecraftModContainer().getStaticVersionRange();
    }
  }