Exemplo n.º 1
0
 private void doModEntityRegistration(Class<? extends Entity> entityClass, String entityName, int id, Object mod, int trackingRange, int updateFrequency, boolean sendsVelocityUpdates)
 {
     ModContainer mc = FMLCommonHandler.instance().findContainerFor(mod);
     EntityRegistration er = new EntityRegistration(mc, entityClass, entityName, id, trackingRange, updateFrequency, sendsVelocityUpdates);
     try
     {
         entityClassRegistrations.put(entityClass, er);
         entityNames.put(entityName, mc);
         if (!EntityList.classToStringMapping.containsKey(entityClass))
         {
             String entityModName = String.format("%s.%s", mc.getModId(), entityName);
             EntityList.classToStringMapping.put(entityClass, entityModName);
             EntityList.stringToClassMapping.put(entityModName, entityClass);
             FMLLog.finest("Automatically registered mod %s entity %s as %s", mc.getModId(), entityName, entityModName);
         }
         else
         {
             FMLLog.fine("Skipping automatic mod %s entity registration for already registered class %s", mc.getModId(), entityClass.getName());
         }
     }
     catch (IllegalArgumentException e)
     {
         FMLLog.log(Level.WARNING, e, "The mod %s tried to register the entity (name,class) (%s,%s) one or both of which are already registered", mc.getModId(), entityName, entityClass.getName());
         return;
     }
     entityRegistrations.put(mc, er);
 }
Exemplo n.º 2
0
  public static void create() {

    boolean register = false;

    if (FMLCommonHandler.instance().getSide() == Side.CLIENT) {
      register = hasOptifine = FMLClientHandler.instance().hasOptifine();
    }

    for (ModContainer modContainer : ModAPIManager.INSTANCE.getAPIList()) {
      if ("appliedenergistics2|API".equals(modContainer.getModId())) {
        if ("rv1".equals(modContainer.getVersion())) {
          hasOldAE2 = modContainer.getVersion() + " from " + modContainer.getSource().getName();
          register = true;
        } else if (!"rv2".equals(modContainer.getVersion())) {
          hasUnknownAE2 = modContainer.getVersion() + " from " + modContainer.getSource().getName();
          register = true;
        }
      } else if ("CoFHAPI|energy".equals(modContainer.getModId())) {
        if ("1.7.10R1.0.0".equals(modContainer.getVersion())
            || "1.7.10R1.0.1".equals(modContainer.getVersion())) {
          hasOldRF = modContainer.getVersion() + " from " + modContainer.getSource().getName();
          register = true;
        }
      }
    }

    if (register) {
      FMLCommonHandler.instance().registerCrashCallable(new EnderIOCrashCallable());
    }
  }
Exemplo n.º 3
0
  @SubscribeEvent
  public void onCrashReportEvent(CrashReportEvent event) {
    if (!diagnostics) return;
    if (event.getHeader().length() > 0) {
      return;
    }
    Throwable t = event.getThrowable();
    if (t instanceof LoaderException
        || t instanceof InvocationTargetException
        || t instanceof ReportedException) {
      t = t.getCause();
    }
    if (t == null) {
      return;
    }
    try {
      event.setHeader(handleThrowable(t));
    } catch (Throwable t2) {
      // Ignore any errors. We don't want to f**k up the crash reports.
    }
    List<ModContainer> mods = Utils.getModsFromStackTrace(event.getThrowable().getStackTrace());
    Set<ModContainer> s = Sets.newHashSet();
    ModContainer active = Loader.instance().activeModContainer();
    if (!mods.isEmpty() || (active != null && !active.getModId().equals("SquidAPI"))) {
      CrashReportCategory c = event.createCategory("Possibly involved mods");
      if (active != null && !active.getModId().equals("SquidAPI"))
        c.addCrashSection(
            active.getName(),
            String.format(
                "Version: %s. Main class: %s. Source: %s. Url: %s. Checksum: %s.",
                active.getVersion(),
                active.getMod().getClass().getName(),
                active.getSource().getName(),
                active.getMetadata().url,
                getChecksum(active.getSource())));
      for (ModContainer mod : mods) {
        if (!s.contains(mod)) {
          c.addCrashSection(
              mod.getName(),
              String.format(
                  "Version: %s. Main class: %s. Source: %s. Url: %s. Checksum: %s.",
                  mod.getVersion(),
                  mod.getMod().getClass().getName(),
                  mod.getSource().getName(),
                  mod.getMetadata().url,
                  getChecksum(mod.getSource())));
          s.add(mod);
        }
      }
    }
    try {
      if (Utils.isCoolSquid()) {
        event.setHeader("DRM!!! IT'S DRMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM!!!!!!!!!");
      }
    } catch (Throwable t2) {

    }
  }
