Search in sources :

Example 1 with PostGenerationContext

use of com.ferreusveritas.dynamictrees.systems.genfeatures.context.PostGenerationContext in project DynamicTrees-BYG by DynamicTreesTeam.

the class MangrovelingsGenFeature method postGenerate.

@Override
protected boolean postGenerate(GenFeatureConfiguration configuration, PostGenerationContext context) {
    IWorld world = context.world();
    Species species = context.species();
    int[] angles = new int[2];
    angles[0] = angles[1] = world.getRandom().nextInt(6);
    while (angles[0] == angles[1]) {
        angles[1] = world.getRandom().nextInt(6);
    }
    anglesLoop: for (int a : angles) {
        double angle = Math.toRadians(a * 60.0f);
        float distance = 3.0f + world.getRandom().nextFloat() * 2.0f;
        BlockPos offPos = context.pos().offset(new Vector3i(Math.sin(angle) * distance, 0, Math.cos(angle) * distance));
        if (context.bounds().inBounds(offPos, true)) {
            if (species.isAcceptableSoil(world, offPos, world.getBlockState(offPos))) {
                if (!(world.isEmptyBlock(offPos.above(1)) && world.isEmptyBlock(offPos.above(2)))) {
                    continue;
                }
                for (Direction hor : CoordUtils.HORIZONTALS) {
                    BlockPos offPos2 = offPos.offset(hor.getNormal());
                    if (!(world.isEmptyBlock(offPos2.above(1)) && world.isEmptyBlock(offPos2.above(2)))) {
                        continue anglesLoop;
                    }
                }
                species.placeRootyDirtBlock(world, offPos, 0);
                species.getFamily().getBranch().ifPresent(branch -> branch.setRadius(world, offPos.above(1), 1, Direction.DOWN, 0));
                if (world.getRandom().nextInt(2) == 0) {
                    world.setBlock(offPos.above(2), species.getLeavesProperties().getDynamicLeavesState(1), 3);
                } else {
                    species.getFamily().getBranch().ifPresent(branch -> branch.setRadius(world, offPos.above(2), 1, Direction.DOWN, 0));
                    if (world.isEmptyBlock(offPos.above(3))) {
                        world.setBlock(offPos.above(3), species.getLeavesProperties().getDynamicLeavesState(1), 3);
                    }
                }
            }
        }
    }
    return false;
}
Also used : PostGenerationContext(com.ferreusveritas.dynamictrees.systems.genfeatures.context.PostGenerationContext) CoordUtils(com.ferreusveritas.dynamictrees.util.CoordUtils) GenFeatureConfiguration(com.ferreusveritas.dynamictrees.systems.genfeatures.GenFeatureConfiguration) ResourceLocation(net.minecraft.util.ResourceLocation) Vector3i(net.minecraft.util.math.vector.Vector3i) IWorld(net.minecraft.world.IWorld) BlockPos(net.minecraft.util.math.BlockPos) Species(com.ferreusveritas.dynamictrees.trees.Species) Direction(net.minecraft.util.Direction) GenFeature(com.ferreusveritas.dynamictrees.systems.genfeatures.GenFeature) IWorld(net.minecraft.world.IWorld) Vector3i(net.minecraft.util.math.vector.Vector3i) BlockPos(net.minecraft.util.math.BlockPos) Species(com.ferreusveritas.dynamictrees.trees.Species) Direction(net.minecraft.util.Direction)

Aggregations

GenFeature (com.ferreusveritas.dynamictrees.systems.genfeatures.GenFeature)1 GenFeatureConfiguration (com.ferreusveritas.dynamictrees.systems.genfeatures.GenFeatureConfiguration)1 PostGenerationContext (com.ferreusveritas.dynamictrees.systems.genfeatures.context.PostGenerationContext)1 Species (com.ferreusveritas.dynamictrees.trees.Species)1 CoordUtils (com.ferreusveritas.dynamictrees.util.CoordUtils)1 Direction (net.minecraft.util.Direction)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 BlockPos (net.minecraft.util.math.BlockPos)1 Vector3i (net.minecraft.util.math.vector.Vector3i)1 IWorld (net.minecraft.world.IWorld)1