Search in sources :

Example 11 with WorldGenerator

use of net.minecraft.world.gen.feature.WorldGenerator in project Realistic-Terrain-Generation by Team-RTG.

the class DecoGrassDoubleTallgrass method generate.

@Override
public void generate(IRealisticBiome biome, RTGWorld rtgWorld, Random rand, int worldX, int worldZ, float strength, float river, boolean hasPlacedVillageBlocks) {
    if (this.allowed) {
        if (TerrainGen.decorate(rtgWorld.world, rand, new BlockPos(worldX, 0, worldZ), GRASS)) {
            WorldGenerator worldGenerator = null;
            if (this.doubleGrassChance > 0) {
                if (rand.nextInt(this.doubleGrassChance) == 0) {
                    worldGenerator = new WorldGenGrass(Blocks.DOUBLE_PLANT.getStateFromMeta(2), 2);
                } else {
                    worldGenerator = new WorldGenGrass(Blocks.TALLGRASS.getStateFromMeta(1), 1);
                }
            } else if (this.grassChance > 0) {
                if (rand.nextInt(this.grassChance) == 0) {
                    worldGenerator = new WorldGenGrass(Blocks.TALLGRASS.getStateFromMeta(1), 1);
                } else {
                    worldGenerator = new WorldGenGrass(Blocks.DOUBLE_PLANT.getStateFromMeta(2), 2);
                }
            } else {
                if (rand.nextBoolean()) {
                    worldGenerator = new WorldGenGrass(Blocks.TALLGRASS.getStateFromMeta(1), 1);
                } else {
                    worldGenerator = new WorldGenGrass(Blocks.DOUBLE_PLANT.getStateFromMeta(2), 2);
                }
            }
            this.setLoops((this.strengthFactor > 0f) ? (int) (this.strengthFactor * strength) : this.loops);
            for (int i = 0; i < this.loops; i++) {
                int intX = worldX + rand.nextInt(16) + 8;
                int intY = rand.nextInt(this.maxY);
                int intZ = worldZ + rand.nextInt(16) + 8;
                if (intY <= this.maxY) {
                    worldGenerator.generate(rtgWorld.world, rand, new BlockPos(intX, intY, intZ));
                }
            }
        }
    }
}
Also used : WorldGenGrass(rtg.api.world.gen.feature.WorldGenGrass) WorldGenerator(net.minecraft.world.gen.feature.WorldGenerator) BlockPos(net.minecraft.util.math.BlockPos)

Example 12 with WorldGenerator

use of net.minecraft.world.gen.feature.WorldGenerator in project Realistic-Terrain-Generation by Team-RTG.

the class DecoLayer method generate.

@Override
public void generate(IRealisticBiome biome, RTGWorld rtgWorld, Random rand, int worldX, int worldZ, float strength, float river, boolean hasPlacedVillageBlocks) {
    if (this.allowed) {
        WorldUtil worldUtil = new WorldUtil(rtgWorld.world);
        WorldGenerator worldGenerator = new WorldGenLayers(this.layerBlock, this.layerProperty, this.dropHeight, this.layerRange, this.layerScatter);
        int loopCount = this.loops;
        loopCount = (this.strengthFactor > 0f) ? (int) (this.strengthFactor * strength) : loopCount;
        for (int i = 0; i < loopCount; i++) {
            // + 8;
            int intX = worldX + rand.nextInt(16);
            // + 8;
            int intZ = worldZ + rand.nextInt(16);
            int intY = rtgWorld.world.getHeight(new BlockPos(intX, 0, intZ)).getY();
            if (this.notEqualsZeroChance > 1) {
                if (intY >= this.minY && intY <= this.maxY && rand.nextInt(this.notEqualsZeroChance) != 0) {
                    generateWorldGenerator(worldGenerator, worldUtil, rtgWorld.world, rand, intX, intY, intZ, hasPlacedVillageBlocks);
                }
            } else {
                if (intY >= this.minY && intY <= this.maxY && rand.nextInt(this.chance) == 0) {
                    generateWorldGenerator(worldGenerator, worldUtil, rtgWorld.world, rand, intX, intY, intZ, hasPlacedVillageBlocks);
                }
            }
        }
    }
}
Also used : WorldGenerator(net.minecraft.world.gen.feature.WorldGenerator) WorldGenLayers(rtg.api.world.gen.feature.WorldGenLayers) BlockPos(net.minecraft.util.math.BlockPos) WorldUtil(rtg.api.util.WorldUtil)