Exemplo n.º 4
0
 public ItemData(Item item, ModContainer mc) {
   this.itemId = item.id;
   if (item.getClass().equals(ItemBlock.class)) {
     this.itemType = Block.byId[this.itemId].getClass().getName();
   } else {
     this.itemType = item.getClass().getName();
   }
   this.modId = mc.getModId();
   if (!modOrdinals.containsKey(mc.getModId())) {
     modOrdinals.put(mc.getModId(), HashMultiset.<String>create());
   }
   this.ordinal = modOrdinals.get(mc.getModId()).add(itemType, 1);
 }
 @Override
 public void applyModContainer(ModContainer activeContainer) {
   this.modContainer = activeContainer;
   this.modMetadata = activeContainer.getMetadata();
   this.sourceFile = activeContainer.getSource();
   this.suggestedConfigFile = new File(configurationDir, activeContainer.getModId() + ".cfg");
 }
Exemplo n.º 6
0
 @Override
 public void addModAsResource(ModContainer container) {
   Class<?> resourcePackType = container.getCustomResourcePackClass();
   if (resourcePackType != null) {
     try {
       ResourcePack pack =
           (ResourcePack)
               resourcePackType.getConstructor(ModContainer.class).newInstance(container);
       resourcePackList.add(pack);
       resourcePackMap.put(container.getModId(), pack);
     } catch (NoSuchMethodException e) {
       FMLLog.log(
           Level.SEVERE,
           "The container %s (type %s) returned an invalid class for it's resource pack.",
           container.getName(),
           container.getClass().getName());
       return;
     } catch (Exception e) {
       FMLLog.log(
           Level.SEVERE,
           e,
           "An unexpected exception occurred constructing the custom resource pack for %s",
           container.getName());
       throw Throwables.propagate(e);
     }
   }
 }
Exemplo n.º 7
0
  public ClassMeta getClassInfo(Class<?> cls) {
    final Package pkg = cls.getPackage();

    URL loadedFrom = null;

    try {
      loadedFrom = cls.getProtectionDomain().getCodeSource().getLocation();
    } catch (Throwable t) {
      Log.warn(t, "Failed to get source for %s", cls);
    }

    final API apiAnnotation = pkg.getAnnotation(API.class);
    final ApiInfo apiInfo = apiAnnotation != null ? new ApiInfo(apiAnnotation) : null;

    Map<File, Set<String>> mods = Maps.newHashMap();
    for (ModCandidate candidate : table.getCandidatesFor(pkg.getName())) {
      if (!candidate.getClassList().contains(cls.getName().replace('.', '/'))) continue;

      final File candidateFile = candidate.getModContainer();

      Set<String> modIds = Sets.newHashSet();
      mods.put(candidateFile, modIds);
      for (ModContainer mod : candidate.getContainedMods()) modIds.add(mod.getModId());
    }

    return new ClassMeta(cls, loadedFrom, apiInfo, mods);
  }
