Search in sources :

Example 1 with Property

use of me.superckl.api.biometweaker.property.Property in project BiomeTweaker by superckl.

the class ReplacementPropertyManager method populatePropertyMap.

public static void populatePropertyMap() {
    final Field[] fields = ReplacementPropertyManager.class.getDeclaredFields();
    for (final Field field : fields) try {
        if (!Property.class.isAssignableFrom(field.getType()) || field.get(null) == null)
            continue;
        ReplacementPropertyManager.propertyMap.put(field.getName().toLowerCase().replace("_", ""), (Property<?>) field.get(null));
    } catch (final Exception e) {
        LogHelper.error("Unable to add property to propertyMap!");
        e.printStackTrace();
    }
}
Also used : Field(java.lang.reflect.Field) Property(me.superckl.api.biometweaker.property.Property)

Example 2 with Property

use of me.superckl.api.biometweaker.property.Property 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)

Example 3 with Property

use of me.superckl.api.biometweaker.property.Property in project BiomeTweaker by superckl.

the class WorldGenPropertyManager method populatePropertyMap.

public static void populatePropertyMap() {
    final Class<?>[] classes = WorldGenPropertyManager.class.getClasses();
    final List<Field> fields = new ArrayList<>();
    Collections.addAll(fields, WorldGenPropertyManager.class.getDeclaredFields());
    for (final Class<?> clazz : classes) Collections.addAll(fields, clazz.getDeclaredFields());
    for (final Field field : fields) try {
        if (!Property.class.isAssignableFrom(field.getType()) || field.get(null) == null)
            continue;
        final Property<?> prop = WarningHelper.uncheckedCast(field.get(null));
        if (!WorldGenPropertyManager.propertyMap.containsKey(prop.getTargetClass()))
            WorldGenPropertyManager.propertyMap.put(prop.getTargetClass(), new HashMap<>());
        WorldGenPropertyManager.propertyMap.get(prop.getTargetClass()).put(field.getName().toLowerCase().replace("_", ""), prop);
    } catch (final Exception e) {
        LogHelper.error("Unable to add property to propertyMap!");
        e.printStackTrace();
    }
}
Also used : Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) Property(me.superckl.api.biometweaker.property.Property)

Aggregations

Property (me.superckl.api.biometweaker.property.Property)3 Field (java.lang.reflect.Field)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BiomeTweakEvent (me.superckl.api.biometweaker.event.BiomeTweakEvent)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