Jump to content

Recommended Posts

Posted

How do you make an update checker? I have my mod pack uploaded now and whenever there is an update for it I want a message to show up in the chat saying there is an update for Fun Craft Mod Pack 2. How would I do that? My modpack is uploaded to MediaFire.

Posted

This forum is for questions about minecraft modding, and this question has nothing to do with that. So this is not the right place for that question!

Don't be afraid to ask question when modding, there are no stupid question! Unless you don't know java then all your questions are stupid!

Posted

First to Mecblader this is about modding. You CAN NOT do this any more but if you make changes in the code where on startup or world launching you check for an update people can manuly install that update which you made it gives notifications. You can not magicly do this without updating the mod.

 

And I don't know how to do this as I (like most) add things along side the update to support the newer versions of minecraft! But it can be done and some have done it (though if you can go for auto update not the notifications!)

I try not to be mean about your english (as my own isn't the best either) but sometimes I can't help myself!

If you get mad at me for this or any other reason, please look at the profile picture so you'll feel better (and pretier) than me!

Thanks.

Posted

Thank you shieldbug1. I have two questions though. For the raw text file is that just a normal .txt file or a diffrent file? And for

String version = sc.nextLine();
        if(!Reference.MOD_VERSION.equals(version))

Do I need to add something there or in the text file if I have v1.0 will it check my mod version from the code then if I change the v1.0 in the text file to v1.1 it will display the message to update?

Posted

The basic idea is to have a plain text file served from some stable URL. Since I use Github for my project's source code hosting, I would have a file in the top level directory, calling it, for example,

version

or something. So if my mod's repo were at github.com/jwosty/MyAwesomeMod , the plaintext version file would probably be at raw.githubusercontent.com/jwosty/MyAwesomeMod/master/version .

 

Here's a mix of pseudocode and actual Java code (you'll have to look up how to do the pseudocode things):

 

public class VersionChecker implements Runnable {
    public void run() {
        string latestVersion = magicMethodToDownloadURI("http://raw.githubusercontent.com/jwosty/MyAwesomeMod/master/version");
        if (!lastestVersion.equals(CommonProxy.Version) {
            magicMethodToAddClientChatMessages(CommonProxy.Modid + " is currently out of date; the latest version is " + latestVersion + ", and the currently installed version is " + CommonProxy.Version + ". Please download and install the latest version.");
        }
    }
    
    public VersionChecker() {}
}

 

It's important that it's implemented in a Runnable, because that will create its very own fancy thread when used like this:

 

@EventHandler
public void postInit(FMLPostInitializationEvent event) {
    Thread versionCheckThread = new Thread(new VersionChecker());
    versionCheckThread.start();
}

 

Haven't verified this code for compilability yet but it should probably work alright.

I like to make mods, just like you. Here's one worth checking out

Posted

Okay, I tried an actual implementation of Jwosty's suggestion and this seemed to work.

 

First I made a version checker class as a runnable (allows it to execute in own thread).

 

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.commons.io.IOUtils;

/**
* @author jabelar
*
*/
public class VersionChecker implements Runnable
{
public static boolean isLatestVersion = false;
public static String latestVersion = "";

/* (non-Javadoc)
 * @see java.lang.Runnable#run()
 */
@Override
public void run() 
{
	InputStream in = null;
	try 
	{
		in = new URL("https://raw.githubusercontent.com/jabelar/MagicBeans-1.7.10/master/src/main/java/com/blogspot/jabelarminecraft/magicbeans/version_file").openStream();
	} 
	catch 
	(MalformedURLException e) 
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	} 
	catch (IOException e) 
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

	try 
	{
		latestVersion = IOUtils.toString(in);
	} 
	catch (IOException e) 
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	} 
	finally 
	{
		IOUtils.closeQuietly(in);
	}
	System.out.println("Latest mod version = "+latestVersion);
    isLatestVersion = MagicBeans.MODVERSION.equals(latestVersion);
    System.out.println("Are you running latest version = "+isLatestVersion);
}
}

 

Then in ClientProxy class (because we want to check on client) I had this code:

	@Override
public void fmlLifeCycleEvent(FMLPostInitializationEvent event)
{
	// DEBUG
        System.out.println("on Client side");

        // do common stuff
	super.fmlLifeCycleEvent(event);

	// do client-specific stuff
	Thread versionCheckThread = new Thread(new VersionChecker(), "Version Check");
	versionCheckThread.start();
}

 

Lastly, I created a text file in my project containing just a version number on the first line and synced it with github.  I then found the URL of that text file (make sure you select the raw view) and that is what I put into the VersionChecker class above.

 

