Jump to content

Version checker?


jordsta95

Recommended Posts

Hey there, I had a look at Botania and COFHcore's version checker, and didn't really understand it, but then I found this http://jabelarminecraft.blogspot.co.uk/p/minecraft-forge-1721710-making-mod.html

 

However, I followed that tutorial, and I still can't get it to work. Any ideas why?

 

Here's the code:

 

version checker class:

 

 

package com.aa.mod.updateChecker;

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

import org.apache.commons.io.IOUtils;

import com.aa.mod.Reference;

public class CheckVersion implements Runnable
{
    private static boolean isLatestVersion = false;
    private static String latestVersion = "";

    @Override
    public void run() 
    {
        InputStream in = null;
        try 
        {
            in = new URL("https://raw.githubusercontent.com/jordsta95/ArcaneArteries/master/aaversion.txt").openStream();
        } 
        catch 
        (MalformedURLException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        catch (IOException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        try 
        {
            latestVersion = IOUtils.readLines(in).get(0);
        } 
        catch (IOException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        finally 
        {
            IOUtils.closeQuietly(in);
        }
        System.out.println("Latest version of Arcane Arteries is = "+latestVersion);
        isLatestVersion = Reference.VERSION.equals(latestVersion);
    }
    
    public boolean isLatestVersion()
    {
     return isLatestVersion;
    }
    
    public String getLatestVersion()
    {
     return latestVersion;
    }
}

 

 

 

Here's the client proxy

 

 

package com.aa.mod.proxies;

import net.minecraft.event.ClickEvent;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatStyle;

import com.aa.mod.Main;
import com.aa.mod.updateChecker.CheckVersion;
import com.aa.mod.updateChecker.VersionChecker;

import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;


public class ClientProxy extends CommonProxy {

    @EventHandler
    public void Init(FMLInitializationEvent event){

    	

    	Main.versionChecker = new CheckVersion();
    	Thread versionCheckThread = new Thread(Main.versionChecker, "Version Check");
    	versionCheckThread.start();
    	
    	
    	
    }



}

 

 

 

And the 2 lines in the main file are:

public static CheckVersion versionChecker;
public static boolean haveWarnedVersionOutOfDate = false;

 

 

I've never even thought about this before, and I learn most of what I do through tutorials (even if they are outdated, as long as it is similar, I can understand it) but that's the only tutorial I could find on version checkers, and I don't know what I am doing wrong.

 

Thanks

-Jordan

 

 

Why bother?

Link to comment
Share on other sites

Is the Init method in ClientProxy called?

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Is the Init method in ClientProxy called?

 

Is that not what the "public static CheckVersion versionChecker;" does?

As I said, I followed the example I linked to the tee, and it never mentioned anything about calling the Init, or anything.

 

I will admit, that tutorial was pretty crap at explaining what everything does and how it works, which is why I came here. Because it doesn't work, and there is no troubleshooting, or reasons why it may not work.

Why bother?

Link to comment
Share on other sites

Hey, I'm the author of the tutorial.

 

I admit it is prorbaly a bit hard to follow because it assumes you're comfortable with Java multi-threading, file I/O, and modding proxy stuff. I'll see if there is a way to link to more info on each topic for those who need it.

 

The first question is: what do you mean it isn't working? Do you mean it never prints anything to the console at all? Or do you mean it doesn't find correct version from your URL? Or do you mean it isn't displaying a chat message?

 

I'm interested actually in larsgerrit's comment. Can you post the rest of how you set up your client proxy? For proxy to work you need to have the @Mod annotation in your main class reference it, and you also need to handle the post-init event in your main class and that should point to the related proxy method. So it would help if you could post that.

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

Link to comment
Share on other sites

Here's the only things I have in the main class that talk about proxies:

@Mod(modid = Reference.MODID, version = Reference.VERSION)
public class Main {

@SidedProxy(clientSide = Reference.CLIENT_PROXY, serverSide = Reference.COMMON_PROXY)
public static CommonProxy proxy;

public static Configuration config;
public static Logger logger;
@Mod.Instance(Reference.MODID)
public static Main instance;

public static CheckVersion versionChecker;
public static boolean haveWarnedVersionOutOfDate = false;

 

As for it not working...

No console message, no message when you log in; not working As for getting the version number, I can only assume it finds that, as that seemed pretty simple.

 

 

And RealMcrafter, I tried it in the Init, not PostInit, just to see if that was the issue. I tried it there, and it didn't work.

Why bother?

Link to comment
Share on other sites

The run() method has a console statement: System.out.println("Latest mod version = "+latestVersion);

 

That should print out no matter whether your version is old or up to date. It may not print out if you get one of the exceptions in that method, but in that case you should also see some console exception output.

 

So if you're really not seeing the "Latest mod version =" console output I think that implies that the run() method isn't being called.

 

I suggest you add additional console statements to trace the execution. I'd add a console statement in the version checking class constructor to prove it is getting constructed, I'd add one in the client proxy method to prove it is getting called.

 

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

Link to comment
Share on other sites

The only log stuff I get that contains anything to do with versions and my mod is:

 

 

[17:46:50] [Client thread/TRACE] [arcanearteries/arcanearteries]: Sending event FMLConstructionEvent to mod arcanearteries

[17:46:50] [Client thread/TRACE] [FML/arcanearteries]: Mod arcanearteries is using network checker : Accepting version 3

[17:46:50] [Client thread/TRACE] [FML/arcanearteries]: Testing mod arcanearteries to verify it accepts its own version in a remote connection

[17:46:50] [Client thread/TRACE] [FML/arcanearteries]: The mod arcanearteries accepts its own version (3)

[17:46:50] [Client thread/DEBUG] [FML/arcanearteries]: Attempting to inject @SidedProxy classes into arcanearteries

 

 

 

And that is obviously not it.

 

So, I added:

public void run(){

System.out.println("Client Proxy Loaded");

}

To the client proxy, just as a test. But it doesn't print anything... So I would assume it is that, however, I don't know what it wouldn't get called.

 

As I have the same proxy calling thing as I have seen in dozens of other places:

@SidedProxy(clientSide = Reference.CLIENT_PROXY, serverSide = Reference.COMMON_PROXY)

public static CommonProxy proxy;

with the correct folder structure in Reference for them:

public static final String CLIENT_PROXY = "com.aa.mod.proxies.ClientProxy";

public static final String COMMON_PROXY = "com.aa.mod.proxies.CommonProxy";

 

I have never had to use the client proxy before, so I never knew about this not working. But I don't get why it doesn't work.

Why bother?

Link to comment
Share on other sites

Does your Reference.CLIENT_PROXY point to the right class? Maybe it is accidentally pointing to your common proxy or something.

 

The way the client proxy usually works:

1) You annotate using @SidedProxy to point to path to the class for your client and common proxy. You have that, although you should check that it's referencing the right classes.

2) You instantiate a proxy field using the common proxy. You already did that properly.

3) Your main class handles each FMLInit, FMLPreInit, etc. and calls the method in your proxy (it will decide to call client proxy or common proxy depending on mode the program is running in) that handles those same events.

4) Your client proxy extends common proxy (you did that already) and implements @Override methods for any place the client needs to do something different/additional to client proxy.

 

