Add ability for modders to designate custom biome types. And remove note about automatically registering. Closes #1167

This commit is contained in:
Lex Manos 2014-07-07 21:29:37 -07:00
parent ba6c2c88ed
commit af9229d3bc
3 changed files with 63 additions and 32 deletions

View file

@ -5,6 +5,7 @@ import java.util.*;
import cpw.mods.fml.common.FMLLog;
import net.minecraft.init.Blocks;
import net.minecraft.world.biome.*;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.event.terraingen.DeferredBiomeDecorator;
import static net.minecraft.world.biome.BiomeGenBase.*;
import static net.minecraftforge.common.BiomeDictionary.Type.*;
@ -73,6 +74,35 @@ public class BiomeDictionary
{
return subTags != null && !subTags.isEmpty();
}
/**
* Retrieves a Type value by name,
* if one does not exist already it creates one.
* This can be used as interm measure for modders to
* add there own category of Biome.
*
* There are NO naming conventions besides:
* MUST be all upper case (enforced by name.toUpper())
* NO Special characters. {Unenforced, just don't be a pain, if it becomes a issue I WILL
* make this RTE with no worry about backwards compatibility}
*
* Note: For performance sake, the return value of this function SHOULD be cached.
* Two calls with the same name SHOULD return the same value.
*
*
* @param name The name of this Type
* @return An instance of Type for this name.
*/
public static Type getType(String name, Type... subTypes)
{
name = name.toUpperCase();
for (Type t : values())
{
if (t.name().equals(name))
return t;
}
return EnumHelper.addEnum(Type.class, name, new Class[]{Type[].class}, new Object[]{subTypes});
}
}
private static final int BIOME_LIST_SIZE = BiomeGenBase.getBiomeGenArray().length;
@ -274,8 +304,6 @@ public class BiomeDictionary
* This method is called automatically if a biome has not been registered with any tags,
* And another method requests information about it
*
* NOTE: You can opt out of having your biome registered by registering it as type NULL
*
* @param biome the biome to be considered
*/
public static void makeBestGuess(BiomeGenBase biome)

View file

@ -6,9 +6,10 @@ import java.util.ArrayList;
import java.util.List;
import net.minecraftforge.client.EnumHelperClient;
import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.common.util.EnumHelper;
import org.apache.logging.log4j.core.helpers.Assert;
import org.junit.Assert;
import org.junit.Test;
import cpw.mods.fml.relauncher.ReflectionHelper;
@ -32,6 +33,8 @@ public class EnumHelperTest
if (failed)
throw new RuntimeException("Enum Helper test failed!");
Assert.assertEquals(BiomeDictionary.Type.BEACH, BiomeDictionary.Type.getType("BEACH"));
Assert.assertEquals(BiomeDictionary.Type.getType("NEWTYPE"), BiomeDictionary.Type.getType("NEWTYPE"));
}
private void testType(Object[] info)
{