Jump to content

[1.10.2][SOLVED] reading/creating/writing config for my mod??


lukas2005

Recommended Posts

i want to make my mod confgurable but how do i read/write it does this uses normal JavaIO or forge has something for this?

In preInit event has a Configuration object for your mod that is what you will use to create a config.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

i want to make my mod confgurable but how do i read/write it does this uses normal JavaIO or forge has something for this?

In preInit event has a Configuration object for your mod that is what you will use to create a config.

do you mean FMLPreInitializationEvent#getSuggestedConfigurationFile()?

Yes

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

i want to make my mod confgurable but how do i read/write it does this uses normal JavaIO or forge has something for this?

In preInit event has a Configuration object for your mod that is what you will use to create a config.

do you mean FMLPreInitializationEvent#getSuggestedConfigurationFile()?

Yes

and then i can use normal JavaIO? and configuration file syntax is created by me? or is there a recommended way of doing this?

Link to comment
Share on other sites

i want to make my mod confgurable but how do i read/write it does this uses normal JavaIO or forge has something for this?

In preInit event has a Configuration object for your mod that is what you will use to create a config.

do you mean FMLPreInitializationEvent#getSuggestedConfigurationFile()?

Yes

and then i can use normal JavaIO? and configuration file syntax is created by me? or is there a recommended way of doing this?

Look into the Configuration methods all syntax/format is defined by it. You have almost no say.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

new Configuration(event.getSuggestedConfigFile())

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

And your goal is...?

 

