Skip to content

Commit

Permalink
Switch config to annotation system so we get the nice GUI
Browse files Browse the repository at this point in the history
Currently everything requires MC restart to work, but maybe something in the future won't. Plus its nicer to the end user
  • Loading branch information
KnightMiner committed Jan 6, 2019
1 parent 223f44b commit 3645533
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 37 deletions.
17 changes: 15 additions & 2 deletions src/main/java/knightminer/tcomplement/TinkersComplement.java
Expand Up @@ -12,10 +12,15 @@
import knightminer.tcomplement.shared.ModuleCommons;
import knightminer.tcomplement.shared.legacy.TileEntityRenamer;
import net.minecraft.util.datafix.FixTypes;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Config.Type;
import net.minecraftforge.common.config.ConfigManager;
import net.minecraftforge.common.util.ModFixs;
import net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import slimeknights.mantle.common.GuiHandler;
import slimeknights.mantle.pulsar.control.PulseManager;
Expand Down Expand Up @@ -53,12 +58,20 @@ public class TinkersComplement {

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
Config.load(event);
NetworkRegistry.INSTANCE.registerGuiHandler(instance, guiHandler);
// config syncing
MinecraftForge.EVENT_BUS.register(this);

NetworkRegistry.INSTANCE.registerGuiHandler(instance, guiHandler);
TCompNetwork.instance.setup();

ModFixs fixer = FMLCommonHandler.instance().getDataFixer().init(modID, 1);
fixer.registerFix(FixTypes.BLOCK_ENTITY, new TileEntityRenamer());
}

@SubscribeEvent
public void onConfigChangedEvent(OnConfigChangedEvent event) {
if (event.getModID().equals(modID)) {
ConfigManager.sync(modID, Type.INSTANCE);
}
}
}
61 changes: 35 additions & 26 deletions src/main/java/knightminer/tcomplement/common/Config.java
Expand Up @@ -6,41 +6,50 @@

import knightminer.tcomplement.TinkersComplement;
import net.minecraft.util.JsonUtils;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Config.Comment;
import net.minecraftforge.common.config.Config.Ignore;
import net.minecraftforge.common.config.Config.LangKey;
import net.minecraftforge.common.config.Config.RangeDouble;
import net.minecraftforge.common.config.Config.RequiresMcRestart;
import net.minecraftforge.common.crafting.IConditionFactory;
import net.minecraftforge.common.crafting.JsonContext;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import slimeknights.mantle.pulsar.config.ForgeCFG;

