Add ability for modders to designate custom biome types. And remove note about automatically registering. Closes #1167
This commit is contained in:
parent
ba6c2c88ed
commit
af9229d3bc
3 changed files with 63 additions and 32 deletions
|
@ -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.*;
|
||||
|
@ -27,7 +28,7 @@ public class BiomeDictionary
|
|||
SAVANNA,
|
||||
CONIFEROUS,
|
||||
JUNGLE,
|
||||
|
||||
|
||||
/*Tags specifying the nature of a biome*/
|
||||
SPOOKY,
|
||||
DEAD,
|
||||
|
@ -36,12 +37,12 @@ public class BiomeDictionary
|
|||
END,
|
||||
MUSHROOM,
|
||||
MAGICAL,
|
||||
|
||||
|
||||
OCEAN,
|
||||
RIVER,
|
||||
/**A general tag for all water-based biomes. Shown as present if OCEAN or RIVER are.**/
|
||||
WATER(OCEAN, RIVER),
|
||||
|
||||
|
||||
/*Generic types which a biome can be*/
|
||||
MESA,
|
||||
FOREST,
|
||||
|
@ -53,7 +54,7 @@ public class BiomeDictionary
|
|||
SNOWY,
|
||||
WASTELAND,
|
||||
BEACH,
|
||||
|
||||
|
||||
/*Deprecated tags, kept for compatibility*/
|
||||
@Deprecated
|
||||
/**Replaced by SANDY**/
|
||||
|
@ -61,18 +62,47 @@ public class BiomeDictionary
|
|||
@Deprecated
|
||||
/**Replaced by SNOWY**/
|
||||
FROZEN(SNOWY);
|
||||
|
||||
|
||||
private List<Type> subTags;
|
||||
|
||||
|
||||
private Type(Type... subTags)
|
||||
{
|
||||
this.subTags = Arrays.asList(subTags);
|
||||
}
|
||||
|
||||
|
||||
private boolean hasSubTags()
|
||||
{
|
||||
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;
|
||||
|
@ -101,15 +131,15 @@ public class BiomeDictionary
|
|||
|
||||
/**
|
||||
* Registers a biome with a specific biome type
|
||||
*
|
||||
*
|
||||
* @param biome the biome to be registered
|
||||
* @param type the type to register the biome as
|
||||
* @return returns true if the biome was registered successfully
|
||||
*/
|
||||
public static boolean registerBiomeType(BiomeGenBase biome, Type ... types)
|
||||
{
|
||||
{
|
||||
types = listSubTags(types);
|
||||
|
||||
|
||||
if(BiomeGenBase.getBiomeGenArray()[biome.biomeID] != null)
|
||||
{
|
||||
for(Type type : types)
|
||||
|
@ -142,7 +172,7 @@ public class BiomeDictionary
|
|||
|
||||
/**
|
||||
* Returns a list of biomes registered with a specific type
|
||||
*
|
||||
*
|
||||
* @param type the Type to look for
|
||||
* @return a list of biomes of the specified type, null if there are none
|
||||
*/
|
||||
|
@ -158,7 +188,7 @@ public class BiomeDictionary
|
|||
|
||||
/**
|
||||
* Gets a list of Types that a specific biome is registered with
|
||||
*
|
||||
*
|
||||
* @param biome the biome to check
|
||||
* @return the list of types, null if there are none
|
||||
*/
|
||||
|
@ -176,7 +206,7 @@ public class BiomeDictionary
|
|||
|
||||
/**
|
||||
* Checks to see if two biomes are registered as having the same type
|
||||
*
|
||||
*
|
||||
* @param biomeA
|
||||
* @param biomeB
|
||||
* @return returns true if a common type is found, false otherwise
|
||||
|
@ -205,7 +235,7 @@ public class BiomeDictionary
|
|||
|
||||
/**
|
||||
* Checks to see if the given biome is registered as being a specific type
|
||||
*
|
||||
*
|
||||
* @param biome the biome to be considered
|
||||
* @param type the type to check for
|
||||
* @return returns true if the biome is registered as being of type type, false otherwise
|
||||
|
@ -228,7 +258,7 @@ public class BiomeDictionary
|
|||
* @return returns true if the biome has been registered, false otherwise
|
||||
*/
|
||||
public static boolean isBiomeRegistered(BiomeGenBase biome)
|
||||
{
|
||||
{
|
||||
return biomeList[biome.biomeID] != null;
|
||||
}
|
||||
|
||||
|
@ -245,7 +275,7 @@ public class BiomeDictionary
|
|||
* Loops through the biome list and automatically adds tags to any biome that does not have any
|
||||
* This is called by Forge at postinit time. It will additionally dispatch any deferred decorator
|
||||
* creation events.
|
||||
*
|
||||
*
|
||||
* DO NOT call this during world generation
|
||||
*/
|
||||
public static void registerAllBiomesAndGenerateEvents()
|
||||
|
@ -273,13 +303,11 @@ public class BiomeDictionary
|
|||
* Automatically looks for and registers a given biome with appropriate tags
|
||||
* 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)
|
||||
{
|
||||
{
|
||||
if (biome.theBiomeDecorator.treesPerChunk >= 3)
|
||||
{
|
||||
if (biome.isHighHumidity() && biome.temperature >= 0.9F)
|
||||
|
@ -290,7 +318,7 @@ public class BiomeDictionary
|
|||
{
|
||||
BiomeDictionary.registerBiomeType(biome, FOREST);
|
||||
|
||||
if (biome.temperature <= 0.2f)
|
||||
if (biome.temperature <= 0.2f)
|
||||
{
|
||||
BiomeDictionary.registerBiomeType(biome, CONIFEROUS);
|
||||
}
|
||||
|
@ -384,7 +412,7 @@ public class BiomeDictionary
|
|||
}
|
||||
}
|
||||
|
||||
//Internal implementation
|
||||
//Internal implementation
|
||||
private static void checkRegistration(BiomeGenBase biome)
|
||||
{
|
||||
if(!isBiomeRegistered(biome))
|
||||
|
@ -401,23 +429,23 @@ public class BiomeDictionary
|
|||
{
|
||||
if (info.typeList.contains(remappedType)) return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return info.typeList.contains(type);
|
||||
}
|
||||
|
||||
|
||||
private static Type[] listSubTags(Type... types)
|
||||
{
|
||||
List<Type> subTags = new ArrayList<Type>();
|
||||
|
||||
|
||||
for (Type type : types)
|
||||
{
|
||||
if (type.hasSubTags()) subTags.addAll(type.subTags);
|
||||
else subTags.add(type);
|
||||
}
|
||||
|
||||
|
||||
return subTags.toArray(new Type[subTags.size()]);
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ public class EnumHelper
|
|||
{EnumStatus.class},
|
||||
{ToolMaterial.class, int.class, int.class, float.class, float.class, int.class},
|
||||
{EnumRarity.class, EnumChatFormatting.class, String.class}
|
||||
};
|
||||
};
|
||||
|
||||
public static EnumAction addAction(String name)
|
||||
{
|
||||
|
@ -190,7 +190,7 @@ public class EnumHelper
|
|||
setup();
|
||||
return addEnum(commonTypes, enumType, enumName, paramValues);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static <T extends Enum<? >> T addEnum(Class[][] map, Class<T> enumType, String enumName, Object... paramValues)
|
||||
{
|
||||
|
@ -219,7 +219,7 @@ public class EnumHelper
|
|||
|
||||
Field valuesField = null;
|
||||
Field[] fields = enumType.getDeclaredFields();
|
||||
|
||||
|
||||
for (Field field : fields)
|
||||
{
|
||||
String name = field.getName();
|
||||
|
@ -234,7 +234,7 @@ public class EnumHelper
|
|||
if (valuesField == null)
|
||||
{
|
||||
String valueType = String.format("[L%s;", enumType.getName().replace('.', '/'));
|
||||
|
||||
|
||||
for (Field field : fields)
|
||||
{
|
||||
if ((field.getModifiers() & flags) == flags &&
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue