boredherobrine13 Posted December 24, 2015 Posted December 24, 2015 Okay so I am working on a mod, and basically I want to use GameRegistry.addSmelting(Items.rotten_flesh, new ItemStack(Items.leather), 0.3F); to make it so that players can smelt rotten flesh into leather. However, I want players to be able to disable this in a .cfg file if they so desire. But I have very little experience with creating config files, virtually no idea how to. I have read multiple tutorials but they are all from different versions and they all say different things. I think there is probably some best way to do this but I just dont know and I cant find a clear tutorial. So here is my entire code: Main.java: package com.bored.morefuelsmod; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.common.config.Configuration; @Mod(modid = Main.MODID, version = Main.VERSION, name=Main.MODNAME) public class Main { public static final String MODID = "morefuels"; public static final String VERSION = "1.1.0"; public static final String MODNAME = "More Fuels Mod"; @Instance(value = Main.MODID) public static Main instance; @EventHandler public void preinit(FMLPreInitializationEvent event){ Configuration config = new Configuration(event.getSuggestedConfigurationFile()); boolean disableRFtLrecipe = config.get(config.CATEGORY_GENERAL, "disableRFtLrecipe", false).getBoolean(false); if(disableRFtLrecipe){ GameRegistry.addSmelting(Items.rotten_flesh, new ItemStack(Items.leather), 0.3F); } } @EventHandler public void init(FMLInitializationEvent event){ GameRegistry.registerFuelHandler(new Fuels()); } } ConfigHandler.java (not sure about this but I heard i should do this seperately. package com.bored.morefuelsmod; import java.io.File; import net.minecraftforge.common.config.Configuration; public class ConfigHandler { public static void init(File configFile) { Configuration config = new Configuration(configFile); config.load(); boolean disableRFtLrecipe = config.get(config.CATEGORY_GENERAL, "disableRFtLrecipe", false).getBoolean(false); config.save(); } } Please be detailed and try to simplify it, I very much appreciate code examples. Quote
larsgerrits Posted December 24, 2015 Posted December 24, 2015 You current get the same config element twice. Only do it once in a central place. And you are now only adding the recipe when disableRFtLrecipe is true, so it is inverted. Quote 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/
boredherobrine13 Posted December 24, 2015 Author Posted December 24, 2015 I think I get what you are saying...but I'm not quite sure how to implement it. Quote
coolAlias Posted December 24, 2015 Posted December 24, 2015 This line: if(disableRFtLrecipe) { add recipe... wait, what?! read what the condition says... } You say "set to true to disable the recipe", but then if it's true, you add the recipe... Either re-write your config option to say "set to true to ENABLE the recipe" and rename your variable to 'enableRFtLrecipe', or invert the condition using the '!' (called 'NOT') operator. Also, as larsgerrits mentioned, either remove the the ConfigHandler class and read in your config from preInit, or remove the config-reading code you have in preInit and replace it with a call to initialize the ConfigHandler. Quote http://i.imgur.com/NdrFdld.png[/img]
boredherobrine13 Posted December 25, 2015 Author Posted December 25, 2015 Thank you. I think I understand. I decided to remove the ConfigHandler.java file. Here is my Main.java: package com.bored.morefuelsmod; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.common.config.Configuration; @Mod(modid = Main.MODID, version = Main.VERSION, name=Main.MODNAME) public class Main { public static final String MODID = "morefuels"; public static final String VERSION = "1.1.0"; public static final String MODNAME = "More Fuels Mod"; @Instance(value = Main.MODID) public static Main instance; @EventHandler public void preinit(FMLPreInitializationEvent event){ Configuration config = new Configuration(event.getSuggestedConfigurationFile()); config.load(); boolean enableRFtLrecipe = config.get(config.CATEGORY_GENERAL, "enableRFtLrecipe", true).getBoolean(true); if(enableRFtLrecipe) GameRegistry.addSmelting(Items.rotten_flesh, new ItemStack(Items.leather), 0.3F); //I feel like I need an "else if" statement here telling it to not add the recipe if it doesnt return true. //Also, how to I get the actual config file to appear......like do I make it or is it generated and if so how //and do i need to type any code for that... } @EventHandler public void init(FMLInitializationEvent event){ GameRegistry.registerFuelHandler(new Fuels()); } } But I have one question. Do I now need an else if statement to say what to do if it doesnt return true. If so, what do I need to put so that it knows not to enable the recipe. Also how do I actually create the config file so this shows up in a file. Do i need to write code for this? Quote
boredherobrine13 Posted December 25, 2015 Author Posted December 25, 2015 Just a note, it creates a totally blank file called morefuels.cfg, but it doesnt work if i try to add anything to it, and errors, only to be replaced by a new one. Quote
coolAlias Posted December 25, 2015 Posted December 25, 2015 You need to tell the config to save, i.e. 'config.save();'. And why would you need an else / else if? What are you going to do if the recipe is not enabled, other than not adding it? You already only add it if it is enabled, so...... Quote http://i.imgur.com/NdrFdld.png[/img]
Recommended Posts
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.