Skip to content

Commit

Permalink
Merge pull request #295 from GrowthcraftCE/feature/292-More-Configura…
Browse files Browse the repository at this point in the history
…tions

Fixed #292 Improvements from feedback in discord
  • Loading branch information
Alatyami authored Dec 25, 2019
2 parents f8e4f7a + ae258b4 commit 90b4ac6
Show file tree
Hide file tree
Showing 22 changed files with 284 additions and 306 deletions.
4 changes: 2 additions & 2 deletions src/main/java/growthcraft/apples/common/Init.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import growthcraft.cellar.shared.definition.BoozeDefinition;
import growthcraft.cellar.shared.item.ItemBoozeBottle;
import growthcraft.cellar.shared.processing.common.Residue;
import growthcraft.core.GrowthcraftCore;
import growthcraft.core.shared.client.render.utils.ItemRenderUtils;
import growthcraft.core.shared.config.GrowthcraftCoreConfig;
import growthcraft.core.shared.definition.BlockDefinition;
import growthcraft.core.shared.definition.BlockTypeDefinition;
import growthcraft.core.shared.definition.ItemDefinition;
Expand Down Expand Up @@ -363,7 +363,7 @@ private static void registerFermentations() {
.brewsFromFallback(spoilInputFs[AppleCiderTypes.APPLE_CIDER_POISONED.ordinal()], TickUtils.minutes(1), null)
.getEffect()
.setTipsy(BoozeUtils.alcoholToTipsy(0.045f), TickUtils.seconds(45))
.createPotionEntry(MobEffects.POISON, TickUtils.seconds(90), 0).toggleDescription(!GrowthcraftCoreConfig.hidePoisonedBooze);
.createPotionEntry(MobEffects.POISON, TickUtils.seconds(90), 0).toggleDescription(!GrowthcraftCore.config.getHidePoisonedBooze());
}

