Search in sources :

Example 1 with BiomeManager

use of net.minecraftforge.common.BiomeManager in project BiomeTweaker by superckl.

the class BiomeHelper method fillJsonObject.

public static JsonObject fillJsonObject(final Biome biome, final int... coords) {
    BiomeHelper.checkFields();
    final JsonObject obj = new JsonObject();
    obj.addProperty("ID", Biome.getIdForBiome(biome));
    obj.addProperty("Name", biome.biomeName);
    obj.addProperty("Resource Location", Biome.REGISTRY.getNameForObject(biome).toString());
    obj.addProperty("Class", biome.getClass().getName());
    obj.addProperty("Root Height", biome.getBaseHeight());
    obj.addProperty("Height Variation", biome.getHeightVariation());
    final boolean topNull = biome.topBlock == null || biome.topBlock.getBlock() == null || biome.topBlock.getBlock().delegate == null;
    final boolean bottomNull = biome.topBlock == null || biome.topBlock.getBlock() == null || biome.topBlock.getBlock().delegate == null;
    obj.addProperty("Top Block", topNull ? "ERROR" : biome.topBlock.toString());
    obj.addProperty("Filler Block", bottomNull ? "ERROR" : biome.fillerBlock.toString());
    if (!BiomeTweaker.getInstance().isTweakEnabled("oceanTopBlock"))
        obj.addProperty("Ocean Top Block", "Disabled. Activate in BiomeTweakerCore.");
    else {
        final String topBlock = BiomePropertyManager.OCEAN_TOP_BLOCK.get(biome).toString();
        obj.addProperty("Ocean Top Block", topBlock);
    }
    if (!BiomeTweaker.getInstance().isTweakEnabled("oceanFillerBlock"))
        obj.addProperty("Ocean Filler Block", "Disabled. Activate in BiomeTweakerCore.");
    else {
        final String topBlock = BiomePropertyManager.OCEAN_FILLER_BLOCK.get(biome).toString();
        obj.addProperty("Ocean Filler Block", topBlock);
    }
    if (!BiomeTweaker.getInstance().isTweakEnabled("actualFillerBlocks"))
        obj.addProperty("Actual Filler Blocks", "Disabled. Activate in BiomeTweakerCore.");
    else {
        final JsonArray array = new JsonArray();
        final IBlockState[] states = BiomePropertyManager.ACTUAL_FILLER_BLOCKS.get(biome);
        for (final IBlockState state : states) array.add(new JsonPrimitive(state.toString()));
        obj.add("Actual Filler Blocks", array);
    }
    try {
        int i = -1;
        final boolean hasCoords = (coords != null) && (coords.length == 3);
        int x = 0, y = 0, z = 0;
        if (hasCoords) {
            x = coords[0];
            y = coords[1];
            z = coords[2];
        }
        if (!BiomeTweaker.getInstance().isTweakEnabled("grassColor"))
            obj.addProperty("Grass Color", "Disabled. Activate in BiomeTweakerCore.");
        else
            obj.addProperty("Grass Color", "" + ((hasCoords && FMLCommonHandler.instance().getSide().isClient()) ? biome.getGrassColorAtPos(new BlockPos(x, y, z)) : (i = BiomePropertyManager.GRASS_COLOR.get(biome)) == -1 ? "Not set. Check in-game." : i));
        if (!BiomeTweaker.getInstance().isTweakEnabled("foliageColor"))
            obj.addProperty("Foliage Color", "Disabled. Activate in BiomeTweakerCore.");
        else
            obj.addProperty("Foliage Color", "" + ((hasCoords && FMLCommonHandler.instance().getSide().isClient()) ? biome.getFoliageColorAtPos(new BlockPos(x, y, z)) : (i = BiomePropertyManager.FOLIAGE_COLOR.get(biome)) == -1 ? "Not set. Check in-game." : i));
        obj.addProperty("Water Color", "" + biome.getWaterColorMultiplier());
    } catch (final Exception e) {
        LogHelper.error("Failed to retrieve inserted fields!");
        e.printStackTrace();
    }
    obj.addProperty("Temperature", biome.getDefaultTemperature());
    obj.addProperty("Humidity", biome.getRainfall());
    obj.addProperty("Water Tint", biome.getWaterColorMultiplier());
    obj.addProperty("Enable Rain", biome.enableRain);
    obj.addProperty("Enable Snow", biome.getEnableSnow());
    JsonArray array = new JsonArray();
    if (BiomeDictionary.hasAnyType(biome))
        for (final Type type : BiomeDictionary.getTypes(biome)) array.add(new JsonPrimitive(type.toString()));
    obj.add("Dictionary Types", array);
    final JsonObject managerWeights = new JsonObject();
    for (final BiomeManager.BiomeType type : BiomeManager.BiomeType.values()) {
        final JsonArray subArray = new JsonArray();
        final List<BiomeEntry> entries = BiomeManager.getBiomes(type);
        for (final BiomeEntry entry : entries) if (Biome.getIdForBiome(entry.biome) == Biome.getIdForBiome(biome))
            subArray.add(new JsonPrimitive(entry.itemWeight));
        if (subArray.size() > 0)
            managerWeights.add(type.name() + " Weights", subArray);
    }
    obj.add("BiomeManager Entries", managerWeights);
    array = new JsonArray();
    for (final Object entity : biome.spawnableCreatureList) {
        final SpawnListEntry entry = (SpawnListEntry) entity;
        final JsonObject object = new JsonObject();
        object.addProperty("Entity Class", entry.entityClass.getName());
        object.addProperty("Weight", entry.itemWeight);
        object.addProperty("Min Group Count", entry.minGroupCount);
        object.addProperty("Max Group Count", entry.maxGroupCount);
        array.add(object);
    }
    obj.add("Spawnable Creatures", array);
    array = new JsonArray();
    for (final Object entity : biome.spawnableMonsterList) {
        final SpawnListEntry entry = (SpawnListEntry) entity;
        final JsonObject object = new JsonObject();
        object.addProperty("Entity Class", entry.entityClass.getName());
        object.addProperty("Weight", entry.itemWeight);
        object.addProperty("Min Group Count", entry.minGroupCount);
        object.addProperty("Max Group Count", entry.maxGroupCount);
        array.add(object);
    }
    obj.add("Spawnable Monsters", array);
    array = new JsonArray();
    for (final Object entity : biome.spawnableWaterCreatureList) {
        final SpawnListEntry entry = (SpawnListEntry) entity;
        final JsonObject object = new JsonObject();
        object.addProperty("Entity Class", entry.entityClass.getName());
        object.addProperty("Weight", entry.itemWeight);
        object.addProperty("Min Group Count", entry.minGroupCount);
        object.addProperty("Max Group Count", entry.maxGroupCount);
        array.add(object);
    }
    obj.add("Spawnable Water Creatures", array);
    array = new JsonArray();
    for (final Object entity : biome.spawnableCaveCreatureList) {
        final SpawnListEntry entry = (SpawnListEntry) entity;
        final JsonObject object = new JsonObject();
        object.addProperty("Entity Class", entry.entityClass.getName());
        object.addProperty("Weight", entry.itemWeight);
        object.addProperty("Min Group Count", entry.minGroupCount);
        object.addProperty("Max Group Count", entry.maxGroupCount);
        array.add(object);
    }
    obj.add("Spawnable Cave Creatures", array);
    obj.add("Spawn Biome", new JsonPrimitive(BiomeProvider.allowedBiomes.contains(biome)));
    obj.addProperty("Tweaked", BiomeTweaker.getInstance().getTweakedBiomes().contains(-1) || BiomeTweaker.getInstance().getTweakedBiomes().contains(Biome.getIdForBiome(biome)));
    IntegrationManager.INSTANCE.addBiomeInfo(biome, obj);
    return obj;
}
Also used : BiomeManager(net.minecraftforge.common.BiomeManager) IBlockState(net.minecraft.block.state.IBlockState) JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject) SpawnListEntry(net.minecraft.world.biome.Biome.SpawnListEntry) JsonArray(com.google.gson.JsonArray) BiomeEntry(net.minecraftforge.common.BiomeManager.BiomeEntry) Type(net.minecraftforge.common.BiomeDictionary.Type) BlockPos(net.minecraft.util.math.BlockPos) JsonObject(com.google.gson.JsonObject)

Aggregations

JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 IBlockState (net.minecraft.block.state.IBlockState)1 BlockPos (net.minecraft.util.math.BlockPos)1 SpawnListEntry (net.minecraft.world.biome.Biome.SpawnListEntry)1 Type (net.minecraftforge.common.BiomeDictionary.Type)1 BiomeManager (net.minecraftforge.common.BiomeManager)1 BiomeEntry (net.minecraftforge.common.BiomeManager.BiomeEntry)1