Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[1.11] Achievement will not be given to player

Featured Replies

Posted

Hello Everyone,

 

I have been working on a small mod lately but ran into a problem, I can not seem to give my achievement to the player.

 

What the problem is in details:

I want to give the player an achievement when they craft a specific item. I got it to the point where everything works except giving the player the achievement, and it does work when I use a vanilla achievement.

 

What I do know:

The Achievement is displayed on the achievement page. The code to trigger the achievement is supposed to work, I have have it output a line into the console which triggers and when I change it to a vanilla achievement it works.

 

Main Class

Spoiler

@Mod(modid = Reference.MODID, name = Reference.NAME, useMetadata = Reference.USEMETA)
public class OmniTools {
	
	@SidedProxy(serverSide = Reference.COMMONPROXY, clientSide = Reference.CLIENTPROXY)
	public static CommonProxy proxy;
	
	@Instance
	public static OmniTools instance;
	
	public static Logger logger;
	
	@EventHandler
	public void preInit(FMLPreInitializationEvent event){
		logger = event.getModLog();
		proxy.preInit(event);
		AchievementInit.Achievements();
	}

	@EventHandler
	public void init(FMLInitializationEvent event){
		proxy.init(event);
		RecipeManager.registerRecipes();
		//AchievementInit.Achievements();
		FMLCommonHandler.instance().bus().register(new CraftingHandler());
	}
	
	@EventHandler
	public void postInit(FMLPostInitializationEvent event){
		proxy.postInit(event);
	}
}

 

 

Achievement Init

Spoiler

package com.jebbuh.omnitools.init;

import net.minecraft.stats.Achievement;
import net.minecraft.stats.AchievementList;

public class AchievementInit {
	
	public static Achievement BUILD_WOOD_OMNITOOL;
	public static Achievement BUILD_STONE_OMNITOOL;
	public static Achievement BUILD_IRON_OMNITOOL;
	public static Achievement BUILD_DIAMOND_OMNITOOL;
	
	public static void Achievements(){
		Achievement BUILD_WOOD_OMNITOOL = new Achievement("achievement.buildWoodOmnitool", "buildWoodOmnitool", 3, 2, OmniItems.woodOmnitool, AchievementList.OPEN_INVENTORY).registerStat();
		AchievementList.ACHIEVEMENTS.add(BUILD_WOOD_OMNITOOL);
		Achievement BUILD_STONE_OMNITOOL = new Achievement("achievement.buildStoneOmnitool", "buildStoneOmnitool", 8, 2, OmniItems.stoneOmnitool, AchievementList.BUILD_BETTER_PICKAXE);
		AchievementList.ACHIEVEMENTS.add(BUILD_STONE_OMNITOOL);
		Achievement BUILD_IRON_OMNITOOL = new Achievement("achievement.buildIronOmnitool", "buildIronOmnitool", 0, 3, OmniItems.ironOmnitool, AchievementList.ACQUIRE_IRON);
		AchievementList.ACHIEVEMENTS.add(BUILD_IRON_OMNITOOL);
		Achievement BUILD_DIAMOND_OMNITOOL = new Achievement("achievement.buildDiamondOmnitool", "buildDiamondOmnitool", -3, 2, OmniItems.diamondOmnitool, AchievementList.DIAMONDS).setSpecial();
		AchievementList.ACHIEVEMENTS.add(BUILD_DIAMOND_OMNITOOL);
	}
}

 

 

Crafting Handler

Spoiler

package com.jebbuh.omnitools.handlers;

import com.jebbuh.omnitools.init.AchievementInit;
import com.jebbuh.omnitools.init.OmniItems;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.Achievement;
import net.minecraft.stats.AchievementList;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent.ItemCraftedEvent;

public class CraftingHandler {
	
	@SubscribeEvent
	public void itemCraftEvent(ItemCraftedEvent e){
		if(e.crafting.getItem().equals((Item)OmniItems.woodOmnitool)){
			e.player.addStat(AchievementInit.BUILD_WOOD_OMNITOOL);
			System.out.println("crafted");
		}
	}
}

 

 

Any help is really appreciated!

Edited by Jebbuh

  • Author
1 hour ago, diesieben07 said:

Don't manually add things into the AchievementList.

Oops, I removed that and just added .registerStat() at the end. But this does not fix the issue

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.