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();
}
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;
}
}
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;
}
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);
}
}
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);
}
}
}
Aggregations