Search in sources :

Example 1 with FeaturePlaceContext

use of net.minecraft.world.level.levelgen.feature.FeaturePlaceContext in project TerraFirmaCraft by TerraFirmaCraft.

the class LooseRockFeature method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
    final WorldGenLevel level = context.level();
    final BlockPos pos = context.origin();
    final Random random = context.random();
    final ChunkDataProvider provider = ChunkDataProvider.get(context.chunkGenerator());
    final ChunkData data = provider.get(level, pos);
    final RockSettings rock = data.getRockData().getRock(pos);
    return rock.loose().map(loose -> {
        final BlockState stateAt = level.getBlockState(pos);
        final BlockState rockState = FluidHelpers.fillWithFluid(loose.defaultBlockState(), stateAt.getFluidState().getType());
        if (EnvironmentHelpers.isWorldgenReplaceable(stateAt) && rockState != null && rockState.canSurvive(level, pos)) {
            setBlock(level, pos, rockState.setValue(TFCBlockStateProperties.COUNT_1_3, 1 + random.nextInt(2)));
            return true;
        }
        return false;
    }).orElse(false);
}
Also used : FeaturePlaceContext(net.minecraft.world.level.levelgen.feature.FeaturePlaceContext) NoneFeatureConfiguration(net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration) TFCBlockStateProperties(net.dries007.tfc.common.blocks.TFCBlockStateProperties) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) Feature(net.minecraft.world.level.levelgen.feature.Feature) ChunkData(net.dries007.tfc.world.chunkdata.ChunkData) RockSettings(net.dries007.tfc.world.settings.RockSettings) Codec(com.mojang.serialization.Codec) WorldGenLevel(net.minecraft.world.level.WorldGenLevel) BlockPos(net.minecraft.core.BlockPos) EnvironmentHelpers(net.dries007.tfc.util.EnvironmentHelpers) FluidHelpers(net.dries007.tfc.common.fluids.FluidHelpers) ChunkDataProvider(net.dries007.tfc.world.chunkdata.ChunkDataProvider) ChunkDataProvider(net.dries007.tfc.world.chunkdata.ChunkDataProvider) ChunkData(net.dries007.tfc.world.chunkdata.ChunkData) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) RockSettings(net.dries007.tfc.world.settings.RockSettings) BlockPos(net.minecraft.core.BlockPos) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 2 with FeaturePlaceContext

use of net.minecraft.world.level.levelgen.feature.FeaturePlaceContext in project artifacts by ochotonida.