Note also that "MagicBeans" in my code above is just name of my mod's main class, you should use your own.

 

I left the catch statements as TODO, but you can put more explicit error statements.

 

diesieben07, does this meet your scrutiny?  Any problems with this?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Will it work if I upload the version textfile to mediafire? Also in the main class do I register the VersionChecker or the ClientProxy.class? From your code it looks like I have to register the ClientProxy.class then when it runs it will import the VersionChecker.class.

Posted

Will it work if I upload the version textfile to mediafire? Also in the main class do I register the VersionChecker or the ClientProxy.class? From your code it looks like I have to register the ClientProxy.class then when it runs it will import the VersionChecker.class.

 

As diesieben07 pointed out, you shouldn't really be doing the version check on the server, or at least if you want to do that you'd probably do it specifically for server.  Mostly you want to tell the client, especially in shieldbug1's attempt where he was doing it every time a player joined.

 

So I just run the thread in the client proxy, so then it is only run on client (or integrated client).

 

From your question, it sounds like maybe you're not confident in how the proxys work.  Do you need further explanation for that?

 

Anyway, if you run it in your main class, then it will be run on both sides (both client and server) and that may not be really appropriate for this purpose.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Will it work if I upload the version textfile to mediafire? Also in the main class do I register the VersionChecker or the ClientProxy.class? From your code it looks like I have to register the ClientProxy.class then when it runs it will import the VersionChecker.class.

 

As diesieben07 pointed out, you shouldn't really be doing the version check on the server, or at least if you want to do that you'd probably do it specifically for server.  Mostly you want to tell the client, especially in shieldbug1's attempt where he was doing it every time a player joined.

 

So I just run the thread in the client proxy, so then it is only run on client (or integrated client).

 

From your question, it sounds like maybe you're not confident in how the proxys work.  Do you need further explanation for that?

 

Anyway, if you run it in your main class, then it will be run on both sides (both client and server) and that may not be really appropriate for this purpose.

I see, well I have never done something like this before. I thought that because when you do things like make your own event or tool or whatever for it to work you need to register it in the main.class so forge will go and grab the code from the class file on which holds the code for the event, ect because if you don't then your code will not be ran. I thought you would have to register it in a main class or it will not be imported. Because what I thought I needed to do was first make a main.class like you would for a mod. Then from that you extend off with a new class file that checks for the update and you register it in the main.class so forge will load and run it. But it seems that I do not understand. I an making a mod pack and you choose what mods you want to use all it is is a zip file will a bunch of mods in it and you just drag and drop what ones you want to use. I also wanted to make the update checker like that to so you could choose to use it or not because if I did not do that then I would need an update checker attached to every mod and I think that would mess things up. When I create the VersionChecker and ClientProxy.class are those the only files I need or do I have to construct it like I would a mod with a main.class that contains the things for forge to load it and then just have it import it?

Posted

Of course you need a main class. How else do you plan to get forge to see it? Call the method to run you version checker in the ClientProxy class, and register the proxy in the main class. Follow a modding tutorial.

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

Posted

Okay, it is okay if you're new to modding.  Basically, in Minecraft Forge they have broken up the execution into "sides", meaning client and server.  Apparently to be more efficient, they decided they'd rather not load client classes (like rendering and keyboard input) on the server side.  So they came up with an annotation @SidedOnly which will actually prevent classes from being loaded if they're not needed on the current side.

 

However, this causes trouble for Java runtime because it will scan all your code and may find something that references something that will only be loaded on the other side and this can cause a crash.  So sometimes you need to ensure to similarly annotate the side of your class.

 

Furthermore, they understood that whole processes of loading the mod would differ for each side.  For example, you wouldn't want to register renderers on the server.  So they came up with the concept of a sided "proxy".

 

Basically, while not technically accurate you could think of the proxy as containing those parts of your main class that are loaded based on the side you're on.  People often handle the pre-init, init, post-init FML life cycle events in the proxy because there are some things (like renderers, keybindings, networking, etc.) that may differ by side.

 

Anyway, you should read up on this concept.  It can take a while to get an understanding.  But basically you take the stuff from your main class that depends on side and put that into the appropriate proxy class.

 

Back to the specific topic of a version update checker, on the client and server side you likely want different behavior on different sides -- on client you might display an actual GUI or chat message, whereas on server you might just output a console or admin interface message.  So that is why I suggested running it from the proxy.

 

I suggest reading TheGreyGhost's tutorial here: http://greyminecraftcoder.blogspot.com/2013/11/how-forge-starts-up-your-code.html

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.