Exemplo n.º 8
0
  public static void openConfigScreen() {
    for (ModContainer mod : Loader.instance().getModList()) {
      if (mod.getModId() == null) continue;

      if (mod.getModId().equals(Main.MOD_ID)) {
        try {
          IModGuiFactory guiFactory = FMLClientHandler.instance().getGuiFactoryFor(mod);
          GuiScreen newScreen =
              guiFactory
                  .mainConfigGuiClass()
                  .getConstructor(GuiScreen.class)
                  .newInstance(Main.mc.currentScreen);
          Main.mc.displayGuiScreen(newScreen);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
Exemplo n.º 9
0
 @Override
 public byte[] generatePacket(Object... data) {
   ByteArrayDataOutput dat = ByteStreams.newDataOutput();
   Set<ModContainer> activeMods = FMLNetworkHandler.instance().getNetworkModList();
   dat.writeInt(activeMods.size());
   for (ModContainer mc : activeMods) {
     dat.writeUTF(mc.getModId());
   }
   dat.writeByte(FMLNetworkHandler.getCompatibilityLevel());
   return dat.toByteArray();
 }
Exemplo n.º 10
0
  public static boolean hasMod(String modid, String version) {
    for (int i = 0; i < Loader.instance().getActiveModList().size(); i++) {
      ModContainer mod = Loader.instance().getActiveModList().get(i);

      if ((mod.getModId() + mod.getVersion().replaceFirst("v", "")).matches(modid + version)) {
        return true;
      }
    }

    return false;
  }
Exemplo n.º 11
0
 public void registerGuiHandler(Object mod, IGuiHandler handler) {
   ModContainer mc = FMLCommonHandler.instance().findContainerFor(mod);
   NetworkModHandler nmh = FMLNetworkHandler.instance().findNetworkModHandler(mc);
   if (nmh == null) {
     FMLLog.log(
         Level.FINE,
         "The mod %s needs to be a @NetworkMod to register a Networked Gui Handler",
         mc.getModId());
   } else {
     serverGuiHandlers.put(mc, handler);
   }
   clientGuiHandlers.put(mc, handler);
 }
Exemplo n.º 12
0
	@EventHandler
	public void load(FMLInitializationEvent evt)
	{
		if (!Loader.isModLoaded("Railcraft"))
		{
			return;
		}
		try
		{
			String id = Block.blockRegistry.getNameForObject(MineFactoryReloadedCore.factoryDecorativeStoneBlock);
			FMLInterModComms.sendMessage("Railcraft", "balast", String.format("%s@%s", id, 8));
			FMLInterModComms.sendMessage("Railcraft", "balast", String.format("%s@%s", id, 9));
			// white sand? black sand?

			Object rockCrusher = Class.forName("mods.railcraft.api.crafting.RailcraftCraftingManager").getField("rockCrusher").get(null);
			Method createNewRecipe = Class.forName("mods.railcraft.api.crafting.IRockCrusherCraftingManager").getMethod("createNewRecipe", ItemStack.class, boolean.class, boolean.class);
			Method addOutput = Class.forName("mods.railcraft.api.crafting.IRockCrusherRecipe").getMethod("addOutput", ItemStack.class, float.class);

			Object recipe = createNewRecipe.invoke(rockCrusher, new ItemStack(MineFactoryReloadedCore.factoryDecorativeStoneBlock, 1, 10), true, false);
			addOutput.invoke(recipe, new ItemStack(MineFactoryReloadedCore.factoryDecorativeStoneBlock, 1, 2), 1.0f); // Paved Blackstone -> Cobble 

			recipe = createNewRecipe.invoke(rockCrusher, new ItemStack(MineFactoryReloadedCore.factoryDecorativeStoneBlock, 1, 11), true, false);
			addOutput.invoke(recipe, new ItemStack(MineFactoryReloadedCore.factoryDecorativeStoneBlock, 1, 3), 1.0f); // Paved Whitestone -> Cobble

			recipe = createNewRecipe.invoke(rockCrusher, new ItemStack(MineFactoryReloadedCore.factoryDecorativeStoneBlock, 1, 0), true, false);
			addOutput.invoke(recipe, new ItemStack(MineFactoryReloadedCore.factoryDecorativeStoneBlock, 1, 2), 1.0f); // Smooth Blackstone -> Cobble 

			recipe = createNewRecipe.invoke(rockCrusher, new ItemStack(MineFactoryReloadedCore.factoryDecorativeStoneBlock, 1, 1), true, false);
			addOutput.invoke(recipe, new ItemStack(MineFactoryReloadedCore.factoryDecorativeStoneBlock, 1, 3), 1.0f); // Smooth Whitestone -> Cobble

			recipe = createNewRecipe.invoke(rockCrusher, new ItemStack(MineFactoryReloadedCore.factoryDecorativeStoneBlock, 1, 2), true, false);
			addOutput.invoke(recipe, new ItemStack(MineFactoryReloadedCore.factoryDecorativeStoneBlock, 1, 8), 1.0f); // Cobble Blackstone -> Gravel + flint
			addOutput.invoke(recipe, new ItemStack(Items.flint, 1, 0), 0.05f);

			recipe = createNewRecipe.invoke(rockCrusher, new ItemStack(MineFactoryReloadedCore.factoryDecorativeStoneBlock, 1, 3), true, false);
			addOutput.invoke(recipe, new ItemStack(MineFactoryReloadedCore.factoryDecorativeStoneBlock, 1, 9), 1.0f); // Cobble Whitestone -> Gravel + flint
			addOutput.invoke(recipe, new ItemStack(Items.flint, 1, 0), 0.05f);
		}
		catch (Throwable _)
		{
			ModContainer This = FMLCommonHandler.instance().findContainerFor(this);
			FMLLog.log(This.getModId(), Level.WARN, "There was a problem loading %s.", This.getName());
			_.printStackTrace();
		}
	}
Exemplo n.º 13
0
  /**
   * Prefix the supplied name with the current mod id.
   *
   * <p>If no mod id can be determined, minecraft will be assumed. The prefix is separated with a
   * colon.
   *
   * <p>If there's already a prefix, it'll be prefixed again if the new prefix doesn't match the old
   * prefix, as used by vanilla calls to addObject.
   *
   * @param name name to prefix.
   * @return prefixed name.
   */
  private String addPrefix(String name) {
    int index = name.lastIndexOf(':');
    String oldPrefix = index == -1 ? "" : name.substring(0, index);
    String prefix;
    ModContainer mc = Loader.instance().activeModContainer();

    if (mc != null) {
      prefix = mc.getModId();
    } else // no mod container, assume minecraft
    {
      prefix = "minecraft";
    }

    if (!oldPrefix.equals(prefix)) {
      name = prefix + ":" + name;
    }

    return name;
  }
Exemplo n.º 14
0
 public static void registerGlobalEntityID(Class <? extends Entity > entityClass, String entityName, int id, int backgroundEggColour, int foregroundEggColour)
 {
     if (EntityList.classToStringMapping.containsKey(entityClass))
     {
         ModContainer activeModContainer = Loader.instance().activeModContainer();
         String modId = "unknown";
         if (activeModContainer != null)
         {
             modId = activeModContainer.getModId();
         }
         else
         {
             FMLLog.severe("There is a rogue mod failing to register entities from outside the context of mod loading. This is incredibly dangerous and should be stopped.");
         }
         FMLLog.warning("The mod %s tried to register the entity class %s which was already registered - if you wish to override default naming for FML mod entities, register it here first", modId, entityClass);
         return;
     }
     instance().validateAndClaimId(id);
     EntityList.addMapping(entityClass, entityName, id, backgroundEggColour, foregroundEggColour);
 }
Exemplo n.º 15
0
 public void loadLocalization(String localizationFile, String lang, boolean isXML) {
   URL urlResource = this.getClass().getResource(localizationFile);
   if (urlResource != null) {
     loadLocalization(urlResource, lang, isXML);
   } else {
     ModContainer activeModContainer = Loader.instance().activeModContainer();
     if (activeModContainer != null) {
       FMLLog.log(
           activeModContainer.getModId(),
           Level.SEVERE,
           "The language resource %s cannot be located on the classpath. This is a programming error.",
           localizationFile);
     } else {
       FMLLog.log(
           Level.SEVERE,
           "The language resource %s cannot be located on the classpath. This is a programming error.",
           localizationFile);
     }
   }
 }
 /**
  * Get a logger instance configured to write to the FML Log as a parent, identified by modid.
  * Handy for mod logging! Configurations can be applied through the <code>
  * config/logging.properties</code> file, specifying logging levels for your ModID. Use this!
  *
  * @return A logger
  */
 public Logger getModLog() {
   Logger log = Logger.getLogger(modContainer.getModId());
   log.setParent(FMLLog.getLogger());
   return log;
 }