Example 13 with WorldGenerator

use of net.minecraft.world.gen.feature.WorldGenerator in project NetherEx by LogicTechCorp.

the class BlockElderMushroom method grow.

@Override
public void grow(World world, Random rand, BlockPos pos, IBlockState state) {
    WorldGenerator elderMushroom;
    if (state.getValue(TYPE) == EnumType.BROWN) {
        elderMushroom = new WorldGenElderMushroom(WorldGenElderMushroom.brownVariants, false);
    } else {
        elderMushroom = new WorldGenElderMushroom(WorldGenElderMushroom.redVariants, false);
    }
    elderMushroom.generate(world, rand, pos.down());
}
Also used : WorldGenerator(net.minecraft.world.gen.feature.WorldGenerator) WorldGenElderMushroom(nex.world.gen.feature.WorldGenElderMushroom)

Example 14 with WorldGenerator

use of net.minecraft.world.gen.feature.WorldGenerator in project BetterWithAddons by DaedalusGame.

the class BlockModSapling method generateTree.

public void generateTree(World worldIn, BlockPos pos, IBlockState state, Random rand) {
    if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(worldIn, rand, pos))
        return;
    WorldGenerator worldgenerator = isBig ? new WorldGenBigTrees(true, log, leaves, this) : new WorldGenTrees(true, 3, log, leaves, false);
    int i = 0;
    int j = 0;
    IBlockState iblockstate2 = Blocks.AIR.getDefaultState();
    worldIn.setBlockState(pos, iblockstate2, 4);
    if (!worldgenerator.generate(worldIn, rand, pos.add(i, 0, j))) {
        worldIn.setBlockState(pos, state, 4);
    }
}
Also used : WorldGenerator(net.minecraft.world.gen.feature.WorldGenerator) IBlockState(net.minecraft.block.state.IBlockState) WorldGenBigTrees(betterwithaddons.world.WorldGenBigTrees) WorldGenTrees(net.minecraft.world.gen.feature.WorldGenTrees)

Example 15 with WorldGenerator

use of net.minecraft.world.gen.feature.WorldGenerator in project Realistic-Terrain-Generation by Team-RTG.

the class DecoTree method generate.

