Jump to content

[1.8.0] HOW to set up a configuration file to disable a furnace recipe. Confused


Recommended Posts

Posted

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.

Posted

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.

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/

Posted

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.

Posted

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?

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.