Search in sources :

Example 1 with SpawnListEntry

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

the class EntityRegistry method addSpawn.

/**
     * Add a spawn entry for the supplied entity in the supplied {@link Biome} list
     * @param entityClass Entity class added
     * @param weightedProb Probability
     * @param min Min spawn count
     * @param max Max spawn count
     * @param typeOfCreature Type of spawn
     * @param biomes List of biomes
     */
public static void addSpawn(Class<? extends EntityLiving> entityClass, int weightedProb, int min, int max, EnumCreatureType typeOfCreature, Biome... biomes) {
    for (Biome biome : biomes) {
        List<SpawnListEntry> spawns = biome.getSpawnableList(typeOfCreature);
        boolean found = false;
        for (SpawnListEntry entry : spawns) {
            //Adjusting an existing spawn entry
            if (entry.entityClass == entityClass) {
                entry.itemWeight = weightedProb;
                entry.minGroupCount = min;
                entry.maxGroupCount = max;
                found = true;
                break;
            }
        }
        if (!found)
            spawns.add(new SpawnListEntry(entityClass, weightedProb, min, max));
    }
}
Also used : Biome(net.minecraft.world.biome.Biome) SpawnListEntry(net.minecraft.world.biome.Biome.SpawnListEntry)

Example 2 with SpawnListEntry

use of net.minecraft.world.biome.Biome.SpawnListEntry in project Minestuck by mraof.

the class SburbHandler method getUnderlingList.

public static List<SpawnListEntry> getUnderlingList(BlockPos pos, World world) {
    BlockPos spawn = world.getSpawnPoint();
    int difficulty = (int) Math.round(Math.sqrt(new Vec3i(pos.getX() >> 4, 0, pos.getZ() >> 4).distanceSq(new Vec3i(spawn.getX() >> 4, 0, spawn.getZ() >> 4))));
    difficulty = Math.min(30, difficulty / 3);
    if (difficultyList[difficulty] != null)
        return difficultyList[difficulty];
    ArrayList<SpawnListEntry> list = new ArrayList<SpawnListEntry>();
    int impWeight, ogreWeight = 0, basiliskWeight = 0, lichWeight = 0, giclopsWeight = 0;
    if (difficulty < 8)
        impWeight = difficulty + 1;
    else {
        impWeight = 8 - (difficulty - 8) / 3;
        if (difficulty < 20)
            ogreWeight = (difficulty - 5) / 3;
        else
            ogreWeight = 5 - (difficulty - 20) / 3;
        if (difficulty >= 16) {
            if (difficulty < 26)
                basiliskWeight = (difficulty - 14) / 2;
            else
                basiliskWeight = 6;
            if (difficulty < 28)
                lichWeight = (difficulty - 12) / 3;
            else
                lichWeight = 6;
            if (difficulty >= 20)
                if (difficulty < 30)
                    giclopsWeight = (difficulty - 17) / 3;
                else
                    giclopsWeight = 5;
        }
    }
    if (impWeight > 0)
        list.add(new SpawnListEntry(EntityImp.class, impWeight, Math.max(1, (int) (impWeight / 2.5)), Math.max(3, impWeight)));
    if (ogreWeight > 0)
        list.add(new SpawnListEntry(EntityOgre.class, ogreWeight, ogreWeight >= 5 ? 2 : 1, Math.max(1, ogreWeight / 2)));
    if (basiliskWeight > 0)
        list.add(new SpawnListEntry(EntityBasilisk.class, basiliskWeight, 1, Math.max(1, basiliskWeight / 2)));
    if (lichWeight > 0)
        list.add(new SpawnListEntry(EntityLich.class, lichWeight, 1, Math.max(1, lichWeight / 2)));
    if (giclopsWeight > 0 && !MinestuckConfig.disableGiclops)
        list.add(new SpawnListEntry(EntityGiclops.class, giclopsWeight, 1, Math.max(1, giclopsWeight / 2)));
    difficultyList[difficulty] = list;
    return list;
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) BlockPos(net.minecraft.util.math.BlockPos) SpawnListEntry(net.minecraft.world.biome.Biome.SpawnListEntry)

Example 3 with SpawnListEntry

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

Example 4 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)

Example 5 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)

Aggregations

SpawnListEntry (net.minecraft.world.biome.Biome.SpawnListEntry)6 Biome (net.minecraft.world.biome.Biome)3 BiomeTweakEvent (me.superckl.api.biometweaker.event.BiomeTweakEvent)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 IBlockState (net.minecraft.block.state.IBlockState)1 EntityLiving (net.minecraft.entity.EntityLiving)1 EnumCreatureType (net.minecraft.entity.EnumCreatureType)1 Vec3i (net.minecraft.util.math.Vec3i)1 TextComponentString (net.minecraft.util.text.TextComponentString)1