Jump to content

[1.12.2] Is it possible to "lock" values in the forge config GUI?


Recommended Posts

Posted

Under certain conditions, I would like to be able to prevent players from changing the config through forge's config GUI interface. Is it possible to grey out values so that the player does not have access to them?

Here is my mod config class:

package oresheepmod.command;

import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.ConfigManager;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import oresheepmod.ModOreSheep;

@Config(modid = ModOreSheep.modid)
@Config.LangKey("oresheepmod.config.title")
public class ModConfig 
{

	@Config.Comment("Ignores the mobGriefing game rule.")
	public static boolean IgnoreGameRuleMobGriefing = true;
	
	@Config.Comment("Determines if sheep can go into love mode.")
	public static boolean CanBreed = true;
	
	@Config.Comment("If false, offspring are not ore sheep, but regular sheep.")
	public static boolean OffspringAreOreSheep = true;
	
	@Config.Comment("If false, ore sheep can't be created with a weakness potion and diamond, but must be spawned with a spawn egg.")
	public static boolean CanBrainwash = true;
	
	@Config.Comment("If false, ore sheep can't eat a different block to change their ore. They can only be changed through creative mode feeding.")
	public static boolean CanChangeOre = true;
	
	@Config.Comment("If false, ore sheep eat in front of themselves before they eat down, otherwise they eat directly down.")
	public static boolean DigStraightDown = false;
	
	@Config.Comment("If false, ore sheep can't eat bedrock.")
	public static boolean Bedrock = false;

	@Mod.EventBusSubscriber(modid = ModOreSheep.modid)
	private static class EventHandler 
	{
		/**
		 * Inject the new values and save to the config file when the config has been changed from the GUI.
		 *
		 * @param event The event
		 */
		@SubscribeEvent
		public static void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event)
		{
			if (event.getModID().equals(ModOreSheep.modid))
			{
				ConfigManager.sync(ModOreSheep.modid, Config.Type.INSTANCE);
			}
		}
	}
}

The event handler class's onConfigChanged method looks like a good place to start, but I wanted to know first if there is any built-in/already-made solution.

Thanks for any and all help!

Posted

Can't the player just change the .cfg file anyway?

Some tips:

  Reveal hidden contents

 

Posted
  On 5/22/2019 at 9:17 PM, Icedice9 said:

I would like to be able to prevent players from changing the config through forge's config GUI

Expand  

You could use your own GUI that doesn’t allow them to change it under certain conditions

About Me

  Reveal hidden contents

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)

Posted (edited)

Let me give a few more details to make what I am doing more clear. I have another custom config text file that is read in per world, but that file can have 0 or more of the config entries. If my custom file doesn't have a config entry, the global config entry is used and changing the global value in the GUI does nothing. What I want to do is make it so changing it in the global GUI doesn't give the player a false sense that they are changing something when it doesn't make a difference.

The point of having a world config and a global one is so regular players can set their global settings, but map makers can set specific values per world that come with the world when it is downloaded.

  On 5/22/2019 at 11:36 PM, DavidM said:

Can't the player just change the .cfg file anyway?

Expand  

DavidM- yes they can, but again, it doesn't change anything in game if my custom config file is filled in the world.

  On 5/23/2019 at 12:35 AM, Cadiboo said:

You could use your own GUI that doesn’t allow them to change it under certain conditions

Expand  

That would be neat! Do you have any tutorial suggestions? It sounds pretty complicated and I want to stick with the forge-made one if at all possible.

Edited by Icedice9
Fixed grammar
Posted
  On 5/23/2019 at 1:40 AM, Icedice9 said:

I have another custom config text file that is read in per world, but that file can have 0 or more of the config entries. If my custom file doesn't have a config entry, the global config entry is used and changing the global value in the GUI does nothing. What I want to do is make it so changing it in the global GUI doesn't give the player a false sense that they are changing something when it doesn't make a difference.

The point of having a world config and a global one is so regular players can set their global settings, but map makers can set specific values per world that come with the world when it is downloaded.

Expand  

This is all part of the new 1.13.2 config system

About Me

  Reveal hidden contents

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)

Posted
  On 5/23/2019 at 1:57 AM, Cadiboo said:

This is all part of the new 1.13.2 config system

Expand  

Nice! I can't wait to upgrade! That's my plan as soon as I put out this new update. Do you have any suggestions for 1.12.2 tutorials I can look into in the mean time?

Posted (edited)

Tutorials for what specifically? Look at/copy/extend the forge GUI code if you’re going to use the GUI approach. You can also just not save the config if it’s locked (you’re already subscribing to the config change event to save the config)

Edited by Cadiboo

About Me

  Reveal hidden contents

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)

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.