@Override
public void generate(IRealisticBiome biome, RTGWorld rtgWorld, Random rand, int worldX, int worldZ, float strength, float river, boolean hasPlacedVillageBlocks) {
    if (this.allowed) {
        /*
             * Determine how many trees we're going to try to generate (loopCount).
             * The actual number of trees that end up being generated could be *less* than this value,
             * depending on environmental conditions.
             */
        float noise = rtgWorld.simplex.noise2(worldX / this.distribution.noiseDivisor, worldZ / this.distribution.noiseDivisor) * this.distribution.noiseFactor + this.distribution.noiseAddend;
        int loopCount = this.loops;
        loopCount = (this.strengthFactorForLoops > 0f) ? (int) (this.strengthFactorForLoops * strength) : loopCount;
        loopCount = (this.strengthNoiseFactorForLoops) ? (int) (noise * strength) : loopCount;
        loopCount = (this.strengthNoiseFactorXForLoops) ? (int) (noise * this.strengthFactorForLoops * strength) : loopCount;
        if (loopCount < 1) {
            return;
        }
        // Now let's check the configs to see if we should increase/decrease this value.
        DecoUtil decoUtil = new DecoUtil(this);
        loopCount = decoUtil.calculateLoopCountFromTreeDensity(loopCount, biome);
        if (loopCount < 1) {
            return;
        }
        /*
             * Since RTG posts a TREE event for each batch of trees it tries to generate (instead of one event per chunk),
             * we post this custom event so that we can pass the number of trees RTG expects to generate in each batch.
             *
             * This provides more contextual information to mods like Recurrent Complex, which can use the info to better
             * determine how to handle each batch of trees.
             *
             * Because the custom event extends DecorateBiomeEvent.Decorate, it still works with mods that don't need
             * the additional context.
             */
        DecorateBiomeEventRTG.DecorateRTG event = new DecorateBiomeEventRTG.DecorateRTG(rtgWorld.world, rand, new BlockPos(worldX, 0, worldZ), TREE, loopCount);
        MinecraftForge.TERRAIN_GEN_BUS.post(event);
        if (event.getResult() != Event.Result.DENY) {
            loopCount = event.getModifiedAmount();
            if (loopCount < 1) {
                return;
            }
            WorldUtil worldUtil = new WorldUtil(rtgWorld.world);
            DecoBase.tweakTreeLeaves(this, false, true);
            for (int i = 0; i < loopCount; i++) {
                // + 8;
                int intX = scatter.get(rand, worldX);
                // + 8;
                int intZ = scatter.get(rand, worldZ);
                int intY = rtgWorld.world.getHeight(new BlockPos(intX, 0, intZ)).getY();
                if (intY <= this.maxY && intY >= this.minY && isValidTreeCondition(noise, rand, strength)) {
                    // If we're in a village, check to make sure the tree has extra room to grow to avoid corrupting the village.
                    if (hasPlacedVillageBlocks) {
                        if (!worldUtil.isSurroundedByBlock(Blocks.AIR.getDefaultState(), 2, WorldUtil.SurroundCheckType.CARDINAL, rand, intX, intY, intZ)) {
                            return;
                        }
                    }
                    switch(this.treeType) {
                        case RTG_TREE:
                            //this.setLogBlock(strength < 0.2f ? BlockUtil.getStateLog(2) : this.logBlock);
                            this.tree.setLogBlock(this.logBlock);
                            this.tree.setLeavesBlock(this.leavesBlock);
                            this.tree.setTrunkSize(RandomUtil.getRandomInt(rand, this.minTrunkSize, this.maxTrunkSize));
                            this.tree.setCrownSize(RandomUtil.getRandomInt(rand, this.minCrownSize, this.maxCrownSize));
                            this.tree.setNoLeaves(this.noLeaves);
                            this.tree.generate(rtgWorld.world, rand, new BlockPos(intX, intY, intZ));
                            break;
                        case WORLDGEN:
                            WorldGenerator worldgenerator = this.worldGen;
                            worldgenerator.generate(rtgWorld.world, rand, new BlockPos(intX, intY, intZ));
                            break;
                        default:
                            break;
                    }
                } else {
                //Logger.debug("%d/%d/%d - minY = %d; maxY = %d; noise = %f", intX, intY, intZ, minY, maxY, noise);
                }
            }
        } else {
        //Logger.debug("Tree generation was cancelled.");
        }
    }
}
Also used : WorldGenerator(net.minecraft.world.gen.feature.WorldGenerator) DecoUtil(rtg.api.util.DecoUtil) DecorateBiomeEventRTG(rtg.api.event.DecorateBiomeEventRTG) BlockPos(net.minecraft.util.math.BlockPos) WorldUtil(rtg.api.util.WorldUtil)

Aggregations

WorldGenerator (net.minecraft.world.gen.feature.WorldGenerator)24 BlockPos (net.minecraft.util.math.BlockPos)22 WorldUtil (rtg.api.util.WorldUtil)7 WorldGenGrass (rtg.api.world.gen.feature.WorldGenGrass)3 IBlockState (net.minecraft.block.state.IBlockState)2 WorldGenBigTrees (betterwithaddons.world.WorldGenBigTrees)1 MapMaker (com.google.common.collect.MapMaker)1 java.util (java.util)1 Predicate (java.util.function.Predicate)1 Nullable (javax.annotation.Nullable)1 RailcraftConfig (mods.railcraft.common.core.RailcraftConfig)1 Metal (mods.railcraft.common.items.Metal)1 NoiseGenSimplex (mods.railcraft.common.worldgen.NoiseGen.NoiseGenSimplex)1 Block (net.minecraft.block.Block)1 World (net.minecraft.world.World)1 Biome (net.minecraft.world.biome.Biome)1 WorldGenBush (net.minecraft.world.gen.feature.WorldGenBush)1 WorldGenDeadBush (net.minecraft.world.gen.feature.WorldGenDeadBush)1 WorldGenDesertWells (net.minecraft.world.gen.feature.WorldGenDesertWells)1 WorldGenMinable (net.minecraft.world.gen.feature.WorldGenMinable)1