Search in sources :

Example 1 with ModContainer

use of net.minecraftforge.fml.common.ModContainer in project MinecraftForge by MinecraftForge.

the class ForgeVersion method startVersionCheck.

public static void startVersionCheck() {
    new Thread("Forge Version Check") {

        @Override
        public void run() {
            if (!ForgeModContainer.getConfig().get(ForgeModContainer.VERSION_CHECK_CAT, "Global", true).getBoolean()) {
                FMLLog.log("ForgeVersionCheck", Level.INFO, "Global Forge version check system disabled, no further processing.");
                return;
            }
            for (Entry<ModContainer, URL> entry : gatherMods().entrySet()) {
                ModContainer mod = entry.getKey();
                if (ForgeModContainer.getConfig().get(ForgeModContainer.VERSION_CHECK_CAT, mod.getModId(), true).getBoolean()) {
                    process(mod, entry.getValue());
                } else {
                    FMLLog.log("ForgeVersionCheck", Level.INFO, "[%s] Skipped version check", mod.getModId());
                }
            }
        }

        private void process(ModContainer mod, URL url) {
            try {
                FMLLog.log("ForgeVersionCheck", Level.INFO, "[%s] Starting version check at %s", mod.getModId(), url.toString());
                Status status = PENDING;
                ComparableVersion target = null;
                InputStream con = url.openStream();
                String data = new String(ByteStreams.toByteArray(con), "UTF-8");
                con.close();
                FMLLog.log("ForgeVersionCheck", Level.DEBUG, "[%s] Received version check data:\n%s", mod.getModId(), data);
                @SuppressWarnings("unchecked") Map<String, Object> json = new Gson().fromJson(data, Map.class);
                @SuppressWarnings("unchecked") Map<String, String> promos = (Map<String, String>) json.get("promos");
                String display_url = (String) json.get("homepage");
                String rec = promos.get(MinecraftForge.MC_VERSION + "-recommended");
                String lat = promos.get(MinecraftForge.MC_VERSION + "-latest");
                ComparableVersion current = new ComparableVersion(mod.getVersion());
                if (rec != null) {
                    ComparableVersion recommended = new ComparableVersion(rec);
                    int diff = recommended.compareTo(current);
                    if (diff == 0)
                        status = UP_TO_DATE;
                    else if (diff < 0) {
                        status = AHEAD;
                        if (lat != null) {
                            ComparableVersion latest = new ComparableVersion(lat);
                            if (current.compareTo(latest) < 0) {
                                status = OUTDATED;
                                target = latest;
                            }
                        }
                    } else {
                        status = OUTDATED;
                        target = recommended;
                    }
                } else if (lat != null) {
                    ComparableVersion latest = new ComparableVersion(lat);
                    if (current.compareTo(latest) < 0) {
                        status = BETA_OUTDATED;
                        target = latest;
                    } else
                        status = BETA;
                } else
                    status = BETA;
                FMLLog.log("ForgeVersionCheck", Level.INFO, "[%s] Found status: %s Target: %s", mod.getModId(), status, target);
                Map<ComparableVersion, String> changes = new LinkedHashMap<ComparableVersion, String>();
                @SuppressWarnings("unchecked") Map<String, String> tmp = (Map<String, String>) json.get(MinecraftForge.MC_VERSION);
                if (tmp != null) {
                    List<ComparableVersion> ordered = new ArrayList<ComparableVersion>();
                    for (String key : tmp.keySet()) {
                        ComparableVersion ver = new ComparableVersion(key);
                        if (ver.compareTo(current) > 0 && (target == null || ver.compareTo(target) < 1)) {
                            ordered.add(ver);
                        }
                    }
                    Collections.sort(ordered);
                    for (ComparableVersion ver : ordered) {
                        changes.put(ver, tmp.get(ver.toString()));
                    }
                }
                if (mod instanceof InjectedModContainer)
                    mod = ((InjectedModContainer) mod).wrappedContainer;
                results.put(mod, new CheckResult(status, target, changes, display_url));
            } catch (Exception e) {
                FMLLog.log("ForgeVersionCheck", Level.DEBUG, e, "Failed to process update information");
                status = FAILED;
            }
        }
    }.start();
}
Also used : Status(net.minecraftforge.common.ForgeVersion.Status) InjectedModContainer(net.minecraftforge.fml.common.InjectedModContainer) ModContainer(net.minecraftforge.fml.common.ModContainer) InputStream(java.io.InputStream) InjectedModContainer(net.minecraftforge.fml.common.InjectedModContainer) Gson(com.google.gson.Gson) ComparableVersion(net.minecraftforge.fml.common.versioning.ComparableVersion) URL(java.net.URL) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) List(java.util.List) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with ModContainer

