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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • This is the last line before the crash: [ebwizardry]: Synchronising spell emitters for PixelTraveler But I have no idea what this means
    • What in particular? I barely used that mod this time around, and it's never been a problem in the past.
    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } } my entire project:https://github.com/kevin051606/DERP-Mod/tree/Derp-1.0-1.20
    • All versions of Minecraft Forge suddenly black screen even without mods (tried reinstalling original Minecraft, Java, updating drivers doesn't work)
  • Topics

×
×
  • Create New...

Important Information

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