Merge branch 'master' into 1.7.10
This commit is contained in:
@@ -6,4 +6,6 @@ More info: http://www.minecraftforum.net/topic/2776217-better-foliage/
|
||||
|
||||
Download
|
||||
========
|
||||
[BetterFoliage 0.9.2-beta] (http://goo.gl/G900w3) (MC 1.7.2)
|
||||
[BetterFoliage 0.9.3-beta] (http://goo.gl/Rm1QRx) (MC 1.7.2)
|
||||
|
||||
[BetterFoliage 0.9.3-beta] (http://goo.gl/BFFr6w) (MC 1.7.10)
|
||||
|
||||
@@ -22,7 +22,7 @@ minecraft {
|
||||
|
||||
jar.baseName = 'BetterFoliage-1.7.10'
|
||||
group = 'com.github.octarine-noise'
|
||||
version='0.9.3b'
|
||||
version='0.9.4b'
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
import mods.betterfoliage.client.BetterFoliageClient;
|
||||
import mods.betterfoliage.common.config.Config;
|
||||
import mods.betterfoliage.common.config.BetterFoliageConfig;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -24,6 +24,8 @@ public class BetterFoliage {
|
||||
@Mod.Instance
|
||||
public static BetterFoliage instance;
|
||||
|
||||
public static BetterFoliageConfig config = new BetterFoliageConfig();
|
||||
|
||||
public static Logger log;
|
||||
|
||||
public static File configDir;
|
||||
@@ -34,7 +36,7 @@ public class BetterFoliage {
|
||||
if (event.getSide() == Side.CLIENT) {
|
||||
configDir = new File(event.getModConfigurationDirectory(), MOD_ID);
|
||||
configDir.mkdir();
|
||||
Config.load();
|
||||
config.load(new File(configDir, "betterfoliage.cfg"));
|
||||
BetterFoliageClient.preInit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mods.betterfoliage.client;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
@@ -9,6 +10,9 @@ import mods.betterfoliage.client.render.impl.RenderBlockBetterCactus;
|
||||
import mods.betterfoliage.client.render.impl.RenderBlockBetterGrass;
|
||||
import mods.betterfoliage.client.render.impl.RenderBlockBetterLeaves;
|
||||
import mods.betterfoliage.client.render.impl.RenderBlockBetterLilypad;
|
||||
import mods.betterfoliage.client.render.impl.RenderBlockBetterReed;
|
||||
import mods.betterfoliage.client.resource.BlockTextureGenerator;
|
||||
import mods.betterfoliage.client.resource.HalfTextureResource;
|
||||
import mods.betterfoliage.client.resource.ILeafTextureRecognizer;
|
||||
import mods.betterfoliage.client.resource.LeafTextureGenerator;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -20,7 +24,9 @@ import net.minecraft.block.BlockPotato;
|
||||
import net.minecraft.block.BlockReed;
|
||||
import net.minecraft.block.BlockTallGrass;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
@@ -45,6 +51,7 @@ public class BetterFoliageClient implements ILeafTextureRecognizer {
|
||||
registerRenderer(new RenderBlockBetterGrass());
|
||||
registerRenderer(new RenderBlockBetterCactus());
|
||||
registerRenderer(new RenderBlockBetterLilypad());
|
||||
registerRenderer(new RenderBlockBetterReed());
|
||||
|
||||
leaves = new BlockMatcher(BlockLeavesBase.class.getName(),
|
||||
"forestry.arboriculture.gadgets.BlockLeaves",
|
||||
@@ -66,6 +73,19 @@ public class BetterFoliageClient implements ILeafTextureRecognizer {
|
||||
leafGenerator = new LeafTextureGenerator();
|
||||
MinecraftForge.EVENT_BUS.register(leafGenerator);
|
||||
leafGenerator.recognizers.add(new BetterFoliageClient());
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new BlockTextureGenerator("bf_reed_bottom", new ResourceLocation("betterfoliage", "textures/blocks/missing_leaf.png")) {
|
||||
@Override
|
||||
public IResource getResource(ResourceLocation var1) throws IOException {
|
||||
return new HalfTextureResource(unwrapResource(var1), true, getMissingResource());
|
||||
}
|
||||
});
|
||||
MinecraftForge.EVENT_BUS.register(new BlockTextureGenerator("bf_reed_top", new ResourceLocation("betterfoliage", "textures/blocks/missing_leaf.png")) {
|
||||
@Override
|
||||
public IResource getResource(ResourceLocation var1) throws IOException {
|
||||
return new HalfTextureResource(unwrapResource(var1), false, getMissingResource());
|
||||
}
|
||||
});
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new BetterFoliageClient());
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import cpw.mods.fml.common.gameevent.InputEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
import mods.betterfoliage.client.gui.ConfigGuiScreen;
|
||||
import mods.betterfoliage.client.gui.ConfigGuiMain;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@@ -22,6 +22,6 @@ public class KeyHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public void handleKeyPress(InputEvent.KeyInputEvent event) {
|
||||
if (guiBinding.isPressed()) FMLClientHandler.instance().showGuiScreen(new ConfigGuiScreen(null));
|
||||
if (guiBinding.isPressed()) FMLClientHandler.instance().showGuiScreen(new ConfigGuiMain(null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class ConfigGuiFactory implements IModGuiFactory {
|
||||
}
|
||||
|
||||
public Class<? extends GuiScreen> mainConfigGuiClass() {
|
||||
return ConfigGuiScreen.class;
|
||||
return ConfigGuiMain.class;
|
||||
}
|
||||
|
||||
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package mods.betterfoliage.client.gui;
|
||||
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
import mods.betterfoliage.client.gui.widget.OptionDoubleWidget;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
|
||||
public class ConfigGuiGrass extends ConfigGuiScreenBase {
|
||||
|
||||
public ConfigGuiGrass(GuiScreen parent) {
|
||||
super(parent);
|
||||
int id = 10;
|
||||
widgets.add(new OptionDoubleWidget(BetterFoliage.config.grassSize, -100, -70, 200, 50, id++, id++, "message.betterfoliage.size", "%.2f"));
|
||||
widgets.add(new OptionDoubleWidget(BetterFoliage.config.grassHOffset, -100, -40, 200, 50, id++, id++, "message.betterfoliage.hOffset", "%.3f"));
|
||||
widgets.add(new OptionDoubleWidget(BetterFoliage.config.grassHeightMin, -100, -10, 200, 50, id++, id++, "message.betterfoliage.minHeight", "%.2f"));
|
||||
widgets.add(new OptionDoubleWidget(BetterFoliage.config.grassHeightMax, -100, 20, 200, 50, id++, id++, "message.betterfoliage.maxHeight", "%.2f"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void addButtons(int x, int y) {
|
||||
buttonList.add(new GuiButton(0, x - 50, y + 50, 100, 20, "Close"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onButtonPress(int id) {
|
||||
if (id == 0) FMLClientHandler.instance().showGuiScreen(parent);
|
||||
|
||||
if (BetterFoliage.config.grassHeightMin.value > BetterFoliage.config.grassHeightMax.value) BetterFoliage.config.grassHeightMin.value = BetterFoliage.config.grassHeightMax.value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package mods.betterfoliage.client.gui;
|
||||
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
import mods.betterfoliage.client.gui.widget.OptionDoubleWidget;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
|
||||
public class ConfigGuiLeaves extends ConfigGuiScreenBase {
|
||||
|
||||
public enum Button {CLOSE, LEAVES_OFFSET_MODE}
|
||||
|
||||
public ConfigGuiLeaves(GuiScreen parent) {
|
||||
super(parent);
|
||||
int id = 10;
|
||||
widgets.add(new OptionDoubleWidget(BetterFoliage.config.leavesSize, -100, -70, 200, 50, id++, id++, "message.betterfoliage.size", "%.2f"));
|
||||
widgets.add(new OptionDoubleWidget(BetterFoliage.config.leavesHOffset, -100, -10, 200, 50, id++, id++, "message.betterfoliage.hOffset", "%.3f"));
|
||||
widgets.add(new OptionDoubleWidget(BetterFoliage.config.leavesVOffset, -100, 20, 200, 50, id++, id++, "message.betterfoliage.vOffset", "%.3f"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void addButtons(int x, int y) {
|
||||
buttonList.add(new GuiButton(Button.CLOSE.ordinal(), x - 50, y + 50, 100, 20, "Close"));
|
||||
buttonList.add(new GuiButton(Button.LEAVES_OFFSET_MODE.ordinal(), x - 100, y - 40, 200, 20, ""));
|
||||
}
|
||||
|
||||
protected void updateButtons() {
|
||||
setButtonOptionBoolean(Button.LEAVES_OFFSET_MODE.ordinal(), "message.betterfoliage.leavesMode", BetterFoliage.config.leavesSkew ? "message.betterfoliage.leavesSkew" : "message.betterfoliage.leavesTranslate");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onButtonPress(int id) {
|
||||
if (id == Button.CLOSE.ordinal()) FMLClientHandler.instance().showGuiScreen(parent);
|
||||
if (id == Button.LEAVES_OFFSET_MODE.ordinal()) BetterFoliage.config.leavesSkew = !BetterFoliage.config.leavesSkew;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package mods.betterfoliage.client.gui;
|
||||
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
import mods.betterfoliage.client.gui.widget.OptionDoubleWidget;
|
||||
import mods.betterfoliage.client.gui.widget.OptionIntegerWidget;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
|
||||
public class ConfigGuiLilypad extends ConfigGuiScreenBase {
|
||||
|
||||
public ConfigGuiLilypad(GuiScreen parent) {
|
||||
super(parent);
|
||||
int id = 10;
|
||||
widgets.add(new OptionDoubleWidget(BetterFoliage.config.lilypadHOffset, -100, -40, 200, 50, id++, id++, "message.betterfoliage.hOffset", "%.3f"));
|
||||
widgets.add(new OptionIntegerWidget(BetterFoliage.config.lilypadChance, -100, -10, 200, 50, id++, id++, "message.betterfoliage.flowerChance"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void addButtons(int x, int y) {
|
||||
buttonList.add(new GuiButton(0, x - 50, y + 50, 100, 20, "Close"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onButtonPress(int id) {
|
||||
if (id == 0) FMLClientHandler.instance().showGuiScreen(parent);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package mods.betterfoliage.client.gui;
|
||||
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ConfigGuiMain extends ConfigGuiScreenBase {
|
||||
|
||||
public enum Button {CLOSE,
|
||||
TOGGLE_LEAVES, CONFIG_LEAVES,
|
||||
TOGGLE_GRASS, CONFIG_GRASS,
|
||||
TOGGLE_CACTUS, CONFIG_CACTUS,
|
||||
TOGGLE_LILYPAD, CONFIG_LILYPAD,
|
||||
TOGGLE_REED, CONFIG_REED}
|
||||
|
||||
public ConfigGuiMain(GuiScreen parent) {
|
||||
super(parent);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void addButtons(int x, int y) {
|
||||
buttonList.add(new GuiButton(Button.CLOSE.ordinal(), x - 50, y + 80, 100, 20, "Close"));
|
||||
buttonList.add(new GuiButton(Button.TOGGLE_LEAVES.ordinal(), x - 100, y - 100, 150, 20, ""));
|
||||
buttonList.add(new GuiButton(Button.CONFIG_LEAVES.ordinal(), x + 60, y - 100, 40, 20, I18n.format("message.betterfoliage.config")));
|
||||
|
||||
buttonList.add(new GuiButton(Button.TOGGLE_GRASS.ordinal(), x - 100, y - 70, 150, 20, ""));
|
||||
buttonList.add(new GuiButton(Button.CONFIG_GRASS.ordinal(), x + 60, y - 70, 40, 20, I18n.format("message.betterfoliage.config")));
|
||||
|
||||
buttonList.add(new GuiButton(Button.TOGGLE_CACTUS.ordinal(), x - 100, y - 40, 150, 20, ""));
|
||||
buttonList.add(new GuiButton(Button.CONFIG_CACTUS.ordinal(), x + 60, y - 40, 40, 20, I18n.format("message.betterfoliage.config")));
|
||||
|
||||
buttonList.add(new GuiButton(Button.TOGGLE_LILYPAD.ordinal(), x - 100, y - 10, 150, 20, ""));
|
||||
buttonList.add(new GuiButton(Button.CONFIG_LILYPAD.ordinal(), x + 60, y - 10, 40, 20, I18n.format("message.betterfoliage.config")));
|
||||
|
||||
buttonList.add(new GuiButton(Button.TOGGLE_REED.ordinal(), x - 100, y + 20, 150, 20, ""));
|
||||
buttonList.add(new GuiButton(Button.CONFIG_REED.ordinal(), x + 60, y + 20, 40, 20, I18n.format("message.betterfoliage.config")));
|
||||
}
|
||||
|
||||
protected void updateButtons() {
|
||||
setButtonOptionBoolean(Button.TOGGLE_LEAVES.ordinal(), "message.betterfoliage.betterLeaves", BetterFoliage.config.leavesEnabled);
|
||||
setButtonOptionBoolean(Button.TOGGLE_GRASS.ordinal(), "message.betterfoliage.betterGrass", BetterFoliage.config.grassEnabled);
|
||||
setButtonOptionBoolean(Button.TOGGLE_CACTUS.ordinal(), "message.betterfoliage.betterCactus", BetterFoliage.config.cactusEnabled);
|
||||
setButtonOptionBoolean(Button.TOGGLE_LILYPAD.ordinal(), "message.betterfoliage.betterLilypad", BetterFoliage.config.lilypadEnabled);
|
||||
setButtonOptionBoolean(Button.TOGGLE_REED.ordinal(), "message.betterfoliage.betterReed", BetterFoliage.config.reedEnabled);
|
||||
((GuiButton) buttonList.get(Button.CONFIG_CACTUS.ordinal())).enabled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onButtonPress(int id) {
|
||||
if (id == Button.CLOSE.ordinal()) {
|
||||
BetterFoliage.config.save();
|
||||
Minecraft.getMinecraft().renderGlobal.loadRenderers();
|
||||
FMLClientHandler.instance().showGuiScreen(parent);
|
||||
}
|
||||
if (id == Button.TOGGLE_LEAVES.ordinal()) BetterFoliage.config.leavesEnabled = !BetterFoliage.config.leavesEnabled;
|
||||
if (id == Button.TOGGLE_GRASS.ordinal()) BetterFoliage.config.grassEnabled = !BetterFoliage.config.grassEnabled;
|
||||
if (id == Button.TOGGLE_CACTUS.ordinal()) BetterFoliage.config.cactusEnabled = !BetterFoliage.config.cactusEnabled;
|
||||
if (id == Button.TOGGLE_LILYPAD.ordinal()) BetterFoliage.config.lilypadEnabled = !BetterFoliage.config.lilypadEnabled;
|
||||
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_GRASS.ordinal()) FMLClientHandler.instance().showGuiScreen(new ConfigGuiGrass(this));
|
||||
if (id== Button.CONFIG_LILYPAD.ordinal()) FMLClientHandler.instance().showGuiScreen(new ConfigGuiLilypad(this));
|
||||
if (id== Button.CONFIG_REED.ordinal()) FMLClientHandler.instance().showGuiScreen(new ConfigGuiReed(this));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package mods.betterfoliage.client.gui;
|
||||
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
import mods.betterfoliage.client.gui.widget.OptionDoubleWidget;
|
||||
import mods.betterfoliage.client.gui.widget.OptionIntegerWidget;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
|
||||
public class ConfigGuiReed extends ConfigGuiScreenBase {
|
||||
|
||||
public ConfigGuiReed(GuiScreen parent) {
|
||||
super(parent);
|
||||
int id = 10;
|
||||
widgets.add(new OptionDoubleWidget(BetterFoliage.config.reedHOffset, -100, -70, 200, 50, id++, id++, "message.betterfoliage.hOffset", "%.3f"));
|
||||
widgets.add(new OptionDoubleWidget(BetterFoliage.config.reedHeightMin, -100, -40, 200, 50, id++, id++, "message.betterfoliage.minHeight", "%.2f"));
|
||||
widgets.add(new OptionDoubleWidget(BetterFoliage.config.reedHeightMax, -100, -10, 200, 50, id++, id++, "message.betterfoliage.maxHeight", "%.2f"));
|
||||
widgets.add(new OptionIntegerWidget(BetterFoliage.config.reedChance, -100, 20, 200, 50, id++, id++, "message.betterfoliage.reedChance"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void addButtons(int x, int y) {
|
||||
buttonList.add(new GuiButton(0, x - 50, y + 50, 100, 20, "Close"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onButtonPress(int id) {
|
||||
if (id == 0) FMLClientHandler.instance().showGuiScreen(parent);
|
||||
|
||||
if (BetterFoliage.config.reedHeightMin.value > BetterFoliage.config.reedHeightMax.value) BetterFoliage.config.reedHeightMin.value = BetterFoliage.config.reedHeightMax.value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
package mods.betterfoliage.client.gui;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import mods.betterfoliage.common.config.Config;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ConfigGuiScreen extends GuiScreen {
|
||||
|
||||
public enum Button {CLOSE, TOGGLE_LEAVES, TOGGLE_GRASS, LEAVES_OFFSET_MODE, TOGGLE_CACTUS, TOGGLE_LILYPAD}
|
||||
|
||||
private GuiScreen parent;
|
||||
protected List<IOptionWidget> widgets = Lists.newLinkedList();
|
||||
|
||||
public ConfigGuiScreen(GuiScreen parent) {
|
||||
this.parent = parent;
|
||||
int id = 10;
|
||||
widgets.add(new OptionDoubleWidget(Config.leavesSize, -160, -40, 150, 40, id++, id++, "message.betterfoliage.size", "%.2f"));
|
||||
widgets.add(new OptionDoubleWidget(Config.leavesHOffset, -160, -10, 150, 40, id++, id++, "message.betterfoliage.hOffset", "%.3f"));
|
||||
widgets.add(new OptionDoubleWidget(Config.leavesVOffset, -160, 20, 150, 40, id++, id++, "message.betterfoliage.vOffset", "%.3f"));
|
||||
|
||||
widgets.add(new OptionDoubleWidget(Config.grassSize, 10, -70, 150, 40, id++, id++, "message.betterfoliage.size", "%.2f"));
|
||||
widgets.add(new OptionDoubleWidget(Config.grassHOffset, 10, -40, 150, 40, id++, id++, "message.betterfoliage.hOffset", "%.3f"));
|
||||
widgets.add(new OptionDoubleWidget(Config.grassHeightMin, 10, -10, 150, 40, id++, id++, "message.betterfoliage.minHeight", "%.2f"));
|
||||
widgets.add(new OptionDoubleWidget(Config.grassHeightMax, 10, 20, 150, 40, id++, id++, "message.betterfoliage.maxHeight", "%.2f"));
|
||||
|
||||
widgets.add(new OptionDoubleWidget(Config.lilypadHOffset, 10, 80, 150, 40, id++, id++, "message.betterfoliage.hOffset", "%.3f"));
|
||||
widgets.add(new OptionIntegerWidget(Config.lilypadChance, 10, 110, 150, 40, id++, id++, "message.betterfoliage.flowerChance"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
this.drawDefaultBackground();
|
||||
int x = width / 2;
|
||||
int y = height / 2 - 30;
|
||||
for (IOptionWidget widget : widgets) widget.drawStrings(this, fontRendererObj, x, y, 14737632, 16777120);
|
||||
super.drawScreen(par1, par2, par3);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui() {
|
||||
int x = width / 2;
|
||||
int y = height / 2 - 30;
|
||||
for (IOptionWidget widget : widgets) widget.addButtons(buttonList, x, y);
|
||||
buttonList.add(new GuiButton(Button.CLOSE.ordinal(), x - 50, y + 130, 100, 20, "Close"));
|
||||
buttonList.add(new GuiButton(Button.TOGGLE_LEAVES.ordinal(), x - 160, y - 100, 150, 20, ""));
|
||||
buttonList.add(new GuiButton(Button.LEAVES_OFFSET_MODE.ordinal(), x - 160, y - 70, 150, 20, ""));
|
||||
buttonList.add(new GuiButton(Button.TOGGLE_GRASS.ordinal(), x + 10, y - 100, 150, 20, ""));
|
||||
buttonList.add(new GuiButton(Button.TOGGLE_CACTUS.ordinal(), x -160, y + 50, 150, 20, ""));
|
||||
buttonList.add(new GuiButton(Button.TOGGLE_LILYPAD.ordinal(), x + 10, y + 50, 150, 20, ""));
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
protected void updateButtons() {
|
||||
setButtonOptionBoolean(Button.TOGGLE_LEAVES, "message.betterfoliage.betterLeaves", Config.leavesEnabled);
|
||||
setButtonOptionBoolean(Button.LEAVES_OFFSET_MODE, "message.betterfoliage.leavesMode", Config.leavesSkew ? "message.betterfoliage.leavesSkew" : "message.betterfoliage.leavesTranslate");
|
||||
setButtonOptionBoolean(Button.TOGGLE_GRASS, "message.betterfoliage.betterGrass", Config.grassEnabled);
|
||||
setButtonOptionBoolean(Button.TOGGLE_CACTUS, "message.betterfoliage.betterCactus", Config.cactusEnabled);
|
||||
setButtonOptionBoolean(Button.TOGGLE_LILYPAD, "message.betterfoliage.betterLilypad", Config.lilypadEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
super.actionPerformed(button);
|
||||
|
||||
if (button.id == Button.CLOSE.ordinal()) {
|
||||
Config.save();
|
||||
Minecraft.getMinecraft().renderGlobal.loadRenderers();
|
||||
FMLClientHandler.instance().showGuiScreen(parent);
|
||||
}
|
||||
if (button.id == Button.TOGGLE_LEAVES.ordinal()) Config.leavesEnabled = !Config.leavesEnabled;
|
||||
if (button.id == Button.TOGGLE_GRASS.ordinal()) Config.grassEnabled = !Config.grassEnabled;
|
||||
if (button.id == Button.LEAVES_OFFSET_MODE.ordinal()) Config.leavesSkew = !Config.leavesSkew;
|
||||
if (button.id == Button.TOGGLE_CACTUS.ordinal()) Config.cactusEnabled = !Config.cactusEnabled;
|
||||
if (button.id == Button.TOGGLE_LILYPAD.ordinal()) Config.lilypadEnabled = !Config.lilypadEnabled;
|
||||
|
||||
for (IOptionWidget widget : widgets) widget.onAction(button.id);
|
||||
if (Config.grassHeightMin.value > Config.grassHeightMax.value) Config.grassHeightMin.value = Config.grassHeightMax.value;
|
||||
if (Config.grassHeightMin.value > Config.grassHeightMax.value) Config.grassHeightMax.value = Config.grassHeightMin.value;
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void setButtonOptionBoolean(Button enumButton, String msgKey, boolean option) {
|
||||
for (GuiButton button : (List<GuiButton>) buttonList) {
|
||||
if (button.id == enumButton.ordinal()) {
|
||||
String optionText = option ? (EnumChatFormatting.GREEN + I18n.format("message.betterfoliage.optionOn")) : (EnumChatFormatting.RED + I18n.format("message.betterfoliage.optionOff"));
|
||||
button.displayString = I18n.format(msgKey, optionText);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void setButtonOptionBoolean(Button enumButton, String msgKey, String optionKey) {
|
||||
for (GuiButton button : (List<GuiButton>) buttonList) {
|
||||
if (button.id == enumButton.ordinal()) {
|
||||
button.displayString = I18n.format(msgKey, I18n.format(optionKey));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package mods.betterfoliage.client.gui;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import mods.betterfoliage.client.gui.widget.IOptionWidget;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class ConfigGuiScreenBase extends GuiScreen {
|
||||
|
||||
protected GuiScreen parent;
|
||||
protected List<IOptionWidget> widgets = Lists.newLinkedList();
|
||||
|
||||
public ConfigGuiScreenBase(GuiScreen parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
this.drawDefaultBackground();
|
||||
int x = width / 2;
|
||||
int y = height / 2;
|
||||
for (IOptionWidget widget : widgets) widget.drawStrings(this, fontRendererObj, x, y, 14737632, 16777120);
|
||||
super.drawScreen(par1, par2, par3);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui() {
|
||||
int x = width / 2;
|
||||
int y = height / 2;
|
||||
for (IOptionWidget widget : widgets) widget.addButtons(buttonList, x, y);
|
||||
addButtons(x, y);
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
protected void addButtons(int x, int y) {}
|
||||
|
||||
protected void updateButtons() {}
|
||||
|
||||
protected void onButtonPress(int id) {}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
super.actionPerformed(button);
|
||||
for (IOptionWidget widget : widgets) widget.onAction(button.id);
|
||||
onButtonPress(button.id);
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void setButtonOptionBoolean(int id, String msgKey, boolean option) {
|
||||
for (GuiButton button : (List<GuiButton>) buttonList) {
|
||||
if (button.id == id) {
|
||||
String optionText = option ? (EnumChatFormatting.GREEN + I18n.format("message.betterfoliage.optionOn")) : (EnumChatFormatting.RED + I18n.format("message.betterfoliage.optionOff"));
|
||||
button.displayString = I18n.format(msgKey, optionText);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void setButtonOptionBoolean(int id, String msgKey, String optionKey) {
|
||||
for (GuiButton button : (List<GuiButton>) buttonList) {
|
||||
if (button.id == id) {
|
||||
button.displayString = I18n.format(msgKey, I18n.format(optionKey));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package mods.betterfoliage.client.gui;
|
||||
package mods.betterfoliage.client.gui.widget;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package mods.betterfoliage.client.gui;
|
||||
package mods.betterfoliage.client.gui.widget;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package mods.betterfoliage.client.gui;
|
||||
package mods.betterfoliage.client.gui.widget;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
58
src/main/java/mods/betterfoliage/client/render/IconSet.java
Normal file
58
src/main/java/mods/betterfoliage/client/render/IconSet.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package mods.betterfoliage.client.render;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
/** Loads an indexed set of textures
|
||||
* @author octarine-noise
|
||||
*/
|
||||
public class IconSet {
|
||||
|
||||
/** Icon array */
|
||||
public IIcon[] icons = new IIcon[16];
|
||||
|
||||
/** Number of successfully loaded icons*/
|
||||
public int numLoaded = 0;
|
||||
|
||||
/** Resource domain of icons */
|
||||
String domain;
|
||||
|
||||
/** Format string of icon paths */
|
||||
String path;
|
||||
|
||||
public IconSet(String domain, String path) {
|
||||
this.domain = domain;
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public void registerIcons(IIconRegister register) {
|
||||
numLoaded = 0;
|
||||
IResourceManager manager = Minecraft.getMinecraft().getResourceManager();
|
||||
|
||||
for (int idx = 0; idx < 16; idx++) {
|
||||
icons[idx] = null;
|
||||
// if the path contains a domain, use that to check if the resource exists
|
||||
String resolvedDomain = path.contains(":") ? new ResourceLocation(path).getResourceDomain() : domain;
|
||||
String resolvedPath = String.format("textures/blocks/" + (path.contains(":") ? new ResourceLocation(path).getResourcePath() : path) + ".png", idx);
|
||||
try {
|
||||
IResource resource = manager.getResource(new ResourceLocation(resolvedDomain, resolvedPath));
|
||||
if (resource != null) icons[numLoaded++] = register.registerIcon(domain + ":" + String.format(path, idx));
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IIcon get(int variation) {
|
||||
return numLoaded == 0 ? null : icons[variation % numLoaded];
|
||||
}
|
||||
|
||||
public boolean hasIcons() {
|
||||
return numLoaded > 0;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package mods.betterfoliage.client.render.impl;
|
||||
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
import mods.betterfoliage.client.render.FakeRenderBlockAOBase;
|
||||
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
||||
import mods.betterfoliage.common.config.Config;
|
||||
import mods.betterfoliage.client.render.IconSet;
|
||||
import mods.betterfoliage.common.util.Double3;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -21,13 +22,13 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
public class RenderBlockBetterCactus extends FakeRenderBlockAOBase implements IRenderBlockDecorator {
|
||||
|
||||
public IIcon cactusRoundIcon;
|
||||
public IIcon cactusSideIcons[] = new IIcon[2];
|
||||
public IconSet cactusSideIcons = new IconSet("bettergrassandleaves", "better_cactus_arm_%d");
|
||||
|
||||
public static ForgeDirection[] cactusDirections = new ForgeDirection[] { ForgeDirection.NORTH, ForgeDirection.SOUTH, ForgeDirection.EAST, ForgeDirection.WEST};
|
||||
public static double cactusRadius = 0.4375;
|
||||
|
||||
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) {
|
||||
@@ -51,7 +52,7 @@ public class RenderBlockBetterCactus extends FakeRenderBlockAOBase implements IR
|
||||
Double3 drawBase = blockCenter.add(new Double3(drawDirection).scale(cactusRadius));
|
||||
|
||||
Tessellator.instance.setBrightness(getBrightness(block, x, y, z));
|
||||
renderCrossedSideQuads(drawBase, drawDirection, 0.5, 0.5, pRot[iconVariation], 0.2, cactusSideIcons[iconVariation % 2], 0, false);
|
||||
if (cactusSideIcons.hasIcons()) renderCrossedSideQuads(drawBase, drawDirection, 0.5, 0.5, pRot[iconVariation], 0.2, cactusSideIcons.get(iconVariation), 0, false);
|
||||
renderCrossedBlockQuadsSkew(blockCenter, 0.65,
|
||||
pRot[iconVariation].scaleAxes(0.1, 0.0, 0.1),
|
||||
pRot[(iconVariation + 1) & 63].scaleAxes(0.1, 0.0, 0.1),
|
||||
@@ -78,7 +79,9 @@ public class RenderBlockBetterCactus extends FakeRenderBlockAOBase implements IR
|
||||
@SubscribeEvent
|
||||
public void handleTextureReload(TextureStitchEvent.Pre event) {
|
||||
if (event.map.getTextureType() != 0) return;
|
||||
|
||||
cactusRoundIcon = event.map.registerIcon("bettergrassandleaves:better_cactus");
|
||||
for (int idx = 0; idx < 2; idx++) cactusSideIcons[idx] = event.map.registerIcon("bettergrassandleaves:better_cactus_arm_" + Integer.toString(idx));
|
||||
cactusSideIcons.registerIcons(event.map);
|
||||
BetterFoliage.log.info(String.format("Found %d cactus arm textures", cactusSideIcons.numLoaded));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package mods.betterfoliage.client.render.impl;
|
||||
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
||||
import mods.betterfoliage.client.render.IconSet;
|
||||
import mods.betterfoliage.client.render.RenderBlockAOBase;
|
||||
import mods.betterfoliage.common.config.Config;
|
||||
import mods.betterfoliage.common.util.Double3;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockGrass;
|
||||
@@ -20,11 +21,12 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class RenderBlockBetterGrass extends RenderBlockAOBase implements IRenderBlockDecorator {
|
||||
|
||||
public IIcon grassIcons[] = new IIcon[5];
|
||||
public IIcon myceliumIcons[] = new IIcon[4];
|
||||
public IconSet grassIcons = new IconSet("bettergrassandleaves", "better_grass_long_%d");
|
||||
public IconSet myceliumIcons = new IconSet("bettergrassandleaves", "better_mycel_%d");
|
||||
|
||||
|
||||
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 (y == 255 || !blockAccess.isAirBlock(x, y + 1, z)) return false;
|
||||
return true;
|
||||
@@ -42,12 +44,13 @@ public class RenderBlockBetterGrass extends RenderBlockAOBase implements IRender
|
||||
int variation = getSemiRandomFromPos(x, y, z, 0);
|
||||
int heightVariation = getSemiRandomFromPos(x, y, z, 1);
|
||||
|
||||
IIcon renderIcon = (block == Blocks.mycelium) ? myceliumIcons[variation % 4] : grassIcons[variation % 5];
|
||||
IIcon renderIcon = (block == Blocks.mycelium) ? myceliumIcons.get(variation) : grassIcons.get(variation);
|
||||
if (renderIcon == null) return true;
|
||||
|
||||
double scale = Config.grassSize.value * 0.5;
|
||||
double halfHeight = 0.5 * (Config.grassHeightMin.value + pRand[heightVariation] * (Config.grassHeightMax.value - Config.grassHeightMin.value));
|
||||
double scale = BetterFoliage.config.grassSize.value * 0.5;
|
||||
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));
|
||||
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;
|
||||
}
|
||||
@@ -55,11 +58,11 @@ public class RenderBlockBetterGrass extends RenderBlockAOBase implements IRender
|
||||
@SubscribeEvent
|
||||
public void handleTextureReload(TextureStitchEvent.Pre event) {
|
||||
if (event.map.getTextureType() != 0) return;
|
||||
for (int idx = 0; idx < 5; idx++) {
|
||||
grassIcons[idx] = event.map.registerIcon(String.format("bettergrassandleaves:better_grass_long_%d", idx));
|
||||
}
|
||||
for (int idx = 0; idx < 4; idx++) {
|
||||
myceliumIcons[idx] = event.map.registerIcon(String.format("bettergrassandleaves:better_mycel_%d", idx));
|
||||
}
|
||||
|
||||
grassIcons.registerIcons(event.map);
|
||||
myceliumIcons.registerIcons(event.map);
|
||||
BetterFoliage.log.info(String.format("Found %d short grass textures", grassIcons.numLoaded));
|
||||
BetterFoliage.log.info(String.format("Found %d mycelium textures", myceliumIcons.numLoaded));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package mods.betterfoliage.client.render.impl;
|
||||
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
import mods.betterfoliage.client.BetterFoliageClient;
|
||||
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
||||
import mods.betterfoliage.client.render.RenderBlockAOBase;
|
||||
import mods.betterfoliage.common.config.Config;
|
||||
import mods.betterfoliage.common.util.Double3;
|
||||
import mods.betterfoliage.common.util.ReflectionUtil;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -22,7 +22,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
public class RenderBlockBetterLeaves extends RenderBlockAOBase implements IRenderBlockDecorator {
|
||||
|
||||
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;
|
||||
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 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 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.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,
|
||||
pRot[offsetVariation].scaleAxes(Config.leavesHOffset.value, Config.leavesVOffset.value, Config.leavesHOffset.value),
|
||||
pRot[(offsetVariation + 1) & 63].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(BetterFoliage.config.leavesHOffset.value, BetterFoliage.config.leavesVOffset.value, BetterFoliage.config.leavesHOffset.value),
|
||||
crossLeafIcon, uvVariation, isAirTop, isAirBottom);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package mods.betterfoliage.client.render.impl;
|
||||
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
import mods.betterfoliage.client.render.FakeRenderBlockAOBase;
|
||||
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
||||
import mods.betterfoliage.common.config.Config;
|
||||
import mods.betterfoliage.client.render.IconSet;
|
||||
import mods.betterfoliage.common.util.Double3;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
@@ -19,11 +19,11 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class RenderBlockBetterLilypad extends FakeRenderBlockAOBase implements IRenderBlockDecorator {
|
||||
|
||||
public IIcon lilypadFlowers[] = new IIcon[2];
|
||||
public IIcon lilypadRoots[] = new IIcon[3];
|
||||
public IconSet lilypadFlowers = new IconSet("bettergrassandleaves", "better_lilypad_flower_%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) {
|
||||
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) {
|
||||
@@ -39,16 +39,16 @@ public class RenderBlockBetterLilypad extends FakeRenderBlockAOBase implements I
|
||||
|
||||
Tessellator.instance.setBrightness(getBrightness(block, x, y, z));
|
||||
Tessellator.instance.setColorOpaque(255, 255, 255);
|
||||
renderCrossedSideQuads(new Double3(x + 0.5, y + 0.015, z + 0.5), ForgeDirection.DOWN,
|
||||
0.2, 0.3,
|
||||
null, 0.0,
|
||||
lilypadRoots[iconVariation % 3], 2,
|
||||
true);
|
||||
if (chanceVariation < Config.lilypadChance.value)
|
||||
if (lilypadRoots.hasIcons()) renderCrossedSideQuads(new Double3(x + 0.5, y + 0.015, z + 0.5), ForgeDirection.DOWN,
|
||||
0.2, 0.3,
|
||||
null, 0.0,
|
||||
lilypadRoots.get(iconVariation), 2,
|
||||
true);
|
||||
if (chanceVariation < BetterFoliage.config.lilypadChance.value && lilypadFlowers.hasIcons())
|
||||
renderCrossedSideQuads(new Double3(x + 0.5, y + 0.02, z + 0.5), ForgeDirection.UP,
|
||||
0.2, 0.3,
|
||||
pRot[offsetVariation], Config.lilypadHOffset.value,
|
||||
lilypadFlowers[iconVariation % 2], 0,
|
||||
pRot[offsetVariation], BetterFoliage.config.lilypadHOffset.value,
|
||||
lilypadFlowers.get(iconVariation), 0,
|
||||
true);
|
||||
|
||||
return true;
|
||||
@@ -57,8 +57,11 @@ public class RenderBlockBetterLilypad extends FakeRenderBlockAOBase implements I
|
||||
@SubscribeEvent
|
||||
public void handleTextureReload(TextureStitchEvent.Pre event) {
|
||||
if (event.map.getTextureType() != 0) return;
|
||||
for (int idx = 0; idx < 2; idx++) lilypadFlowers[idx] = event.map.registerIcon("bettergrassandleaves:better_lilypad_flower_" + Integer.toString(idx));
|
||||
for (int idx = 0; idx < 3; idx++) lilypadRoots[idx] = event.map.registerIcon("bettergrassandleaves:better_lilypad_roots_" + Integer.toString(idx));
|
||||
|
||||
lilypadFlowers.registerIcons(event.map);
|
||||
lilypadRoots.registerIcons(event.map);
|
||||
BetterFoliage.log.info(String.format("Found %d lilypad flower textures", lilypadFlowers.numLoaded));
|
||||
BetterFoliage.log.info(String.format("Found %d lilypad root textures", lilypadRoots.numLoaded));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package mods.betterfoliage.client.render.impl;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
import mods.betterfoliage.client.render.IRenderBlockDecorator;
|
||||
import mods.betterfoliage.client.render.IconSet;
|
||||
import mods.betterfoliage.client.render.RenderBlockAOBase;
|
||||
import mods.betterfoliage.common.util.Double3;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDirt;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.gen.NoiseGeneratorSimplex;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class RenderBlockBetterReed extends RenderBlockAOBase implements IRenderBlockDecorator {
|
||||
|
||||
public IconSet reedBottomIcons = new IconSet("bf_reed_bottom", "bettergrassandleaves:better_reed_%d");
|
||||
public IconSet reedTopIcons = new IconSet("bf_reed_top", "bettergrassandleaves:better_reed_%d");
|
||||
public NoiseGeneratorSimplex noise;
|
||||
|
||||
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
||||
if (!BetterFoliage.config.reedEnabled) return false;
|
||||
if (y >= 254 || !(block instanceof BlockDirt)) 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 < BetterFoliage.config.reedChance.value;
|
||||
}
|
||||
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||
// store world for later use
|
||||
blockAccess = world;
|
||||
|
||||
// render grass block
|
||||
setPassCounters(1);
|
||||
setRenderBoundsFromBlock(block);
|
||||
renderStandardBlock(block, x, y, z);
|
||||
|
||||
int iconVariation = getSemiRandomFromPos(x, y, z, 0);
|
||||
int heightVariation = getSemiRandomFromPos(x, y, z, 1);
|
||||
|
||||
IIcon bottomIcon = reedBottomIcons.get(iconVariation);
|
||||
IIcon topIcon = reedTopIcons.get(iconVariation);
|
||||
if (bottomIcon == null || topIcon == null) return true;
|
||||
|
||||
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.setColorOpaque(255, 255, 255);
|
||||
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], BetterFoliage.config.reedHOffset.value, topIcon, 0, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void handleTextureReload(TextureStitchEvent.Pre event) {
|
||||
if (event.map.getTextureType() != 0) return;
|
||||
|
||||
reedBottomIcons.registerIcons(event.map);
|
||||
reedTopIcons.registerIcons(event.map);
|
||||
BetterFoliage.log.info(String.format("Found %d reed textures", reedBottomIcons.numLoaded));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void handleWorldLoad(WorldEvent.Load event) {
|
||||
noise = new NoiseGeneratorSimplex(new Random(event.world.getWorldInfo().getSeed()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package mods.betterfoliage.client.resource;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
import mods.betterfoliage.common.util.ReflectionUtil;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public abstract class BlockTextureGenerator implements IResourceManager {
|
||||
|
||||
/** Resource domain name of generated textures */
|
||||
public String domainName;
|
||||
|
||||
/** Resource location for fallback texture (if the generation process fails) */
|
||||
public ResourceLocation missingResource;
|
||||
|
||||
/** Texture atlas for block textures used in the current run */
|
||||
public TextureMap blockTextures;
|
||||
|
||||
/** Number of textures generated in the current run */
|
||||
int counter = 0;
|
||||
|
||||
public BlockTextureGenerator(String domainName, ResourceLocation missingResource) {
|
||||
this.domainName = domainName;
|
||||
this.missingResource = missingResource;
|
||||
}
|
||||
|
||||
public void onStitchStart(TextureStitchEvent.Pre event) {}
|
||||
|
||||
public void onStitchEnd(TextureStitchEvent.Post event) {}
|
||||
|
||||
@SubscribeEvent
|
||||
public void handleTextureReload(TextureStitchEvent.Pre event) {
|
||||
if (event.map.getTextureType() != 0) return;
|
||||
|
||||
blockTextures = event.map;
|
||||
counter = 0;
|
||||
Map<String, IResourceManager> domainManagers = ReflectionUtil.getDomainResourceManagers();
|
||||
if (domainManagers == null) {
|
||||
BetterFoliage.log.warn("Failed to inject texture generator");
|
||||
return;
|
||||
}
|
||||
domainManagers.put(domainName, this);
|
||||
|
||||
onStitchStart(event);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void endTextureReload(TextureStitchEvent.Post event) {
|
||||
blockTextures = null;
|
||||
if (event.map.getTextureType() != 0) return;
|
||||
|
||||
// don't leave a mess
|
||||
Map<String, IResourceManager> domainManagers = ReflectionUtil.getDomainResourceManagers();
|
||||
if (domainManagers != null) domainManagers.remove(domainName);
|
||||
|
||||
onStitchEnd(event);
|
||||
}
|
||||
|
||||
public Set<String> getResourceDomains() {
|
||||
return ImmutableSet.<String>of(domainName);
|
||||
}
|
||||
|
||||
public List<IResource> getAllResources(ResourceLocation resource) throws IOException {
|
||||
return ImmutableList.<IResource>of(getResource(resource));
|
||||
}
|
||||
|
||||
public IResource getMissingResource() throws IOException {
|
||||
return Minecraft.getMinecraft().getResourceManager().getResource(missingResource);
|
||||
}
|
||||
|
||||
public ResourceLocation unwrapResource(ResourceLocation wrapped) {
|
||||
return new ResourceLocation(wrapped.getResourcePath().substring(16));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package mods.betterfoliage.client.resource;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import mods.betterfoliage.BetterFoliage;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.data.IMetadataSection;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
/** {@link IResource} of PNG containing one half (top or bottom) of a given texture resource
|
||||
* @author octarine-noise
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class HalfTextureResource implements IResource {
|
||||
|
||||
/** Raw PNG data*/
|
||||
public byte[] data = null;
|
||||
|
||||
/** Resource to return if generation fails */
|
||||
public IResource fallbackResource;
|
||||
|
||||
public HalfTextureResource(ResourceLocation resource, boolean bottom, IResource fallbackResource) {
|
||||
this.fallbackResource = fallbackResource;
|
||||
|
||||
IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
|
||||
try {
|
||||
// load full texture
|
||||
ResourceLocation origResource = new ResourceLocation(resource.getResourceDomain(), "textures/blocks/" + resource.getResourcePath());
|
||||
BufferedImage origImage = ImageIO.read(resourceManager.getResource(origResource).getInputStream());
|
||||
|
||||
// draw half texture
|
||||
BufferedImage result = new BufferedImage(origImage.getWidth(), origImage.getHeight() / 2, BufferedImage.TYPE_4BYTE_ABGR);
|
||||
Graphics2D graphics = result.createGraphics();
|
||||
graphics.drawImage(origImage, 0, bottom ? -origImage.getHeight() / 2 : 0, null);
|
||||
|
||||
// create PNG image
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageIO.write(result, "PNG", baos);
|
||||
data = baos.toByteArray();
|
||||
} catch (Exception e) {
|
||||
// stop log spam with GLSL installed
|
||||
if (e instanceof FileNotFoundException) return;
|
||||
BetterFoliage.log.info(String.format("Could not load texture: %s, exception: %s", resource.toString(), e.getClass().getSimpleName()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() {
|
||||
return data != null ? new ByteArrayInputStream(data) : fallbackResource.getInputStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMetadata() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMetadataSection getMetadata(String var1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,22 +11,17 @@ import mods.betterfoliage.client.BetterFoliageClient;
|
||||
import mods.betterfoliage.common.util.DeobfNames;
|
||||
import mods.betterfoliage.common.util.ReflectionUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent.Post;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent.Pre;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -34,41 +29,19 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
* @author octarine-noise
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class LeafTextureGenerator implements IIconRegister, IResourceManager {
|
||||
public class LeafTextureGenerator extends BlockTextureGenerator implements IIconRegister {
|
||||
|
||||
public LeafTextureGenerator() {
|
||||
super("bf_leaves_autogen", new ResourceLocation("betterfoliage", "textures/blocks/missing_leaf.png"));
|
||||
}
|
||||
|
||||
/** Resource domain name of autogenerated crossleaf textures */
|
||||
public String domainName = "bf_leaves_autogen";
|
||||
|
||||
/** Resource location for fallback texture (if the generation process fails) */
|
||||
public ResourceLocation missing_resource = new ResourceLocation("betterfoliage", "textures/blocks/missingleaf.png");
|
||||
|
||||
/** Texture atlas for block textures used in the current run */
|
||||
public TextureMap blockTextures;
|
||||
|
||||
/** List of helpers which can identify leaf textures loaded by alternate means */
|
||||
public List<ILeafTextureRecognizer> recognizers = Lists.newLinkedList();
|
||||
|
||||
/** Number of textures generated in the current run */
|
||||
int counter = 0;
|
||||
|
||||
public Set<String> getResourceDomains() {
|
||||
return ImmutableSet.<String>of(domainName);
|
||||
}
|
||||
|
||||
public IResource getResource(ResourceLocation resourceLocation) throws IOException {
|
||||
// remove "/blocks/textures/" from beginning
|
||||
String origResPath = resourceLocation.getResourcePath().substring(16);
|
||||
LeafTextureResource result = new LeafTextureResource(new ResourceLocation(origResPath));
|
||||
if (result.data == null) {
|
||||
return Minecraft.getMinecraft().getResourceManager().getResource(missing_resource);
|
||||
} else {
|
||||
counter++;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public List<IResource> getAllResources(ResourceLocation resource) throws IOException {
|
||||
return ImmutableList.<IResource>of();
|
||||
LeafTextureResource result = new LeafTextureResource(unwrapResource(resourceLocation), getMissingResource());
|
||||
if (result.data != null) counter++;
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Leaf blocks register their textures here. An extra texture will be registered in the atlas
|
||||
@@ -87,21 +60,10 @@ public class LeafTextureGenerator implements IIconRegister, IResourceManager {
|
||||
* @param event
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@SubscribeEvent
|
||||
public void handleTextureReload(TextureStitchEvent.Pre event) {
|
||||
if (event.map.getTextureType() != 0) return;
|
||||
|
||||
blockTextures = event.map;
|
||||
counter = 0;
|
||||
@Override
|
||||
public void onStitchStart(Pre event) {
|
||||
BetterFoliage.log.info("Reloading leaf textures");
|
||||
|
||||
Map<String, IResourceManager> domainManagers = ReflectionUtil.getDomainResourceManagers();
|
||||
if (domainManagers == null) {
|
||||
BetterFoliage.log.warn("Failed to inject leaf texture generator");
|
||||
return;
|
||||
}
|
||||
domainManagers.put(domainName, this);
|
||||
|
||||
// register simple block textures
|
||||
Iterator<Block> iter = Block.blockRegistry.iterator();
|
||||
while(iter.hasNext()) {
|
||||
@@ -130,18 +92,10 @@ public class LeafTextureGenerator implements IIconRegister, IResourceManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void endTextureReload(TextureStitchEvent.Post event) {
|
||||
blockTextures = null;
|
||||
if (event.map.getTextureType() == 0) {
|
||||
BetterFoliage.log.info(String.format("Generated %d leaf textures", counter));
|
||||
|
||||
// don't leave a mess
|
||||
Map<String, IResourceManager> domainManagers = ReflectionUtil.getDomainResourceManagers();
|
||||
if (domainManagers == null) return;
|
||||
domainManagers.remove(domainName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStitchEnd(Post event) {
|
||||
BetterFoliage.log.info(String.format("Generated %d leaf textures", counter));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,12 @@ public class LeafTextureResource implements IResource {
|
||||
/** Name of the default alpha mask to use */
|
||||
public static String defaultMask = "rough";
|
||||
|
||||
public LeafTextureResource(ResourceLocation resLeaf) {
|
||||
/** Resource to return if generation fails */
|
||||
public IResource fallbackResource;
|
||||
|
||||
public LeafTextureResource(ResourceLocation resLeaf, IResource fallbackResource) {
|
||||
this.fallbackResource = fallbackResource;
|
||||
|
||||
IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
|
||||
try {
|
||||
// load normal leaf texture
|
||||
@@ -97,7 +102,7 @@ public class LeafTextureResource implements IResource {
|
||||
}
|
||||
|
||||
public InputStream getInputStream() {
|
||||
return data != null ? new ByteArrayInputStream(data) : null;
|
||||
return data != null ? new ByteArrayInputStream(data) : fallbackResource.getInputStream();
|
||||
}
|
||||
|
||||
public boolean hasMetadata() {
|
||||
|
||||
@@ -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,108 +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 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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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(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);
|
||||
option.value = prop.getInt(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);
|
||||
option.value = prop.getDouble(option.value);
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,14 @@ key.betterfoliage.gui=Open Settings
|
||||
|
||||
message.betterfoliage.optionOn=ON
|
||||
message.betterfoliage.optionOff=OFF
|
||||
message.betterfoliage.config=Config
|
||||
|
||||
message.betterfoliage.close=Close
|
||||
message.betterfoliage.betterLeaves=Better Leaves: %s
|
||||
message.betterfoliage.betterGrass=Better Grass: %s
|
||||
message.betterfoliage.betterCactus=Better Cactus: %s
|
||||
message.betterfoliage.betterLilypad=Better Lilypad: %s
|
||||
message.betterfoliage.betterReed=Better Reeds: %s
|
||||
|
||||
message.betterfoliage.size=Size
|
||||
message.betterfoliage.hOffset=H.Offset
|
||||
@@ -15,6 +17,7 @@ message.betterfoliage.vOffset=V.Offset
|
||||
message.betterfoliage.minHeight=Min.Height
|
||||
message.betterfoliage.maxHeight=Max.Height
|
||||
message.betterfoliage.flowerChance=Flower Chance
|
||||
message.betterfoliage.reedChance=Reed Chance
|
||||
message.betterfoliage.leavesMode=Leaves Offset: %s
|
||||
message.betterfoliage.leavesSkew=Skew
|
||||
message.betterfoliage.leavesTranslate=Translate
|
||||
Reference in New Issue
Block a user