I think you're close, but for some reason your client proxy isn't going so the thread isn't starting...

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

Link to comment
Share on other sites

It's probably easier to link the full thing, because it may be something unrelated: https://github.com/ThisIsASuperAwesomeAccount/AMod/tree/master/main/java/com/aa/mod

 

Ignore the fact there's two separate version checker thingies (I was trying to get yours to work, so that I could figure out how to get the other to work -- If that makes sense)

 

Why bother?

Link to comment
Share on other sites

Okay, you're not using the proxies properly. Here's what you need to do.

 

Create methods for the pre-init, init and post-init in the common proxy. So your common proxy should look like this:

 

 

public class CommonProxy {

   

    public void preInit(FMLPreInitializationEvent event){

        //Config

        config = new Configuration(event.getSuggestedConfigurationFile());

        logger = event.getModLog();

        MinecraftForge.EVENT_BUS.register(this);

        ConfigFile.INSTANCE.syncConfig();

    }

   

    public void init(FMLInitializationEvent event){

        //Recipes

        recipeRegist.Register();

    }

   

    public void postInit(FMLPostInitializationEvent event){

        //Thaumcraft Shit

        if(Loader.isModLoaded("Thaumcraft")){

            thaumRegist.Register(event);

        }

    }

}

 

 

Then in your Main class, you should just call the proxy method for each of these events, like this:

 

 

    @EventHandler

    public void preInit(FMLPreInitializationEvent event){

        proxy.preInit(event);

    }

   

    @EventHandler

    public void init(FMLInitializationEvent event){

        proxy.init(event);

    }

   

    @EventHandler

    public void postInit(FMLPostInitializationEvent event){

        proxy.postInit(event);

    }

 

 

 