the class CampsiteFeature method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
    WorldGenLevel level = context.level();
    BlockPos origin = context.origin();
    Random random = context.random();
    if (!isSufficientlyFlat(level, origin)) {
        return false;
    }
    BlockPos.betweenClosedStream(origin.offset(-2, 0, -2), origin.offset(2, 2, 2)).filter(pos -> Math.abs(pos.getX() - origin.getX()) < 2 || Math.abs(pos.getZ() - origin.getZ()) < 2).filter(pos -> !level.getBlockState(pos).isAir()).forEach(pos -> setBlock(level, pos, Blocks.CAVE_AIR.defaultBlockState()));
    placeFloor(level, origin, random);
    setBlock(level, origin, CAMPFIRES.getState(random, origin));
    Direction direction = Direction.Plane.HORIZONTAL.getRandomDirection(random);
    BlockPos pos = origin.relative(direction, 2);
    if (random.nextInt(3) == 0) {
        BlockPos.betweenClosedStream(pos.relative(direction.getClockWise()), pos.relative(direction.getCounterClockWise())).forEach(barrelPos -> {
            placeBarrel(level, barrelPos, random);
            if (random.nextInt(3) == 0) {
                placeBarrel(level, barrelPos.above(), random);
            }
        });
    } else {
        Direction bedDirection = random.nextBoolean() ? direction.getClockWise() : direction.getCounterClockWise();
        BlockState bedBlock = BEDS.getState(random, pos).setValue(BedBlock.FACING, bedDirection);
        setBlock(level, pos, bedBlock.setValue(BedBlock.PART, BedPart.HEAD));
        setBlock(level, pos.relative(bedDirection.getOpposite()), bedBlock.setValue(BedBlock.PART, BedPart.FOOT));
        placeBarrel(level, pos.relative(bedDirection), random);
        if (random.nextBoolean()) {
            setBlock(level, pos.relative(bedDirection).above(), LIGHTS.getState(random, pos));
        }
    }
    direction = random.nextBoolean() ? direction.getClockWise() : direction.getCounterClockWise();
    pos = origin.relative(direction, 2);
    List<BlockPos> positions = BlockPos.betweenClosedStream(pos.relative(direction.getClockWise()), pos.relative(direction.getCounterClockWise())).map(BlockPos::immutable).collect(Collectors.toCollection(ArrayList::new));
    Collections.shuffle(positions);
    placeCraftingStation(level, positions.remove(0), random, direction.getOpposite());
    placeFurnace(level, positions.remove(0), random, direction.getOpposite());
    placeChest(level, positions.remove(0), random, direction.getOpposite());
    return true;
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) NoneFeatureConfiguration(net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration) Tags(net.minecraftforge.common.Tags) RandomizableContainerBlockEntity(net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity) Direction(net.minecraft.core.Direction) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) ArrayList(java.util.ArrayList) Registry(net.minecraft.core.Registry) Holder(net.minecraft.core.Holder) WorldGenLevel(net.minecraft.world.level.WorldGenLevel) net.minecraft.world.level.block(net.minecraft.world.level.block) FeaturePlaceContext(net.minecraft.world.level.levelgen.feature.FeaturePlaceContext) BlockStateProperties(net.minecraft.world.level.block.state.properties.BlockStateProperties) BedPart(net.minecraft.world.level.block.state.properties.BedPart) BlockStateProvider(net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider) SimpleWeightedRandomList(net.minecraft.util.random.SimpleWeightedRandomList) Artifacts(artifacts.Artifacts) WeightedStateProvider(net.minecraft.world.level.levelgen.feature.stateproviders.WeightedStateProvider) Collectors(java.util.stream.Collectors) Feature(net.minecraft.world.level.levelgen.feature.Feature) List(java.util.List) BlockPos(net.minecraft.core.BlockPos) ModEntityTypes(artifacts.common.init.ModEntityTypes) ModConfig(artifacts.common.config.ModConfig) MimicEntity(artifacts.common.entity.MimicEntity) Collections(java.util.Collections) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 3 with FeaturePlaceContext

use of net.minecraft.world.level.levelgen.feature.FeaturePlaceContext in project EdenRing by paulevsGitch.

