Search in sources :

Example 1 with IWorldGenerator

use of net.minecraftforge.fml.common.IWorldGenerator in project MinecraftForge by MinecraftForge.

the class GameRegistry method generateWorld.

/**
     * Callback hook for world gen - if your mod wishes to add extra mod related generation to the world
     * call this
     *
     * @param chunkX         Chunk X coordinate
     * @param chunkZ         Chunk Z coordinate
     * @param world          World we're generating into
     * @param chunkGenerator The chunk generator
     * @param chunkProvider  The chunk provider
     */
public static void generateWorld(int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
    if (sortedGeneratorList == null) {
        computeSortedGeneratorList();
    }
    long worldSeed = world.getSeed();
    Random fmlRandom = new Random(worldSeed);
    long xSeed = fmlRandom.nextLong() >> 2 + 1L;
    long zSeed = fmlRandom.nextLong() >> 2 + 1L;
    long chunkSeed = (xSeed * chunkX + zSeed * chunkZ) ^ worldSeed;
    for (IWorldGenerator generator : sortedGeneratorList) {
        fmlRandom.setSeed(chunkSeed);
        generator.generate(fmlRandom, chunkX, chunkZ, world, chunkGenerator, chunkProvider);
    }
}
Also used : Random(java.util.Random) IWorldGenerator(net.minecraftforge.fml.common.IWorldGenerator)

Example 2 with IWorldGenerator

use of net.minecraftforge.fml.common.IWorldGenerator in project Galacticraft by micdoodle8.

the class TransformerHooks method otherModPreventGenerate.

public static boolean otherModPreventGenerate(int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
    if (!(world.provider instanceof IGalacticraftWorldProvider)) {
        return false;
    }
    if (world.provider instanceof WorldProviderSpaceStation) {
        return true;
    }
    if (ConfigManagerCore.enableOtherModsFeatures) {
        return false;
    }
    if (!generatorsInitialised) {
        generatorsInitialised = true;
        if (ConfigManagerCore.whitelistCoFHCoreGen) {
            addWorldGenForName("CoFHCore custom oregen", "cofh.core.world.WorldHandler");
        }
        addWorldGenForName("GalacticGreg oregen", "bloodasp.galacticgreg.GT_Worldgenerator_Space");
        addWorldGenForName("Dense Ores oregen", "com.rwtema.denseores.WorldGenOres");
        addWorldGenForName("AE2 meteorites worldgen", "appeng.worldgen.MeteoriteWorldGen");
        try {
            Class genThaumCraft = Class.forName("thaumcraft.common.lib.world.ThaumcraftWorldGenerator");
            if (genThaumCraft != null && ConfigManagerCore.enableThaumCraftNodes) {
                final Field regField = GameRegistry.class.getDeclaredField("worldGenerators");
                regField.setAccessible(true);
                Set<IWorldGenerator> registeredGenerators = (Set<IWorldGenerator>) regField.get(null);
                for (IWorldGenerator gen : registeredGenerators) {
                    if (genThaumCraft.isInstance(gen)) {
                        generatorTCAuraNodes = gen;
                        break;
                    }
                }
                if (generatorTCAuraNodes != null) {
                    generateTCAuraNodes = genThaumCraft.getDeclaredMethod("generateWildNodes", World.class, Random.class, int.class, int.class, boolean.class, boolean.class);
                    generateTCAuraNodes.setAccessible(true);
                    GCLog.info("Whitelisting ThaumCraft aura node generation on planets.");
                }
            }
        } catch (Exception e) {
        }
    }
    if (otherModGeneratorsWhitelist.size() > 0 || generateTCAuraNodes != null) {
        try {
            long worldSeed = world.getSeed();
            Random fmlRandom = new Random(worldSeed);
            long xSeed = fmlRandom.nextLong() >> 2 + 1L;
            long zSeed = fmlRandom.nextLong() >> 2 + 1L;
            long chunkSeed = (xSeed * chunkX + zSeed * chunkZ) ^ worldSeed;
            fmlRandom.setSeed(chunkSeed);
            for (IWorldGenerator gen : otherModGeneratorsWhitelist) {
                gen.generate(fmlRandom, chunkX, chunkZ, world, chunkGenerator, chunkProvider);
            }
            if (generateTCAuraNodes != null) {
                generateTCAuraNodes.invoke(generatorTCAuraNodes, world, fmlRandom, chunkX, chunkZ, false, true);
            }
        } catch (Exception e) {
            GCLog.severe("Error in another mod's worldgen.  This is *NOT* a Galacticraft bug, report it to the other mod please.");
            e.printStackTrace();
        }
    }
    return true;
}
Also used : Field(java.lang.reflect.Field) Set(java.util.Set) Random(java.util.Random) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) World(net.minecraft.world.World) IWorldGenerator(net.minecraftforge.fml.common.IWorldGenerator)

Example 3 with IWorldGenerator

use of net.minecraftforge.fml.common.IWorldGenerator in project Galacticraft by micdoodle8.

the class TransformerHooks method addWorldGenForName.

private static void addWorldGenForName(String logString, String name) {
    try {
        Class target = Class.forName(name);
        if (target != null) {
            final Field regField = GameRegistry.class.getDeclaredField("worldGenerators");
            regField.setAccessible(true);
            Set<IWorldGenerator> registeredGenerators = (Set<IWorldGenerator>) regField.get(null);
            for (IWorldGenerator gen : registeredGenerators) {
                if (target.isInstance(gen)) {
                    otherModGeneratorsWhitelist.add(gen);
                    GCLog.info("Whitelisting " + logString + " on planets.");
                    return;
                }
            }
        }
    } catch (Exception e) {
    }
}
Also used : Field(java.lang.reflect.Field) Set(java.util.Set) IWorldGenerator(net.minecraftforge.fml.common.IWorldGenerator)

Aggregations

IWorldGenerator (net.minecraftforge.fml.common.IWorldGenerator)3 Field (java.lang.reflect.Field)2 Random (java.util.Random)2 Set (java.util.Set)2 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)1 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)1 World (net.minecraft.world.World)1