Search in sources :

Example 1 with BiomeTweakerBiome

use of me.superckl.biometweaker.common.world.biome.BiomeTweakerBiome in project BiomeTweaker by superckl.

the class ScriptCommandCreateBiome method perform.

@Override
public void perform() throws Exception {
    if (RegistryEventHandler.registry == null)
        throw new IllegalStateException("No biome registry avilable! Make sure you're using the biome registry script stage!");
    if (this.toCopy == null) {
        final BiomeTweakerBiome biome = new BiomeTweakerBiome(new BiomeProperties("BiomeTweaker Biome").setBaseHeight(0.125F).setHeightVariation(0.05F).setTemperature(0.8F).setRainfall(0.4F));
        if (!MinecraftForge.EVENT_BUS.post(new BiomeTweakEvent.Create(this, biome))) {
            biome.setRegistryName(ModData.MOD_ID, this.rLoc.toLowerCase());
            RegistryEventHandler.registry.register(biome);
            BiomeTweaker.getInstance().onTweak(Biome.getIdForBiome(biome));
        }
    } else {
        final Iterator<Biome> it = this.toCopy.getIterator();
        if (!it.hasNext())
            throw new IllegalStateException("No biome found to copy!");
        final Biome toCopy = it.next();
        if (it.hasNext())
            LogHelper.warn("More than one biome found to copy! Only the first one will be copied.");
        Constructor<? extends Biome> construct = null;
        try {
            // catches all vanilla biomes
            if (ScriptCommandCreateBiome.extraParameters.containsKey(toCopy.getBiomeClass())) {
                final List<? extends Property<?>> props = ScriptCommandCreateBiome.extraParameters.get(toCopy.getBiomeClass());
                final Class<?>[] types = new Class<?>[props.size() + 1];
                for (int i = 0; i < props.size(); i++) types[i] = Primitives.unwrap(props.get(i).getTypeClass());
                types[types.length - 1] = BiomeProperties.class;
                construct = toCopy.getBiomeClass().getConstructor(types);
            } else
                construct = toCopy.getBiomeClass().getConstructor(BiomeProperties.class);
        } catch (final Exception e) {
            try {
                // Catches most BOP biomes
                construct = toCopy.getBiomeClass().getConstructor();
            } catch (final Exception e1) {
            }
        }
        Biome biome;
        if (construct == null) {
            LogHelper.warn("Unable to copy biome class " + toCopy.getBiomeClass().getCanonicalName() + "! Some functionality may not be copied!");
            biome = new BiomeTweakerBiome(new BiomeProperties("BiomeTweaker Biome").setBaseHeight(0.125F).setHeightVariation(0.05F).setTemperature(0.8F).setRainfall(0.4F));
        } else
            switch(construct.getParameterCount()) {
                case 0:
                    biome = construct.newInstance();
                    break;
                case 1:
                    biome = construct.newInstance(new BiomeProperties(toCopy.getBiomeName()));
                    break;
                default:
                    final List<? extends Property<?>> props = ScriptCommandCreateBiome.extraParameters.get(toCopy.getBiomeClass());
                    final Object[] objs = new Object[props.size() + 1];
                    for (int i = 0; i < props.size(); i++) objs[i] = props.get(i).get(toCopy);
                    objs[objs.length - 1] = new BiomeProperties(toCopy.getBiomeName());
                    biome = construct.newInstance(objs);
                    break;
            }
        if (MinecraftForge.EVENT_BUS.post(new BiomeTweakEvent.Create(this, biome)))
            return;
        biome.setRegistryName(ModData.MOD_ID, this.rLoc.toLowerCase());
        RegistryEventHandler.registry.register(biome);
        // Copy props
        for (final Property<?> prop : BiomePropertyManager.getAllProperties()) if (prop.isCopyable())
            prop.copy(toCopy, biome);
        // Copy dict types
        if (BiomeDictionary.hasAnyType(toCopy))
            BiomeDictionary.addTypes(biome, BiomeDictionary.getTypes(toCopy).toArray(new BiomeDictionary.Type[0]));
        // Copy spawns
        for (final EnumCreatureType type : EnumCreatureType.values()) {
            final List<SpawnListEntry> entries = biome.getSpawnableList(type);
            entries.clear();
            entries.addAll(toCopy.getSpawnableList(type));
        }
        BiomeTweaker.getInstance().onTweak(Biome.getIdForBiome(biome));
    }
}
Also used : BiomeTweakEvent(me.superckl.api.biometweaker.event.BiomeTweakEvent) EnumCreatureType(net.minecraft.entity.EnumCreatureType) BiomeProperties(net.minecraft.world.biome.Biome.BiomeProperties) SpawnListEntry(net.minecraft.world.biome.Biome.SpawnListEntry) BiomeTweakerBiome(me.superckl.biometweaker.common.world.biome.BiomeTweakerBiome) Biome(net.minecraft.world.biome.Biome) BiomeTweakerBiome(me.superckl.biometweaker.common.world.biome.BiomeTweakerBiome) BiomeDictionary(net.minecraftforge.common.BiomeDictionary) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Property(me.superckl.api.biometweaker.property.Property)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1 BiomeTweakEvent (me.superckl.api.biometweaker.event.BiomeTweakEvent)1 Property (me.superckl.api.biometweaker.property.Property)1 BiomeTweakerBiome (me.superckl.biometweaker.common.world.biome.BiomeTweakerBiome)1 EnumCreatureType (net.minecraft.entity.EnumCreatureType)1 Biome (net.minecraft.world.biome.Biome)1 BiomeProperties (net.minecraft.world.biome.Biome.BiomeProperties)1 SpawnListEntry (net.minecraft.world.biome.Biome.SpawnListEntry)1 BiomeDictionary (net.minecraftforge.common.BiomeDictionary)1