use of net.minecraftforge.fml.common.ModContainer in project MinecraftForge by MinecraftForge.

the class FluidRegistry method enableUniversalBucket.

/**
     * Enables the universal bucket in forge.
     * Has to be called before pre-initialization.
     * Actually just call it statically in your mod class.
     */
public static void enableUniversalBucket() {
    if (Loader.instance().hasReachedState(LoaderState.PREINITIALIZATION)) {
        ModContainer modContainer = Loader.instance().activeModContainer();
        String modContainerName = modContainer == null ? null : modContainer.getName();
        FMLLog.getLogger().log(Level.ERROR, "Trying to activate the universal filled bucket too late. Call it statically in your Mods class. Mod: {}", modContainerName);
    } else {
        universalBucketEnabled = true;
    }
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 3 with ModContainer

use of net.minecraftforge.fml.common.ModContainer in project MinecraftForge by MinecraftForge.

the class ForgeChunkManager method requestTicket.

/**
     * Request a chunkloading ticket of the appropriate type for the supplied mod
     *
     * @param mod The mod requesting a ticket
     * @param world The world in which it is requesting the ticket
     * @param type The type of ticket
     * @return A ticket with which to register chunks for loading, or null if no further tickets are available
     */
@Nullable
public static Ticket requestTicket(Object mod, World world, Type type) {
    ModContainer container = getContainer(mod);
    if (container == null) {
        FMLLog.log(Level.ERROR, "Failed to locate the container for mod instance %s (%s : %x)", mod, mod.getClass().getName(), System.identityHashCode(mod));
        return null;
    }
    String modId = container.getModId();
    if (!callbacks.containsKey(modId)) {
        FMLLog.severe("The mod %s has attempted to request a ticket without a listener in place", modId);
        throw new RuntimeException("Invalid ticket request");
    }
    int allowedCount = getMaxTicketLengthFor(modId);
    if (tickets.get(world).get(modId).size() >= allowedCount) {
        if (!warnedMods.contains(modId)) {
            FMLLog.info("The mod %s has attempted to allocate a chunkloading ticket beyond it's currently allocated maximum : %d", modId, allowedCount);
            warnedMods.add(modId);
        }
        return null;
    }
    Ticket ticket = new Ticket(modId, type, world);
    tickets.get(world).put(modId, ticket);
    return ticket;
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer) Nullable(javax.annotation.Nullable)

Example 4 with ModContainer

use of net.minecraftforge.fml.common.ModContainer in project MinecraftForge by MinecraftForge.

the class ForgeChunkManager method addConfigProperty.

public static void addConfigProperty(Object mod, String propertyName, String value, Property.Type type) {
    ModContainer container = getContainer(mod);
    if (container != null) {
        ConfigCategory cat = config.getCategory(container.getModId());
        Property prop = new Property(propertyName, value, type).setLanguageKey("forge.configgui." + propertyName);
        if (type == Property.Type.INTEGER) {
            prop.setMinValue(0);
        }
        cat.put(propertyName, prop);
    }
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer) ConfigCategory(net.minecraftforge.common.config.ConfigCategory) Property(net.minecraftforge.common.config.Property)

Example 5 with ModContainer

use of net.minecraftforge.fml.common.ModContainer in project MinecraftForge by MinecraftForge.

the class FMLClientHandler method beginMinecraftLoading.

/**
     * Called to start the whole game off
     *
     * @param minecraft The minecraft instance being launched
     * @param resourcePackList The resource pack list we will populate with mods
     * @param resourceManager The resource manager
     */
@SuppressWarnings("unchecked")
public void beginMinecraftLoading(Minecraft minecraft, List<IResourcePack> resourcePackList, IReloadableResourceManager resourceManager, MetadataSerializer metaSerializer) {
    detectOptifine();
    SplashProgress.start();
    client = minecraft;
    this.resourcePackList = resourcePackList;
    this.metaSerializer = metaSerializer;
    this.resourcePackMap = Maps.newHashMap();
    if (minecraft.isDemo()) {
        FMLLog.severe("DEMO MODE DETECTED, FML will not work. Finishing now.");
        haltGame("FML will not run in demo mode", new RuntimeException());
        return;
    }
    List<String> injectedModContainers = FMLCommonHandler.instance().beginLoading(this);
    try {
        Loader.instance().loadMods(injectedModContainers);
    } catch (WrongMinecraftVersionException wrong) {
        wrongMC = wrong;
    } catch (DuplicateModsFoundException dupes) {
        dupesFound = dupes;
    } catch (Java8VersionException j8mods) {
        j8onlymods = j8mods;
    } catch (MissingModsException missing) {
        modsMissing = missing;
    } catch (ModSortingException sorting) {
        modSorting = sorting;
    } catch (CustomModLoadingErrorDisplayException custom) {
        FMLLog.log(Level.ERROR, custom, "A custom exception was thrown by a mod, the game will now halt");
        customError = custom;
    } catch (MultipleModsErrored multiple) {
        multipleModsErrored = multiple;
    } catch (LoaderException le) {
        haltGame("There was a severe problem during mod loading that has caused the game to fail", le);
        return;
    } finally {
        client.refreshResources();
    }
    try {
        Loader.instance().preinitializeMods();
    } catch (CustomModLoadingErrorDisplayException custom) {
        FMLLog.log(Level.ERROR, custom, "A custom exception was thrown by a mod, the game will now halt");
        customError = custom;
    } catch (LoaderException le) {
        haltGame("There was a severe problem during mod loading that has caused the game to fail", le);
        return;
    }
    Map<String, Map<String, String>> sharedModList = (Map<String, Map<String, String>>) Launch.blackboard.get("modList");
    if (sharedModList == null) {
        sharedModList = Maps.newHashMap();
        Launch.blackboard.put("modList", sharedModList);
    }
    for (ModContainer mc : Loader.instance().getActiveModList()) {
        Map<String, String> sharedModDescriptor = mc.getSharedModDescriptor();
        if (sharedModDescriptor != null) {
            String sharedModId = "fml:" + mc.getModId();
            sharedModList.put(sharedModId, sharedModDescriptor);
        }
    }
}
Also used : MultipleModsErrored(net.minecraftforge.fml.common.MultipleModsErrored) Java8VersionException(net.minecraftforge.fml.common.Java8VersionException) ForgeModContainer(net.minecraftforge.common.ForgeModContainer) ModContainer(net.minecraftforge.fml.common.ModContainer) DummyModContainer(net.minecraftforge.fml.common.DummyModContainer) DuplicateModsFoundException(net.minecraftforge.fml.common.DuplicateModsFoundException) LoaderException(net.minecraftforge.fml.common.LoaderException) ModSortingException(net.minecraftforge.fml.common.toposort.ModSortingException) WrongMinecraftVersionException(net.minecraftforge.fml.common.WrongMinecraftVersionException) MissingModsException(net.minecraftforge.fml.common.MissingModsException) Map(java.util.Map) BiMap(com.google.common.collect.BiMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashBiMap(com.google.common.collect.HashBiMap)

Aggregations

ModContainer (net.minecraftforge.fml.common.ModContainer)34 ResourceLocation (net.minecraft.util.ResourceLocation)4 DummyModContainer (net.minecraftforge.fml.common.DummyModContainer)4 LoaderException (net.minecraftforge.fml.common.LoaderException)4 Nullable (javax.annotation.Nullable)3 ForgeModContainer (net.minecraftforge.common.ForgeModContainer)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 JsonObject (com.google.gson.JsonObject)2 File (java.io.File)2 InputStream (java.io.InputStream)2 List (java.util.List)2 Map (java.util.Map)2 BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1 SetMultimap (com.google.common.collect.SetMultimap)1 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 RCConfig (ivorius.reccomplex.RCConfig)1