Skip to content

Commit

Permalink
Add a version check mechanic to startup, it is done in a seperate thr…
Browse files Browse the repository at this point in the history
…ead 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.
  • Loading branch information
LexManos committed Dec 25, 2013
1 parent 572bc48 commit 40d02fe
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 15 deletions.
18 changes: 18 additions & 0 deletions patches/minecraft/net/minecraft/client/gui/GuiMainMenu.java.patch
Original file line number Diff line number Diff line change
@@ -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);

49 changes: 49 additions & 0 deletions src/main/java/net/minecraftforge/client/ForgeHooksClient.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
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.Map;
import java.util.Random;
import java.util.TreeSet;

import javax.imageio.ImageIO;

import net.minecraftforge.client.event.MouseEvent;
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 org.lwjgl.LWJGLException;
Expand All @@ -16,9 +24,16 @@
import org.lwjgl.opengl.GL12;
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.registry.RenderingRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
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.block.Block;
import net.minecraft.block.BlockLiquid;
Expand All @@ -31,6 +46,7 @@
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.ResourceLocation;
Expand All @@ -50,11 +66,14 @@
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.ForgeModContainer;
import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.common.ForgeVersion.Status;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.RenderBlockFluid;
import static net.minecraftforge.client.IItemRenderer.ItemRenderType.*;
import static net.minecraftforge.client.IItemRenderer.ItemRendererHelper.*;
import static net.minecraftforge.common.ForgeVersion.Status.*;

public class ForgeHooksClient
{
Expand Down Expand Up @@ -404,4 +423,34 @@ public static int getSkyBlendColour(World world, int playerX, int playerY, int p
//FluidRegistry.renderIdFluid = RenderingRegistry.getNextAvailableRenderId();
//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;

This comment has been minimized.

Copy link
@GuntherDW

GuntherDW Dec 27, 2013

Contributor

Small typo here, avalible -> available.

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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class GuiIngameForge extends GuiIngame
private ScaledResolution res = null;
private FontRenderer fontrenderer = null;
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)
{
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/net/minecraftforge/common/ForgeHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,6 @@

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
{
public final ItemStack seed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
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 float zombieBabyChance = 0.05f;
public static boolean shouldSortRecipies = false;
public static boolean shouldSortRecipies = true;
public static boolean disableVersionCheck = false;

public ForgeModContainer()
{
Expand Down Expand Up @@ -159,6 +160,10 @@ public ForgeModContainer()
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);

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())
{
config.save();
Expand Down
104 changes: 104 additions & 0 deletions src/main/java/net/minecraftforge/common/ForgeVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
*/

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
{
Expand All @@ -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.
public static final int buildVersion = 0;

private static Status status = PENDING;
private static String target = null;

public static int getMajorVersion()
{
return majorVersion;
Expand All @@ -36,9 +50,99 @@ public static int getBuildVersion()
return buildVersion;
}

public static Status getStatus()
{
return status;
}

public static String getTarget()
{
return target;
}

public static String getVersion()
{
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();
}
}

7 changes: 6 additions & 1 deletion src/main/java/net/minecraftforge/common/MinecraftForge.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.ForgeHooks.GrassEntry;
import net.minecraftforge.common.ForgeHooks.SeedEntry;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.oredict.OreDictionary;
Expand All @@ -35,6 +34,7 @@ public class MinecraftForge
public static final EventBus EVENT_BUS = new EventBus();
public static final EventBus TERRAIN_GEN_BUS = new EventBus();
public static final EventBus ORE_GEN_BUS = new EventBus();
public static final String MC_VERSION = "1.7.2";

This comment has been minimized.

Copy link
@yuuka-miya

yuuka-miya Dec 27, 2013

Shouldn't this be in net.minecraftforge.common.ForgeVersion, so you only have to update all the numberings in one place?


private static final ForgeInternalHandler INTERNAL_HANDLER = new ForgeInternalHandler();

Expand All @@ -60,6 +60,11 @@ public static void initialize()
EVENT_BUS.register(INTERNAL_HANDLER);
OreDictionary.getOreName(0);

if (!ForgeModContainer.disableVersionCheck)
{
ForgeVersion.startVersionCheck();
}

//Force these classes to be defined, Should prevent derp error hiding.
new CrashReport("ThisIsFake", new Exception("Not real"));
}
Expand Down

0 comments on commit 40d02fe

Please sign in to comment.