Search in sources :

Example 1 with IntPoint2D

use of net.cr24.primeval.util.IntPoint2D in project Primeval by devs-immortal.

the class OreClusterFeature method generate.

@Override
public boolean generate(FeatureContext<OreClusterFeatureConfig> context) {
    BlockPos blockPos = context.getOrigin();
    StructureWorldAccess structureWorldAccess = context.getWorld();
    Random random = context.getRandom();
    OreClusterFeatureConfig config = context.getConfig();
    BlockStateProvider largeState = config.largeState();
    BlockStateProvider mediumState = config.mediumState();
    BlockStateProvider smallState = config.smallState();
    int radius = config.radius().get(random);
    int height = config.height().get(random);
    float density = config.density().get(random);
    float richness = config.richness().get(random);
    IntPoint2D[] circleCoords = ShapesUtil.getCoordinatesInCircle(radius);
    float oreRichness;
    for (IntPoint2D point : circleCoords) {
        // for each height step
        for (int y = 0; y < height; y++) {
            // for each coord in circle
            if (random.nextFloat() < density) {
                // density check
                oreRichness = (richness + ((random.nextFloat() * 2.0f) - 1.0f) * richness);
                if (oreRichness > 0.75) {
                    setBlockIfAble(structureWorldAccess, point.getOffsetBlockPos(blockPos).up(y), largeState, random);
                } else if (oreRichness > 0.3) {
                    setBlockIfAble(structureWorldAccess, point.getOffsetBlockPos(blockPos).up(y), mediumState, random);
                } else {
                    setBlockIfAble(structureWorldAccess, point.getOffsetBlockPos(blockPos).up(y), smallState, random);
                }
            }
        }
    }
    return true;
}
Also used : Random(java.util.Random) BlockPos(net.minecraft.util.math.BlockPos) IntPoint2D(net.cr24.primeval.util.IntPoint2D) BlockStateProvider(net.minecraft.world.gen.stateprovider.BlockStateProvider) StructureWorldAccess(net.minecraft.world.StructureWorldAccess)

Aggregations

Random (java.util.Random)1 IntPoint2D (net.cr24.primeval.util.IntPoint2D)1 BlockPos (net.minecraft.util.math.BlockPos)1 StructureWorldAccess (net.minecraft.world.StructureWorldAccess)1 BlockStateProvider (net.minecraft.world.gen.stateprovider.BlockStateProvider)1