moved BlockMatcher configuration into main config file

This commit is contained in:
octarine-noise
2014-08-20 11:59:25 +02:00
parent 8b4967584e
commit f8092685a8
16 changed files with 305 additions and 139 deletions

View File

@@ -1,6 +1,5 @@
package mods.betterfoliage.client;
import java.io.File;
import java.util.Map;
import mods.betterfoliage.BetterFoliage;
@@ -43,11 +42,6 @@ public class BetterFoliageClient {
public static LeafParticleTextures leafParticles = new LeafParticleTextures(0);
public static WindTracker wind = new WindTracker();
public static BlockMatcher leaves = new BlockMatcher();
public static BlockMatcher crops = new BlockMatcher();
public static BlockMatcher dirt = new BlockMatcher();
public static BlockMatcher grass = new BlockMatcher();
public static void preInit() {
FMLCommonHandler.instance().bus().register(new KeyHandler());
FMLCommonHandler.instance().bus().register(new Config());
@@ -66,17 +60,10 @@ public class BetterFoliageClient {
MinecraftForge.EVENT_BUS.register(wind);
FMLCommonHandler.instance().bus().register(wind);
leaves.load(new File(BetterFoliage.configDir, "classesLeaves.cfg"), new ResourceLocation("betterfoliage:classesLeavesDefault.cfg"));
MinecraftForge.EVENT_BUS.register(leaves);
crops.load(new File(BetterFoliage.configDir, "classesCrops.cfg"), new ResourceLocation("betterfoliage:classesCropsDefault.cfg"));
MinecraftForge.EVENT_BUS.register(crops);
dirt.load(new File(BetterFoliage.configDir, "classesDirt.cfg"), new ResourceLocation("betterfoliage:classesDirtDefault.cfg"));
MinecraftForge.EVENT_BUS.register(dirt);
grass.load(new File(BetterFoliage.configDir, "classesGrass.cfg"), new ResourceLocation("betterfoliage:classesGrassDefault.cfg"));
MinecraftForge.EVENT_BUS.register(grass);
MinecraftForge.EVENT_BUS.register(Config.leaves);
MinecraftForge.EVENT_BUS.register(Config.crops);
MinecraftForge.EVENT_BUS.register(Config.dirt);
MinecraftForge.EVENT_BUS.register(Config.grass);
BetterFoliage.log.info("Registering texture generators");
MinecraftForge.EVENT_BUS.register(leafGenerator);
@@ -110,7 +97,7 @@ public class BetterFoliageClient {
public static void onRandomDisplayTick(Block block, World world, int x, int y, int z) {
if (!Config.leafFXEnabled) return;
if (!leaves.matchesID(block) || !world.isAirBlock(x, y - 1, z)) return;
if (!Config.leaves.matchesID(block) || !world.isAirBlock(x, y - 1, z)) return;
if (Math.random() > Config.leafFXChance) return;
Minecraft.getMinecraft().effectRenderer.addEffect(new EntityFXFallingLeaves(world, x, y, z));
}

View File

@@ -1,19 +1,19 @@
package mods.betterfoliage.client;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import mods.betterfoliage.BetterFoliage;
import mods.betterfoliage.common.util.Utils;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.world.WorldEvent;
import com.google.common.base.Charsets;
import com.google.common.collect.Sets;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
@@ -23,16 +23,7 @@ public class BlockMatcher {
public Set<Class<?>> whiteList = Sets.newHashSet();
public Set<Class<?>> blackList = Sets.newHashSet();
public Set<Integer> blockIDs = Sets.newHashSet();
public void addClass(String className) {
try {
if (className.startsWith("-"))
blackList.add(Class.forName(className.substring(1)));
else
whiteList.add(Class.forName(className));
} catch(ClassNotFoundException e) {}
}
public boolean matchesClass(Block block) {
for (Class<?> clazz : blackList) if (clazz.isAssignableFrom(block.getClass())) return false;
for (Class<?> clazz : whiteList) if (clazz.isAssignableFrom(block.getClass())) return true;
@@ -47,43 +38,56 @@ public class BlockMatcher {
return blockIDs.contains(Block.blockRegistry.getIDForObject(block));
}
public void load(File file, ResourceLocation defaults) {
if (!file.exists()) try {
Utils.copyFromTextResource(defaults, file);
} catch (IOException e) {
BetterFoliage.log.error(String.format("Error copying default resource: %s", defaults.toString()));
e.printStackTrace();
}
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
whiteList.clear();
blackList.clear();
String line = reader.readLine();
while(line != null) {
addClass(line.trim());
line = reader.readLine();
}
reader.close();
} catch (Exception e) {
BetterFoliage.log.warn(String.format("Error reading configuration: %s", file.getName()));
}
public void updateClassLists(String[] newWhitelist, String[] newBlacklist) {
whiteList.clear();
for(String className : newWhitelist) try {
whiteList.add(Class.forName(className));
} catch(ClassNotFoundException e) {}
blackList.clear();
for(String className : newBlacklist) try {
blackList.add(Class.forName(className));
} catch(ClassNotFoundException e) {}
updateBlockIDs();
}
@SuppressWarnings("unchecked")
public void updateBlockIDs() {
blockIDs.clear();
Iterator<Block> iter = Block.blockRegistry.iterator();
while (iter.hasNext()) {
Block block = iter.next();
if (matchesClass(block)) blockIDs.add(Block.blockRegistry.getIDForObject(block));
}
}
public static void loadDefaultLists(ResourceLocation defaults, Collection<String> blacklist, Collection<String> whitelist) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(Minecraft.getMinecraft().getResourceManager().getResource(defaults).getInputStream(), Charsets.UTF_8));
String line = reader.readLine();
while(line != null) {
line = line.trim();
if (!line.isEmpty() && !line.startsWith("//")) {
if (line.startsWith("-"))
blacklist.add(line.substring(1));
else
whitelist.add(line);
}
line = reader.readLine();
}
reader.close();
} catch (Exception e) {
BetterFoliage.log.warn(String.format("Error reading configuration %s", defaults.toString()));
}
}
/** Caches block IDs on world load for fast lookup
* @param event
*/
@SuppressWarnings("unchecked")
@SubscribeEvent
public void handleWorldLoad(WorldEvent.Load event) {
if (!(event.world instanceof WorldClient)) return;
blockIDs.clear();
Iterator<Block> iter = Block.blockRegistry.iterator();
while (iter.hasNext()) {
Block block = iter.next();
if (matchesClass(block)) blockIDs.add(Block.blockRegistry.getIDForObject(block));
}
if (event.world instanceof WorldClient) updateBlockIDs();
}
}

View File

@@ -5,6 +5,7 @@ import java.lang.reflect.Field;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mods.betterfoliage.common.config.Config;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.util.ResourceLocation;
@@ -70,8 +71,8 @@ public class ShadersModIntegration {
* @return entity data to use
*/
public static int getBlockIdOverride(int original, Block block) {
if (BetterFoliageClient.leaves.matchesID(original & 0xFFFF)) return leavesEntityData;
if (BetterFoliageClient.crops.matchesID(original & 0xFFFF)) return tallGrassEntityData;
if (Config.leaves.matchesID(original & 0xFFFF)) return leavesEntityData;
if (Config.crops.matchesID(original & 0xFFFF)) return tallGrassEntityData;
return original;
}

View File

@@ -35,7 +35,7 @@ public class ConfigGuiFactory implements IModGuiFactory {
public static class ConfigGuiBetterFoliage extends GuiConfig {
public ConfigGuiBetterFoliage(GuiScreen parentScreen) {
super(parentScreen, Config.getConfigRootCategories(), BetterFoliage.MOD_ID, null, false, false, BetterFoliage.MOD_NAME);
super(parentScreen, Config.getConfigRootElements(), BetterFoliage.MOD_ID, null, false, false, BetterFoliage.MOD_NAME);
}
}
}

View File

@@ -3,7 +3,6 @@ package mods.betterfoliage.client.render.impl;
import java.util.Random;
import mods.betterfoliage.BetterFoliage;
import mods.betterfoliage.client.BetterFoliageClient;
import mods.betterfoliage.client.render.IRenderBlockDecorator;
import mods.betterfoliage.client.render.IconSet;
import mods.betterfoliage.client.render.RenderBlockAOBase;
@@ -32,7 +31,7 @@ public class RenderBlockBetterAlgae extends RenderBlockAOBase implements IRender
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
if (!Config.algaeEnabled) return false;
if (!(BetterFoliageClient.dirt.matchesID(block))) return false;
if (!(Config.dirt.matchesID(block))) return false;
if (blockAccess.getBlock(x, y + 1, z).getMaterial() != Material.water) return false;
if (blockAccess.getBlock(x, y + 2, z).getMaterial() != Material.water) return false;
if (blockAccess.getBiomeGenForCoords(x, z).temperature < 0.4f) return false;

View File

@@ -1,7 +1,6 @@
package mods.betterfoliage.client.render.impl;
import mods.betterfoliage.BetterFoliage;
import mods.betterfoliage.client.BetterFoliageClient;
import mods.betterfoliage.client.ShadersModIntegration;
import mods.betterfoliage.client.render.IRenderBlockDecorator;
import mods.betterfoliage.client.render.IconSet;
@@ -32,7 +31,7 @@ public class RenderBlockBetterGrass extends RenderBlockAOBase implements IRender
protected boolean connectXP, connectXN, connectZP, connectZN;
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
return BetterFoliageClient.grass.matchesID(block);
return Config.grass.matchesID(block);
}
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
@@ -77,16 +76,16 @@ public class RenderBlockBetterGrass extends RenderBlockAOBase implements IRender
protected void checkConnectedGrass(int x, int y, int z) {
Block blockBelow = blockAccess.getBlock(x, y - 1, z);
if (Config.ctxGrassAggressiveEnabled && (BetterFoliageClient.grass.matchesID(blockBelow) || BetterFoliageClient.dirt.matchesID(blockBelow))) {
if (Config.ctxGrassAggressiveEnabled && (Config.grass.matchesID(blockBelow) || Config.dirt.matchesID(blockBelow))) {
connectXP = true;
connectXN = true;
connectZP = true;
connectZN = true;
} else if (Config.ctxGrassClassicEnabled) {
connectXP = BetterFoliageClient.grass.matchesID(blockAccess.getBlock(x + 1, y - 1, z));
connectXN = BetterFoliageClient.grass.matchesID(blockAccess.getBlock(x - 1, y - 1, z));
connectZP = BetterFoliageClient.grass.matchesID(blockAccess.getBlock(x, y - 1, z + 1));
connectZN = BetterFoliageClient.grass.matchesID(blockAccess.getBlock(x, y - 1, z - 1));
connectXP = Config.grass.matchesID(blockAccess.getBlock(x + 1, y - 1, z));
connectXN = Config.grass.matchesID(blockAccess.getBlock(x - 1, y - 1, z));
connectZP = Config.grass.matchesID(blockAccess.getBlock(x, y - 1, z + 1));
connectZN = Config.grass.matchesID(blockAccess.getBlock(x, y - 1, z - 1));
} else {
connectXP = false;
connectXN = false;

View File

@@ -25,7 +25,7 @@ public class RenderBlockBetterLeaves extends RenderBlockAOBase implements IRende
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
if (!Config.leavesEnabled) return false;
if (original > 0 && original < 42) return false;
return BetterFoliageClient.leaves.matchesID(block) && !isBlockSurrounded(blockAccess, x, y, z);
return Config.leaves.matchesID(block) && !isBlockSurrounded(blockAccess, x, y, z);
}
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {

View File

@@ -3,7 +3,6 @@ package mods.betterfoliage.client.render.impl;
import java.util.Random;
import mods.betterfoliage.BetterFoliage;
import mods.betterfoliage.client.BetterFoliageClient;
import mods.betterfoliage.client.ShadersModIntegration;
import mods.betterfoliage.client.render.IRenderBlockDecorator;
import mods.betterfoliage.client.render.IconSet;
@@ -34,12 +33,12 @@ public class RenderBlockBetterReed extends RenderBlockAOBase implements IRenderB
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
if (!Config.reedEnabled) return false;
if (!(BetterFoliageClient.dirt.matchesID(block))) return false;
if (!(Config.dirt.matchesID(block))) return false;
if (blockAccess.getBlock(x, y + 1, z).getMaterial() != Material.water) return false;
if (!blockAccess.isAirBlock(x, y + 2, z)) return false;
if (blockAccess.getBiomeGenForCoords(x, z).temperature < 0.4f || blockAccess.getBiomeGenForCoords(x, z).rainfall < 0.4f) return false;
int terrainVariation = MathHelper.floor_double((noise.func_151605_a(x, z) + 1.0) * 32.0);
return terrainVariation < Config.reedChance;
return terrainVariation < Config.reedPopulation;
}
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {

View File

@@ -1,6 +1,5 @@
package mods.betterfoliage.client.render.impl;
import mods.betterfoliage.client.BetterFoliageClient;
import mods.betterfoliage.client.render.FakeRenderBlockAOBase;
import mods.betterfoliage.client.render.IRenderBlockDecorator;
import mods.betterfoliage.common.config.Config;
@@ -23,8 +22,8 @@ public class RenderBlocksBetterGrassSide extends FakeRenderBlockAOBase implement
@Override
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
return Config.ctxGrassAggressiveEnabled &&
BetterFoliageClient.dirt.matchesID(block) &&
BetterFoliageClient.grass.matchesID(blockAccess.getBlock(x, y + 1, z));
Config.dirt.matchesID(block) &&
Config.grass.matchesID(blockAccess.getBlock(x, y + 1, z));
}
@Override

View File

@@ -6,6 +6,7 @@ import java.util.Set;
import mods.betterfoliage.BetterFoliage;
import mods.betterfoliage.client.BetterFoliageClient;
import mods.betterfoliage.common.config.Config;
import mods.betterfoliage.common.util.Utils;
import mods.betterfoliage.loader.DeobfHelper;
import net.minecraft.block.Block;
@@ -75,7 +76,7 @@ public class LeafTextureEnumerator implements IIconRegister {
Iterator<Block> iter = Block.blockRegistry.iterator();
while(iter.hasNext()) {
Block block = iter.next();
if (BetterFoliageClient.leaves.matchesClass(block)) {
if (Config.leaves.matchesClass(block)) {
BetterFoliage.log.debug(String.format("Inspecting leaf block: %s", block.getClass().getName()));
block.registerBlockIcons(this);
}

View File

@@ -0,0 +1,92 @@
package mods.betterfoliage.common.config;
import net.minecraft.client.resources.I18n;
import cpw.mods.fml.client.config.GuiConfig;
import cpw.mods.fml.client.config.GuiConfigEntries;
import cpw.mods.fml.client.config.IConfigElement;
public class AlternateTextBooleanEntry extends GuiConfigEntries.ButtonEntry {
protected final boolean beforeValue;
protected boolean currentValue;
public AlternateTextBooleanEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement<Boolean> configElement)
{
super(owningScreen, owningEntryList, configElement);
this.beforeValue = Boolean.valueOf(configElement.get().toString());
this.currentValue = beforeValue;
this.btnValue.enabled = enabled();
updateValueButtonText();
}
@Override
public void updateValueButtonText()
{
this.btnValue.displayString = I18n.format(configElement.getLanguageKey() + "." + String.valueOf(currentValue));
// btnValue.packedFGColour = currentValue ? GuiUtils.getColorCode('2', true) : GuiUtils.getColorCode('4', true);
}
@Override
public void valueButtonPressed(int slotIndex)
{
if (enabled())
currentValue = !currentValue;
}
@Override
public boolean isDefault()
{
return currentValue == Boolean.valueOf(configElement.getDefault().toString());
}
@Override
public void setToDefault()
{
if (enabled())
{
currentValue = Boolean.valueOf(configElement.getDefault().toString());
updateValueButtonText();
}
}
@Override
public boolean isChanged()
{
return currentValue != beforeValue;
}
@Override
public void undoChanges()
{
if (enabled())
{
currentValue = beforeValue;
updateValueButtonText();
}
}
@SuppressWarnings("unchecked")
@Override
public boolean saveConfigElement()
{
if (enabled() && isChanged())
{
configElement.set(currentValue);
return configElement.requiresMcRestart();
}
return false;
}
@Override
public Boolean getCurrentValue()
{
return currentValue;
}
@Override
public Boolean[] getCurrentValues()
{
return new Boolean[] { getCurrentValue() };
}
}

View File

@@ -4,7 +4,10 @@ import java.io.File;
import java.util.List;
import mods.betterfoliage.BetterFoliage;
import mods.betterfoliage.client.BlockMatcher;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.config.ConfigCategory;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
@@ -18,11 +21,19 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public class Config {
public enum Category {
extraLeaves, shortGrass, cactus, lilypad, reed, algae, coral, fallingLeaves, connectedGrass;
blockTypes, extraLeaves, shortGrass, cactus, lilypad, reed, algae, coral, fallingLeaves, connectedGrass;
}
/** {@link Configuration} object bound to the config file */
public static Configuration rawConfig;
// block matchers
public static BlockMatcher leaves = new BlockMatcher();
public static BlockMatcher crops = new BlockMatcher();
public static BlockMatcher dirt = new BlockMatcher();
public static BlockMatcher grass = new BlockMatcher();
// extracted config values
public static boolean leavesEnabled;
public static boolean leavesSkew;
public static double leavesHOffset;
@@ -46,7 +57,7 @@ public class Config {
public static double reedHOffset;
public static double reedHeightMin;
public static double reedHeightMax;
public static int reedChance;
public static int reedPopulation;
public static boolean algaeEnabled;
public static double algaeHOffset;
@@ -75,25 +86,30 @@ public class Config {
public static boolean ctxGrassClassicEnabled;
public static boolean ctxGrassAggressiveEnabled;
/** Read the config file
* @param configFile
*/
public static void readConfig(File configFile) {
rawConfig = new Configuration(configFile, true);
updateValues();
if (rawConfig.hasChanged()) rawConfig.save();
}
/** Extract the config properties to static value fields for quick access */
public static void updateValues() {
leavesEnabled = getBoolean(Category.extraLeaves, "enabled", true, "betterfoliage.enabled");
leavesSkew = getBoolean(Category.extraLeaves, "skewMode", true, "betterfoliage.leavesMode");
leavesSkew = getBoolean(Category.extraLeaves, "skewMode", false, "betterfoliage.leavesMode");
leavesHOffset = getDouble(Category.extraLeaves, "hOffset", 0.2, 0.0, 0.4, "betterfoliage.hOffset");
leavesVOffset = getDouble(Category.extraLeaves, "vOffset", 0.1, 0.0, 0.4, "betterfoliage.vOffset");
leavesSize = getDouble(Category.extraLeaves, "size", 1.4, 0.75, 1.8, "betterfoliage.size");
grassEnabled = getBoolean(Category.shortGrass, "enabled", true, "betterfoliage.enabled");
grassHOffset = getDouble(Category.shortGrass, "hOffset", 0.2, 0.0, 0.4, "betterfoliage.hOffset");
grassHeightMin = getDouble(Category.shortGrass, "heightMin", 0.8, 0.1, 1.5, "betterfoliage.minHeight");
grassHeightMin = getDouble(Category.shortGrass, "heightMin", 0.6, 0.1, 1.5, "betterfoliage.minHeight");
grassHeightMax = getDouble(Category.shortGrass, "heightMax", 0.8, 0.1, 1.5, "betterfoliage.maxHeight");
grassSize = getDouble(Category.shortGrass, "size", 1.0, 0.5, 1.5, "betterfoliage.size");
grassUseGenerated = getBoolean(Category.shortGrass, "useGenerated", false, "betterfoliage.shortGrass.useGenerated");
grassHeightMin = clampDoubleToMax(Category.shortGrass, "heightMin", "heightMax");
cactusEnabled = getBoolean(Category.cactus, "enabled", true, "betterfoliage.enabled");
@@ -105,7 +121,8 @@ public class Config {
reedHOffset = getDouble(Category.reed, "hOffset", 0.2, 0.0, 0.4, "betterfoliage.hOffset");
reedHeightMin = getDouble(Category.reed, "heightMin", 2.0, 1.5, 3.5, "betterfoliage.minHeight");
reedHeightMax = getDouble(Category.reed, "heightMax", 2.5, 1.5, 3.5, "betterfoliage.maxHeight");
reedChance = getInt(Category.reed, "chance", 32, 0, 64, "betterfoliage.chance");
reedPopulation = getInt(Category.reed, "population", 32, 0, 64, "betterfoliage.population");
reedHeightMin = clampDoubleToMax(Category.reed, "heightMin", "heightMax");
algaeEnabled = getBoolean(Category.algae, "enabled", true, "betterfoliage.enabled");
algaeHOffset = getDouble(Category.algae, "hOffset", 0.1, 0.0, 0.25, "betterfoliage.hOffset");
@@ -113,13 +130,14 @@ public class Config {
algaeHeightMin = getDouble(Category.algae, "heightMin", 0.5, 0.1, 1.5, "betterfoliage.minHeight");
algaeHeightMax = getDouble(Category.algae, "heightMax", 1.0, 0.1, 1.5, "betterfoliage.maxHeight");
algaePopulation = getInt(Category.algae, "population", 48, 0, 64, "betterfoliage.population");
algaeHeightMin = clampDoubleToMax(Category.algae, "heightMin", "heightMax");
coralEnabled = getBoolean(Category.coral, "enabled", true, "betterfoliage.enabled");
coralHOffset = getDouble(Category.coral, "hOffset", 0.2, 0.0, 0.4, "betterfoliage.hOffset");
coralVOffset = getDouble(Category.coral, "vOffset", 0.1, 0.0, 0.4, "betterfoliage.vOffset");
coralSize = getDouble(Category.coral, "size", 1.0, 0.5, 1.5, "betterfoliage.coral.size");
coralCrustSize = getDouble(Category.coral, "crustSize", 1.0, 0.5, 1.5, "betterfoliage.coral.crustSize");
coralChance = getInt(Category.coral, "chance", 48, 0, 64, "betterfoliage.coral.chance");
coralSize = getDouble(Category.coral, "size", 0.7, 0.5, 1.5, "betterfoliage.coral.size");
coralCrustSize = getDouble(Category.coral, "crustSize", 1.4, 0.5, 1.5, "betterfoliage.coral.crustSize");
coralChance = getInt(Category.coral, "chance", 32, 0, 64, "betterfoliage.coral.chance");
coralPopulation = getInt(Category.coral, "population", 48, 0, 64, "betterfoliage.population");
leafFXEnabled = getBoolean(Category.fallingLeaves, "enabled", true, "betterfoliage.enabled");
@@ -129,18 +147,31 @@ public class Config {
leafFXSize = getDouble(Category.fallingLeaves, "size", 0.75, 0.25, 1.5, "betterfoliage.fallingLeaves.size");
leafFXChance = getDouble(Category.fallingLeaves, "chance", 0.05, 0.001, 1.0, "betterfoliage.fallingLeaves.chance");
leafFXPerturb = getDouble(Category.fallingLeaves, "perturb", 0.25, 0.01, 1.0, "betterfoliage.fallingLeaves.perturb");
leafFXLifetime = getDouble(Category.fallingLeaves, "lifetime", 5.0, 1.0, 10.0, "betterfoliage.fallingLeaves.lifetime");
leafFXLifetime = getDouble(Category.fallingLeaves, "lifetime", 5.0, 1.0, 15.0, "betterfoliage.fallingLeaves.lifetime");
ctxGrassClassicEnabled = getBoolean(Category.connectedGrass, "classic", true, "betterfoliage.connectedGrass.classic");
ctxGrassAggressiveEnabled= getBoolean(Category.connectedGrass, "aggressive", true, "betterfoliage.connectedGrass.aggressive");
updateBlockMatcher(dirt, Category.blockTypes, "dirtWhitelist", "betterfoliage.blockTypes.dirtWhitelist", "dirtBlacklist", "betterfoliage.blockTypes.dirtBlacklist", new ResourceLocation("betterfoliage:classesDirtDefault.cfg"));
updateBlockMatcher(grass, Category.blockTypes, "grassWhitelist", "betterfoliage.blockTypes.grassWhitelist", "grassBlacklist", "betterfoliage.blockTypes.grassBlacklist", new ResourceLocation("betterfoliage:classesGrassDefault.cfg"));
updateBlockMatcher(leaves, Category.blockTypes, "leavesWhitelist", "betterfoliage.blockTypes.leavesWhitelist", "leavesBlacklist", "betterfoliage.blockTypes.leavesBlacklist", new ResourceLocation("betterfoliage:classesLeavesDefault.cfg"));
updateBlockMatcher(crops, Category.blockTypes, "cropWhitelist", "betterfoliage.blockTypes.cropWhitelist", "cropBlacklist", "betterfoliage.blockTypes.cropBlacklist", new ResourceLocation("betterfoliage:classesCropDefault.cfg"));
rawConfig.getCategory(Category.extraLeaves.toString()).get("skewMode").setConfigEntryClass(AlternateTextBooleanEntry.class);
for (Category category : Category.values()) rawConfig.setCategoryLanguageKey(category.toString(), String.format("betterfoliage.%s", category.toString()));
setOrder(Category.extraLeaves, "enabled", "skewMode", "hOffset", "vOffset", "size");
setOrder(Category.shortGrass, "enabled", "useGenerated", "hOffset", "heightMin", "heightMax", "size");
setOrder(Category.lilypad, "enabled", "hOffset", "flowerChance");
setOrder(Category.reed, "enabled", "hOffset", "heightMin", "heightMax", "population");
setOrder(Category.algae, "enabled", "hOffset", "heightMin", "heightMax", "population");
setOrder(Category.coral, "enabled", "hOffset", "vOffset", "size", "crustSize", "population", "chance");
setOrder(Category.fallingLeaves, "enabled", "size", "chance", "lifetime", "speed", "windStrength", "stormStrength", "perturb");
setOrder(Category.connectedGrass, "classic", "aggressive");
}
@SuppressWarnings("rawtypes")
public static List<IConfigElement> getConfigRootCategories() {
public static List<IConfigElement> getConfigRootElements() {
List<IConfigElement> result = Lists.newLinkedList();
for (Category category : Category.values()) {
ConfigElement<?> element = new ConfigElement(rawConfig.getCategory(category.toString()));
@@ -157,6 +188,14 @@ public class Config {
return prop.getDouble();
}
protected static double clampDoubleToMax(Category category, String keySmaller, String keyLarger) {
ConfigCategory cfgCat = rawConfig.getCategory(category.toString());
Property smaller = cfgCat.get(keySmaller);
Property larger = cfgCat.get(keyLarger);
if (smaller.getDouble() > larger.getDouble()) smaller.set(larger.getDouble());
return smaller.getDouble();
}
protected static int getInt(Category category, String key, int defaultValue, int min, int max, String langKey) {
Property prop = rawConfig.get(category.toString(), key, defaultValue);
prop.setMinValue(min);
@@ -165,21 +204,37 @@ public class Config {
return prop.getInt();
}
protected static boolean getBoolean(Category category, String key, boolean defaultValue, String langKey) {
Property prop = rawConfig.get(category.toString(), key, defaultValue);
prop.setLanguageKey(langKey);
return prop.getBoolean();
protected static boolean getBoolean(Category category, String key, boolean defaultValue, String langKey) {
Property prop = rawConfig.get(category.toString(), key, defaultValue);
prop.setLanguageKey(langKey);
return prop.getBoolean();
}
protected static void updateBlockMatcher(BlockMatcher bm, Category category, String whitelistKey, String whitelistLangKey, String blacklistKey, String blacklistLangKey, ResourceLocation defaults) {
List<String> defaultWhitelist = Lists.newLinkedList();
List<String> defaultBlacklist = Lists.newLinkedList();
BlockMatcher.loadDefaultLists(defaults, defaultBlacklist, defaultWhitelist);
Property whitelist = rawConfig.get(category.toString(), whitelistKey, defaultWhitelist.toArray(new String[]{}));
Property blacklist = rawConfig.get(category.toString(), blacklistKey, defaultBlacklist.toArray(new String[]{}));
whitelist.setLanguageKey(whitelistLangKey);
blacklist.setLanguageKey(blacklistLangKey);
whitelist.setConfigEntryClass(NonVerboseArrayEntry.class);
blacklist.setConfigEntryClass(NonVerboseArrayEntry.class);
bm.updateClassLists(whitelist.getStringList(), blacklist.getStringList());
}
protected static void setOrder(Category category, String... properties) {
rawConfig.setCategoryPropertyOrder(category.toString(), Lists.newArrayList(properties));
}
@SubscribeEvent
public void handleConfigChange(ConfigChangedEvent.OnConfigChangedEvent event) {
if (event.modID.equals(BetterFoliage.MOD_ID)) {
rawConfig.save();
updateValues();
if (rawConfig.hasChanged()) rawConfig.save();
Minecraft.getMinecraft().renderGlobal.loadRenderers();
}
}

View File

@@ -0,0 +1,35 @@
package mods.betterfoliage.common.config;
import java.util.Iterator;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.EnumChatFormatting;
import cpw.mods.fml.client.config.GuiConfig;
import cpw.mods.fml.client.config.GuiConfigEntries;
import cpw.mods.fml.client.config.IConfigElement;
public class NonVerboseArrayEntry extends GuiConfigEntries.ArrayEntry {
@SuppressWarnings("unchecked")
public NonVerboseArrayEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement<?> configElement) {
super(owningScreen, owningEntryList, configElement);
// strip defaults from tooltip as they can get quite long
boolean defaultRows = false;
Iterator<String> iter = toolTip.iterator();
while(iter.hasNext()) {
if (iter.next().startsWith(EnumChatFormatting.AQUA.toString())) defaultRows = true;
if (defaultRows) iter.remove();
}
String shortDefaults = I18n.format("betterfoliage.arrayEntryDisplay", configElement.getDefaults().length);
toolTip.addAll(this.mc.fontRenderer.listFormattedStringToWidth(EnumChatFormatting.AQUA + I18n.format("fml.configgui.tooltip.default", shortDefaults),300));
}
@Override
public void updateValueButtonText() {
this.btnValue.displayString = I18n.format("betterfoliage.arrayEntryDisplay", currentValues.length);
}
}

View File

@@ -1,24 +1,47 @@
key.betterfoliage.gui=Open Settings
betterfoliage.arrayEntryDisplay=%d entries
betterfoliage.enabled=Enable
betterfoliage.enabled.tooltip=Is this feature enabled?
betterfoliage.hOffset=Horizontal offset
betterfoliage.hOffset.tooltip=Distance feature is shifted horizontally, in blocks
betterfoliage.hOffset.tooltip=The distance this element is shifted horizontally, in blocks
betterfoliage.vOffset=Vertical offset
betterfoliage.vOffset.tooltip=Distance feature is shifted vertically, in blocks
betterfoliage.vOffset.tooltip=The distance this element is shifted vertically, in blocks
betterfoliage.size=Size
betterfoliage.size.tooltip=Size of element
betterfoliage.size.tooltip=Size of this element
betterfoliage.minHeight=Minimum height
betterfoliage.minHeight.tooltip=Minimum height of element
betterfoliage.minHeight=Maximum height
betterfoliage.minHeight.tooltip=Maximum height of element
betterfoliage.maxHeight=Maximum height
betterfoliage.maxHeight.tooltip=Maximum height of element
betterfoliage.population=Population
betterfoliage.population.tooltip=Chance (N in 64) that an eligible block will have this feature
betterfoliage.blockTypes=Block Types
betterfoliage.blockTypes.tooltip=Configure lists of block classes that will have specific features applied to them
betterfoliage.blockTypes.dirtWhitelist=Dirt Whitelist
betterfoliage.blockTypes.dirtBlacklist=Dirt Blacklist
betterfoliage.blockTypes.grassWhitelist=Grass Whitelist
betterfoliage.blockTypes.grassBlacklist=Grass Blacklist
betterfoliage.blockTypes.leavesWhitelist=Leaves Whitelist
betterfoliage.blockTypes.leavesBlacklist=Leaves Blacklist
betterfoliage.blockTypes.cropWhitelist=Crop Whitelist
betterfoliage.blockTypes.cropBlacklist=Crop Blacklist
betterfoliage.blockTypes.dirtWhitelist.tooltip=Blocks recognized as Dirt. Has an impact on Reeds, Algae, Connected Grass
betterfoliage.blockTypes.dirtBlacklist.tooltip=Blocks recognized as Dirt. Has an impact on Reeds, Algae, Connected Grass
betterfoliage.blockTypes.grassWhitelist.tooltip=Blocks recognized as Grass. Has an impact on Short Grass, Connected Grass
betterfoliage.blockTypes.grassBlacklist.tooltip=Blocks recognized as Grass. Has an impact on Short Grass, Connected Grass
betterfoliage.blockTypes.leavesWhitelist.tooltip=Blocks recognized as Leaves. Has an impact on Extra Leaves, Falling Leaves. Blocks will render with leaves block ID in shader programs
betterfoliage.blockTypes.leavesBlacklist.tooltip=Blocks recognized as Leaves. Has an impact on Extra Leaves, Falling Leaves. Blocks will render with leaves block ID in shader programs
betterfoliage.blockTypes.cropWhitelist.tooltip=Blocks recognized as crops. Blocks will render with wheat block ID in shader programs
betterfoliage.blockTypes.cropBlacklist.tooltip=Blocks recognized as crops. Blocks will render with wheat block ID in shader programs
betterfoliage.extraLeaves=Extra Leaves
betterfoliage.extraLeaves.tooltip=Extra round leaves on leaf blocks
message.betterfoliage.leavesMode=Leaves offset mode
message.betterfoliage.leavesMode.tooltip="true" means leaf quads are skewed, "false" means translated
betterfoliage.leavesMode=Leaves offset mode
betterfoliage.leavesMode.tooltip=Translate draws the leaves off-center at a 45deg angle, Skew draws them dentered but with a slightly changed angle
betterfoliage.leavesMode.true=Skew
betterfoliage.leavesMode.false=Translate
betterfoliage.shortGrass=Short Grass
betterfoliage.shortGrass.tooltip=Tufts of grass on top of grass blocks
@@ -62,8 +85,11 @@ betterfoliage.fallingLeaves.chance.tooltip=Chance of each random render tick hit
betterfoliage.fallingLeaves.perturb=Perturbation
betterfoliage.fallingLeaves.perturb.tooltip=Magnitude of perturbation effect. Adds a corkscrew-like motion to the particle synchronized to its rotation
betterfoliage.fallingLeaves.lifetime=Maximum lifetime
betterfoliage.fallingLeaves.lifetime.tooltip=Maximum lifetime of particle in seconds. Minimum lifetime is 60% of this value
betterfoliage.fallingLeaves.lifetime.tooltip=Maximum lifetime of particle in seconds. Minimum lifetime is 60%% of this value
betterfoliage.connectedGrass=Connected grass textures
betterfoliage.connectedGrass.tooltip=Connected grass textures
betterfoliage.connectedGrass.classic=Classic connected grass
betterfoliage.connectedGrass.classic.tooltip=Draw grass top texture on grass block face if there is a grass block diagonally under it
betterfoliage.connectedGrass.aggressive=Aggressive connected grass
betterfoliage.connectedGrass.aggressive.tooltip=If there is a grass block on top of a dirt block: draw grass top texture on all grass block sides, render dirt block as standard grass block

View File

@@ -1,31 +0,0 @@
key.betterfoliage.gui=Открыть настройки
message.betterfoliage.optionOn=Вкл.
message.betterfoliage.optionOff=Выкл.
message.betterfoliage.config=Конфиг
message.betterfoliage.back=Назад
message.betterfoliage.close=Закрыть
message.betterfoliage.betterLeaves=Доп. листва: %s
message.betterfoliage.betterGrass=Короткая трава: %s
message.betterfoliage.betterCactus=Красивый кактус: %s
message.betterfoliage.betterLilypad=Красивая кувшинка: %s
message.betterfoliage.betterReed=Тростник: %s
message.betterfoliage.betterAlgae=Водоросли: %s
message.betterfoliage.betterCoral=Кораллы: %s
message.betterfoliage.size=Размер
message.betterfoliage.hOffset=H.Offset
message.betterfoliage.vOffset=V.Offset
message.betterfoliage.minHeight=Мин. высота
message.betterfoliage.maxHeight=Макс. высота
message.betterfoliage.flowerChance=Шанс цветов
message.betterfoliage.reedChance=Популяция тростника
message.betterfoliage.leavesMode=Корректировка листвы: %s
message.betterfoliage.genShortgrass=Использовать сгенерированную: %s
message.betterfoliage.leavesSkew=Косая
message.betterfoliage.leavesTranslate=Плавная
message.betterfoliage.algaeChance=Популяция водорослей
message.betterfoliage.crustSize=Размер коры
message.betterfoliage.coralChance=Шанс кораллов
message.betterfoliage.coralPopulation=Популяция кораллов