Search in sources :

Example 6 with WorldUtil

use of rtg.api.util.WorldUtil in project Realistic-Terrain-Generation by Team-RTG.

the class WorldGenFlowersRTG method generate.

@Override
public boolean generate(World world, Random rand, BlockPos pos) {
    int x = pos.getX();
    int y = pos.getY();
    int z = pos.getZ();
    int randomFlower = flowers[rand.nextInt(flowers.length)];
    if (randomFlower > 9) {
        //for (int l = 0; l < 64; ++l)
        {
            // + rand.nextInt(8) - rand.nextInt(8);
            int i1 = x;
            // + rand.nextInt(4) - rand.nextInt(4);
            int j1 = y;
            // + rand.nextInt(8) - rand.nextInt(8);
            int k1 = z;
            IBlockState doublePlant = BlockUtil.getStateFlower(randomFlower);
            BlockPos doublePlantPos = new BlockPos(i1, j1, k1);
            WorldUtil worldUtil = new WorldUtil(world);
            if (world.isAirBlock(doublePlantPos) && (!world.provider.hasNoSky() || j1 < 254) && Blocks.DOUBLE_PLANT.canPlaceBlockAt(world, doublePlantPos)) {
                worldUtil.setDoublePlant(doublePlantPos, doublePlant);
            }
        }
    } else if (randomFlower == 9) {
        //for (int l = 0; l < 64; ++l)
        {
            // + rand.nextInt(8) - rand.nextInt(8);
            int i1 = x;
            // + rand.nextInt(4) - rand.nextInt(4);
            int j1 = y;
            // + rand.nextInt(8) - rand.nextInt(8);
            int k1 = z;
            IBlockState flower = BlockUtil.getStateFlower(randomFlower);
            BlockPos flowerPos = new BlockPos(i1, j1, k1);
            if (world.isAirBlock(flowerPos) && (!world.provider.hasNoSky() || j1 < 254) && Blocks.YELLOW_FLOWER.canPlaceBlockAt(world, flowerPos) && Blocks.YELLOW_FLOWER.canBlockStay(world, flowerPos, flower)) {
                world.setBlockState(flowerPos, flower, 2);
            }
        }
    } else {
        //for (int l = 0; l < 64; ++l)
        {
            // + rand.nextInt(8) - rand.nextInt(8);
            int i1 = x;
            // + rand.nextInt(4) - rand.nextInt(4);
            int j1 = y;
            // + rand.nextInt(8) - rand.nextInt(8);
            int k1 = z;
            IBlockState flower = BlockUtil.getStateFlower(randomFlower);
            BlockPos flowerPos = new BlockPos(i1, j1, k1);
            if (world.isAirBlock(flowerPos) && (!world.provider.hasNoSky() || j1 < 254) && Blocks.RED_FLOWER.canPlaceBlockAt(world, flowerPos) && Blocks.RED_FLOWER.canBlockStay(world, flowerPos, flower)) {
                world.setBlockState(flowerPos, flower, 2);
            }
        }
    }
    return true;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) WorldUtil(rtg.api.util.WorldUtil)

Example 7 with WorldUtil

use of rtg.api.util.WorldUtil 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 8 with WorldUtil

use of rtg.api.util.WorldUtil 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)

Example 9 with WorldUtil

use of rtg.api.util.WorldUtil in project Realistic-Terrain-Generation by Team-RTG.

the class DecoBoulder 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 WorldGenBlob(boulderBlock, 0, rand, this.water, validGroundBlocks);
        for (int l1 = 0; l1 < this.strengthFactor * strength; ++l1) {
            // + 8;
            int i1 = worldX + rand.nextInt(16);
            // + 8;
            int j1 = worldZ + rand.nextInt(16);
            int k1;
            switch(this.heightType) {
                case NEXT_INT:
                    k1 = RandomUtil.getRandomInt(rand, this.minY, this.maxY);
                    break;
                case GET_HEIGHT_VALUE:
                    k1 = rtgWorld.world.getHeight(new BlockPos(i1, 0, j1)).getY();
                    break;
                default:
                    k1 = rtgWorld.world.getHeight(new BlockPos(i1, 0, j1)).getY();
                    break;
            }
            if (k1 >= this.minY && k1 <= this.maxY && rand.nextInt(this.chance) == 0) {
                // If we're in a village, check to make sure the boulder has extra room to grow to avoid corrupting the village.
                if (hasPlacedVillageBlocks) {
                    if (!worldUtil.isSurroundedByBlock(Blocks.AIR.getDefaultState(), 2, WorldUtil.SurroundCheckType.CARDINAL, rand, i1, k1, j1)) {
                        return;
                    }
                }
                worldGenerator.generate(rtgWorld.world, rand, new BlockPos(i1, k1, j1));
            }
        }
    }
}
Also used : WorldGenerator(net.minecraft.world.gen.feature.WorldGenerator) WorldGenBlob(rtg.api.world.gen.feature.WorldGenBlob) BlockPos(net.minecraft.util.math.BlockPos) WorldUtil(rtg.api.util.WorldUtil)

Aggregations

BlockPos (net.minecraft.util.math.BlockPos)9 WorldUtil (rtg.api.util.WorldUtil)9 WorldGenerator (net.minecraft.world.gen.feature.WorldGenerator)7 IBlockState (net.minecraft.block.state.IBlockState)2 ArrayList (java.util.ArrayList)1 DecorateBiomeEventRTG (rtg.api.event.DecorateBiomeEventRTG)1 DecoUtil (rtg.api.util.DecoUtil)1 WorldGenBlob (rtg.api.world.gen.feature.WorldGenBlob)1 WorldGenCrops (rtg.api.world.gen.feature.WorldGenCrops)1 WorldGenLayers (rtg.api.world.gen.feature.WorldGenLayers)1 WorldGenLog (rtg.api.world.gen.feature.WorldGenLog)1 WorldGenShrubRTG (rtg.api.world.gen.feature.WorldGenShrubRTG)1 WorldGenSponge (rtg.api.world.gen.feature.WorldGenSponge)1