Then your client proxy should @Override any of these methods where you need to do something additional on client side by calling super method then do anything special for client side, like this:

 

 

public class ClientProxy extends CommonProxy {

   

    @Override

    public void postInit(FMLPostInitializationEvent event){

        super.postInit(event);

    Main.versionChecker = new CheckVersion();

    Thread versionCheckThread = new Thread(Main.versionChecker, "Version Check");

    versionCheckThread.start();

    }

}

 

 

 

Note also that you should only have the @EventHandler annotation on the methods in the Main class. Then those methods simply call the methods in the proxy. Make sense?

 

It is important to get a good understanding of this in order to do effective modding.

 

 

 

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

Link to comment
Share on other sites

Okay, you're not using the proxies properly. Here's what you need to do.

 

Create methods for the pre-init, init and post-init in the common proxy. So your common proxy should look like this:

 

 

public class CommonProxy {

   

    public void preInit(FMLPreInitializationEvent event){

        //Config

        config = new Configuration(event.getSuggestedConfigurationFile());

        logger = event.getModLog();

        MinecraftForge.EVENT_BUS.register(this);

        ConfigFile.INSTANCE.syncConfig();

    }

   

    public void init(FMLInitializationEvent event){

        //Recipes

        recipeRegist.Register();

    }

   

    public void postInit(FMLPostInitializationEvent event){

        //Thaumcraft Shit

        if(Loader.isModLoaded("Thaumcraft")){

            thaumRegist.Register(event);

        }

    }

}

 

 

Then in your Main class, you should just call the proxy method for each of these events, like this:

 

 

    @EventHandler

    public void preInit(FMLPreInitializationEvent event){

        proxy.preInit(event);

    }

   

    @EventHandler

    public void init(FMLInitializationEvent event){

        proxy.init(event);

    }

   

    @EventHandler

    public void postInit(FMLPostInitializationEvent event){

        proxy.postInit(event);

    }

 

 

 

Then your client proxy should @Override any of these methods where you need to do something additional on client side by calling super method then do anything special for client side, like this:

 

 

public class ClientProxy extends CommonProxy {

   

    @Override

    public void postInit(FMLPostInitializationEvent event){

        super.postInit(event);

    Main.versionChecker = new CheckVersion();

    Thread versionCheckThread = new Thread(Main.versionChecker, "Version Check");

    versionCheckThread.start();

    }

}

 

 

 

Note also that you should only have the @EventHandler annotation on the methods in the Main class. Then those methods simply call the methods in the proxy. Make sense?

 

It is important to get a good understanding of this in order to do effective modding.

 

I did as you said here, everything still works as it did before... and that includes the update checker not working... It prints to the Log, but not in game

Why bother?

Link to comment
Share on other sites

So now the log shows it printing out "Latest version is ..."? That is better than before, right? Does it give the right version as listed on your URL that you pointed to?

 

For it printing a message in the game, the problem would be that your PlayerTick event isn't firing any more. That is because the registration of on the event bus refers to "this" but since it is in the CommonProxy it doesn't see the methods with the @SubscribeEvent.

 

So you need to move your @SubscribeEvent methods from your Main class to your CommonProxy.

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

Link to comment
Share on other sites

Alright, so this is in the client proxy:

 

@Override

    public void postInit(FMLPostInitializationEvent event){

        super.postInit(event);

      Main.versionChecker = new CheckVersion();

      Thread versionCheckThread = new Thread(Main.versionChecker, "Version Check");

      versionCheckThread.start();

    }

 

 

    @SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)

public void onEvent(PlayerTickEvent event1)

{

 

    if (!Main.haveWarnedVersionOutOfDate && event1.player.worldObj.isRemote

          && !Main.versionChecker.isLatestVersion())

    {

        ClickEvent versionCheckChatClickEvent = new ClickEvent(ClickEvent.Action.OPEN_URL,

              "http://jabelarminecraft.blogspot.com");

        ChatStyle clickableChatStyle = new ChatStyle().setChatClickEvent(versionCheckChatClickEvent);

        ChatComponentText versionWarningChatComponent =

              new ChatComponentText("Your Magic Beans Mod is not latest version!  Click here to update.");

        versionWarningChatComponent.setChatStyle(clickableChatStyle);

        event1.player.addChatMessage(versionWarningChatComponent);

        Main.haveWarnedVersionOutOfDate = true;

    }

}

 

