Search in sources :

Example 1 with FruitTreeConfig

use of net.tropicraft.core.common.dimension.feature.config.FruitTreeConfig in project Tropicraft by Tropicraft.

the class FruitTreeFeature method place.

@Override
public boolean place(FeaturePlaceContext<FruitTreeConfig> context) {
    WorldGenLevel world = context.level();
    Random rand = context.random();
    BlockPos pos = context.origin();
    FruitTreeConfig config = context.config();
    pos = pos.immutable();
    int height = rand.nextInt(3) + 4;
    if (goesBeyondWorldSize(world, pos.getY(), height)) {
        return false;
    }
    if (!isBBAvailable(world, pos, height)) {
        return false;
    }
    BlockState sapling = config.sapling;
    if (!sapling.canSurvive(world, pos)) {
        return false;
    }
    setDirtAt(world, pos.below());
    for (int y = (pos.getY() - 3) + height; y <= pos.getY() + height; y++) {
        int presizeMod = y - (pos.getY() + height);
        int size = 1 - presizeMod / 2;
        for (int x = pos.getX() - size; x <= pos.getX() + size; x++) {
            int localX = x - pos.getX();
            for (int z = pos.getZ() - size; z <= pos.getZ() + size; z++) {
                int localZ = z - pos.getZ();
                if ((Math.abs(localX) != size || Math.abs(localZ) != size || rand.nextInt(2) != 0 && presizeMod != 0) && TreeFeature.isAirOrLeaves(world, new BlockPos(x, y, z))) {
                    BlockPos leafPos = new BlockPos(x, y, z);
                    if (rand.nextBoolean()) {
                        // Set fruit-bearing leaves here
                        setBlock(world, leafPos, config.fruitLeaves);
                    } else {
                        // Set plain fruit tree leaves here
                        setBlock(world, leafPos, config.leaves);
                    }
                }
            }
        }
    }
    // Tree stem
    for (int y = 0; y < height; y++) {
        BlockPos logPos = pos.above(y);
        if (TreeFeature.validTreePos(world, logPos)) {
            setBlock(world, logPos, config.wood);
        }
    }
    return true;
}
Also used : FruitTreeConfig(net.tropicraft.core.common.dimension.feature.config.FruitTreeConfig) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) BlockPos(net.minecraft.core.BlockPos) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Aggregations

Random (java.util.Random)1 BlockPos (net.minecraft.core.BlockPos)1 WorldGenLevel (net.minecraft.world.level.WorldGenLevel)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 FruitTreeConfig (net.tropicraft.core.common.dimension.feature.config.FruitTreeConfig)1