Add a version check mechanic to startup, it is done in a seperate thread and has a config option to compleetly disable it. This allows us to notify users of new recomended builds. Hopefully stemming the flow of outdated help request. Also adds a warning to the main screen if you are running a 'Beta' Forge. Which means a Forge for a new version of Minecraft that we have not promoted a recomended build for yet.

This commit is contained in:
Lex Manos 2013-12-25 00:35:59 -08:00
parent 572bc48a25
commit 40d02fe6c3
7 changed files with 184 additions and 15 deletions

View file

@ -0,0 +1,18 @@
--- ../src-base/minecraft/net/minecraft/client/gui/GuiMainMenu.java
+++ ../src-work/minecraft/net/minecraft/client/gui/GuiMainMenu.java
@@ -30,6 +30,7 @@
import net.minecraft.world.demo.DemoWorldServer;
import net.minecraft.world.storage.ISaveFormat;
import net.minecraft.world.storage.WorldInfo;
+import net.minecraftforge.client.ForgeHooksClient;
import org.apache.commons.io.Charsets;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -630,6 +631,7 @@
this.drawString(this.field_146289_q, brd, 2, this.field_146295_m - ( 10 + i * (this.field_146289_q.FONT_HEIGHT + 1)), 16777215);
}
}
+ ForgeHooksClient.renderMainMenu(this, field_146289_q, field_146294_l, field_146295_m);
String s1 = "Copyright Mojang AB. Do not distribute!";
this.drawString(this.field_146289_q, s1, this.field_146294_l - this.field_146289_q.getStringWidth(s1) - 2, this.field_146295_m - 10, -1);

View file

@ -1,6 +1,12 @@
package net.minecraftforge.client; package net.minecraftforge.client;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.TreeSet; import java.util.TreeSet;
@ -8,6 +14,8 @@ import javax.imageio.ImageIO;
import net.minecraftforge.client.event.MouseEvent; import net.minecraftforge.client.event.MouseEvent;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraftforge.client.event.FOVUpdateEvent; import net.minecraftforge.client.event.FOVUpdateEvent;
import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLException;
@ -16,9 +24,16 @@ import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12; import org.lwjgl.opengl.GL12;
import org.lwjgl.opengl.PixelFormat; import org.lwjgl.opengl.PixelFormat;
import com.google.common.io.ByteStreams;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.versioning.ArtifactVersion;
import cpw.mods.fml.common.versioning.DefaultArtifactVersion;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid; import net.minecraft.block.BlockLiquid;
@ -31,6 +46,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@ -50,11 +66,14 @@ import net.minecraftforge.client.event.DrawBlockHighlightEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.ForgeModContainer; import net.minecraftforge.common.ForgeModContainer;
import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.common.ForgeVersion.Status;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.RenderBlockFluid; import net.minecraftforge.fluids.RenderBlockFluid;
import static net.minecraftforge.client.IItemRenderer.ItemRenderType.*; import static net.minecraftforge.client.IItemRenderer.ItemRenderType.*;
import static net.minecraftforge.client.IItemRenderer.ItemRendererHelper.*; import static net.minecraftforge.client.IItemRenderer.ItemRendererHelper.*;
import static net.minecraftforge.common.ForgeVersion.Status.*;
public class ForgeHooksClient public class ForgeHooksClient
{ {
@ -404,4 +423,34 @@ public class ForgeHooksClient
//FluidRegistry.renderIdFluid = RenderingRegistry.getNextAvailableRenderId(); //FluidRegistry.renderIdFluid = RenderingRegistry.getNextAvailableRenderId();
//RenderingRegistry.registerBlockHandler(RenderBlockFluid.instance); //RenderingRegistry.registerBlockHandler(RenderBlockFluid.instance);
} }
public static void renderMainMenu(GuiMainMenu gui, FontRenderer font, int width, int height)
{
Status status = ForgeVersion.getStatus();
if (status == BETA || status == BETA_OUTDATED)
{
// render a warning at the top of the screen,
String line = EnumChatFormatting.RED + "WARNING:" + EnumChatFormatting.RESET + " Forge Beta,";
gui.drawString(font, line, (width - font.getStringWidth(line)) / 2, 4 + (0 * (font.FONT_HEIGHT + 1)), -1);
line = "Major issues may arise, verify before reporting.";
gui.drawString(font, line, (width - font.getStringWidth(line)) / 2, 4 + (1 * (font.FONT_HEIGHT + 1)), -1);
}
String line = null;
switch(status)
{
//case FAILED: line = " Version check failed"; break;
//case UP_TO_DATE: line = "Forge up to date"}; break;
//case AHEAD: line = "Using non-recommended Forge build, issues may arise."}; break;
case OUTDATED:
case BETA_OUTDATED: line = "New Forge version avalible: " + ForgeVersion.getTarget(); break;
default: break;
}
if (line != null)
{
// if we have a line, render it in the bottom right, above Mojang's copyright line
gui.drawString(font, line, width - font.getStringWidth(line) - 2, height - (2 * (font.FONT_HEIGHT + 1)), -1);
}
}
} }

