make reeds, algae, coral biomes configurable
This commit is contained in:
@@ -42,7 +42,7 @@ public class BetterFoliageClient {
|
||||
public static LeafParticleTextures leafParticles = new LeafParticleTextures(0);
|
||||
public static WindTracker wind = new WindTracker();
|
||||
|
||||
public static void preInit() {
|
||||
public static void postInit() {
|
||||
FMLCommonHandler.instance().bus().register(new KeyHandler());
|
||||
FMLCommonHandler.instance().bus().register(new Config());
|
||||
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package mods.betterfoliage.client.gui;
|
||||
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import cpw.mods.fml.client.config.GuiConfig;
|
||||
import cpw.mods.fml.client.config.GuiConfigEntries;
|
||||
import cpw.mods.fml.client.config.IConfigElement;
|
||||
|
||||
|
||||
public class AlternateTextBooleanEntry extends GuiConfigEntries.ButtonEntry {
|
||||
|
||||
protected final boolean beforeValue;
|
||||
protected boolean currentValue;
|
||||
|
||||
public AlternateTextBooleanEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement<Boolean> configElement)
|
||||
{
|
||||
super(owningScreen, owningEntryList, configElement);
|
||||
this.beforeValue = Boolean.valueOf(configElement.get().toString());
|
||||
this.currentValue = beforeValue;
|
||||
this.btnValue.enabled = enabled();
|
||||
updateValueButtonText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateValueButtonText()
|
||||
{
|
||||
this.btnValue.displayString = I18n.format(configElement.getLanguageKey() + "." + String.valueOf(currentValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void valueButtonPressed(int slotIndex)
|
||||
{
|
||||
if (enabled())
|
||||
currentValue = !currentValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefault()
|
||||
{
|
||||
return currentValue == Boolean.valueOf(configElement.getDefault().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setToDefault()
|
||||
{
|
||||
if (enabled())
|
||||
{
|
||||
currentValue = Boolean.valueOf(configElement.getDefault().toString());
|
||||
updateValueButtonText();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChanged()
|
||||
{
|
||||
return currentValue != beforeValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undoChanges()
|
||||
{
|
||||
if (enabled())
|
||||
{
|
||||
currentValue = beforeValue;
|
||||
updateValueButtonText();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean saveConfigElement()
|
||||
{
|
||||
if (enabled() && isChanged())
|
||||
{
|
||||
configElement.set(currentValue);
|
||||
return configElement.requiresMcRestart();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getCurrentValue()
|
||||
{
|
||||
return currentValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean[] getCurrentValues()
|
||||
{
|
||||
return new Boolean[] { getCurrentValue() };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package mods.betterfoliage.client.gui;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import cpw.mods.fml.client.config.GuiConfig;
|
||||
import cpw.mods.fml.client.config.GuiConfigEntries;
|
||||
import cpw.mods.fml.client.config.IConfigElement;
|
||||
|
||||
|
||||
public class BiomeListConfigEntry extends SelectListConfigEntry<BiomeGenBase> {
|
||||
|
||||
public static List<BiomeGenBase> reedBiomeList = Lists.newArrayList();
|
||||
public static List<BiomeGenBase> algaeBiomeList = Lists.newArrayList();
|
||||
public static List<BiomeGenBase> coralBiomeList = Lists.newArrayList();
|
||||
|
||||
public BiomeListConfigEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement<?> configElement) {
|
||||
super(owningScreen, owningEntryList, configElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<BiomeGenBase> getBaseSet(String qualifiedName) {
|
||||
List<BiomeGenBase> biomes = Lists.newArrayList(Collections2.filter(Arrays.asList(BiomeGenBase.getBiomeGenArray()), Predicates.notNull()));
|
||||
Collections.sort(biomes, new Comparator<BiomeGenBase>() {
|
||||
@Override
|
||||
public int compare(BiomeGenBase o1, BiomeGenBase o2) {
|
||||
return o1.biomeName.compareTo(o2.biomeName);
|
||||
}
|
||||
});
|
||||
return biomes;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<BiomeGenBase> getDefaultSelected(String name) {
|
||||
if (name.equals("reedBiomeList")) return reedBiomeList;
|
||||
if (name.equals("algaeBiomeList")) return algaeBiomeList;
|
||||
if (name.equals("coralBiomeList")) return coralBiomeList;
|
||||
return ImmutableList.<BiomeGenBase>of();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getItemId(BiomeGenBase item) {
|
||||
return item.biomeID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getItemName(BiomeGenBase item) {
|
||||
return item.biomeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTooltipLangKey(String name) {
|
||||
if (name.equals("reedBiomeList")) return "betterfoliage.reeds.biomeSelectTooltip";
|
||||
if (name.equals("algaeBiomeList")) return "betterfoliage.algae.biomeSelectTooltip";
|
||||
if (name.equals("coralBiomeList")) return "betterfoliage.coral.biomeSelectTooltip";
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package mods.betterfoliage.client.gui;
|
||||
|
||||
import mods.betterfoliage.common.util.Utils;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import cpw.mods.fml.client.config.GuiConfig;
|
||||
import cpw.mods.fml.client.config.GuiConfigEntries;
|
||||
import cpw.mods.fml.client.config.IConfigElement;
|
||||
|
||||
|
||||
public class NonVerboseArrayEntry extends GuiConfigEntries.ArrayEntry {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public NonVerboseArrayEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement<?> configElement) {
|
||||
super(owningScreen, owningEntryList, configElement);
|
||||
|
||||
Utils.stripTooltipDefaultText(toolTip);
|
||||
String shortDefaults = I18n.format("betterfoliage.arrayEntryDisplay", configElement.getDefaults().length);
|
||||
toolTip.addAll(this.mc.fontRenderer.listFormattedStringToWidth(EnumChatFormatting.AQUA + I18n.format("fml.configgui.tooltip.default", shortDefaults),300));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateValueButtonText() {
|
||||
this.btnValue.displayString = I18n.format("betterfoliage.arrayEntryDisplay", currentValues.length);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package mods.betterfoliage.client.gui;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import mods.betterfoliage.common.util.Utils;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import cpw.mods.fml.client.config.ConfigGuiType;
|
||||
import cpw.mods.fml.client.config.DummyConfigElement;
|
||||
import cpw.mods.fml.client.config.GuiConfig;
|
||||
import cpw.mods.fml.client.config.GuiConfigEntries;
|
||||
import cpw.mods.fml.client.config.GuiConfigEntries.CategoryEntry;
|
||||
import cpw.mods.fml.client.config.IConfigElement;
|
||||
|
||||
|
||||
public abstract class SelectListConfigEntry<T> extends CategoryEntry {
|
||||
|
||||
List<ItemWrapperElement> children;
|
||||
List<Integer> notFoundIdList;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public SelectListConfigEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement<?> configElement) {
|
||||
super(owningScreen, owningEntryList, configElement);
|
||||
Utils.stripTooltipDefaultText(toolTip);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiScreen buildChildScreen()
|
||||
{
|
||||
return new GuiConfig(this.owningScreen, createChildElements(), this.owningScreen.modID,
|
||||
owningScreen.allRequireWorldRestart || this.configElement.requiresWorldRestart(),
|
||||
owningScreen.allRequireMcRestart || this.configElement.requiresMcRestart(), this.owningScreen.title,
|
||||
((this.owningScreen.titleLine2 == null ? "" : this.owningScreen.titleLine2) + " > " + this.name));
|
||||
}
|
||||
|
||||
protected abstract List<T> getBaseSet(String qualifiedName);
|
||||
protected abstract List<T> getDefaultSelected(String qualifiedName);
|
||||
protected abstract int getItemId(T item);
|
||||
protected abstract String getItemName(T item);
|
||||
protected abstract String getTooltipLangKey(String qualifiedName);
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected List<IConfigElement> createChildElements() {
|
||||
children = Lists.newArrayList();
|
||||
|
||||
List<Integer> idList = Lists.newArrayList();
|
||||
for (Object id : configElement.getList()) idList.add((Integer) id);
|
||||
|
||||
List<T> defaults = getDefaultSelected(configElement.getName());
|
||||
for(T item : getBaseSet(configElement.getQualifiedName())) {
|
||||
children.add(new ItemWrapperElement(item, defaults.contains(item), idList.contains(getItemId(item))));
|
||||
idList.remove(new Integer(getItemId(item)));
|
||||
}
|
||||
|
||||
notFoundIdList = idList;
|
||||
List<IConfigElement> result = Lists.newArrayList();
|
||||
result.addAll(children);
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean saveConfigElement() {
|
||||
boolean requiresRestart = ((GuiConfig) childScreen).entryList.saveConfigElements();
|
||||
|
||||
Set<Integer> idSet = Sets.newHashSet();
|
||||
for (ItemWrapperElement child : children)
|
||||
if (Boolean.TRUE.equals(child.getCurrentValue()))
|
||||
idSet.add(getItemId(child.item));
|
||||
|
||||
idSet.addAll(notFoundIdList);
|
||||
List<Integer> result = Lists.newArrayList(idSet);
|
||||
Collections.sort(result);
|
||||
configElement.set(result.toArray());
|
||||
|
||||
return requiresRestart;
|
||||
}
|
||||
|
||||
public class ItemWrapperElement extends DummyConfigElement<Boolean> implements IConfigElement<Boolean> {
|
||||
|
||||
public T item;
|
||||
|
||||
public ItemWrapperElement(T item, boolean defaultValue, boolean currentValue) {
|
||||
super(getItemName(item), defaultValue, ConfigGuiType.BOOLEAN, getItemName(item));
|
||||
set(currentValue);
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComment() {
|
||||
return I18n.format(getTooltipLangKey(configElement.getQualifiedName()), EnumChatFormatting.GOLD + getItemName(item) + EnumChatFormatting.YELLOW);
|
||||
}
|
||||
|
||||
public Boolean getCurrentValue() {
|
||||
return (Boolean) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(Boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void setDefault(Boolean value) {
|
||||
this.defaultValue = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,8 @@ public class RenderBlockBetterAlgae extends RenderBlockAOBase implements IRender
|
||||
|
||||
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
||||
if (!Config.algaeEnabled) return false;
|
||||
if (!(Config.dirt.matchesID(block))) return false;
|
||||
if (!Config.dirt.matchesID(block)) return false;
|
||||
if (!Config.algaeBiomeList.contains(blockAccess.getBiomeGenForCoords(x, z).biomeID)) return false;
|
||||
if (blockAccess.getBlock(x, y + 1, z).getMaterial() != Material.water) return false;
|
||||
if (blockAccess.getBlock(x, y + 2, z).getMaterial() != Material.water) return false;
|
||||
int terrainVariation = MathHelper.floor_double((noise.func_151605_a(x, z) + 1.0) * 32.0);
|
||||
|
||||
@@ -32,6 +32,7 @@ public class RenderBlockBetterCoral extends RenderBlockAOBase implements IRender
|
||||
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
||||
if (!Config.coralEnabled) return false;
|
||||
if (block != Blocks.sand) return false;
|
||||
if (!Config.coralBiomeList.contains(blockAccess.getBiomeGenForCoords(x, z).biomeID)) return false;
|
||||
int terrainVariation = MathHelper.floor_double((noise.func_151605_a(x * 0.1, z * 0.1) + 1.0) * 32.0);
|
||||
return terrainVariation < Config.coralPopulation;
|
||||
}
|
||||
|
||||
@@ -34,9 +34,9 @@ public class RenderBlockBetterReed extends RenderBlockAOBase implements IRenderB
|
||||
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
||||
if (!Config.reedEnabled) return false;
|
||||
if (!(Config.dirt.matchesID(block))) return false;
|
||||
if (!Config.reedBiomeList.contains(blockAccess.getBiomeGenForCoords(x, z).biomeID)) return false;
|
||||
if (blockAccess.getBlock(x, y + 1, z).getMaterial() != Material.water) return false;
|
||||
if (!blockAccess.isAirBlock(x, y + 2, z)) return false;
|
||||
if (blockAccess.getBiomeGenForCoords(x, z).temperature < 0.4f || blockAccess.getBiomeGenForCoords(x, z).rainfall < 0.4f) return false;
|
||||
int terrainVariation = MathHelper.floor_double((noise.func_151605_a(x, z) + 1.0) * 32.0);
|
||||
return terrainVariation < Config.reedPopulation;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user