Jump to content

GuiConfig Not working 1.12.2


Discult

Recommended Posts

Can anyone Help me i cant figure out why my gui config wont work when i click on mods and select my mod. Here is the code of anyone is interested.

Config Handler:

package com.saoteam.swordartonline.config;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.saoteam.swordartonline.main.Reference;

import net.minecraft.client.resources.I18n;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class ConfigHandler 
{
	private static Configuration config = null;
	
	public static final String CATEGORY_GAME = "game";
	
	public static int mobQuality;
	
	public static void preInit()
	{
		File configFile = new File(Loader.instance().getConfigDir(), "SAOMod.config");
		config = new Configuration(configFile);
		syncFromFiles();
	}
	
	public static Configuration getConfig()
	{
		return config;
	}
	
	public static void clientPreInit()
	{
		MinecraftForge.EVENT_BUS.register(new ConfigEventHandler());
	}
	
	public static void syncFromFiles()
	{
		syncConfig(true, true);
	}
	
	public static void syncFromGUI()
	{
		syncConfig(false, true);
	}
	
	public static void syncFromFields()
	{
		syncConfig(false, false);
	}
	
	private static void syncConfig(boolean loadFromConfigFIle, boolean readFieldsFromConfig)
	{
		if(loadFromConfigFIle) config.load();
		
		Property propertyMobQuality = config.get(CATEGORY_GAME, "mob_quality", 1);
		propertyMobQuality.setLanguageKey("gui.config.game.mob_quality");
		propertyMobQuality.setComment(I18n.format("gui.config.game.mob_quality.comment"));
		propertyMobQuality.setMinValue(0);
		propertyMobQuality.setMaxValue(2);
		
		List<String> propertyOrderGame = new ArrayList<String>();
		propertyOrderGame.add(propertyMobQuality.getName());
		config.setCategoryPropertyOrder(CATEGORY_GAME, propertyOrderGame);
		
		if(readFieldsFromConfig)
		{
			mobQuality = propertyMobQuality.getInt();
		}
		
		propertyMobQuality.set(mobQuality);
		
		if(config.hasChanged())
		{
			config.save();
		}
	}
	
	public static class ConfigEventHandler
	{
		@SubscribeEvent(priority = EventPriority.LOWEST)
		public void onEvent(ConfigChangedEvent.OnConfigChangedEvent event)
		{
			if(event.getModID().equals(Reference.MODID))
			{
				syncFromGUI();
			}
		}
	}
	
}

 

GuiFactory:

package com.saoteam.swordartonline.client.gui;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.saoteam.swordartonline.config.ConfigHandler;
import com.saoteam.swordartonline.main.Reference;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.client.IModGuiFactory;
import net.minecraftforge.fml.client.config.GuiConfig;
import net.minecraftforge.fml.client.config.GuiConfigEntries;
import net.minecraftforge.fml.client.config.GuiConfigEntries.CategoryEntry;
import net.minecraftforge.fml.client.config.IConfigElement;
import net.minecraftforge.fml.client.config.DummyConfigElement.DummyCategoryElement;

public class ConfigGuiFactory implements IModGuiFactory
{

	@Override
	public void initialize(Minecraft minecraftInstance) 
	{
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean hasConfigGui() 
	{
		return true;
	}

	@Override
	public GuiScreen createConfigGui(GuiScreen parentScreen) {
		return new SAOConfigGui(parentScreen);
	}

	@Override
	public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
		return null;
	}
	
	public static class SAOConfigGui extends GuiConfig
	{
		public SAOConfigGui(GuiScreen parent)
		{
			super(parent, getConfigElements(), Reference.MODID, false, false, I18n.format("gui.config.main_title"));
		}

		private static List<IConfigElement> getConfigElements() 
		{
			List<IConfigElement> list = new ArrayList<IConfigElement>();
			list.add(new DummyCategoryElement(I18n.format("gui.config.category.game"), "gui.config.category.game", CategoryEntryGame.class));
			return list;
		}
	}
	
	public static class CategoryEntryGame extends CategoryEntry
	{

		public CategoryEntryGame(GuiConfig owningScreen, GuiConfigEntries owningEntryList,
				IConfigElement configElement) 
		{
			super(owningScreen, owningEntryList, configElement);
		}
		
		@Override
		protected GuiScreen buildChildScreen() 
		{
			Configuration config = ConfigHandler.getConfig();
			ConfigElement categoryGame = new ConfigElement(config.getCategory(ConfigHandler.CATEGORY_GAME));
			List<IConfigElement> propertiesOnScreen = categoryGame.getChildElements();
			String windowTitle = I18n.format("gui.config.category.game");
			return new GuiConfig(owningScreen, propertiesOnScreen, owningScreen.modID,
					this.configElement.requiresWorldRestart() || this.owningScreen.allRequireWorldRestart,
					this.configElement.requiresMcRestart() || this.owningScreen.allRequireMcRestart, windowTitle);
		}
		
	}
	
}

 

Main Class and client proxy:

@Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUIFACTORY)
public class SwordArtOnline 
{
	
	@SidedProxy(clientSide = Reference.CLIENTPROXY, serverSide = Reference.COMMONPROXY)
	public static CommonProxy PROXY;
	
	@Mod.Instance(Reference.MODID)
	public static SwordArtOnline INSTANCE;
	
	public static Logger LOGGER = LogManager.getLogger(Reference.NAME);
	
	@EventHandler
	public void preInit(FMLPreInitializationEvent event)
	{
		PROXY.preInit();
		ConfigHandler.preInit();
	}


//In Reference Class
public static final String GUIFACTORY = "com.saoteam.swordartonline.client.gui.ConfigGuiFactory";

//ClientProxy
@Override
	public void preInit() 
	{
		super.preInit();
		SAOGuis.registerGuis();
		ConfigHandler.clientPreInit();
	}

 

Link to comment
Share on other sites

Why aren’t you using @Config? And config files are named .cfg not .config

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

13 hours ago, Discult said:

how does a @config work

Magic (I'm not joking, it uses a bit of ASM)

13 hours ago, Discult said:

do i still need to make GuiFactory?

No

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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.

Announcements



×
×
  • Create New...

Important Information

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