(Also, you're not entirely correct)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Again, you can totally do that, and the code I linked does something similar.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

It works like this:

Rather than getting a value from the config file, get a Property.

The property then contains both get and set methods.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

The config class does it for you.

Same thing with all the config options. If they aren't there, you provide a default value.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Show your code.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Show your code.

 

in pre init of main

	@EventHandler
public static void preInit(FMLPreInitializationEvent e) {
	Logger.setLogger(LogManager.getLogger(Reference.MODID.toUpperCase()));
	Logger.info("Pre Init!");

	Reference.CONFIG = new Configuration(e.getSuggestedConfigurationFile());

	ModItems.main();
	//Logger.info("Loaded and registered succesfully: " + ModItems.ITEMS.size() + " Items");

	CustomValues.initValues(Reference.CONFIG);


	proxy.preInit(e);
}

in CustomValues class

package lukas2005.idea;

import java.util.HashMap;

import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;

public class CustomValues {

public static HashMap<Item,Integer> ITEMWEIGHT = new HashMap<Item,Integer>();
public static HashMap<Block,Integer> BLOCKWEIGHT = new HashMap<Block,Integer>();

public static void initValues(Configuration cONFIG) {

	Reference.CONFIG.addCustomCategoryComment("BLOCKS WEIGHT", "Here you can change how much ceratin blocks weight");

	for (Block block : Block.REGISTRY) {

		Property pr = Reference.CONFIG.get("BLOCKS WEIGHT", block.getRegistryName().toString(), "1");

		BLOCKWEIGHT.put(block, pr.getInt());

		pr.setComment("Weight of a " + block.getRegistryName().toString());

	}

	Reference.CONFIG.addCustomCategoryComment("ITEMS WEIGHT", "Here you can change how much ceratin items weight");

	for (Item item : Item.REGISTRY) {

		Property pr = Reference.CONFIG.get("ITEMS WEIGHT", item.getRegistryName().toString(), "1");

		ITEMWEIGHT.put(item, pr.getInt());

		pr.setComment("Weight of a " + item.getRegistryName().toString());

	}

}

}

 

Link to comment
Share on other sites

Let's look at what Config.getFloat does

 

Float.parseFloat(prop.getString()) < minValue ? minValue : (Float.parseFloat(prop.getString()) > maxValue ? maxValue : Float.parseFloat(prop.getString()));

 

Oh, hey, its just parsing a string.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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

    • TO update, no dice, sadly. I switched replace to true, but it's not showing up. I found something odd though. I installed JER to verify the loot tables for the dragon eggs, but it's not working on those items. I made sure that the server-config to allow loot tables was enabled for the single player world I'm testing in as well. It almost seems like the mod itself is not spawning eggs at all for some reason, but I figure a loot modifier should still make that happen regardless?
    • *First of all, thank you, because of what you pointed out, I managed to make even more progress and now I know where to start fixing this problem (and any problems that I will have later on) *Second,actually I'm making a new block and not trying to replace a minecraft block because I know I don't have the knowledge for that. *Third, I didn't know about this forum rule, I thought I could get some help since I love to program but I've never taken a class on it and everything I know I'm learning the hard way. But I want to share a success here, I managed to make a first progress. (it still only stays in that position and if I aim at the ground, in addition to just opening the grindstone menu for half a second, but I already know where to start to solve this)
    • Broken configuration file. If you don't have a backup of the file and don't know how to fix it, delete the file and it will be recreated with default values.
    • Not sure how to fix this one; Time: 2023-03-22 17:31:08 Description: Initializing game java.lang.ExceptionInInitializerError: null     at net.minecraftforge.resource.ResourceCacheManager.shouldUseCache(ResourceCacheManager.java:111) ~[forge-1.19.2-43.2.0-universal.jar%23166!/:?] {re:classloading}     at net.minecraftforge.resource.PathPackResources.m_5698_(PathPackResources.java:154) ~[forge-1.19.2-43.2.0-universal.jar%23166!/:?] {re:classloading}     at net.minecraftforge.resource.DelegatingPackResources.buildNamespaceMap(DelegatingPackResources.java:64) ~[forge-1.19.2-43.2.0-universal.jar%23166!/:?] {re:classloading}     at net.minecraftforge.resource.DelegatingPackResources.<init>(DelegatingPackResources.java:40) ~[forge-1.19.2-43.2.0-universal.jar%23166!/:?] {re:classloading}     at net.minecraftforge.client.loading.ClientModLoader.lambda$clientPackFinder$12(ClientModLoader.java:209) ~[forge-1.19.2-43.2.0-universal.jar%23166!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.server.packs.repository.Pack.m_10430_(Pack.java:35) ~[client-1.19.2-20220805.130853-srg.jar%23161!/:?] {re:classloading}     at net.minecraftforge.client.loading.ClientModLoader.clientPackFinder(ClientModLoader.java:208) ~[forge-1.19.2-43.2.0-universal.jar%23166!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraftforge.client.loading.ClientModLoader.lambda$buildPackFinder$11(ClientModLoader.java:186) ~[forge-1.19.2-43.2.0-universal.jar%23166!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.server.packs.repository.PackRepository.m_10526_(PackRepository.java:47) ~[client-1.19.2-20220805.130853-srg.jar%23161!/:?] {re:classloading}     at net.minecraft.server.packs.repository.PackRepository.m_10506_(PackRepository.java:39) ~[client-1.19.2-20220805.130853-srg.jar%23161!/:?] {re:classloading}     at net.minecraft.client.Minecraft.<init>(Minecraft.java:469) ~[client-1.19.2-20220805.130853-srg.jar%23161!/:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.m_239872_(Main.java:176) ~[client-1.19.2-20220805.130853-srg.jar%23161!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:51) ~[client-1.19.2-20220805.130853-srg.jar%23161!/:?] {re:classloading,pl:runtimedistcleaner:A}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}     at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}     at net.minecraftforge.fml.loading.targets.CommonClientLaunchHandler.lambda$launchService$0(CommonClientLaunchHandler.java:27) ~[fmlloader-1.19.2-43.2.0.jar%2395!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) [modlauncher-10.0.8.jar%2382!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-10.0.8.jar%2382!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-10.0.8.jar%2382!/:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-10.0.8.jar%2382!/:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-10.0.8.jar%2382!/:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-10.0.8.jar%2382!/:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-10.0.8.jar%2382!/:?] {}     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) [bootstraplauncher-1.1.2.jar:?] {} Caused by: java.lang.RuntimeException: Failed to load Force Resource Cache Configuration from C:\Users\Nathan\AppData\Roaming\.minecraft\config\forge-resource-caching.toml     at net.minecraftforge.resource.ResourceCacheManager$ResourceManagerBootCacheConfigurationHandler.createConfiguration(ResourceCacheManager.java:531) ~[forge-1.19.2-43.2.0-universal.jar%23166!/:?] {re:classloading}     at net.minecraftforge.resource.ResourceCacheManager$ResourceManagerBootCacheConfigurationHandler.<init>(ResourceCacheManager.java:510) ~[forge-1.19.2-43.2.0-universal.jar%23166!/:?] {re:classloading}     at net.minecraftforge.resource.ResourceCacheManager$ResourceManagerBootCacheConfigurationHandler.<clinit>(ResourceCacheManager.java:497) ~[forge-1.19.2-43.2.0-universal.jar%23166!/:?] {re:classloading}     ... 26 more Caused by: com.electronwill.nightconfig.core.io.ParsingException: Not enough data available     at com.electronwill.nightconfig.core.io.ParsingException.notEnoughData(ParsingException.java:22) ~[core-3.6.4.jar%2384!/:?] {}     at com.electronwill.nightconfig.core.io.ReaderInput.directReadChar(ReaderInput.java:36) ~[core-3.6.4.jar%2384!/:?] {}     at com.electronwill.nightconfig.core.io.AbstractInput.readChar(AbstractInput.java:49) ~[core-3.6.4.jar%2384!/:?] {}     at com.electronwill.nightconfig.core.io.AbstractInput.readCharsUntil(AbstractInput.java:123) ~[core-3.6.4.jar%2384!/:?] {}     at com.electronwill.nightconfig.toml.TableParser.parseKey(TableParser.java:166) ~[toml-3.6.4.jar%2385!/:?] {}     at com.electronwill.nightconfig.toml.TableParser.parseDottedKey(TableParser.java:145) ~[toml-3.6.4.jar%2385!/:?] {}     at com.electronwill.nightconfig.toml.TableParser.parseNormal(TableParser.java:55) ~[toml-3.6.4.jar%2385!/:?] {}     at com.electronwill.nightconfig.toml.TomlParser.parse(TomlParser.java:44) ~[toml-3.6.4.jar%2385!/:?] {}     at com.electronwill.nightconfig.toml.TomlParser.parse(TomlParser.java:37) ~[toml-3.6.4.jar%2385!/:?] {}     at com.electronwill.nightconfig.core.io.ConfigParser.parse(ConfigParser.java:113) ~[core-3.6.4.jar%2384!/:?] {}     at com.electronwill.nightconfig.core.io.ConfigParser.parse(ConfigParser.java:219) ~[core-3.6.4.jar%2384!/:?] {}     at com.electronwill.nightconfig.core.io.ConfigParser.parse(ConfigParser.java:202) ~[core-3.6.4.jar%2384!/:?] {}     at com.electronwill.nightconfig.core.file.WriteSyncFileConfig.load(WriteSyncFileConfig.java:73) ~[core-3.6.4.jar%2384!/:?] {}     at com.electronwill.nightconfig.core.file.AutoreloadFileConfig.load(AutoreloadFileConfig.java:41) ~[core-3.6.4.jar%2384!/:?] {}     at com.electronwill.nightconfig.core.file.AutosaveCommentedFileConfig.load(AutosaveCommentedFileConfig.java:85) ~[core-3.6.4.jar%2384!/:?] {}     at net.minecraftforge.resource.ResourceCacheManager$ResourceManagerBootCacheConfigurationHandler.createConfiguration(ResourceCacheManager.java:527) ~[forge-1.19.2-43.2.0-universal.jar%23166!/:?] {re:classloading}     at net.minecraftforge.resource.ResourceCacheManager$ResourceManagerBootCacheConfigurationHandler.<init>(ResourceCacheManager.java:510) ~[forge-1.19.2-43.2.0-universal.jar%23166!/:?] {re:classloading}     at net.minecraftforge.resource.ResourceCacheManager$ResourceManagerBootCacheConfigurationHandler.<clinit>(ResourceCacheManager.java:497) ~[forge-1.19.2-43.2.0-universal.jar%23166!/:?] {re:classloading}     ... 26 more A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Render thread Stacktrace:     at net.minecraftforge.resource.ResourceCacheManager.shouldUseCache(ResourceCacheManager.java:111) ~[forge-1.19.2-43.2.0-universal.jar%23166!/:?] {re:classloading}     at net.minecraftforge.resource.PathPackResources.m_5698_(PathPackResources.java:154) ~[forge-1.19.2-43.2.0-universal.jar%23166!/:?] {re:classloading}     at net.minecraftforge.resource.DelegatingPackResources.buildNamespaceMap(DelegatingPackResources.java:64) ~[forge-1.19.2-43.2.0-universal.jar%23166!/:?] {re:classloading}     at net.minecraftforge.resource.DelegatingPackResources.<init>(DelegatingPackResources.java:40) ~[forge-1.19.2-43.2.0-universal.jar%23166!/:?] {re:classloading}     at net.minecraftforge.client.loading.ClientModLoader.lambda$clientPackFinder$12(ClientModLoader.java:209) ~[forge-1.19.2-43.2.0-universal.jar%23166!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.server.packs.repository.Pack.m_10430_(Pack.java:35) ~[client-1.19.2-20220805.130853-srg.jar%23161!/:?] {re:classloading}     at net.minecraftforge.client.loading.ClientModLoader.clientPackFinder(ClientModLoader.java:208) ~[forge-1.19.2-43.2.0-universal.jar%23166!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraftforge.client.loading.ClientModLoader.lambda$buildPackFinder$11(ClientModLoader.java:186) ~[forge-1.19.2-43.2.0-universal.jar%23166!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.server.packs.repository.PackRepository.m_10526_(PackRepository.java:47) ~[client-1.19.2-20220805.130853-srg.jar%23161!/:?] {re:classloading}     at net.minecraft.server.packs.repository.PackRepository.m_10506_(PackRepository.java:39) ~[client-1.19.2-20220805.130853-srg.jar%23161!/:?] {re:classloading}     at net.minecraft.client.Minecraft.<init>(Minecraft.java:469) ~[client-1.19.2-20220805.130853-srg.jar%23161!/:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}  
    • At the top of this forum is the EAQ (excessively asked questions). Read the part where it asks "How do I install Forge?". There is no windows specific installer. The installer uses java. https://en.wikipedia.org/wiki/Write_once,_run_anywhere
  • Topics

×
×
  • Create New...

Important Information

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