View file

@ -81,7 +81,7 @@ public class GuiIngameForge extends GuiIngame
private ScaledResolution res = null; private ScaledResolution res = null;
private FontRenderer fontrenderer = null; private FontRenderer fontrenderer = null;
private RenderGameOverlayEvent eventParent; private RenderGameOverlayEvent eventParent;
private static final String MC_VERSION = "1.7.2"; private static final String MC_VERSION = MinecraftForge.MC_VERSION;
public GuiIngameForge(Minecraft mc) public GuiIngameForge(Minecraft mc)
{ {

View file

@ -60,18 +60,6 @@ import static net.minecraft.init.Blocks.*;
public class ForgeHooks public class ForgeHooks
{ {
static class GrassEntry extends WeightedRandom.Item
{
public final Block block;
public final int metadata;
public GrassEntry(Block block, int meta, int weight)
{
super(weight);
this.block = block;
this.metadata = meta;
}
}
static class SeedEntry extends WeightedRandom.Item static class SeedEntry extends WeightedRandom.Item
{ {
public final ItemStack seed; public final ItemStack seed;

View file

@ -54,7 +54,8 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
public static double zombieSummonBaseChance = 0.1; public static double zombieSummonBaseChance = 0.1;
public static int[] blendRanges = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32 }; public static int[] blendRanges = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32 };
public static float zombieBabyChance = 0.05f; public static float zombieBabyChance = 0.05f;
public static boolean shouldSortRecipies = false; public static boolean shouldSortRecipies = true;
public static boolean disableVersionCheck = false;
public ForgeModContainer() public ForgeModContainer()
{ {
@ -159,6 +160,10 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
prop.comment = "Set to true to enable the post initlization sorting of crafting recipes using Froge's sorter. May cause desyncing on conflicting recipies. ToDo: Set to true by default in 1.7"; prop.comment = "Set to true to enable the post initlization sorting of crafting recipes using Froge's sorter. May cause desyncing on conflicting recipies. ToDo: Set to true by default in 1.7";
shouldSortRecipies = prop.getBoolean(shouldSortRecipies); shouldSortRecipies = prop.getBoolean(shouldSortRecipies);
prop = config.get(CATEGORY_GENERAL, "disableVersionCheck", disableVersionCheck);
prop.comment = "Set to true to disable Forge's version check mechanics, Forge queries a small json file on our server for version information. For more details see the ForgeVersion class in our github.";
disableVersionCheck = prop.getBoolean(disableVersionCheck);
if (config.hasChanged()) if (config.hasChanged())
{ {
config.save(); config.save();

View file

@ -4,6 +4,17 @@
*/ */
package net.minecraftforge.common; package net.minecraftforge.common;
import static net.minecraftforge.common.ForgeVersion.Status.*;
import java.io.InputStream;
import java.net.URL;
import java.util.Map;
import com.google.common.io.ByteStreams;
import com.google.gson.Gson;
import cpw.mods.fml.common.versioning.ArtifactVersion;
import cpw.mods.fml.common.versioning.DefaultArtifactVersion;
public class ForgeVersion public class ForgeVersion
{ {
@ -16,6 +27,9 @@ public class ForgeVersion
//This number is incremented every time Jenkins builds Forge, and never reset. Should always be 0 in the repo code. //This number is incremented every time Jenkins builds Forge, and never reset. Should always be 0 in the repo code.
public static final int buildVersion = 0; public static final int buildVersion = 0;
private static Status status = PENDING;
private static String target = null;
public static int getMajorVersion() public static int getMajorVersion()
{ {
return majorVersion; return majorVersion;
@ -36,9 +50,99 @@ public class ForgeVersion
return buildVersion; return buildVersion;
} }
public static Status getStatus()
{
return status;
}
public static String getTarget()
{
return target;
}
public static String getVersion() public static String getVersion()
{ {
return String.format("%d.%d.%d.%d", majorVersion, minorVersion, revisionVersion, buildVersion); return String.format("%d.%d.%d.%d", majorVersion, minorVersion, revisionVersion, buildVersion);
} }
public static enum Status
{
PENDING,
FAILED,
UP_TO_DATE,
OUTDATED,
AHEAD,
BETA,
BETA_OUTDATED
}
public static void startVersionCheck()
{
new Thread("Forge Version Check")
{
@Override
public void run()
{
try
{
URL url = new URL("http://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json");
InputStream con = url.openStream();
String data = new String(ByteStreams.toByteArray(con));
con.close();
Map<String, Object> json = new Gson().fromJson(data, Map.class);
String homepage = (String)json.get("homepage");
Map<String, String> promos = (Map<String, String>)json.get("promos");
String rec = promos.get(MinecraftForge.MC_VERSION + "-recommended");
String lat = promos.get(MinecraftForge.MC_VERSION + "-latest");
ArtifactVersion current = new DefaultArtifactVersion(getVersion());
if (rec != null)
{
ArtifactVersion recommended = new DefaultArtifactVersion(rec);
int diff = recommended.compareTo(current);
if (diff == 0)
status = UP_TO_DATE;
else if (diff < 0)
{
status = AHEAD;
if (lat != null)
{
if (current.compareTo(new DefaultArtifactVersion(lat)) < 0)
{
status = OUTDATED;
target = lat;
}
}
}
else
{
status = OUTDATED;
target = rec;
}
}
else if (lat != null)
{
if (current.compareTo(new DefaultArtifactVersion(lat)) < 0)
{
status = BETA_OUTDATED;
target = lat;
}
else
status = BETA;
}
else
status = BETA;
}
catch (Exception e)
{
e.printStackTrace();
status = FAILED;
}
}
}.start();
}
} }

View file

@ -17,7 +17,6 @@ import net.minecraft.crash.CrashReport;
import net.minecraft.entity.monster.EntityEnderman; import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.common.ForgeHooks.GrassEntry;
import net.minecraftforge.common.ForgeHooks.SeedEntry; import net.minecraftforge.common.ForgeHooks.SeedEntry;
import net.minecraftforge.event.entity.EntityEvent; import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
@ -35,6 +34,7 @@ public class MinecraftForge
public static final EventBus EVENT_BUS = new EventBus(); public static final EventBus EVENT_BUS = new EventBus();
public static final EventBus TERRAIN_GEN_BUS = new EventBus(); public static final EventBus TERRAIN_GEN_BUS = new EventBus();
public static final EventBus ORE_GEN_BUS = new EventBus(); public static final EventBus ORE_GEN_BUS = new EventBus();
public static final String MC_VERSION = "1.7.2";
private static final ForgeInternalHandler INTERNAL_HANDLER = new ForgeInternalHandler(); private static final ForgeInternalHandler INTERNAL_HANDLER = new ForgeInternalHandler();
@ -60,6 +60,11 @@ public class MinecraftForge
EVENT_BUS.register(INTERNAL_HANDLER); EVENT_BUS.register(INTERNAL_HANDLER);
OreDictionary.getOreName(0); OreDictionary.getOreName(0);
if (!ForgeModContainer.disableVersionCheck)
{
ForgeVersion.startVersionCheck();
}
//Force these classes to be defined, Should prevent derp error hiding. //Force these classes to be defined, Should prevent derp error hiding.
new CrashReport("ThisIsFake", new Exception("Not real")); new CrashReport("ThisIsFake", new Exception("Not real"));
} }