However, it still doesn't notify (it gets the version number "4" from the URL, and I have the version number set to 3, to test.) So it should notify now, but it doesn't :/

Why bother?

Link to comment
Share on other sites

I think I said to put it in your CommonProxy not your ClientProxy. The point is that when you registered the event handler you referred to "this" so that means you need to have the @SubscribeEvent method in the same class that you register the event handler, which I believe in your case is the CommonProxy.

 

Anyway, the key point is that wherever you register the event handler you need to reference the proper class that contains the event handling method.

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

Link to comment
Share on other sites

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi! If you have your forge installation file not in the system disc on PC (D, E etc.), drag it to disk C and try to start again. In my case it solved the problem.
    • KILAT77 : Waspada Situs Scam dengan Withdraw Yang Tidak Dibayar Di era digital saat ini, banyak orang yang mencari keberuntungan melalui situs perjudian online. Namun, dibalik gemerlap janji-janji manis kemenangan, ada bahaya yang mengintai. Salah satu situs yang patut diwaspadai adalah KILAT77. Situs ini mendapat reputasi buruk karena banyak laporan dari pengguna yang mengklaim bahwa mereka tidak bisa menarik dana kemenangan mereka. Dalam artikel ini, kita akan membahas mengapa ROTER88 dianggap sebagai situs scam dan bagaimana Anda bisa melindungi diri dari penipuan serupa. Pengalaman Pengguna: Penarikan Tidak Dibayar Beberapa pengguna telah melaporkan pengalaman buruk mereka dengan KILAT77. Mereka mengaku bahwa setelah memenangkan sejumlah uang dan mencoba menariknya, proses penarikan mereka ditolak tanpa alasan yang jelas. Bahkan, beberapa pengguna melaporkan bahwa akun mereka tiba-tiba diblokir setelah mencoba melakukan penarikan, sehingga mereka kehilangan akses ke dana mereka sama sekali.
    • It is a dupe mod issue Remove Rubidium - you are already using Embeddium which is a fork of Rubidium
    • I made a block entity in forge 1.20.1, I want to prevent hopper from taking input slot item, i tried to override the extractItem method, it prevented hopper from taking input slot item, but the player also unable to take/change the item in input slot unless the slot is empty. public class FluidSeparatorBlockEntity extends BlockEntity implements MenuProvider { private static final int INPUT_SLOT = 0; private final CustomItemHandler itemHandler = new CustomItemHandler(3){ @Override protected void onContentsChanged(int slot) { setChanged(); } @Override public boolean isItemValid(int slot, @NotNull ItemStack stack) { return slot == INPUT_SLOT; } @Override public @NotNull ItemStack extractItem(int slot, int amount, boolean simulate) { if (slot == INPUT_SLOT) { return ItemStack.EMPTY; } return super.extractItem(slot, amount, simulate); } }; private LazyOptional<IItemHandler> lazyItemHandler = LazyOptional.empty(); protected final ContainerData data; private int progress = 0; private int maxProgress = 78; public FluidSeparatorBlockEntity(BlockPos pPos, BlockState pBlockState) { super(ModBlockEntities.FLUID_SEPARATOR_BE.get(), pPos, pBlockState); this.data = new ContainerData() { @Override public int get(int pIndex) { return switch (pIndex) { case 0 -> FluidSeparatorBlockEntity.this.progress; case 1, 2 -> FluidSeparatorBlockEntity.this.maxProgress; default -> 0; }; } @Override public void set(int pIndex, int pValue) { switch (pIndex) { case 0 -> FluidSeparatorBlockEntity.this.progress = pValue; case 1, 2 -> FluidSeparatorBlockEntity.this.maxProgress = pValue; } } @Override public int getCount() { return 3; } }; } @Override public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { if(cap == ForgeCapabilities.ITEM_HANDLER) { return lazyItemHandler.cast(); } return super.getCapability(cap, side); } @Override public void onLoad() { super.onLoad(); lazyItemHandler = LazyOptional.of(() -> itemHandler); } @Override public void invalidateCaps() { super.invalidateCaps(); lazyItemHandler.invalidate(); } public void drops() { SimpleContainer inventory = new SimpleContainer(itemHandler.getSlots()); for(int i = 0; i < itemHandler.getSlots(); i++) { inventory.setItem(i, itemHandler.getStackInSlot(i)); } Containers.dropContents(this.level, this.worldPosition, inventory); } @Override public Component getDisplayName() { return Component.translatable("block.chemmaster.fluid_separator"); } @Nullable @Override public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) { return new FluidSeparatorMenu(pContainerId, pPlayerInventory, this, this.data); } @Override protected void saveAdditional(CompoundTag pTag) { pTag.put("inventory", itemHandler.serializeNBT()); pTag.putInt("fluid_separator.progress", progress); super.saveAdditional(pTag); } @Override public void load(CompoundTag pTag) { super.load(pTag); itemHandler.deserializeNBT(pTag.getCompound("inventory")); progress = pTag.getInt("fluid_separator.progress"); } public void tick(Level pLevel, BlockPos pPos, BlockState pState) { ItemStack inputStack = this.itemHandler.getStackInSlot(INPUT_SLOT); if (inputStack.getCount() < 2) { resetProgress(); return; } if(hasRecipe()) { increaseCraftingProgress(); setChanged(pLevel, pPos, pState); if(hasProgressFinished()) { craftItem(); resetProgress(); } } else { resetProgress(); } } private void resetProgress() { progress = 0; } private void craftItem() { Optional<FluidSeparatingRecipe> recipe = getCurrentRecipe(); if (recipe.isPresent()) { List<ItemStack> results = recipe.get().getOutputs(); ItemStack inputStack = this.itemHandler.getStackInSlot(INPUT_SLOT); if (inputStack.getCount() < 2) { // If there are not enough items, do not proceed with crafting return; } // Extract the input item from the input slot this.itemHandler.internalExtractItem(INPUT_SLOT, 2, false); // Loop through each result item and find suitable output slots for (ItemStack result : results) { int outputSlot = findSuitableOutputSlot(result); if (outputSlot != -1) { this.itemHandler.setStackInSlot(outputSlot, new ItemStack(result.getItem(), this.itemHandler.getStackInSlot(outputSlot).getCount() + result.getCount())); } else { // Handle the case where no suitable output slot is found // This can be logging an error, throwing an exception, or any other handling logic System.err.println("No suitable output slot found for item: " + result); } } } } private int findSuitableOutputSlot(ItemStack result) { // Implement logic to find a suitable output slot for the given result // Return the slot index or -1 if no suitable slot is found for (int i = 0; i < this.itemHandler.getSlots(); i++) { // Ensure we do not place the output item in the input slot if (i == INPUT_SLOT) { continue; } ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || (stackInSlot.getItem() == result.getItem() && stackInSlot.getCount() + result.getCount() <= stackInSlot.getMaxStackSize())) { return i; } } return -1; } private boolean hasRecipe() { Optional<FluidSeparatingRecipe> recipe = getCurrentRecipe(); if (recipe.isEmpty()) { return false; } List<ItemStack> results = recipe.get().getOutputs(); for (ItemStack result : results) { if (!canInsertAmountIntoOutputSlot(result) || !canInsertItemIntoOutputSlot(result.getItem())) { return false; } } return true; } private Optional<FluidSeparatingRecipe> getCurrentRecipe(){ SimpleContainer inventory = new SimpleContainer(this.itemHandler.getSlots()); for (int i = 0; i < itemHandler.getSlots(); i++) { inventory.setItem(i, this.itemHandler.getStackInSlot(i)); } return this.level.getRecipeManager().getRecipeFor(FluidSeparatingRecipe.Type.INSTANCE, inventory, level); } private boolean canInsertAmountIntoOutputSlot(ItemStack result) { for (int i = 1; i < this.itemHandler.getSlots(); i++) { ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || (stackInSlot.getItem() == result.getItem() && stackInSlot.getCount() + result.getCount() <= stackInSlot.getMaxStackSize())) { return true; } } return false; } private boolean canInsertItemIntoOutputSlot(Item item) { for (int i = 1; i < this.itemHandler.getSlots(); i++) { ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || stackInSlot.getItem() == item) { return true; } } return false; } private boolean hasProgressFinished() { return progress >= maxProgress; } private void increaseCraftingProgress() { progress++; } }  
  • Topics

×
×
  • Create New...

Important Information

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