////////
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/growthcraft/bees/common/Init.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import growthcraft.bees.shared.init.GrowthcraftBeesItems;
import growthcraft.bees.shared.init.GrowthcraftBeesItems.BeesWaxTypes;
import growthcraft.bees.shared.init.GrowthcraftBeesItems.MeadTypes;
import growthcraft.core.GrowthcraftCore;
import growthcraft.core.shared.CoreRegistry;
import growthcraft.core.shared.GrowthcraftCoreApis;
import growthcraft.core.shared.client.render.utils.ItemRenderUtils;
import growthcraft.core.shared.config.GrowthcraftCoreConfig;
import growthcraft.core.shared.definition.BlockDefinition;
import growthcraft.core.shared.definition.ItemDefinition;
import growthcraft.cellar.shared.GrowthcraftCellarApis;
Expand Down Expand Up @@ -350,7 +350,7 @@ private static void registerFermentations() {
.brewsFromFallback(spoilInputFs[MeadTypes.MEAD_POISONED.ordinal()], TickUtils.minutes(1), null)
.getEffect()
.setTipsy(BoozeUtils.alcoholToTipsy(0.15f), TickUtils.seconds(90))
.createPotionEntry(MobEffects.POISON, TickUtils.seconds(90), 0).toggleDescription(!GrowthcraftCoreConfig.hidePoisonedBooze);
.createPotionEntry(MobEffects.POISON, TickUtils.seconds(90), 0).toggleDescription(!GrowthcraftCore.config.getHidePoisonedBooze());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
import growthcraft.cellar.shared.block.BlockFluidBooze;
import growthcraft.cellar.shared.CellarRegistry;
import growthcraft.cellar.shared.fluids.Booze;
import growthcraft.cellar.shared.booze.BoozeEffect;
import growthcraft.cellar.shared.booze.BoozeEntry;
import growthcraft.cellar.shared.booze.BoozeRegistry;
import growthcraft.cellar.shared.booze.BoozeTag;
import growthcraft.cellar.shared.definition.BlockBoozeDefinition;
import growthcraft.cellar.shared.definition.BoozeDefinition;
import growthcraft.cellar.shared.item.ItemBoozeBottle;
Expand All @@ -20,16 +16,13 @@
import growthcraft.core.shared.definition.ItemTypeDefinition;
import growthcraft.core.shared.legacy.FluidContainerRegistry;
import net.minecraft.block.Block;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeModContainer;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.UniversalBucket;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.registries.IForgeRegistry;

public class BoozeRegistryHelper {
Expand Down Expand Up @@ -96,7 +89,7 @@ public static <ET extends Enum<?> & IObjectVariant & IStringSerializable> void i
final ItemStack bucket = UniversalBucket.getFilledBucket(ForgeModContainer.getInstance().universalBucket, boozes[i].getFluid());

int bottleVariantID = values[i].getVariantID();
final FluidStack fluidStack = boozes[i].asFluidStack(GrowthcraftCoreConfig.bottleCapacity);
final FluidStack fluidStack = boozes[i].asFluidStack(GrowthcraftCoreConfig.BOTTLE_CAPACITY);
FluidContainerRegistry.registerFluidContainer(fluidStack, bottle.asStack(1, bottleVariantID), FluidContainerRegistry.EMPTY_BOTTLE);

//OFF GameRegistry.addShapelessRecipe(bottle.asStack(3, bottleVariantID), bucket, Items.GLASS_BOTTLE, Items.GLASS_BOTTLE, Items.GLASS_BOTTLE);
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/growthcraft/core/GrowthcraftCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import net.minecraftforge.oredict.RecipeSorter;
import net.minecraftforge.oredict.RecipeSorter.Category;
import net.minecraftforge.registries.IForgeRegistry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION,
dependencies = "after:rustic;" +
Expand All @@ -43,6 +45,9 @@ public class GrowthcraftCore {
@SidedProxy(serverSide = SERVER_PROXY_CLASS, clientSide = CLIENT_PROXY_CLASS)
public static CommonProxy proxy;

public static final GrowthcraftCoreConfig config = new GrowthcraftCoreConfig();
public static final Logger logger = LogManager.getLogger(Reference.MODID);

@Mod.EventHandler
public void construct(FMLConstructionEvent event) {
GrowthcraftCoreApis.tabGrowthcraft = new TabGrowthcraft();
Expand All @@ -52,7 +57,7 @@ public void construct(FMLConstructionEvent event) {
@Mod.EventHandler
@SuppressWarnings("deprecation")
public void preInit(FMLPreInitializationEvent event) {
GrowthcraftCoreConfig.preInit();
config.preInit(event, "growthcraft/growthcraft-core.cfg");

Init.preInitBlocks();
Init.preInitItems();
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/growthcraft/core/common/CommonProxy.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package growthcraft.core.common;

import growthcraft.core.common.worldgen.BlockSaltGeneration;
import growthcraft.core.shared.compat.theoneprobe.TheOneProbeCompat;
import growthcraft.core.shared.compat.theoneprobe.TheOneProbeHandler;
import growthcraft.core.shared.config.GrowthcraftCoreConfig;
import net.minecraftforge.fml.common.registry.GameRegistry;
Expand All @@ -14,7 +13,7 @@ public void preInit() {
}

public void init() {
if (GrowthcraftCoreConfig.blockSaltOreWorldGen) {
if (GrowthcraftCoreConfig.BLOCK_SALT_ORE_WORLD_GEN) {
GameRegistry.registerWorldGenerator(new BlockSaltGeneration(), 0);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
public class BlockSaltGeneration implements IWorldGenerator {

// Needs to be configurable
private int minHieght = GrowthcraftCoreConfig.blockSaltOreMinHeight;
private int maxHieght = GrowthcraftCoreConfig.blockSaltOreMaxHeight;
private int minHieght = GrowthcraftCoreConfig.BLOCK_SALT_ORE_MIN_HEIGHT;
private int maxHieght = GrowthcraftCoreConfig.BLOCK_SALT_ORE_MAX_HEIGHT;

private WorldGenerator salt_overworld;

Expand Down Expand Up @@ -44,7 +44,7 @@ private void runGenerator(WorldGenerator generator, World world, Random rand, in
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
switch (world.provider.getDimension()) {
case 0: // Overworld
this.runGenerator(salt_overworld, world, random, chunkX, chunkZ, GrowthcraftCoreConfig.blockSaltOreChanceToSpawn, minHieght, maxHieght);
this.runGenerator(salt_overworld, world, random, chunkX, chunkZ, GrowthcraftCoreConfig.BLOCK_SALT_ORE_CHANCE_TO_SPAWN, minHieght, maxHieght);
break;
case 1: // The End
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,60 +1,82 @@
package growthcraft.core.shared.config;

import growthcraft.core.shared.GrowthcraftLogger;
import growthcraft.core.shared.Reference;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

import java.io.File;

import org.apache.logging.log4j.Level;

import growthcraft.core.shared.Reference;
import growthcraft.core.shared.GrowthcraftLogger;
import java.io.File;

public class GrowthcraftConfiguration extends Configuration {
// REVISE_TEAM 0: Reused pattern from GrowthcraftBambooConfig, correct?
// REVISE_ME 0: Remove cellar dependency.
// INITIALIZE

private static Configuration configuration;
private Configuration configuration;

// Categories
private static final String CATEGORY_GENERAL = "general";
private static final String CATEGORY_BOOZE = "Booze/Effects";
/* Categories */
private static final String categoryGeneral = "general";

// Values
public static boolean isDebug = false;
public static String logLevel = "info";
public static boolean hidePoisonedBooze = true;
/* Default Values */
private Level logLevel = Level.INFO;

/* public GrowthcraftConfiguration(File configDirectory, String name) {
configuration = new Configuration(new File(configDirectory.getPath(), "growthcraft/" + name + ".cfg"));
} */
public GrowthcraftConfiguration() { /* Nothing to do */ }

public void preInit(FMLPreInitializationEvent e) {
File directory = e.getModConfigurationDirectory();
configuration = new Configuration(new File(directory.getPath(), "modtut.cfg"));
readConfig();
public void preInit(FMLPreInitializationEvent event, String configFilePath) {
File directory = event.getModConfigurationDirectory();
configuration = new Configuration(
new File(directory.getPath(), configFilePath)
);
readConfig(configFilePath);
}

public static void readConfig() {
protected void readConfig(String configFilePath) {
try {
configuration.load();
initDebugConfig();
initBoozeConfig();
initGeneralConfig();
} catch (Exception e) {
GrowthcraftLogger.getLogger(Reference.MODID).log(Level.ERROR, "Unable to load configuration files for Growthcraft Bamboo!", e);
GrowthcraftLogger.getLogger(Reference.MODID).log(
Level.ERROR,
String.format("Unable to read configuration file at: %s", configFilePath)
);
} finally {
if (configuration.hasChanged()) {
configuration.save();
}
}
}

private static void initDebugConfig() {
logLevel = configuration.getString("logLevel", CATEGORY_GENERAL, logLevel, "Set standard logging levels. (INFO, ERROR, DEBUG)");
/**
* Initialize the general configuration. By default this will also initialize the debug config
* and set the log level for mod that is using this configuration.
* You should override this method and append your custom configurations.
*/
protected void initGeneralConfig() {
// Always call the initialization of the debug configuration as we need it for logging.
initDebugConfig();
}

/**
* Initialize the log level for the module. This function is private as it should not be allowed to the overriden unless the caller decides not call super on initGeneralConfig.
*/
private void initDebugConfig() {
logLevel = Level.getLevel(
configuration.getString(
"logLevel",
categoryGeneral,
logLevel.toString(),
"Set standard logging levels, such as INFO, DEBUG, ERROR"
)
);
}

public Configuration getConfiguration() {
return configuration;
}

private static void initBoozeConfig() {
hidePoisonedBooze = configuration.getBoolean("hidePoisoned", CATEGORY_BOOZE, hidePoisonedBooze, "Should purposely poisoned booze have its effect hidden?");
/**
* Sub-modules should call this to check the verbosity of logging.
* @return
*/
public Level getLogLevel() {
return logLevel;
}
}
Loading

0 comments on commit 90b4ac6

Please sign in to comment.