the class StonePillar method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) {
    WorldGenLevel level = featurePlaceContext.level();
    BlockPos center = featurePlaceContext.origin();
    Random random = featurePlaceContext.random();
    center = getPosOnSurface(level, center);
    if (center.getY() < 5) {
        return false;
    }
    float height = MHelper.randRange(1.5F, 3.5F, random);
    center = center.above(Mth.floor(height));
    float r1 = MHelper.randRange(2.5F, 3.5F, random);
    float r2 = MHelper.randRange(1.5F, 2.5F, random);
    SDF sdf = new SDFCappedCone().setHeight(height * 2).setRadius1(r1).setRadius2(r2).setBlock(Blocks.STONE);
    int count = random.nextInt(3);
    float radius = r2 * MHelper.randRange(1.5F, 2F, random);
    for (int i = 0; i < count; i++) {
        height += radius * 0.7F;
        SDF sphere = new SDFSphere().setRadius(MHelper.randRange(2F, 4F, random)).setBlock(Blocks.STONE);
        sphere = new SDFScale3D().setScale(MHelper.randRange(2F, 3F, random), 1, MHelper.randRange(2F, 3F, random)).setSource(sphere);
        sphere = new SDFTranslate().setTranslate(0, height, 0).setSource(sphere);
        sdf = new SDFSmoothUnion().setRadius(4f).setSourceA(sdf).setSourceB(sphere);
        height += radius;
        radius += MHelper.randRange(0.75F, 1.5F, random);
    }
    OpenSimplexNoise noise = new OpenSimplexNoise(random.nextInt());
    sdf = new SDFDisplacement().setFunction(pos -> {
        float disp = (float) noise.eval(pos.x() * 0.06F, pos.y() * 0.06F, pos.z() * 0.06F) * 2.0F;
        disp += (float) noise.eval(pos.x() * 0.1F, pos.y() * 0.1F, pos.z() * 0.1F) * 0.35F;
        return disp;
    }).setSource(sdf);
    BlockState bottom = EdenBlocks.EDEN_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM);
    BlockState middle = EdenBlocks.EDEN_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE);
    BlockState top = EdenBlocks.EDEN_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP);
    BlockState roots = Blocks.HANGING_ROOTS.defaultBlockState();
    sdf.addPostProcess(info -> {
        if (info.getState().is(EdenBlocks.EDEN_VINE) || info.getState().is(Blocks.HANGING_ROOTS)) {
            return info.getState();
        }
        if (info.getPos().getY() > 3 && info.getStateDown().isAir() && random.nextInt(8) == 0) {
            if (random.nextBoolean()) {
                info.setBlockPos(info.getPos().below(), roots);
            } else {
                int h = MHelper.randRange(1, 3, random);
                for (int i = 0; i < h; i++) {
                    int p = i + 1;
                    info.setBlockPos(info.getPos().below(p), i == 0 ? top : i == p ? bottom : middle);
                }
            }
        }
        if (info.getStateUp().isAir() && noise.eval(info.getPos().getX() * 0.4F, info.getPos().getY() * 0.4F, info.getPos().getZ() * 0.4F) > 0.1) {
            if (random.nextInt(5) == 0) {
                info.setBlockPos(info.getPos().above(), Blocks.GRASS.defaultBlockState());
            }
            return EdenBlocks.MOSSY_STONE.defaultBlockState();
        } else if (noise.eval(info.getPos().getX() * 0.4F, info.getPos().getY() * 0.4F + 50, info.getPos().getZ() * 0.4F) > 0.3) {
            return Blocks.MOSSY_COBBLESTONE.defaultBlockState();
        } else if (noise.eval(info.getPos().getX() * 0.4F, info.getPos().getY() * 0.4F + 100, info.getPos().getZ() * 0.4F) > 0.3) {
            return Blocks.COBBLESTONE.defaultBlockState();
        } else if (noise.eval(info.getPos().getX() * 0.4F, info.getPos().getY() * 0.4F + 150, info.getPos().getZ() * 0.4F) > 0.3) {
            if (info.getStateUp().isAir() && random.nextInt(5) == 0) {
                info.setBlockPos(info.getPos().above(), Blocks.GRASS.defaultBlockState());
            }
            return Blocks.MOSS_BLOCK.defaultBlockState();
        }
        return info.getState();
    });
    sdf.setReplaceFunction(state -> {
        return state.isAir() || state.getBlock() instanceof EdenGrassBlock || state.is(Blocks.DIRT);
    }).fillRecursive(level, center);
    return true;
}
Also used : FeaturePlaceContext(net.minecraft.world.level.levelgen.feature.FeaturePlaceContext) NoneFeatureConfiguration(net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) DefaultFeature(ru.bclib.world.features.DefaultFeature) Blocks(net.minecraft.world.level.block.Blocks) TripleShape(ru.bclib.blocks.BlockProperties.TripleShape) SDFSphere(ru.bclib.sdf.primitive.SDFSphere) EdenGrassBlock(paulevs.edenring.blocks.EdenGrassBlock) SDFSmoothUnion(ru.bclib.sdf.operator.SDFSmoothUnion) SDFCappedCone(ru.bclib.sdf.primitive.SDFCappedCone) WorldGenLevel(net.minecraft.world.level.WorldGenLevel) BlockPos(net.minecraft.core.BlockPos) SDFDisplacement(ru.bclib.sdf.operator.SDFDisplacement) SDFTranslate(ru.bclib.sdf.operator.SDFTranslate) SDFScale3D(ru.bclib.sdf.operator.SDFScale3D) Mth(net.minecraft.util.Mth) BlockProperties(ru.bclib.blocks.BlockProperties) SDF(ru.bclib.sdf.SDF) EdenBlocks(paulevs.edenring.registries.EdenBlocks) OpenSimplexNoise(ru.bclib.noise.OpenSimplexNoise) MHelper(ru.bclib.util.MHelper) SDFSmoothUnion(ru.bclib.sdf.operator.SDFSmoothUnion) EdenGrassBlock(paulevs.edenring.blocks.EdenGrassBlock) SDFCappedCone(ru.bclib.sdf.primitive.SDFCappedCone) SDFScale3D(ru.bclib.sdf.operator.SDFScale3D) SDFSphere(ru.bclib.sdf.primitive.SDFSphere) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) SDF(ru.bclib.sdf.SDF) SDFDisplacement(ru.bclib.sdf.operator.SDFDisplacement) SDFTranslate(ru.bclib.sdf.operator.SDFTranslate) BlockPos(net.minecraft.core.BlockPos) OpenSimplexNoise(ru.bclib.noise.OpenSimplexNoise) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 4 with FeaturePlaceContext

