Merged IGeneratorBase and IGeneratorController, since the distinction is no longer necessary

This commit is contained in:
Adubbz 2015-04-10 09:21:58 +10:00
parent 026c69b4e6
commit 9dca60f94c
13 changed files with 59 additions and 51 deletions

View file

@ -15,7 +15,7 @@ import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.BiomeManager.BiomeType;
import biomesoplenty.api.biome.generation.GenerationManager;
import biomesoplenty.api.biome.generation.GeneratorStage;
import biomesoplenty.api.biome.generation.IGeneratorController;
import biomesoplenty.api.biome.generation.IGenerator;
public class BOPBiome extends BiomeGenBase implements IExtendedBiome
{
@ -41,7 +41,7 @@ public class BOPBiome extends BiomeGenBase implements IExtendedBiome
}
@Override
public void addGenerator(String name, GeneratorStage stage, IGeneratorController generator)
public void addGenerator(String name, GeneratorStage stage, IGenerator generator)
{
this.generationManager.addGenerator(name, stage, generator);
}

View file

@ -13,12 +13,12 @@ import java.util.Map;
import net.minecraftforge.common.BiomeManager.BiomeType;
import biomesoplenty.api.biome.generation.GenerationManager;
import biomesoplenty.api.biome.generation.GeneratorStage;
import biomesoplenty.api.biome.generation.IGeneratorController;
import biomesoplenty.api.biome.generation.IGenerator;
public interface IExtendedBiome
{
public BiomeOwner getBiomeOwner();
public void addGenerator(String name, GeneratorStage stage, IGeneratorController generator);
public void addGenerator(String name, GeneratorStage stage, IGenerator generator);
public GenerationManager getGenerationManager();
public Map<BiomeType, Integer> getWeightMap();
public void clearWeights();

View file

@ -8,7 +8,7 @@
package biomesoplenty.api.biome.generation;
public abstract class CustomizableGenerator implements IGeneratorController
public abstract class CustomizableGenerator implements IGenerator
{
private final String identifier;
private String name;
@ -16,7 +16,7 @@ public abstract class CustomizableGenerator implements IGeneratorController
protected CustomizableGenerator()
{
this.identifier = GeneratorRegistry.getIdentifier((Class<? extends IGeneratorBase>)this.getClass());
this.identifier = GeneratorRegistry.getIdentifier((Class<? extends IGenerator>)this.getClass());
if (this.identifier == null)
{

View file

@ -20,9 +20,9 @@ import com.google.common.collect.Table;
public class GenerationManager
{
private Table<GeneratorStage, String, IGeneratorController> generatorTable = HashBasedTable.create();
private Table<GeneratorStage, String, IGenerator> generatorTable = HashBasedTable.create();
public void addGenerator(String name, GeneratorStage stage, IGeneratorController generator)
public void addGenerator(String name, GeneratorStage stage, IGenerator generator)
{
if (!this.generatorTable.containsColumn(name))
{
@ -37,19 +37,19 @@ public class GenerationManager
}
}
public ImmutableCollection<IGeneratorController> getGeneratorsForStage(GeneratorStage stage)
public ImmutableCollection<IGenerator> getGeneratorsForStage(GeneratorStage stage)
{
Map<String, IGeneratorController> columnMap = this.generatorTable.rowMap().get(stage);
Collection<IGeneratorController> result = columnMap == null ? null : columnMap.values();
Map<String, IGenerator> columnMap = this.generatorTable.rowMap().get(stage);
Collection<IGenerator> result = columnMap == null ? null : columnMap.values();
return result == null ? ImmutableList.<IGeneratorController>of() : ImmutableList.<IGeneratorController>copyOf(result);
return result == null ? ImmutableList.<IGenerator>of() : ImmutableList.<IGenerator>copyOf(result);
}
public Map<String, IGeneratorController> createGeneratorMap()
public Map<String, IGenerator> createGeneratorMap()
{
Map<String, IGeneratorController> result = new HashMap<String, IGeneratorController>();
Map<String, IGenerator> result = new HashMap<String, IGenerator>();
for (IGeneratorController generator : this.generatorTable.values())
for (IGenerator generator : this.generatorTable.values())
{
result.put(generator.getName(), generator);
}
@ -57,14 +57,14 @@ public class GenerationManager
return result;
}
public void createGeneratorTable(Map<String, IGeneratorController> generators)
public void createGeneratorTable(Map<String, IGenerator> generators)
{
Table<GeneratorStage, String, IGeneratorController> result = HashBasedTable.create();
Table<GeneratorStage, String, IGenerator> result = HashBasedTable.create();
for (Entry<String, IGeneratorController> entry : generators.entrySet())
for (Entry<String, IGenerator> entry : generators.entrySet())
{
String name = entry.getKey();
IGeneratorController generator = entry.getValue();
IGenerator generator = entry.getValue();
generator.setName(name);
result.put(generator.getStage(), generator.getName(), generator);

View file

@ -13,19 +13,19 @@ import com.google.common.collect.HashBiMap;
public class GeneratorRegistry
{
private static BiMap<String, Class<? extends IGeneratorBase>> generatorClasses = HashBiMap.create();
private static BiMap<String, Class<? extends IGenerator>> generatorClasses = HashBiMap.create();
public static void registerGenerator(String identifier, Class<? extends IGeneratorBase> generatorClass)
public static void registerGenerator(String identifier, Class<? extends IGenerator> generatorClass)
{
generatorClasses.put(identifier, generatorClass);
}
public static String getIdentifier(Class<? extends IGeneratorBase> generatorClass)
public static String getIdentifier(Class<? extends IGenerator> generatorClass)
{
return generatorClasses.inverse().get(generatorClass);
}
public static Class<? extends IGeneratorBase> getGeneratorClass(String identifier)
public static Class<? extends IGenerator> getGeneratorClass(String identifier)
{
return generatorClasses.get(identifier);
}

View file

@ -27,7 +27,7 @@ public class GeneratorWeighted extends CustomizableGenerator
public GeneratorWeighted() {}
public void add(int weight, IGeneratorController entry)
public void add(int weight, IGenerator entry)
{
this.weightedEntries.add(new GeneratorWeightedEntry(weight, entry));
}

View file

@ -19,22 +19,22 @@ import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
public final class GeneratorWeightedEntry extends WeightedRandom.Item implements IGeneratorController
public final class GeneratorWeightedEntry extends WeightedRandom.Item implements IGenerator
{
private final String identifier;
private GeneratorStage stage;
private IGeneratorController wrappedGenerator;
private IGenerator wrappedGenerator;
public GeneratorWeightedEntry()
{
this(-1, null);
}
public GeneratorWeightedEntry(int weight, IGeneratorController wrappedGenerator)
public GeneratorWeightedEntry(int weight, IGenerator wrappedGenerator)
{
super(weight);
this.identifier = GeneratorRegistry.getIdentifier((Class<? extends IGeneratorBase>)this.getClass());
this.identifier = GeneratorRegistry.getIdentifier((Class<? extends IGenerator>)this.getClass());
this.stage = GeneratorStage.PARENT;
this.wrappedGenerator = wrappedGenerator;

View file

@ -17,10 +17,18 @@ import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
public interface IGeneratorBase
public interface IGenerator
{
public void setStage(GeneratorStage stage);
public void scatter(World world, Random random, BlockPos pos);
public boolean generate(World world, Random random, BlockPos pos);
public void setStage(GeneratorStage stage);
public void setName(String name);
/**A unique name use to classify the purpose of a generator. For example, emeralds and ruby use the
* same generator (and thus, have the same identifier) but have differing names.
*/
public String getName();
/**The identifier for this generator should be consistent across all instances of the same type*/
public String getIdentifier();
public GeneratorStage getStage();

View file

@ -17,7 +17,7 @@ import biomesoplenty.api.biome.BiomeOwner;
import biomesoplenty.api.biome.IExtendedBiome;
import biomesoplenty.api.biome.generation.GenerationManager;
import biomesoplenty.api.biome.generation.GeneratorStage;
import biomesoplenty.api.biome.generation.IGeneratorController;
import biomesoplenty.api.biome.generation.IGenerator;
public class ExtendedBiomeRegistry
{
@ -65,7 +65,7 @@ public class ExtendedBiomeRegistry
}
@Override
public void addGenerator(String name, GeneratorStage stage, IGeneratorController generator)
public void addGenerator(String name, GeneratorStage stage, IGenerator generator)
{
this.generationManager.addGenerator(name, stage, generator);
}

View file

@ -21,8 +21,8 @@ import biomesoplenty.api.biome.BiomeOwner;
import biomesoplenty.api.biome.IExtendedBiome;
import biomesoplenty.api.biome.generation.GenerationManager;
import biomesoplenty.api.biome.generation.GeneratorStage;
import biomesoplenty.api.biome.generation.IGeneratorBase;
import biomesoplenty.api.biome.generation.IGeneratorController;
import biomesoplenty.api.biome.generation.IGenerator;
import biomesoplenty.api.biome.generation.IGenerator;
import biomesoplenty.common.biome.ExtendedBiomeRegistry;
public class DecorateBiomeEventHandler
@ -59,7 +59,7 @@ public class DecorateBiomeEventHandler
{
GenerationManager generationManager = extendedBiome.getGenerationManager();
for (IGeneratorController generator : generationManager.getGeneratorsForStage(stage))
for (IGenerator generator : generationManager.getGeneratorsForStage(stage))
{
generator.scatter(world, random, pos);
}

View file

@ -12,8 +12,8 @@ import java.util.Random;
import org.apache.commons.lang3.tuple.Pair;
import biomesoplenty.api.biome.generation.IGeneratorBase;
import biomesoplenty.api.biome.generation.IGeneratorController;
import biomesoplenty.api.biome.generation.IGenerator;
import biomesoplenty.api.biome.generation.IGenerator;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
@ -73,12 +73,12 @@ public class GeneratorUtils
return state;
}
public static IGeneratorController deserializeGenerator(JsonObject json, String memberName, JsonDeserializationContext context)
public static IGenerator deserializeGenerator(JsonObject json, String memberName, JsonDeserializationContext context)
{
return deserializeGeneratorOfType(json, memberName, context, IGeneratorController.class);
return deserializeGeneratorOfType(json, memberName, context, IGenerator.class);
}
public static <T extends IGeneratorBase> T deserializeGeneratorOfType(JsonObject json, String memberName, JsonDeserializationContext context, Class<T> type)
public static <T extends IGenerator> T deserializeGeneratorOfType(JsonObject json, String memberName, JsonDeserializationContext context, Class<T> type)
{
T generator = context.deserialize(json.get(memberName), type);

View file

@ -12,7 +12,7 @@ import java.lang.reflect.Type;
import biomesoplenty.api.biome.generation.GeneratorRegistry;
import biomesoplenty.api.biome.generation.GeneratorStage;
import biomesoplenty.api.biome.generation.IGeneratorBase;
import biomesoplenty.api.biome.generation.IGenerator;
import com.google.common.reflect.TypeToken;
import com.google.gson.JsonDeserializationContext;
@ -24,10 +24,10 @@ import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.JsonSyntaxException;
public class GeneratorTypeAdaptor implements JsonSerializer<IGeneratorBase>, JsonDeserializer<IGeneratorBase>
public class GeneratorTypeAdaptor implements JsonSerializer<IGenerator>, JsonDeserializer<IGenerator>
{
@Override
public JsonElement serialize(IGeneratorBase src, Type typeOfSrc, JsonSerializationContext context)
public JsonElement serialize(IGenerator src, Type typeOfSrc, JsonSerializationContext context)
{
JsonObject jsonObject = new JsonObject();
src.writeToJson(jsonObject, context);
@ -39,14 +39,14 @@ public class GeneratorTypeAdaptor implements JsonSerializer<IGeneratorBase>, Jso
}
@Override
public IGeneratorBase deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
public IGenerator deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{
JsonObject jsonObject = json.getAsJsonObject();
if (jsonObject.has("generator"))
{
String generatorIdentifier = jsonObject.get("generator").getAsString();
Class<? extends IGeneratorBase> generatorClass = GeneratorRegistry.getGeneratorClass(generatorIdentifier);
Class<? extends IGenerator> generatorClass = GeneratorRegistry.getGeneratorClass(generatorIdentifier);
if (generatorClass == null)
{
@ -54,10 +54,10 @@ public class GeneratorTypeAdaptor implements JsonSerializer<IGeneratorBase>, Jso
}
else
{
IGeneratorBase generator;
IGenerator generator;
try
{
generator = (IGeneratorBase)generatorClass.newInstance();
generator = (IGenerator)generatorClass.newInstance();
Type generatorStageType = new TypeToken<GeneratorStage>() {}.getType();
GeneratorStage generatorStage = (GeneratorStage)context.deserialize(jsonObject.get("stage"), generatorStageType);

View file

@ -19,8 +19,8 @@ import net.minecraftforge.common.BiomeManager.BiomeType;
import biomesoplenty.api.biome.BiomeOwner;
import biomesoplenty.api.biome.IExtendedBiome;
import biomesoplenty.api.biome.generation.GenerationManager;
import biomesoplenty.api.biome.generation.IGeneratorBase;
import biomesoplenty.api.biome.generation.IGeneratorController;
import biomesoplenty.api.biome.generation.IGenerator;
import biomesoplenty.api.biome.generation.IGenerator;
import biomesoplenty.common.biome.BOPBiomeManager;
import biomesoplenty.common.biome.ExtendedBiomeRegistry;
@ -32,7 +32,7 @@ import com.google.gson.GsonBuilder;
public class JsonBiome
{
public static final Gson serializer = new GsonBuilder().setPrettyPrinting().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).registerTypeHierarchyAdapter(IBlockState.class, new JsonBlockState()).registerTypeHierarchyAdapter(IGeneratorBase.class, new GeneratorTypeAdaptor()).create();
public static final Gson serializer = new GsonBuilder().setPrettyPrinting().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).registerTypeHierarchyAdapter(IBlockState.class, new JsonBlockState()).registerTypeHierarchyAdapter(IGenerator.class, new GeneratorTypeAdaptor()).create();
public String biomeName;
public int biomeId;
@ -46,7 +46,7 @@ public class JsonBiome
public int color;
public int waterColorMultiplier;
public ArrayList<JsonEntitySpawn> entities;
public Map<String, IGeneratorController> decoration;
public Map<String, IGenerator> decoration;
public static JsonBiome createFromBiomeGenBase(BiomeGenBase baseBiome)
{