consolidated config handling
This commit is contained in:
@@ -4,7 +4,7 @@ import java.io.File;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import mods.betterfoliage.client.BetterFoliageClient;
|
import mods.betterfoliage.client.BetterFoliageClient;
|
||||||
import mods.betterfoliage.common.config.Config;
|
import mods.betterfoliage.common.config.BetterFoliageConfig;
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@@ -24,6 +24,8 @@ public class BetterFoliage {
|
|||||||
@Mod.Instance
|
@Mod.Instance
|
||||||
public static BetterFoliage instance;
|
public static BetterFoliage instance;
|
||||||
|
|
||||||
|
public static BetterFoliageConfig config = new BetterFoliageConfig();
|
||||||
|
|
||||||
public static Logger log;
|
public static Logger log;
|
||||||
|
|
||||||
public static File configDir;
|
public static File configDir;
|
||||||
@@ -34,7 +36,7 @@ public class BetterFoliage {
|
|||||||
if (event.getSide() == Side.CLIENT) {
|
if (event.getSide() == Side.CLIENT) {
|
||||||
configDir = new File(event.getModConfigurationDirectory(), MOD_ID);
|
configDir = new File(event.getModConfigurationDirectory(), MOD_ID);
|
||||||
configDir.mkdir();
|
configDir.mkdir();
|
||||||
Config.load();
|
config.load(new File(configDir, "betterfoliage.cfg"));
|
||||||
BetterFoliageClient.preInit();
|
BetterFoliageClient.preInit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package mods.betterfoliage.client.gui;
|
package mods.betterfoliage.client.gui;
|
||||||
|
|
||||||
|
import mods.betterfoliage.BetterFoliage;
|
||||||
import mods.betterfoliage.client.gui.widget.OptionDoubleWidget;
|
import mods.betterfoliage.client.gui.widget.OptionDoubleWidget;
|
||||||
import mods.betterfoliage.common.config.Config;
|
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
import cpw.mods.fml.client.FMLClientHandler;
|
import cpw.mods.fml.client.FMLClientHandler;
|
||||||
@@ -11,10 +11,10 @@ public class ConfigGuiGrass extends ConfigGuiScreenBase {
|
|||||||
public ConfigGuiGrass(GuiScreen parent) {
|
public ConfigGuiGrass(GuiScreen parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
int id = 10;
|
int id = 10;
|
||||||
widgets.add(new OptionDoubleWidget(Config.grassSize, -100, -70, 200, 50, id++, id++, "message.betterfoliage.size", "%.2f"));
|
widgets.add(new OptionDoubleWidget(BetterFoliage.config.grassSize, -100, -70, 200, 50, id++, id++, "message.betterfoliage.size", "%.2f"));
|
||||||
widgets.add(new OptionDoubleWidget(Config.grassHOffset, -100, -40, 200, 50, id++, id++, "message.betterfoliage.hOffset", "%.3f"));
|
widgets.add(new OptionDoubleWidget(BetterFoliage.config.grassHOffset, -100, -40, 200, 50, id++, id++, "message.betterfoliage.hOffset", "%.3f"));
|
||||||
widgets.add(new OptionDoubleWidget(Config.grassHeightMin, -100, -10, 200, 50, id++, id++, "message.betterfoliage.minHeight", "%.2f"));
|
widgets.add(new OptionDoubleWidget(BetterFoliage.config.grassHeightMin, -100, -10, 200, 50, id++, id++, "message.betterfoliage.minHeight", "%.2f"));
|
||||||
widgets.add(new OptionDoubleWidget(Config.grassHeightMax, -100, 20, 200, 50, id++, id++, "message.betterfoliage.maxHeight", "%.2f"));
|
widgets.add(new OptionDoubleWidget(BetterFoliage.config.grassHeightMax, -100, 20, 200, 50, id++, id++, "message.betterfoliage.maxHeight", "%.2f"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -27,7 +27,7 @@ public class ConfigGuiGrass extends ConfigGuiScreenBase {
|
|||||||
protected void onButtonPress(int id) {
|
protected void onButtonPress(int id) {
|
||||||
if (id == 0) FMLClientHandler.instance().showGuiScreen(parent);
|
if (id == 0) FMLClientHandler.instance().showGuiScreen(parent);
|
||||||
|
|
||||||
if (Config.grassHeightMin.value > Config.grassHeightMax.value) Config.grassHeightMin.value = Config.grassHeightMax.value;
|
if (BetterFoliage.config.grassHeightMin.value > BetterFoliage.config.grassHeightMax.value) BetterFoliage.config.grassHeightMin.value = BetterFoliage.config.grassHeightMax.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package mods.betterfoliage.client.gui;
|
package mods.betterfoliage.client.gui;
|
||||||
|
|
||||||
|
import mods.betterfoliage.BetterFoliage;
|
||||||
import mods.betterfoliage.client.gui.widget.OptionDoubleWidget;
|
import mods.betterfoliage.client.gui.widget.OptionDoubleWidget;
|
||||||
import mods.betterfoliage.common.config.Config;
|
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
import cpw.mods.fml.client.FMLClientHandler;
|
import cpw.mods.fml.client.FMLClientHandler;
|
||||||
@@ -13,9 +13,9 @@ public class ConfigGuiLeaves extends ConfigGuiScreenBase {
|
|||||||
public ConfigGuiLeaves(GuiScreen parent) {
|
public ConfigGuiLeaves(GuiScreen parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
int id = 10;
|
int id = 10;
|
||||||
widgets.add(new OptionDoubleWidget(Config.leavesSize, -100, -70, 200, 50, id++, id++, "message.betterfoliage.size", "%.2f"));
|
widgets.add(new OptionDoubleWidget(BetterFoliage.config.leavesSize, -100, -70, 200, 50, id++, id++, "message.betterfoliage.size", "%.2f"));
|
||||||
widgets.add(new OptionDoubleWidget(Config.leavesHOffset, -100, -10, 200, 50, id++, id++, "message.betterfoliage.hOffset", "%.3f"));
|
widgets.add(new OptionDoubleWidget(BetterFoliage.config.leavesHOffset, -100, -10, 200, 50, id++, id++, "message.betterfoliage.hOffset", "%.3f"));
|
||||||
widgets.add(new OptionDoubleWidget(Config.leavesVOffset, -100, 20, 200, 50, id++, id++, "message.betterfoliage.vOffset", "%.3f"));
|
widgets.add(new OptionDoubleWidget(BetterFoliage.config.leavesVOffset, -100, 20, 200, 50, id++, id++, "message.betterfoliage.vOffset", "%.3f"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -26,13 +26,13 @@ public class ConfigGuiLeaves extends ConfigGuiScreenBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void updateButtons() {
|
protected void updateButtons() {
|
||||||
setButtonOptionBoolean(Button.LEAVES_OFFSET_MODE.ordinal(), "message.betterfoliage.leavesMode", Config.leavesSkew ? "message.betterfoliage.leavesSkew" : "message.betterfoliage.leavesTranslate");
|
setButtonOptionBoolean(Button.LEAVES_OFFSET_MODE.ordinal(), "message.betterfoliage.leavesMode", BetterFoliage.config.leavesSkew ? "message.betterfoliage.leavesSkew" : "message.betterfoliage.leavesTranslate");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onButtonPress(int id) {
|
protected void onButtonPress(int id) {
|
||||||
if (id == Button.CLOSE.ordinal()) FMLClientHandler.instance().showGuiScreen(parent);
|
if (id == Button.CLOSE.ordinal()) FMLClientHandler.instance().showGuiScreen(parent);
|
||||||
if (id == Button.LEAVES_OFFSET_MODE.ordinal()) Config.leavesSkew = !Config.leavesSkew;
|
if (id == Button.LEAVES_OFFSET_MODE.ordinal()) BetterFoliage.config.leavesSkew = !BetterFoliage.config.leavesSkew;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package mods.betterfoliage.client.gui;
|
package mods.betterfoliage.client.gui;
|
||||||
|
|
||||||
|
import mods.betterfoliage.BetterFoliage;
|
||||||
import mods.betterfoliage.client.gui.widget.OptionDoubleWidget;
|
import mods.betterfoliage.client.gui.widget.OptionDoubleWidget;
|
||||||
import mods.betterfoliage.client.gui.widget.OptionIntegerWidget;
|
import mods.betterfoliage.client.gui.widget.OptionIntegerWidget;
|
||||||
import mods.betterfoliage.common.config.Config;
|
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
import cpw.mods.fml.client.FMLClientHandler;
|
import cpw.mods.fml.client.FMLClientHandler;
|
||||||
@@ -12,8 +12,8 @@ public class ConfigGuiLilypad extends ConfigGuiScreenBase {
|
|||||||
public ConfigGuiLilypad(GuiScreen parent) {
|
public ConfigGuiLilypad(GuiScreen parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
int id = 10;
|
int id = 10;
|
||||||
widgets.add(new OptionDoubleWidget(Config.lilypadHOffset, -100, -40, 200, 50, id++, id++, "message.betterfoliage.hOffset", "%.3f"));
|
widgets.add(new OptionDoubleWidget(BetterFoliage.config.lilypadHOffset, -100, -40, 200, 50, id++, id++, "message.betterfoliage.hOffset", "%.3f"));
|
||||||
widgets.add(new OptionIntegerWidget(Config.lilypadChance, -100, -10, 200, 50, id++, id++, "message.betterfoliage.flowerChance"));
|
widgets.add(new OptionIntegerWidget(BetterFoliage.config.lilypadChance, -100, -10, 200, 50, id++, id++, "message.betterfoliage.flowerChance"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package mods.betterfoliage.client.gui;
|
package mods.betterfoliage.client.gui;
|
||||||
|
|
||||||
import mods.betterfoliage.common.config.Config;
|
import mods.betterfoliage.BetterFoliage;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
@@ -45,26 +45,26 @@ public class ConfigGuiMain extends ConfigGuiScreenBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void updateButtons() {
|
protected void updateButtons() {
|
||||||
setButtonOptionBoolean(Button.TOGGLE_LEAVES.ordinal(), "message.betterfoliage.betterLeaves", Config.leavesEnabled);
|
setButtonOptionBoolean(Button.TOGGLE_LEAVES.ordinal(), "message.betterfoliage.betterLeaves", BetterFoliage.config.leavesEnabled);
|
||||||
setButtonOptionBoolean(Button.TOGGLE_GRASS.ordinal(), "message.betterfoliage.betterGrass", Config.grassEnabled);
|
setButtonOptionBoolean(Button.TOGGLE_GRASS.ordinal(), "message.betterfoliage.betterGrass", BetterFoliage.config.grassEnabled);
|
||||||
setButtonOptionBoolean(Button.TOGGLE_CACTUS.ordinal(), "message.betterfoliage.betterCactus", Config.cactusEnabled);
|
setButtonOptionBoolean(Button.TOGGLE_CACTUS.ordinal(), "message.betterfoliage.betterCactus", BetterFoliage.config.cactusEnabled);
|
||||||
setButtonOptionBoolean(Button.TOGGLE_LILYPAD.ordinal(), "message.betterfoliage.betterLilypad", Config.lilypadEnabled);
|
setButtonOptionBoolean(Button.TOGGLE_LILYPAD.ordinal(), "message.betterfoliage.betterLilypad", BetterFoliage.config.lilypadEnabled);
|
||||||
setButtonOptionBoolean(Button.TOGGLE_REED.ordinal(), "message.betterfoliage.betterReed", Config.reedEnabled);
|
setButtonOptionBoolean(Button.TOGGLE_REED.ordinal(), "message.betterfoliage.betterReed", BetterFoliage.config.reedEnabled);
|
||||||
((GuiButton) buttonList.get(Button.CONFIG_CACTUS.ordinal())).enabled = false;
|
((GuiButton) buttonList.get(Button.CONFIG_CACTUS.ordinal())).enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onButtonPress(int id) {
|
protected void onButtonPress(int id) {
|
||||||
if (id == Button.CLOSE.ordinal()) {
|
if (id == Button.CLOSE.ordinal()) {
|
||||||
Config.save();
|
BetterFoliage.config.save();
|
||||||
Minecraft.getMinecraft().renderGlobal.loadRenderers();
|
Minecraft.getMinecraft().renderGlobal.loadRenderers();
|
||||||
FMLClientHandler.instance().showGuiScreen(parent);
|
FMLClientHandler.instance().showGuiScreen(parent);
|
||||||
}
|
}
|
||||||
if (id == Button.TOGGLE_LEAVES.ordinal()) Config.leavesEnabled = !Config.leavesEnabled;
|
if (id == Button.TOGGLE_LEAVES.ordinal()) BetterFoliage.config.leavesEnabled = !BetterFoliage.config.leavesEnabled;
|
||||||
if (id == Button.TOGGLE_GRASS.ordinal()) Config.grassEnabled = !Config.grassEnabled;
|
if (id == Button.TOGGLE_GRASS.ordinal()) BetterFoliage.config.grassEnabled = !BetterFoliage.config.grassEnabled;
|
||||||
if (id == Button.TOGGLE_CACTUS.ordinal()) Config.cactusEnabled = !Config.cactusEnabled;
|
if (id == Button.TOGGLE_CACTUS.ordinal()) BetterFoliage.config.cactusEnabled = !BetterFoliage.config.cactusEnabled;
|
||||||
if (id == Button.TOGGLE_LILYPAD.ordinal()) Config.lilypadEnabled = !Config.lilypadEnabled;
|
if (id == Button.TOGGLE_LILYPAD.ordinal()) BetterFoliage.config.lilypadEnabled = !BetterFoliage.config.lilypadEnabled;
|
||||||
if (id == Button.TOGGLE_REED.ordinal()) Config.reedEnabled = !Config.reedEnabled;
|
if (id == Button.TOGGLE_REED.ordinal()) BetterFoliage.config.reedEnabled = !BetterFoliage.config.reedEnabled;
|
||||||
|
|
||||||
if (id== Button.CONFIG_LEAVES.ordinal()) FMLClientHandler.instance().showGuiScreen(new ConfigGuiLeaves(this));
|
if (id== Button.CONFIG_LEAVES.ordinal()) FMLClientHandler.instance().showGuiScreen(new ConfigGuiLeaves(this));
|
||||||
if (id== Button.CONFIG_GRASS.ordinal()) FMLClientHandler.instance().showGuiScreen(new ConfigGuiGrass(this));
|
if (id== Button.CONFIG_GRASS.ordinal()) FMLClientHandler.instance().showGuiScreen(new ConfigGuiGrass(this));
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package mods.betterfoliage.client.gui;
|
package mods.betterfoliage.client.gui;
|
||||||
|
|
||||||
|
import mods.betterfoliage.BetterFoliage;
|
||||||
import mods.betterfoliage.client.gui.widget.OptionDoubleWidget;
|
import mods.betterfoliage.client.gui.widget.OptionDoubleWidget;
|
||||||
import mods.betterfoliage.client.gui.widget.OptionIntegerWidget;
|
import mods.betterfoliage.client.gui.widget.OptionIntegerWidget;
|
||||||
import mods.betterfoliage.common.config.Config;
|
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
import cpw.mods.fml.client.FMLClientHandler;
|
import cpw.mods.fml.client.FMLClientHandler;
|
||||||
@@ -12,10 +12,10 @@ public class ConfigGuiReed extends ConfigGuiScreenBase {
|
|||||||
public ConfigGuiReed(GuiScreen parent) {
|
public ConfigGuiReed(GuiScreen parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
int id = 10;
|
int id = 10;
|
||||||
widgets.add(new OptionDoubleWidget(Config.reedHOffset, -100, -70, 200, 50, id++, id++, "message.betterfoliage.hOffset", "%.3f"));
|
widgets.add(new OptionDoubleWidget(BetterFoliage.config.reedHOffset, -100, -70, 200, 50, id++, id++, "message.betterfoliage.hOffset", "%.3f"));
|
||||||
widgets.add(new OptionDoubleWidget(Config.reedHeightMin, -100, -40, 200, 50, id++, id++, "message.betterfoliage.minHeight", "%.2f"));
|
widgets.add(new OptionDoubleWidget(BetterFoliage.config.reedHeightMin, -100, -40, 200, 50, id++, id++, "message.betterfoliage.minHeight", "%.2f"));
|
||||||
widgets.add(new OptionDoubleWidget(Config.reedHeightMax, -100, -10, 200, 50, id++, id++, "message.betterfoliage.maxHeight", "%.2f"));
|
widgets.add(new OptionDoubleWidget(BetterFoliage.config.reedHeightMax, -100, -10, 200, 50, id++, id++, "message.betterfoliage.maxHeight", "%.2f"));
|
||||||
widgets.add(new OptionIntegerWidget(Config.reedChance, -100, 20, 200, 50, id++, id++, "message.betterfoliage.reedChance"));
|
widgets.add(new OptionIntegerWidget(BetterFoliage.config.reedChance, -100, 20, 200, 50, id++, id++, "message.betterfoliage.reedChance"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -28,7 +28,7 @@ public class ConfigGuiReed extends ConfigGuiScreenBase {
|
|||||||
protected void onButtonPress(int id) {
|
protected void onButtonPress(int id) {
|
||||||
if (id == 0) FMLClientHandler.instance().showGuiScreen(parent);
|
if (id == 0) FMLClientHandler.instance().showGuiScreen(parent);
|
||||||
|
|
||||||
if (Config.reedHeightMin.value > Config.reedHeightMax.value) Config.reedHeightMin.value = Config.reedHeightMax.value;
|
if (BetterFoliage.config.reedHeightMin.value > BetterFoliage.config.reedHeightMax.value) BetterFoliage.config.reedHeightMin.value = BetterFoliage.config.reedHeightMax.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import mods.betterfoliage.BetterFoliage;
|
|||||||
import mods.betterfoliage.client.render.FakeRenderBlockAOBase;
|
import mods.betterfoliage.client.render.FakeRenderBlockAOBase;
|
||||||
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
||||||
import mods.betterfoliage.client.render.IconSet;
|
import mods.betterfoliage.client.render.IconSet;
|
||||||
import mods.betterfoliage.common.config.Config;
|
|
||||||
import mods.betterfoliage.common.util.Double3;
|
import mods.betterfoliage.common.util.Double3;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
@@ -29,7 +28,7 @@ public class RenderBlockBetterCactus extends FakeRenderBlockAOBase implements IR
|
|||||||
public static double cactusRadius = 0.4375;
|
public static double cactusRadius = 0.4375;
|
||||||
|
|
||||||
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
||||||
return Config.cactusEnabled && block == Blocks.cactus;
|
return BetterFoliage.config.cactusEnabled && block == Blocks.cactus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import mods.betterfoliage.BetterFoliage;
|
|||||||
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
||||||
import mods.betterfoliage.client.render.IconSet;
|
import mods.betterfoliage.client.render.IconSet;
|
||||||
import mods.betterfoliage.client.render.RenderBlockAOBase;
|
import mods.betterfoliage.client.render.RenderBlockAOBase;
|
||||||
import mods.betterfoliage.common.config.Config;
|
|
||||||
import mods.betterfoliage.common.util.Double3;
|
import mods.betterfoliage.common.util.Double3;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockGrass;
|
import net.minecraft.block.BlockGrass;
|
||||||
@@ -27,7 +26,7 @@ public class RenderBlockBetterGrass extends RenderBlockAOBase implements IRender
|
|||||||
|
|
||||||
|
|
||||||
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
||||||
if (!Config.grassEnabled) return false;
|
if (!BetterFoliage.config.grassEnabled) return false;
|
||||||
if (!((block instanceof BlockGrass || block == Blocks.mycelium))) return false;
|
if (!((block instanceof BlockGrass || block == Blocks.mycelium))) return false;
|
||||||
if (y == 255 || !blockAccess.isAirBlock(x, y + 1, z)) return false;
|
if (y == 255 || !blockAccess.isAirBlock(x, y + 1, z)) return false;
|
||||||
return true;
|
return true;
|
||||||
@@ -48,10 +47,10 @@ public class RenderBlockBetterGrass extends RenderBlockAOBase implements IRender
|
|||||||
IIcon renderIcon = (block == Blocks.mycelium) ? myceliumIcons.get(variation) : grassIcons.get(variation);
|
IIcon renderIcon = (block == Blocks.mycelium) ? myceliumIcons.get(variation) : grassIcons.get(variation);
|
||||||
if (renderIcon == null) return true;
|
if (renderIcon == null) return true;
|
||||||
|
|
||||||
double scale = Config.grassSize.value * 0.5;
|
double scale = BetterFoliage.config.grassSize.value * 0.5;
|
||||||
double halfHeight = 0.5 * (Config.grassHeightMin.value + pRand[heightVariation] * (Config.grassHeightMax.value - Config.grassHeightMin.value));
|
double halfHeight = 0.5 * (BetterFoliage.config.grassHeightMin.value + pRand[heightVariation] * (BetterFoliage.config.grassHeightMax.value - BetterFoliage.config.grassHeightMin.value));
|
||||||
Tessellator.instance.setBrightness(getBrightness(block, x, y + 1, z));
|
Tessellator.instance.setBrightness(getBrightness(block, x, y + 1, z));
|
||||||
renderCrossedSideQuads(new Double3(x + 0.5, y + 1.0, z + 0.5), ForgeDirection.UP, scale, halfHeight, pRot[variation], Config.grassHOffset.value, renderIcon, 0, false);
|
renderCrossedSideQuads(new Double3(x + 0.5, y + 1.0 - 0.125 * halfHeight, z + 0.5), ForgeDirection.UP, scale, halfHeight, pRot[variation], BetterFoliage.config.grassHOffset.value, renderIcon, 0, false);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package mods.betterfoliage.client.render.impl;
|
package mods.betterfoliage.client.render.impl;
|
||||||
|
|
||||||
|
import mods.betterfoliage.BetterFoliage;
|
||||||
import mods.betterfoliage.client.BetterFoliageClient;
|
import mods.betterfoliage.client.BetterFoliageClient;
|
||||||
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
||||||
import mods.betterfoliage.client.render.RenderBlockAOBase;
|
import mods.betterfoliage.client.render.RenderBlockAOBase;
|
||||||
import mods.betterfoliage.common.config.Config;
|
|
||||||
import mods.betterfoliage.common.util.Double3;
|
import mods.betterfoliage.common.util.Double3;
|
||||||
import mods.betterfoliage.common.util.ReflectionUtil;
|
import mods.betterfoliage.common.util.ReflectionUtil;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
@@ -22,7 +22,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||||||
public class RenderBlockBetterLeaves extends RenderBlockAOBase implements IRenderBlockDecorator {
|
public class RenderBlockBetterLeaves extends RenderBlockAOBase implements IRenderBlockDecorator {
|
||||||
|
|
||||||
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
||||||
if (!Config.leavesEnabled) return false;
|
if (!BetterFoliage.config.leavesEnabled) return false;
|
||||||
if (original > 0 && original < 42) return false;
|
if (original > 0 && original < 42) return false;
|
||||||
return BetterFoliageClient.leaves.matchesID(block) && !isBlockSurrounded(blockAccess, x, y, z);
|
return BetterFoliageClient.leaves.matchesID(block) && !isBlockSurrounded(blockAccess, x, y, z);
|
||||||
}
|
}
|
||||||
@@ -51,21 +51,21 @@ public class RenderBlockBetterLeaves extends RenderBlockAOBase implements IRende
|
|||||||
|
|
||||||
int offsetVariation = getSemiRandomFromPos(x, y, z, 0);
|
int offsetVariation = getSemiRandomFromPos(x, y, z, 0);
|
||||||
int uvVariation = getSemiRandomFromPos(x, y, z, 1);
|
int uvVariation = getSemiRandomFromPos(x, y, z, 1);
|
||||||
double halfSize = 0.5 * Config.leavesSize.value;
|
double halfSize = 0.5 * BetterFoliage.config.leavesSize.value;
|
||||||
boolean isAirTop = y == 255 || blockAccess.isAirBlock(x, y + 1, z);
|
boolean isAirTop = y == 255 || blockAccess.isAirBlock(x, y + 1, z);
|
||||||
boolean isAirBottom = y == 0 || blockAccess.isAirBlock(x, y - 1, z);
|
boolean isAirBottom = y == 0 || blockAccess.isAirBlock(x, y - 1, z);
|
||||||
|
|
||||||
Tessellator.instance.setBrightness(isAirTop ? getBrightness(block, x, y + 1, z) : (isAirBottom ? getBrightness(block, x, y - 1, z) : getBrightness(block, x, y, z)));
|
Tessellator.instance.setBrightness(isAirTop ? getBrightness(block, x, y + 1, z) : (isAirBottom ? getBrightness(block, x, y - 1, z) : getBrightness(block, x, y, z)));
|
||||||
Tessellator.instance.setColorOpaque_I(block.colorMultiplier(blockAccess, x, y, z));
|
Tessellator.instance.setColorOpaque_I(block.colorMultiplier(blockAccess, x, y, z));
|
||||||
|
|
||||||
if (Config.leavesSkew) {
|
if (BetterFoliage.config.leavesSkew) {
|
||||||
renderCrossedBlockQuadsSkew(new Double3(x + 0.5, y + 0.5, z + 0.5), halfSize,
|
renderCrossedBlockQuadsSkew(new Double3(x + 0.5, y + 0.5, z + 0.5), halfSize,
|
||||||
pRot[offsetVariation].scaleAxes(Config.leavesHOffset.value, Config.leavesVOffset.value, Config.leavesHOffset.value),
|
pRot[offsetVariation].scaleAxes(BetterFoliage.config.leavesHOffset.value, BetterFoliage.config.leavesVOffset.value, BetterFoliage.config.leavesHOffset.value),
|
||||||
pRot[(offsetVariation + 1) & 63].scaleAxes(Config.leavesHOffset.value, Config.leavesVOffset.value, Config.leavesHOffset.value),
|
pRot[(offsetVariation + 1) & 63].scaleAxes(BetterFoliage.config.leavesHOffset.value, BetterFoliage.config.leavesVOffset.value, BetterFoliage.config.leavesHOffset.value),
|
||||||
crossLeafIcon, uvVariation, isAirTop, isAirBottom);
|
crossLeafIcon, uvVariation, isAirTop, isAirBottom);
|
||||||
} else {
|
} else {
|
||||||
renderCrossedBlockQuadsTranslate(new Double3(x + 0.5, y + 0.5, z + 0.5), halfSize,
|
renderCrossedBlockQuadsTranslate(new Double3(x + 0.5, y + 0.5, z + 0.5), halfSize,
|
||||||
pRot[offsetVariation].scaleAxes(Config.leavesHOffset.value, Config.leavesVOffset.value, Config.leavesHOffset.value),
|
pRot[offsetVariation].scaleAxes(BetterFoliage.config.leavesHOffset.value, BetterFoliage.config.leavesVOffset.value, BetterFoliage.config.leavesHOffset.value),
|
||||||
crossLeafIcon, uvVariation, isAirTop, isAirBottom);
|
crossLeafIcon, uvVariation, isAirTop, isAirBottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import mods.betterfoliage.BetterFoliage;
|
|||||||
import mods.betterfoliage.client.render.FakeRenderBlockAOBase;
|
import mods.betterfoliage.client.render.FakeRenderBlockAOBase;
|
||||||
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
||||||
import mods.betterfoliage.client.render.IconSet;
|
import mods.betterfoliage.client.render.IconSet;
|
||||||
import mods.betterfoliage.common.config.Config;
|
|
||||||
import mods.betterfoliage.common.util.Double3;
|
import mods.betterfoliage.common.util.Double3;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.client.renderer.RenderBlocks;
|
import net.minecraft.client.renderer.RenderBlocks;
|
||||||
@@ -24,7 +23,7 @@ public class RenderBlockBetterLilypad extends FakeRenderBlockAOBase implements I
|
|||||||
public IconSet lilypadRoots = new IconSet("bettergrassandleaves", "better_lilypad_roots_%d");
|
public IconSet lilypadRoots = new IconSet("bettergrassandleaves", "better_lilypad_roots_%d");
|
||||||
|
|
||||||
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
||||||
return Config.lilypadEnabled && block == Blocks.waterlily;
|
return BetterFoliage.config.lilypadEnabled && block == Blocks.waterlily;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||||
@@ -45,10 +44,10 @@ public class RenderBlockBetterLilypad extends FakeRenderBlockAOBase implements I
|
|||||||
null, 0.0,
|
null, 0.0,
|
||||||
lilypadRoots.get(iconVariation), 2,
|
lilypadRoots.get(iconVariation), 2,
|
||||||
true);
|
true);
|
||||||
if (chanceVariation < Config.lilypadChance.value && lilypadFlowers.hasIcons())
|
if (chanceVariation < BetterFoliage.config.lilypadChance.value && lilypadFlowers.hasIcons())
|
||||||
renderCrossedSideQuads(new Double3(x + 0.5, y + 0.02, z + 0.5), ForgeDirection.UP,
|
renderCrossedSideQuads(new Double3(x + 0.5, y + 0.02, z + 0.5), ForgeDirection.UP,
|
||||||
0.2, 0.3,
|
0.2, 0.3,
|
||||||
pRot[offsetVariation], Config.lilypadHOffset.value,
|
pRot[offsetVariation], BetterFoliage.config.lilypadHOffset.value,
|
||||||
lilypadFlowers.get(iconVariation), 0,
|
lilypadFlowers.get(iconVariation), 0,
|
||||||
true);
|
true);
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import mods.betterfoliage.BetterFoliage;
|
|||||||
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
||||||
import mods.betterfoliage.client.render.IconSet;
|
import mods.betterfoliage.client.render.IconSet;
|
||||||
import mods.betterfoliage.client.render.RenderBlockAOBase;
|
import mods.betterfoliage.client.render.RenderBlockAOBase;
|
||||||
import mods.betterfoliage.common.config.Config;
|
|
||||||
import mods.betterfoliage.common.util.Double3;
|
import mods.betterfoliage.common.util.Double3;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockDirt;
|
import net.minecraft.block.BlockDirt;
|
||||||
@@ -29,13 +28,13 @@ public class RenderBlockBetterReed extends RenderBlockAOBase implements IRenderB
|
|||||||
public NoiseGeneratorSimplex noise;
|
public NoiseGeneratorSimplex noise;
|
||||||
|
|
||||||
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
||||||
if (!Config.reedEnabled) return false;
|
if (!BetterFoliage.config.reedEnabled) return false;
|
||||||
if (y >= 254 || !(block instanceof BlockDirt)) return false;
|
if (y >= 254 || !(block instanceof BlockDirt)) return false;
|
||||||
if (blockAccess.getBlock(x, y + 1, z).getMaterial() != Material.water) 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.isAirBlock(x, y + 2, z)) return false;
|
||||||
|
|
||||||
int terrainVariation = MathHelper.floor_double((noise.func_151605_a(x, z) + 1.0) * 32.0);
|
int terrainVariation = MathHelper.floor_double((noise.func_151605_a(x, z) + 1.0) * 32.0);
|
||||||
return terrainVariation < Config.reedChance.value;
|
return terrainVariation < BetterFoliage.config.reedChance.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||||
@@ -54,11 +53,11 @@ public class RenderBlockBetterReed extends RenderBlockAOBase implements IRenderB
|
|||||||
IIcon topIcon = reedTopIcons.get(iconVariation);
|
IIcon topIcon = reedTopIcons.get(iconVariation);
|
||||||
if (bottomIcon == null || topIcon == null) return true;
|
if (bottomIcon == null || topIcon == null) return true;
|
||||||
|
|
||||||
double quarterHeight = 0.25 * (Config.reedHeightMin.value + pRand[heightVariation] * (Config.reedHeightMax.value - Config.reedHeightMin.value));
|
double quarterHeight = 0.25 * (BetterFoliage.config.reedHeightMin.value + pRand[heightVariation] * (BetterFoliage.config.reedHeightMax.value - BetterFoliage.config.reedHeightMin.value));
|
||||||
Tessellator.instance.setBrightness(getBrightness(block, x, y + 2, z));
|
Tessellator.instance.setBrightness(getBrightness(block, x, y + 2, z));
|
||||||
Tessellator.instance.setColorOpaque(255, 255, 255);
|
Tessellator.instance.setColorOpaque(255, 255, 255);
|
||||||
renderCrossedSideQuads(new Double3(x + 0.5, y + 1.0, z + 0.5), ForgeDirection.UP, 0.5, quarterHeight, pRot[iconVariation], Config.reedHOffset.value, bottomIcon, 0, true);
|
renderCrossedSideQuads(new Double3(x + 0.5, y + 1.0, z + 0.5), ForgeDirection.UP, 0.5, quarterHeight, pRot[iconVariation], BetterFoliage.config.reedHOffset.value, bottomIcon, 0, true);
|
||||||
renderCrossedSideQuads(new Double3(x + 0.5, y + 1.0 + 2.0 * quarterHeight, z + 0.5), ForgeDirection.UP, 0.5, quarterHeight, pRot[iconVariation], Config.reedHOffset.value, topIcon, 0, true);
|
renderCrossedSideQuads(new Double3(x + 0.5, y + 1.0 + 2.0 * quarterHeight, z + 0.5), ForgeDirection.UP, 0.5, quarterHeight, pRot[iconVariation], BetterFoliage.config.reedHOffset.value, topIcon, 0, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package mods.betterfoliage.common.config;
|
||||||
|
|
||||||
|
public class BetterFoliageConfig extends ConfigBase {
|
||||||
|
|
||||||
|
@CfgElement(category="leaves", key="enabled")
|
||||||
|
public boolean leavesEnabled = true;
|
||||||
|
|
||||||
|
@CfgElement(category="leaves", key="skewMode")
|
||||||
|
public boolean leavesSkew = false;
|
||||||
|
|
||||||
|
@CfgElement(category="grass", key="enabled")
|
||||||
|
public boolean grassEnabled = true;
|
||||||
|
|
||||||
|
@CfgElement(category="cactus", key="enabled")
|
||||||
|
public boolean cactusEnabled = true;
|
||||||
|
|
||||||
|
@CfgElement(category="lilypad", key="enabled")
|
||||||
|
public boolean lilypadEnabled = true;
|
||||||
|
|
||||||
|
@CfgElement(category="reed", key="enabled")
|
||||||
|
public boolean reedEnabled = true;
|
||||||
|
|
||||||
|
@CfgElement(category="leaves", key="horizontalOffset")
|
||||||
|
public OptionDouble leavesHOffset = new OptionDouble(0.0, 0.4, 0.025, 0.2);
|
||||||
|
|
||||||
|
@CfgElement(category="leaves", key="verticalOffset")
|
||||||
|
public OptionDouble leavesVOffset = new OptionDouble(0.0, 0.4, 0.025, 0.1);
|
||||||
|
|
||||||
|
@CfgElement(category="leaves", key="size")
|
||||||
|
public OptionDouble leavesSize = new OptionDouble(0.75, 1.8, 0.05, 1.4);
|
||||||
|
|
||||||
|
@CfgElement(category="grass", key="horizontalOffset")
|
||||||
|
public OptionDouble grassHOffset = new OptionDouble(0.0, 0.4, 0.025, 0.2);
|
||||||
|
|
||||||
|
@CfgElement(category="grass", key="heightMin")
|
||||||
|
@Limit(max="grassHeightMax")
|
||||||
|
public OptionDouble grassHeightMin = new OptionDouble(0.1, 1.5, 0.05, 0.5);
|
||||||
|
|
||||||
|
@CfgElement(category="grass", key="heightMax")
|
||||||
|
public OptionDouble grassHeightMax = new OptionDouble(0.1, 1.5, 0.05, 1.0);
|
||||||
|
|
||||||
|
@CfgElement(category="grass", key="size")
|
||||||
|
public OptionDouble grassSize = new OptionDouble(0.5, 1.5, 0.05, 1.0);
|
||||||
|
|
||||||
|
@CfgElement(category="lilypad", key="horizontalOffset")
|
||||||
|
public OptionDouble lilypadHOffset = new OptionDouble(0.0, 0.25, 0.025, 0.1);
|
||||||
|
|
||||||
|
@CfgElement(category="lilypad", key="chance")
|
||||||
|
public OptionInteger lilypadChance = new OptionInteger(0, 64, 1, 16);
|
||||||
|
|
||||||
|
@CfgElement(category="reed", key="horizontalOffset")
|
||||||
|
public OptionDouble reedHOffset = new OptionDouble(0.0, 0.25, 0.025, 0.1);
|
||||||
|
|
||||||
|
@CfgElement(category="reed", key="heightMin")
|
||||||
|
@Limit(max="reedHeightMax")
|
||||||
|
public OptionDouble reedHeightMin = new OptionDouble(1.5, 3.5, 0.1, 2.0);
|
||||||
|
|
||||||
|
@CfgElement(category="reed", key="heightMax")
|
||||||
|
public OptionDouble reedHeightMax = new OptionDouble(1.5, 3.5, 0.1, 2.5);
|
||||||
|
|
||||||
|
@CfgElement(category="reed", key="chance")
|
||||||
|
public OptionInteger reedChance = new OptionInteger(0, 64, 1, 32);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,125 +0,0 @@
|
|||||||
package mods.betterfoliage.common.config;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import mods.betterfoliage.BetterFoliage;
|
|
||||||
import net.minecraftforge.common.config.Configuration;
|
|
||||||
|
|
||||||
public class Config {
|
|
||||||
|
|
||||||
public static boolean leavesEnabled = true;
|
|
||||||
public static boolean leavesSkew = false;
|
|
||||||
public static boolean grassEnabled = true;
|
|
||||||
public static boolean cactusEnabled = true;
|
|
||||||
public static boolean lilypadEnabled = true;
|
|
||||||
public static boolean reedEnabled = true;
|
|
||||||
|
|
||||||
public static OptionDouble leavesHOffset = new OptionDouble(0.0, 0.4, 0.025, 0.2);
|
|
||||||
public static OptionDouble leavesVOffset = new OptionDouble(0.0, 0.4, 0.025, 0.1);
|
|
||||||
public static OptionDouble leavesSize = new OptionDouble(0.75, 1.8, 0.05, 1.4);
|
|
||||||
|
|
||||||
public static OptionDouble grassHOffset = new OptionDouble(0.0, 0.4, 0.025, 0.2);
|
|
||||||
public static OptionDouble grassHeightMin = new OptionDouble(0.1, 1.5, 0.05, 0.5);
|
|
||||||
public static OptionDouble grassHeightMax = new OptionDouble(0.1, 1.5, 0.05, 1.0);
|
|
||||||
public static OptionDouble grassSize = new OptionDouble(0.5, 1.5, 0.05, 1.0);
|
|
||||||
|
|
||||||
public static OptionDouble lilypadHOffset = new OptionDouble(0.0, 0.25, 0.025, 0.1);
|
|
||||||
public static OptionInteger lilypadChance = new OptionInteger(0, 64, 1, 16);
|
|
||||||
|
|
||||||
public static OptionDouble reedHOffset = new OptionDouble(0.0, 0.25, 0.025, 0.1);
|
|
||||||
public static OptionDouble reedHeightMin = new OptionDouble(1.5, 3.5, 0.1, 2.0);
|
|
||||||
public static OptionDouble reedHeightMax = new OptionDouble(1.5, 3.5, 0.1, 2.5);
|
|
||||||
public static OptionInteger reedChance = new OptionInteger(0, 64, 1, 32);
|
|
||||||
|
|
||||||
private Config() {}
|
|
||||||
|
|
||||||
public static void load() {
|
|
||||||
Configuration config = new Configuration(new File(BetterFoliage.configDir, "betterfoliage.cfg"));
|
|
||||||
config.load();
|
|
||||||
|
|
||||||
leavesEnabled = config.get("render", "leavesEnabled", true).getBoolean(true);
|
|
||||||
leavesSkew = config.get("render", "leavesOffsetSkew", false).getBoolean(false);
|
|
||||||
loadValue(config, "render", "leavesHorizontalOffset", leavesHOffset);
|
|
||||||
loadValue(config, "render", "leavesVerticalOffset", leavesVOffset);
|
|
||||||
loadValue(config, "render", "leavesSize", leavesSize);
|
|
||||||
|
|
||||||
grassEnabled = config.get("render", "grassEnabled", true).getBoolean(true);
|
|
||||||
loadValue(config, "render", "grassHorizontalOffset", grassHOffset);
|
|
||||||
loadValue(config, "render", "grassHeightMin", grassHeightMin);
|
|
||||||
loadValue(config, "render", "grassHeightMax", grassHeightMax);
|
|
||||||
if (grassHeightMin.value > grassHeightMax.value) grassHeightMin.value = grassHeightMax.value;
|
|
||||||
|
|
||||||
grassEnabled = config.get("render", "cactusEnabled", true).getBoolean(true);
|
|
||||||
grassEnabled = config.get("render", "lilypadEnabled", true).getBoolean(true);
|
|
||||||
loadValue(config, "render", "lilypadHorizontalOffset", lilypadHOffset);
|
|
||||||
loadValue(config, "render", "lilypadChance", lilypadChance);
|
|
||||||
|
|
||||||
reedEnabled = config.get("render", "reedEnabled", true).getBoolean(true);
|
|
||||||
loadValue(config, "render", "reedHeightMin", reedHeightMin);
|
|
||||||
loadValue(config, "render", "reedHeightMax", reedHeightMax);
|
|
||||||
loadValue(config, "render", "reedChance", reedChance);
|
|
||||||
if (reedHeightMin.value > reedHeightMax.value) reedHeightMin.value = reedHeightMax.value;
|
|
||||||
|
|
||||||
if (config.hasChanged()) config.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void save() {
|
|
||||||
Configuration config = new Configuration(new File(BetterFoliage.configDir, "betterfoliage.cfg"));
|
|
||||||
config.load();
|
|
||||||
|
|
||||||
config.get("render", "leavesEnabled", true).set(leavesEnabled);
|
|
||||||
config.get("render", "leavesOffsetSkew", false).set(leavesSkew);
|
|
||||||
saveValue(config, "render", "leavesHorizontalOffset", leavesHOffset);
|
|
||||||
saveValue(config, "render", "leavesVerticalOffset", leavesVOffset);
|
|
||||||
saveValue(config, "render", "leavesSize", leavesSize);
|
|
||||||
|
|
||||||
config.get("render", "grassEnabled", true).set(grassEnabled);
|
|
||||||
saveValue(config, "render", "grassHorizontalOffset", grassHOffset);
|
|
||||||
saveValue(config, "render", "grassHeightMin", grassHeightMin);
|
|
||||||
saveValue(config, "render", "grassHeightMax", grassHeightMax);
|
|
||||||
|
|
||||||
config.get("render", "cactusEnabled", true).set(cactusEnabled);
|
|
||||||
config.get("render", "lilypadEnabled", true).set(lilypadEnabled);
|
|
||||||
saveValue(config, "render", "lilypadHorizontalOffset", lilypadHOffset);
|
|
||||||
saveValue(config, "render", "lilypadChance", lilypadChance);
|
|
||||||
|
|
||||||
config.get("render", "reedEnabled", true).set(reedEnabled);
|
|
||||||
saveValue(config, "render", "reedHeightMin", reedHeightMin);
|
|
||||||
saveValue(config, "render", "reedHeightMax", reedHeightMax);
|
|
||||||
saveValue(config, "render", "reedChance", reedChance);
|
|
||||||
|
|
||||||
if (config.hasChanged()) config.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void saveValue(Configuration config, String category, String key, OptionDouble option) {
|
|
||||||
config.get(category, key, option.value).set(option.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void loadValue(Configuration config, String category, String key, OptionDouble option) {
|
|
||||||
option.value = config.get(category, key, option.value).getDouble(option.value);
|
|
||||||
if (option.value > option.max) {
|
|
||||||
option.value = option.max;
|
|
||||||
saveValue(config, category, key, option);
|
|
||||||
}
|
|
||||||
if (option.value < option.min) {
|
|
||||||
option.value = option.min;
|
|
||||||
saveValue(config, category, key, option);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void saveValue(Configuration config, String category, String key, OptionInteger option) {
|
|
||||||
config.get(category, key, option.value).set(option.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void loadValue(Configuration config, String category, String key, OptionInteger option) {
|
|
||||||
option.value = config.get(category, key, option.value).getInt(option.value);
|
|
||||||
if (option.value > option.max) {
|
|
||||||
option.value = option.max;
|
|
||||||
saveValue(config, category, key, option);
|
|
||||||
}
|
|
||||||
if (option.value < option.min) {
|
|
||||||
option.value = option.min;
|
|
||||||
saveValue(config, category, key, option);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
128
src/main/java/mods/betterfoliage/common/config/ConfigBase.java
Normal file
128
src/main/java/mods/betterfoliage/common/config/ConfigBase.java
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
package mods.betterfoliage.common.config;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import net.minecraftforge.common.config.Configuration;
|
||||||
|
import net.minecraftforge.common.config.Property;
|
||||||
|
|
||||||
|
public class ConfigBase {
|
||||||
|
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public static @interface CfgElement {
|
||||||
|
String category();
|
||||||
|
String key();
|
||||||
|
String comment() default "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public static @interface Limit {
|
||||||
|
String min() default "";
|
||||||
|
String max() default "";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Configuration config;
|
||||||
|
|
||||||
|
public void load(File configFile) {
|
||||||
|
config = new Configuration(configFile);
|
||||||
|
config.load();
|
||||||
|
|
||||||
|
for (Field field : getClass().getDeclaredFields()) {
|
||||||
|
CfgElement annot = field.getAnnotation(CfgElement.class);
|
||||||
|
if (annot == null) continue;
|
||||||
|
|
||||||
|
field.setAccessible(true);
|
||||||
|
if (field.getType().equals(boolean.class) || field.getType().equals(Boolean.class)) {
|
||||||
|
try {
|
||||||
|
Property prop = config.get(annot.category(), annot.key(), field.getBoolean(this));
|
||||||
|
field.setBoolean(this, prop.getBoolean());
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
} else if (field.getType().equals(OptionInteger.class)) {
|
||||||
|
try {
|
||||||
|
OptionInteger option = (OptionInteger) field.get(this);
|
||||||
|
Property prop = config.get(annot.category(), annot.key(), option.value);
|
||||||
|
option.value = prop.getInt();
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
} else if (field.getType().equals(OptionDouble.class)) {
|
||||||
|
try {
|
||||||
|
OptionDouble option = (OptionDouble) field.get(this);
|
||||||
|
Property prop = config.get(annot.category(), annot.key(), option.value);
|
||||||
|
option.value = prop.getDouble();
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
validateLimits();
|
||||||
|
if (config.hasChanged()) config.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void validateLimits() {
|
||||||
|
for (Field fieldThis : getClass().getDeclaredFields()) {
|
||||||
|
Limit annot = fieldThis.getAnnotation(Limit.class);
|
||||||
|
if (annot == null) continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Field fieldMin = annot.min().isEmpty() ? null : getClass().getDeclaredField(annot.min());
|
||||||
|
Field fieldMax = annot.max().isEmpty() ? null : getClass().getDeclaredField(annot.max());
|
||||||
|
fieldThis.setAccessible(true);
|
||||||
|
fieldMin.setAccessible(true);
|
||||||
|
fieldMax.setAccessible(true);
|
||||||
|
|
||||||
|
if (fieldThis.getType().equals(OptionInteger.class)) {
|
||||||
|
OptionInteger optionThis = (OptionInteger) fieldThis.get(this);
|
||||||
|
OptionInteger optionMin = fieldMin == null ? null : (OptionInteger) fieldMin.get(this);
|
||||||
|
OptionInteger optionMax = fieldMax == null ? null : (OptionInteger) fieldMax.get(this);
|
||||||
|
if (optionMin != null) optionThis.value = Math.max(optionThis.value, optionMin.value);
|
||||||
|
if (optionMax != null) optionThis.value = Math.min(optionThis.value, optionMax.value);
|
||||||
|
} else if (fieldThis.getType().equals(OptionDouble.class)) {
|
||||||
|
OptionDouble optionThis = (OptionDouble) fieldThis.get(this);
|
||||||
|
OptionDouble optionMin = fieldMin == null ? null : (OptionDouble) fieldMin.get(this);
|
||||||
|
OptionDouble optionMax = fieldMax == null ? null : (OptionDouble) fieldMax.get(this);
|
||||||
|
if (optionMin != null) optionThis.value = Math.max(optionThis.value, optionMin.value);
|
||||||
|
if (optionMax != null) optionThis.value = Math.min(optionThis.value, optionMax.value);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
for (Field field : getClass().getDeclaredFields()) {
|
||||||
|
CfgElement annot = field.getAnnotation(CfgElement.class);
|
||||||
|
if (annot == null) continue;
|
||||||
|
|
||||||
|
field.setAccessible(true);
|
||||||
|
if (field.getType().equals(boolean.class) || field.getType().equals(Boolean.class)) {
|
||||||
|
try {
|
||||||
|
Property prop = config.get(annot.category(), annot.key(), field.getBoolean(this));
|
||||||
|
prop.set(field.getBoolean(this));
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
} else if (field.getType().equals(OptionInteger.class)) {
|
||||||
|
try {
|
||||||
|
OptionInteger option = (OptionInteger) field.get(this);
|
||||||
|
Property prop = config.get(annot.category(), annot.key(), option.value);
|
||||||
|
prop.set(option.value);
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
} else if (field.getType().equals(OptionDouble.class)) {
|
||||||
|
try {
|
||||||
|
OptionDouble option = (OptionDouble) field.get(this);
|
||||||
|
Property prop = config.get(annot.category(), annot.key(), option.value);
|
||||||
|
prop.set(option.value);
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user