Search in sources :

Example 6 with SpawnListEntry

use of net.minecraft.world.biome.Biome.SpawnListEntry 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 7 with SpawnListEntry

use of net.minecraft.world.biome.Biome.SpawnListEntry in project BiomeTweaker by superckl.

the class ScriptCommandAddRemoveSpawn method perform.

@Override
public void perform() throws Exception {
    final Class<? extends Entity> clazz2 = EntityHelper.getEntityClass(this.entityClass);
    if (clazz2 == null)
        throw new IllegalArgumentException("Failed to find entity class: " + this.entityClass);
    if (!EntityLiving.class.isAssignableFrom(clazz2))
        throw new IllegalArgumentException("entity class " + this.entityClass + " is not assignable to EntityLiving. It cannot be spawned!");
    final Class<? extends EntityLiving> clazz = WarningHelper.uncheckedCast(clazz2);
    final SpawnListEntry entry = new SpawnListEntry(clazz, this.weight, this.minCount, this.maxCount);
    final Iterator<Biome> it = this.pack.getIterator();
    while (it.hasNext()) {
        final Biome biome = it.next();
        if (this.remove && MinecraftForge.EVENT_BUS.post(new BiomeTweakEvent.RemoveSpawn(this, biome, this.type, clazz)))
            continue;
        else if (!this.remove && MinecraftForge.EVENT_BUS.post(new BiomeTweakEvent.AddSpawn(this, biome, entry)))
            continue;
        if (this.remove)
            this.removeEntry(clazz, biome.getSpawnableList(this.type));
        else
            biome.getSpawnableList(this.type).add(new Biome.SpawnListEntry(clazz, this.weight, this.minCount, this.maxCount));
        BiomeTweaker.getInstance().onTweak(Biome.getIdForBiome(biome));
    }
}
Also used : BiomeTweakEvent(me.superckl.api.biometweaker.event.BiomeTweakEvent) Biome(net.minecraft.world.biome.Biome) EntityLiving(net.minecraft.entity.EntityLiving) SpawnListEntry(net.minecraft.world.biome.Biome.SpawnListEntry) ParameterOverride(me.superckl.api.biometweaker.script.AutoRegister.ParameterOverride)

Example 8 with SpawnListEntry

use of net.minecraft.world.biome.Biome.SpawnListEntry in project malmo by Microsoft.

the class ServerStateMachine method onGetPotentialSpawns.

/**
 * Called by Forge - call setCanceled(true) to prevent spawning in our world.
 */
@SubscribeEvent
public void onGetPotentialSpawns(PotentialSpawns ps) {
    // Decide whether or not to allow spawning.
    // We shouldn't allow spawning unless it has been specifically turned on - whether
    // a mission is running or not. (Otherwise spawning may happen in between missions.)
    boolean allowSpawning = false;
    if (currentMissionInit() != null && currentMissionInit().getMission() != null) {
        // There is a mission running - does it allow spawning?
        ServerSection ss = currentMissionInit().getMission().getServerSection();
        ServerInitialConditions sic = (ss != null) ? ss.getServerInitialConditions() : null;
        if (sic != null)
            allowSpawning = (sic.isAllowSpawning() == Boolean.TRUE);
        if (allowSpawning && sic.getAllowedMobs() != null && !sic.getAllowedMobs().isEmpty()) {
            // Spawning is allowed, but restricted to our list:
            Iterator<SpawnListEntry> it = ps.getList().iterator();
            while (it.hasNext()) {
                // Is this on our list?
                SpawnListEntry sle = it.next();
                net.minecraftforge.fml.common.registry.EntityEntry entry = net.minecraftforge.fml.common.registry.EntityRegistry.getEntry(sle.entityClass);
                String mobName = entry == null ? null : entry.getName();
                boolean allowed = false;
                for (EntityTypes mob : sic.getAllowedMobs()) {
                    if (mob.value().equals(mobName))
                        allowed = true;
                }
                if (!allowed)
                    it.remove();
            }
        }
    }
    // Cancel spawn event:
    if (!allowSpawning)
        ps.setCanceled(true);
}
Also used : EntityTypes(com.microsoft.Malmo.Schemas.EntityTypes) ServerSection(com.microsoft.Malmo.Schemas.ServerSection) SpawnListEntry(net.minecraft.world.biome.Biome.SpawnListEntry) TextComponentString(net.minecraft.util.text.TextComponentString) ServerInitialConditions(com.microsoft.Malmo.Schemas.ServerInitialConditions) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

SpawnListEntry (net.minecraft.world.biome.Biome.SpawnListEntry)8 Biome (net.minecraft.world.biome.Biome)3 BiomeTweakEvent (me.superckl.api.biometweaker.event.BiomeTweakEvent)2 AtmosphereInfo (micdoodle8.mods.galacticraft.api.world.AtmosphereInfo)2 ItemStack (net.minecraft.item.ItemStack)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 BlockPos (net.minecraft.util.math.BlockPos)2 ImmutableList (com.google.common.collect.ImmutableList)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 EntityTypes (com.microsoft.Malmo.Schemas.EntityTypes)1 ServerInitialConditions (com.microsoft.Malmo.Schemas.ServerInitialConditions)1 ServerSection (com.microsoft.Malmo.Schemas.ServerSection)1 List (java.util.List)1 Property (me.superckl.api.biometweaker.property.Property)1 ParameterOverride (me.superckl.api.biometweaker.script.AutoRegister.ParameterOverride)1 BiomeTweakerBiome (me.superckl.biometweaker.common.world.biome.BiomeTweakerBiome)1 ConnectionEvents (micdoodle8.mods.galacticraft.core.network.ConnectionEvents)1 SchematicAdd (micdoodle8.mods.galacticraft.core.schematic.SchematicAdd)1