From d0adeca126844717e2807c46ec70313bac5ed08f Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Sat, 5 Dec 2015 15:56:54 +0000 Subject: [PATCH] Lowered worldgen flower rates and added adaptative config. --- .../client/core/proxy/ClientProxy.java | 40 ++-- .../common/core/handler/ConfigHandler.java | 172 +++++++++++++++++- .../common/core/proxy/CommonProxy.java | 5 + .../common/core/version/AdaptorNotifier.java | 40 ++++ .../resources/assets/botania/lang/en_US.lang | 1 + 5 files changed, 239 insertions(+), 19 deletions(-) create mode 100644 src/main/java/vazkii/botania/common/core/version/AdaptorNotifier.java diff --git a/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java b/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java index 530a2bd89..8f50f6f8b 100644 --- a/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java +++ b/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java @@ -155,6 +155,7 @@ import vazkii.botania.common.core.handler.ConfigHandler; import vazkii.botania.common.core.helper.MathHelper; import vazkii.botania.common.core.helper.Vector3; import vazkii.botania.common.core.proxy.CommonProxy; +import vazkii.botania.common.core.version.AdaptorNotifier; import vazkii.botania.common.core.version.VersionChecker; import vazkii.botania.common.entity.EntityBabylonWeapon; import vazkii.botania.common.entity.EntityCorporeaSpark; @@ -167,8 +168,8 @@ import vazkii.botania.common.entity.EntityPoolMinecart; import vazkii.botania.common.entity.EntitySpark; import vazkii.botania.common.entity.EntityThornChakram; import vazkii.botania.common.entity.EntityVineBall; -import vazkii.botania.common.item.ModItems; import vazkii.botania.common.item.ItemSextant.MultiblockSextant; +import vazkii.botania.common.item.ModItems; import vazkii.botania.common.item.equipment.bauble.ItemMonocle; import vazkii.botania.common.lib.LibObfuscation; import cpw.mods.fml.client.registry.ClientRegistry; @@ -188,9 +189,16 @@ public class ClientProxy extends CommonProxy { @Override public void preInit(FMLPreInitializationEvent event) { - super.preInit(event); - PersistentVariableHelper.setCacheFile(new File(Minecraft.getMinecraft().mcDataDir, "BotaniaVars.dat")); + try { + PersistentVariableHelper.load(); + PersistentVariableHelper.save(); + } catch (IOException e) { + FMLLog.severe("Botania's persistent Variables couldn't load!"); + e.printStackTrace(); + } + + super.preInit(event); } @Override @@ -211,9 +219,11 @@ public class ClientProxy extends CommonProxy { MinecraftForge.EVENT_BUS.register(new MultiblockRenderHandler()); FMLCommonHandler.instance().bus().register(new CorporeaAutoCompleteHandler()); + if(ConfigHandler.useAdaptativeConfig) + FMLCommonHandler.instance().bus().register(new AdaptorNotifier()); if(ConfigHandler.versionCheckEnabled) new VersionChecker().init(); - + if(ConfigHandler.enableSeasonalFeatures) { Calendar calendar = Calendar.getInstance(); if(calendar.get(2) == 11 && calendar.get(5) >= 24 && calendar.get(5) <= 26 || calendar.get(2) == 0 && calendar.get(5) <= 6) @@ -224,15 +234,8 @@ public class ClientProxy extends CommonProxy { initRenderers(); - - try { - PersistentVariableHelper.load(); - PersistentVariableHelper.save(); - } catch (IOException e) { - FMLLog.severe("Botania's persistent Variables couldn't load!"); - e.printStackTrace(); - } } + @Override public void postInit(FMLPostInitializationEvent event) { super.postInit(event); @@ -409,6 +412,19 @@ public class ClientProxy extends CommonProxy { } return false; } + + @Override + public String getLastVersion() { + String s = PersistentVariableHelper.lastBotaniaVersion; + + if(s == null) + return "N/A"; + + if(s.indexOf("-") > 0) + return s.split("-")[1]; + + return s; + } @Override public void playRecordClientSided(World world, int x, int y, int z, ItemRecord record) { diff --git a/src/main/java/vazkii/botania/common/core/handler/ConfigHandler.java b/src/main/java/vazkii/botania/common/core/handler/ConfigHandler.java index 4a20da0a2..31b8b3241 100644 --- a/src/main/java/vazkii/botania/common/core/handler/ConfigHandler.java +++ b/src/main/java/vazkii/botania/common/core/handler/ConfigHandler.java @@ -11,10 +11,22 @@ package vazkii.botania.common.core.handler; import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.potion.Potion; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.ChatStyle; +import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Property; +import vazkii.botania.api.BotaniaAPI; +import vazkii.botania.common.Botania; import vazkii.botania.common.lib.LibMisc; import vazkii.botania.common.lib.LibPotionNames; import cpw.mods.fml.client.event.ConfigChangedEvent; @@ -25,11 +37,14 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent; public final class ConfigHandler { public static Configuration config; + public static ConfigAdaptor adaptor; private static final String CATEGORY_POTIONS = "potions"; public static final int hardcorePassiveGeneration = 72000; + public static boolean useAdaptativeConfig = true; + public static boolean useShaders = true; public static boolean lexiconRotatingItems = true; public static boolean lexiconJustifiedText = false; @@ -72,10 +87,10 @@ public final class ConfigHandler { public static boolean invertMagnetRing = false; public static int flowerQuantity = 2; - public static int flowerDensity = 16; + public static int flowerDensity = 2; public static int flowerPatchSize = 6; - public static int flowerPatchChance = 4; - public static double flowerTallChance = 0.1; + public static int flowerPatchChance = 16; + public static double flowerTallChance = 0.05; public static int mushroomQuantity = 40; private static boolean verifiedPotionArray = false; @@ -100,6 +115,10 @@ public final class ConfigHandler { public static void load() { String desc; + desc = "Set this to false to disable the Adaptative Config. Adaptative Config changes any default config values from old versions to the new defaults to make sure you aren't missing out on changes because of old configs. It will not touch any values that were changed manually."; + useAdaptativeConfig = loadPropBool("adaptativeConfig.enabled", desc, useAdaptativeConfig); + adaptor = new ConfigAdaptor(useAdaptativeConfig); + desc = "Set this to false to disable the use of shaders for some of the mod's renders."; useShaders = loadPropBool("shaders.enabled", desc, useShaders); @@ -214,16 +233,22 @@ public final class ConfigHandler { desc = "The quantity of Botania flower patches to generate in the world, defaults to 2, the lower the number the less patches generate."; flowerQuantity = loadPropInt("worldgen.flower.quantity", desc, flowerQuantity); - desc = "The density of each Botania flower patch generated, defaults to 16, the lower the number, the less each patch will have."; + desc = "The density of each Botania flower patch generated, defaults to 2, the lower the number, the less each patch will have."; + adaptor.addMappingInt(0, "worldgen.flower.density", 16); + adaptor.addMappingInt(238, "worldgen.flower.density", 2); flowerDensity = loadPropInt("worldgen.flower.density", desc, flowerDensity); - desc = "The size of each Botania flower patch. The larger this is the farther the each patch can spread"; + desc = "The size of each Botania flower patch, defaults to 6. The larger this is the farther the each patch can spread"; flowerPatchSize = loadPropInt("worldgen.flower.patchSize", desc, flowerPatchSize); - desc = "The chance for a Botania flower patch to be generated. The higher this value is the less patches will exist and the more flower each will have."; + desc = "The inverse chance for a Botania flower patch to be generated, defaults to 16. The higher this value is the less patches will exist and the more flower each will have."; + adaptor.addMappingInt(0, "worldgen.flower.patchChance", 4); + adaptor.addMappingInt(238, "worldgen.flower.patchChance", 16); flowerPatchChance = loadPropInt("worldgen.flower.patchChance", desc, flowerPatchChance); - desc = "The chance for a Botania flower generated in a patch to be a tall flowe. 0.1 is 10%, 1 is 100%."; + desc = "The chance for a Botania flower generated in a patch to be a tall flower. 0.1 is 10%, 1 is 100%. Defaults to 0.05"; + adaptor.addMappingDouble(0, "worldgen.flower.tallChance", 0.1); + adaptor.addMappingDouble(238, "worldgen.flower.tallChance", 0.05); flowerTallChance = loadPropDouble("worldgen.flower.tallChance", desc, flowerTallChance); desc = "The quantity of Botania mushrooms to generate underground, in the world, defaults to 40, the lower the number the less patches generate."; @@ -250,18 +275,30 @@ public final class ConfigHandler { public static int loadPropInt(String propName, String desc, int default_) { Property prop = config.get(Configuration.CATEGORY_GENERAL, propName, default_); prop.comment = desc; + + if(adaptor != null) + adaptor.adaptPropertyInt(prop, prop.getInt(default_)); + return prop.getInt(default_); } public static double loadPropDouble(String propName, String desc, double default_) { Property prop = config.get(Configuration.CATEGORY_GENERAL, propName, default_); prop.comment = desc; + + if(adaptor != null) + adaptor.adaptPropertyDouble(prop, prop.getDouble(default_)); + return prop.getDouble(default_); } public static boolean loadPropBool(String propName, String desc, boolean default_) { Property prop = config.get(Configuration.CATEGORY_GENERAL, propName, default_); prop.comment = desc; + + if(adaptor != null) + adaptor.adaptPropertyBool(prop, prop.getBoolean(default_)); + return prop.getBoolean(default_); } @@ -287,6 +324,127 @@ public final class ConfigHandler { verifiedPotionArray = true; } + public static class ConfigAdaptor { + + private boolean enabled; + private int lastBuild; + private int currentBuild; + + private Map> adaptableValues = new HashMap(); + private List changes = new ArrayList(); + + public ConfigAdaptor(boolean enabled) { + this.enabled = enabled; + + String lastVersion = Botania.proxy.getLastVersion(); + try { + lastBuild = Integer.parseInt(lastVersion); +// currentBuild = Integer.parseInt(LibMisc.BUILD); + currentBuild = 238; // DEBUG REMOVE TODO + } catch(NumberFormatException e) { + this.enabled = false; + } + } + + public void adaptProperty(Property prop, T val) { + if(!enabled) + return; + + String name = prop.getName(); + + if(!adaptableValues.containsKey(name)) + return; + + AdaptableValue bestValue = null; + for(AdaptableValue value : adaptableValues.get(name)) { + if(value.version >= lastBuild) // If version is newer than what we last used we don't care about it + continue; + + if(bestValue == null || value.version > bestValue.version) + bestValue = value; + } + + if(bestValue != null) { + T expected = bestValue.value; + if(val.getClass() == Double.class || val.getClass() == Float.class) { + double epsilon = 1.0E-6; + float valF = ((Number) val).floatValue(); + float expectedF = ((Number) expected).floatValue(); + + if(Math.abs(valF - expectedF) < epsilon) { + prop.setValue(prop.getDefault()); + changes.add(" " + prop.getName() + ": " + val + " -> " + prop.getDefault()); + } + } else if(val == expected) { + prop.setValue(prop.getDefault()); + changes.add(" " + prop.getName() + ": " + val + " -> " + prop.getDefault()); + } + } + } + + public void addMapping(int version, String key, T val) { + if(!enabled) + return; + + AdaptableValue adapt = new AdaptableValue(version, val); + if(!adaptableValues.containsKey(key)) { + ArrayList list = new ArrayList(); + adaptableValues.put(key, list); + } + + List list = adaptableValues.get(key); + list.add(adapt); + } + + public void tellChanges(EntityPlayer player) { + if(changes.size() == 0) + return; + + player.addChatComponentMessage(new ChatComponentTranslation("botaniamisc.adaptativeConfigChanges").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.GOLD))); + for(String change : changes) + player.addChatMessage(new ChatComponentText(change).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.LIGHT_PURPLE))); + } + + public void addMappingInt(int version, String key, int val) { + this.addMapping(version, key, val); + } + + public void addMappingDouble(int version, String key, double val) { + this.addMapping(version, key, val); + } + + public void addMappingBool(int version, String key, boolean val) { + this.addMapping(version, key, val); + } + + public void adaptPropertyInt(Property prop, int val) { + this.adaptProperty(prop, val); + } + + public void adaptPropertyDouble(Property prop, double val) { + this.adaptProperty(prop, val); + } + + public void adaptPropertyBool(Property prop, boolean val) { + this.adaptProperty(prop, val); + } + + public static class AdaptableValue { + + public final int version; + public final T value; + public final Class valueType; + + public AdaptableValue(int version, T value) { + this.version = version; + this.value = value; + valueType = (Class) value.getClass(); + } + + } + + } + public static class ChangeListener { @SubscribeEvent diff --git a/src/main/java/vazkii/botania/common/core/proxy/CommonProxy.java b/src/main/java/vazkii/botania/common/core/proxy/CommonProxy.java index 1249071e3..6f3951d7e 100644 --- a/src/main/java/vazkii/botania/common/core/proxy/CommonProxy.java +++ b/src/main/java/vazkii/botania/common/core/proxy/CommonProxy.java @@ -64,6 +64,7 @@ import vazkii.botania.common.integration.buildcraft.StatementAPIPlugin; import vazkii.botania.common.integration.etfuturum.ModBanners; import vazkii.botania.common.item.ModItems; import vazkii.botania.common.lexicon.LexiconData; +import vazkii.botania.common.lib.LibMisc; import vazkii.botania.common.network.GuiHandler; import vazkii.botania.common.world.WorldTypeSkyblock; import cpw.mods.fml.common.FMLCommonHandler; @@ -200,6 +201,10 @@ public class CommonProxy { public boolean isClientPlayerWearingMonocle() { return false; } + + public String getLastVersion() { + return LibMisc.BUILD; + } public void setExtraReach(EntityLivingBase entity, float reach) { if(entity instanceof EntityPlayerMP) diff --git a/src/main/java/vazkii/botania/common/core/version/AdaptorNotifier.java b/src/main/java/vazkii/botania/common/core/version/AdaptorNotifier.java new file mode 100644 index 000000000..c48c4c029 --- /dev/null +++ b/src/main/java/vazkii/botania/common/core/version/AdaptorNotifier.java @@ -0,0 +1,40 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [05/12/2015, 15:31:51 (GMT)] + */ +package vazkii.botania.common.core.version; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.ChatStyle; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IChatComponent; +import net.minecraft.util.StatCollector; +import vazkii.botania.common.core.handler.ConfigHandler; +import vazkii.botania.common.lib.LibMisc; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent; +import cpw.mods.fml.common.gameevent.TickEvent.Phase; + +public final class AdaptorNotifier { + + boolean triedToWarnPlayer; + + @SubscribeEvent + public void onTick(ClientTickEvent event) { + if(!triedToWarnPlayer && Minecraft.getMinecraft().thePlayer != null) { + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + ConfigHandler.adaptor.tellChanges(player); + + triedToWarnPlayer = true; + } + } + +} diff --git a/src/main/resources/assets/botania/lang/en_US.lang b/src/main/resources/assets/botania/lang/en_US.lang index 784138acb..94b992fea 100644 --- a/src/main/resources/assets/botania/lang/en_US.lang +++ b/src/main/resources/assets/botania/lang/en_US.lang @@ -147,6 +147,7 @@ botaniamisc.tutorialText=Ingame botaniamisc.tutorialVideo=Video botaniamisc.shiftToStopSpin=(SHIFT to stop animation) botaniamisc.noVideo=&4Video will be back soon. Sorry :( +botaniamisc.adaptativeConfigChanges=Botania's Adaptative Config has changed the following config defaults for you: # NEI INTEGRATION botania.nei.brewery=Botanical Brewery