use of net.minecraft.world.level.levelgen.feature.FeaturePlaceContext in project Ecologics by samedifferent.

the class ThinIceFeature method place.

@Override
public boolean place(FeaturePlaceContext<DiskConfiguration> context) {
    WorldGenLevel level = context.level();
    BlockPos blockpos;
    for (blockpos = context.origin(); level.isEmptyBlock(blockpos) && blockpos.getY() > level.getMinBuildHeight() + 2; blockpos = blockpos.below()) {
    }
    return level.getBlockState(blockpos).is(Blocks.ICE) && super.place(new FeaturePlaceContext<>(context.topFeature(), level, context.chunkGenerator(), context.random(), blockpos, context.config()));
}
Also used : FeaturePlaceContext(net.minecraft.world.level.levelgen.feature.FeaturePlaceContext) BlockPos(net.minecraft.core.BlockPos) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 5 with FeaturePlaceContext

use of net.minecraft.world.level.levelgen.feature.FeaturePlaceContext in project BCLib by paulevsGitch.

the class FeatureSaplingBlock method advanceTree.

@Override
public void advanceTree(ServerLevel world, BlockPos pos, BlockState blockState, Random random) {
    FeaturePlaceContext context = new FeaturePlaceContext(Optional.empty(), world, world.getChunkSource().getGenerator(), random, pos, null);
    getFeature(blockState).place(context);
}
Also used : FeaturePlaceContext(net.minecraft.world.level.levelgen.feature.FeaturePlaceContext)

Aggregations

FeaturePlaceContext (net.minecraft.world.level.levelgen.feature.FeaturePlaceContext)8 BlockPos (net.minecraft.core.BlockPos)6 WorldGenLevel (net.minecraft.world.level.WorldGenLevel)4 Random (java.util.Random)3 BlockState (net.minecraft.world.level.block.state.BlockState)3 NoneFeatureConfiguration (net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration)3 NMSService (de.derfrzocker.ore.control.api.NMSService)2 ChunkCoordIntPair (de.derfrzocker.spigot.utils.ChunkCoordIntPair)2 Feature (net.minecraft.world.level.levelgen.feature.Feature)2 World (org.bukkit.World)2 Artifacts (artifacts.Artifacts)1 ModConfig (artifacts.common.config.ModConfig)1 MimicEntity (artifacts.common.entity.MimicEntity)1 ModEntityTypes (artifacts.common.init.ModEntityTypes)1 Codec (com.mojang.serialization.Codec)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 TFCBlockStateProperties (net.dries007.tfc.common.blocks.TFCBlockStateProperties)1