Search in sources :

Example 41 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(final IRealisticBiome biome, final RTGWorld rtgWorld, final Random rand, final ChunkPos chunkPos, final float river, final boolean hasVillage) {
    final BlockPos offsetPos = getOffsetPos(chunkPos);
    /*
         * 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.
         */
    // TODO: [1.12] What is the point of deriving a noise value from static BlockPos within a chunk (population origin) and then applying
    // it to a feature taking place at some other arbitrary place in the chunk. This seems nonsensical and makes needless
    // calls to the noise generator. This should be replaced by a random amount.
    float noise = rtgWorld.simplexInstance(0).noise2f(offsetPos.getX() / this.distribution.getNoiseDivisor(), offsetPos.getZ() / this.distribution.getNoiseDivisor()) * this.distribution.getNoiseFactor() + this.distribution.getNoiseAddend();
    int loopCount = (this.strengthFactorForLoops > 0f) ? (int) this.strengthFactorForLoops : this.loops;
    loopCount = (this.strengthNoiseFactorForLoops) ? (int) noise : loopCount;
    loopCount = (this.strengthNoiseFactorXForLoops) ? (int) (noise * this.strengthFactorForLoops) : loopCount;
    if (loopCount < 1) {
        return;
    }
    // Now let's check the configs to see if we should increase/decrease this value.
    loopCount = this.applyConfigMultipliers(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.
         */
    // TODO [1.12] Trees should just generate how they do in the vanilla BiomeDecorator::genDecorations and use the Forge event.
    DecorateBiomeEventRTG.DecorateRTG event = new DecorateBiomeEventRTG.DecorateRTG(rtgWorld.world(), rand, offsetPos, Decorate.EventType.TREE, loopCount);
    MinecraftForge.TERRAIN_GEN_BUS.post(event);
    if (event.getResult() != Event.Result.DENY) {
        loopCount = event.getModifiedAmount();
        if (loopCount < 1) {
            return;
        }
        // TODO: [1.12] This should be done in #setLeavesBlock.
        DecoBase.tweakTreeLeaves(this, false, true);
        for (int i = 0; i < loopCount; i++) {
            final BlockPos pos = offsetPos.add(rand.nextInt(16), 0, rand.nextInt(16));
            int y = rtgWorld.world().getHeight(pos).getY();
            if (y <= this.maxY && y >= this.minY && isValidTreeCondition(noise, rand)) {
                // If we're in a village, check to make sure the tree has extra room to grow to avoid corrupting the village.
                if (hasVillage) {
                    if (BlockUtil.checkVerticalBlocks(MatchType.ALL, rtgWorld.world(), pos, -1, Blocks.FARMLAND) || !BlockUtil.checkAreaBlocks(MatchType.ALL_IGNORE_REPLACEABLE, rtgWorld.world(), pos, 2)) {
                        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(getRangedRandom(rand, this.minTrunkSize, this.maxTrunkSize));
                        this.tree.setCrownSize(getRangedRandom(rand, this.minCrownSize, this.maxCrownSize));
                        this.tree.setNoLeaves(this.noLeaves);
                        this.tree.generate(rtgWorld.world(), rand, pos.up(y));
                        break;
                    case WORLDGEN:
                        WorldGenerator worldgenerator = this.worldGen;
                        worldgenerator.generate(rtgWorld.world(), rand, pos.up(y));
                        break;
                    default:
                        break;
                }
            }
        }
    } else if (RTGConfig.enableDebugging()) {
        Logger.debug("Tree generation was cancelled @ ChunkPos{}", chunkPos);
    }
}
Also used : WorldGenerator(net.minecraft.world.gen.feature.WorldGenerator) DecorateBiomeEventRTG(rtg.api.event.DecorateBiomeEventRTG) BlockPos(net.minecraft.util.math.BlockPos)

Example 42 with WorldGenerator

use of net.minecraft.world.gen.feature.WorldGenerator in project BiomesOPlenty by Glitchfiend.

the class BlockBOPSapling method generateTree.

// try to generate a tree at the specified location, return true on success and false on failure
public boolean generateTree(World worldIn, BlockPos pos, IBlockState state, Random rand) {
    if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(worldIn, rand, pos)) {
        return false;
    }
    BOPTrees treeType = ((BOPTrees) state.getValue(this.variantProperty));
    WorldGenerator smallTreeGenerator = this.getSmallTreeGenerator(treeType);
    WorldGenerator bigTreeGenerator = this.getBigTreeGenerator(treeType);
    WorldGenerator megaTreeGenerator = this.getMegaTreeGenerator(treeType);
    if (megaTreeGenerator != null) {
        // if we have 4 saplings in a square, then try to grow a mega tree
        int i;
        int j;
        for (i = 0; i >= -1; --i) {
            for (j = 0; j >= -1; --j) {
                if (this.thisSaplingHere(worldIn, pos.add(i, 0, j)) && this.thisSaplingHere(worldIn, pos.add(i + 1, 0, j)) && this.thisSaplingHere(worldIn, pos.add(i, 0, j + 1)) && this.thisSaplingHere(worldIn, pos.add(i + 1, 0, j + 1))) {
                    if (this.generateMegaTree(worldIn, pos.add(i, 0, j), state, rand, megaTreeGenerator)) {
                        return true;
                    }
                }
            }
        }
    }
    if (bigTreeGenerator != null) {
        // with a one in 10 chance, try to grow a big tree
        if (rand.nextInt(10) == 0) {
            if (this.generateSmallOrBigTree(worldIn, pos, state, rand, bigTreeGenerator)) {
                return true;
            }
        }
    }
    // otherwise, try to grow a small tree
    if (smallTreeGenerator != null) {
        return this.generateSmallOrBigTree(worldIn, pos, state, rand, smallTreeGenerator);
    }
    return false;
}
Also used : BOPTrees(biomesoplenty.api.enums.BOPTrees) WorldGenerator(net.minecraft.world.gen.feature.WorldGenerator)

Example 43 with WorldGenerator

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

the class TileSapling method tryGrow.

public int tryGrow(boolean bonemealed) {
    int result = 0;
    if (this.getTree() == null) {
        return result;
    }
    int maturity = (int) (getTree().getRequiredMaturity() * PluginArboriculture.treeInterface.getTreekeepingMode(worldObj).getMaturationModifier(getTree().getGenome(), 1f));
    if (bonemealed && timesTicked < maturity) {
        timesTicked++;
        result = 1;
    }
    if (timesTicked < maturity) {
        return result;
    }
    WorldGenerator generator = this.getTree().getTreeGenerator(worldObj, xCoord, yCoord, zCoord, bonemealed);
    if (generator.generate(worldObj, worldObj.rand, xCoord, yCoord, zCoord)) {
        PluginArboriculture.treeInterface.getBreedingTracker(worldObj, getOwnerProfile()).registerBirth(getTree());
        return 2;
    }
    return 3;
}
Also used : WorldGenerator(net.minecraft.world.gen.feature.WorldGenerator)

Example 44 with WorldGenerator

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

the class TreeSpawner method spawn.

@Override
public boolean spawn(ICommandSender sender, String treeName, EntityPlayer player) {
    Vec3 look = player.getLookVec();
    int x = (int) Math.round(player.posX + (3 * look.xCoord));
    int y = (int) Math.round(player.posY);
    int z = (int) Math.round(player.posZ + (3 * look.zCoord));
    WorldGenerator gen = TreeGenHelper.getWorldGen(treeName, player, x, y, z);
    if (gen == null) {
        return false;
    }
    TreeGenHelper.generateTree(gen, player, x, y, z);
    return true;
}
Also used : WorldGenerator(net.minecraft.world.gen.feature.WorldGenerator) Vec3(net.minecraft.util.Vec3)

Aggregations

WorldGenerator (net.minecraft.world.gen.feature.WorldGenerator)44 BlockPos (net.minecraft.util.math.BlockPos)25 IBlockState (net.minecraft.block.state.IBlockState)8 WorldUtil (rtg.api.util.WorldUtil)7 World (net.minecraft.world.World)3 WorldGenMinable (net.minecraft.world.gen.feature.WorldGenMinable)3 WorldGenGrass (rtg.api.world.gen.feature.WorldGenGrass)3 MapMaker (com.google.common.collect.MapMaker)2 ITree (forestry.api.arboriculture.ITree)2 WorldGenBase (forestry.core.worldgen.WorldGenBase)2 Predicate (java.util.function.Predicate)2 RailcraftConfig (mods.railcraft.common.core.RailcraftConfig)2 NoiseGenSimplex (mods.railcraft.common.worldgen.NoiseGen.NoiseGenSimplex)2 Vec3 (net.minecraft.util.Vec3)2 Biome (net.minecraft.world.biome.Biome)2 WorldGenTrees (net.minecraft.world.gen.feature.WorldGenTrees)2 EventType (net.minecraftforge.event.terraingen.OreGenEvent.GenerateMinable.EventType)2 TerrainGen (net.minecraftforge.event.terraingen.TerrainGen)2 DecorateBiomeEventRTG (rtg.api.event.DecorateBiomeEventRTG)2 WorldGenBigTrees (betterwithaddons.world.WorldGenBigTrees)1