@net.minecraftforge.common.config.Config(modid = TinkersComplement.modID, category = "")
public class Config {

@Ignore
public static ForgeCFG pulseConfig = new ForgeCFG("TComplementModules", "Modules");

public static float oreToIngotRatio = 1.0f;
public static boolean blacklistMelterStone = true;
public static boolean separateMelterTab = true;


static Configuration configFile;

public static void load(FMLPreInitializationEvent event) {
configFile = new Configuration(event.getSuggestedConfigurationFile(), "0.1", false);

// melter
blacklistMelterStone = configFile.getBoolean("blacklistStone", "melter", true,
"Disallows creating seared stone in the melter using cobblestone or tool parts");
oreToIngotRatio = configFile.getFloat("oreToIngotRatio", "melter", 1.0f, 0f, 16.0f,
"Ratio of ore to material produced in the melter.");

// jei
separateMelterTab = configFile.getBoolean("separateMelterTab", "jei", true,
"If true, puts the melter in its own recipe tab in JEI to make the blacklist and overrides more clear. If false, the melter is just added to the normal Tinkers tab.");

if(configFile.hasChanged()) {
configFile.save();
}
@Comment("Options to configure the melter")
@LangKey("tcomplement.config.melter")
public static Melter melter = new Melter();

@Comment("Options to configure JEI integration")
@LangKey("tcomplement.config.jei")
public static JEI jei = new JEI();

public static class Melter {
@RequiresMcRestart
@Comment("Ratio of ore to material produced in the melter.")
@RangeDouble(min = 0, max = 16)
@LangKey("tcomplement.config.melter.oreToIngotRatio")
public double oreToIngotRatio = 1.0f;

@RequiresMcRestart
@Comment("Disallows creating seared stone in the melter using cobblestone or tool parts.")
@LangKey("tcomplement.config.melter.blacklistStone")
public boolean blacklistStone = true;
}

public static class JEI {
@RequiresMcRestart
@Comment({
"If true, puts the melter in its own recipe tab in JEI to make the blacklist and overrides more clear.",
"If false, the melter is just added to the normal Tinkers tab."
})
@LangKey("tcomplement.config.jei.separateMelterTab")
public boolean separateMelterTab = true;
}

public static class PulseLoaded implements IConditionFactory {
@Override
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/knightminer/tcomplement/feature/ModuleFeature.java
Expand Up @@ -185,7 +185,7 @@ private void registerMeltingCasting() {
}

// don't allow seared stone from cobblestone or stone
if(Config.blacklistMelterStone) {
if(Config.melter.blacklistStone) {
TCompRegistry.registerMelterBlacklist(RecipeMatch.of("cobblestone"));
TCompRegistry.registerMelterBlacklist(RecipeMatch.of("stone"));
TCompRegistry.registerMelterBlacklist(new PartMaterialBlacklist(TinkerMaterials.stone));
Expand All @@ -194,11 +194,11 @@ private void registerMeltingCasting() {

private static void registerOredictMeltingCasting(Fluid fluid, String ore) {
ImmutableSet.Builder<Pair<String, Integer>> builder = ImmutableSet.builder();
builder.add(Pair.of("ore" + ore, (int) (Material.VALUE_Ingot * Config.oreToIngotRatio)));
builder.add(Pair.of("oreNether" + ore, (int) (2 * Material.VALUE_Ingot * Config.oreToIngotRatio)));
builder.add(Pair.of("denseore" + ore, (int) (3 * Material.VALUE_Ingot * Config.oreToIngotRatio)));
builder.add(Pair.of("orePoor" + ore, (int) (Material.VALUE_Nugget * 3 * Config.oreToIngotRatio)));
builder.add(Pair.of("oreNugget" + ore, (int) (Material.VALUE_Nugget * Config.oreToIngotRatio)));
builder.add(Pair.of("ore" + ore, (int) (Material.VALUE_Ingot * Config.melter.oreToIngotRatio)));
builder.add(Pair.of("oreNether" + ore, (int) (2 * Material.VALUE_Ingot * Config.melter.oreToIngotRatio)));
builder.add(Pair.of("denseore" + ore, (int) (3 * Material.VALUE_Ingot * Config.melter.oreToIngotRatio)));
builder.add(Pair.of("orePoor" + ore, (int) (Material.VALUE_Nugget * 3 * Config.melter.oreToIngotRatio)));
builder.add(Pair.of("oreNugget" + ore, (int) (Material.VALUE_Nugget * Config.melter.oreToIngotRatio)));

Set<Pair<String, Integer>> knownOres = builder.build();

Expand Down
Expand Up @@ -39,7 +39,7 @@ public void registerCategories(IRecipeCategoryRegistration registry) {
final IGuiHelper guiHelper = registry.getJeiHelpers().getGuiHelper();

// Melter
if(Config.separateMelterTab && TinkersComplement.pulseManager.isPulseLoaded(ModuleFeature.pulseID)) {
if(Config.jei.separateMelterTab && TinkersComplement.pulseManager.isPulseLoaded(ModuleFeature.pulseID)) {
registry.addRecipeCategories(meltingCategory = new MeltingRecipeCategory(guiHelper));
}
}
Expand All @@ -48,7 +48,7 @@ public void registerCategories(IRecipeCategoryRegistration registry) {
public void register(IModRegistry registry) {
if(TinkersComplement.pulseManager.isPulseLoaded(ModuleFeature.pulseID)) {
String melterCategory = TINKERS_SMELTERY;
if(Config.separateMelterTab) {
if(Config.jei.separateMelterTab) {
melterCategory = MeltingRecipeCategory.CATEGORY;
registry.handleRecipes(MeltingRecipe.class, MeltingRecipeWrapper::new, MeltingRecipeCategory.CATEGORY);
registry.addRecipes(MeltingRecipeChecker.getMeltingRecipes(), MeltingRecipeCategory.CATEGORY);
Expand Down
13 changes: 12 additions & 1 deletion src/main/resources/assets/tcomplement/lang/en_us.lang
Expand Up @@ -69,4 +69,15 @@ gui.tcomplement.melter.solid_fuel.amount=%s units

gui.tcomplement.heater.name=Heater

gui.jei.melter.title=Melter
gui.jei.melter.title=Melter


################
# Config #
################

tcomplement.config.melter=Melter
tcomplement.config.melter.oreToIngotRatio=Ore to Ingot Ratio
tcomplement.config.melter.blacklistStone=Blacklist Stone
tcomplement.config.jei=JEI Integration
tcomplement.config.jei.separateMelterTab=Separate Melter Tab

0 comments on commit 3645533

Please sign in to comment.