Search in sources :

Example 1 with WeightedBiomeEntry

use of biomesoplenty.api.enums.BOPClimates.WeightedBiomeEntry in project BiomeTweaker by superckl.

the class BOPIntegrationModule method addBiomeInfo.

@Override
public void addBiomeInfo(Biome biome, final JsonObject obj) {
    final IExtendedBiome eBiome = BOPIntegrationModule.getExtendedBiome(biome);
    biome = eBiome.getBaseBiome();
    final IGenerationManager gManager = eBiome.getGenerationManager();
    final JsonObject genNames = new JsonObject();
    for (final GeneratorStage stage : GeneratorStage.values()) {
        final Collection<IGenerator> gens = gManager.getGeneratorsForStage(stage);
        if (gens.isEmpty())
            continue;
        final JsonArray subArray = new JsonArray();
        final Iterator<IGenerator> it = gens.iterator();
        while (it.hasNext()) {
            final JsonObject subSubObj = new JsonObject();
            final IGenerator gen = it.next();
            subSubObj.addProperty("ID", gen.getIdentifier());
            subSubObj.addProperty("Name", gen.getName());
            subArray.add(subSubObj);
        }
        genNames.add(stage.name() + " Generators", subArray);
    }
    obj.add("BOP Generators", genNames);
    obj.addProperty("BOP Owner", eBiome.getBiomeOwner().name());
    final Gson gson = new Gson();
    obj.add("BOP Weight Map", gson.toJsonTree(eBiome.getWeightMap()));
    try {
        final JsonObject weights = new JsonObject();
        for (final BOPClimates climate : BOPClimates.values()) {
            final List<WeightedBiomeEntry> entries = WarningHelper.uncheckedCast(BOPBiomeProperties.LAND_BIOMES.get(climate));
            final JsonArray subArray = new JsonArray();
            for (final WeightedBiomeEntry entry : entries) if (Biome.getIdForBiome(entry.biome) == Biome.getIdForBiome(biome))
                subArray.add(new JsonPrimitive(entry.weight));
            if (subArray.size() > 0)
                weights.add(climate.name(), subArray);
        }
        obj.add("BOP Climate Weights", weights);
        if (ModBiomes.islandBiomesMap.containsKey(Biome.getIdForBiome(biome)))
            obj.add("BOP Island Weight", new JsonPrimitive(ModBiomes.islandBiomesMap.get(Biome.getIdForBiome(biome))));
        else
            obj.add("BOP Island Weight", new JsonPrimitive(0));
    } catch (final Exception e) {
        LogHelper.error("Failed to retrieve all BOP biome info!");
        e.printStackTrace();
    }
}
Also used : IExtendedBiome(biomesoplenty.api.biome.IExtendedBiome) JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) IGenerationManager(biomesoplenty.api.generation.IGenerationManager) JsonArray(com.google.gson.JsonArray) WeightedBiomeEntry(biomesoplenty.api.enums.BOPClimates.WeightedBiomeEntry) IGenerator(biomesoplenty.api.generation.IGenerator) GeneratorStage(biomesoplenty.api.generation.GeneratorStage) BOPClimates(biomesoplenty.api.enums.BOPClimates)

Example 2 with WeightedBiomeEntry

use of biomesoplenty.api.enums.BOPClimates.WeightedBiomeEntry in project BiomeTweaker by superckl.

the class ScriptCommandRemoveBOP method perform.

@Override
public void perform() throws Exception {
    final Iterator<Biome> it = this.pack.getIterator();
    while (it.hasNext()) {
        Biome biome = it.next();
        final IExtendedBiome eBiome = BOPIntegrationModule.getExtendedBiome(biome);
        biome = eBiome.getBaseBiome();
        if (this.types == null)
            for (final BOPClimates climate : BOPClimates.values()) {
                final Iterator<WeightedBiomeEntry> bit = WarningHelper.<List<WeightedBiomeEntry>>uncheckedCast(BOPBiomeProperties.LAND_BIOMES.get(climate)).iterator();
                while (bit.hasNext()) {
                    final WeightedBiomeEntry entry = bit.next();
                    if (Biome.getIdForBiome(entry.biome) == Biome.getIdForBiome(biome)) {
                        bit.remove();
                        BOPBiomeProperties.TOTAL_BIOMES_WEIGHT.set(climate, BOPBiomeProperties.TOTAL_BIOMES_WEIGHT.get(climate) - entry.weight);
                    }
                }
            }
        else
            for (final String type : this.types) {
                final BOPClimates climate = BOPClimates.valueOf(type);
                if (climate == null)
                    throw new IllegalArgumentException("No climate type found for: " + type);
                final Iterator<WeightedBiomeEntry> bit = WarningHelper.<List<WeightedBiomeEntry>>uncheckedCast(BOPBiomeProperties.LAND_BIOMES.get(climate)).iterator();
                while (bit.hasNext()) {
                    final WeightedBiomeEntry entry = bit.next();
                    if (Biome.getIdForBiome(entry.biome) == Biome.getIdForBiome(biome)) {
                        bit.remove();
                        BOPBiomeProperties.TOTAL_BIOMES_WEIGHT.set(climate, BOPBiomeProperties.TOTAL_BIOMES_WEIGHT.get(climate) - entry.weight);
                    }
                }
            }
        BiomeTweaker.getInstance().onTweak(Biome.getIdForBiome(biome));
    }
}
Also used : IExtendedBiome(biomesoplenty.api.biome.IExtendedBiome) Biome(net.minecraft.world.biome.Biome) IExtendedBiome(biomesoplenty.api.biome.IExtendedBiome) WeightedBiomeEntry(biomesoplenty.api.enums.BOPClimates.WeightedBiomeEntry) Iterator(java.util.Iterator) List(java.util.List) BOPClimates(biomesoplenty.api.enums.BOPClimates)

Aggregations

IExtendedBiome (biomesoplenty.api.biome.IExtendedBiome)2 BOPClimates (biomesoplenty.api.enums.BOPClimates)2 WeightedBiomeEntry (biomesoplenty.api.enums.BOPClimates.WeightedBiomeEntry)2 GeneratorStage (biomesoplenty.api.generation.GeneratorStage)1 IGenerationManager (biomesoplenty.api.generation.IGenerationManager)1 IGenerator (biomesoplenty.api.generation.IGenerator)1 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Biome (net.minecraft.world.biome.Biome)1