Search in sources :

Example 1 with PlacedFeature

use of net.minecraft.world.level.levelgen.placement.PlacedFeature in project BYG by AOCAWOL.

the class NoisyCaveSphere method place.

public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos position, NoisySphereConfig config) {
    setSeed(world.getSeed());
    BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos().set(position.below(2 + random.nextInt(10)));
    BlockPos.MutableBlockPos mutable2 = new BlockPos.MutableBlockPos().set(mutable);
    int stackHeight = config.stackHeight().sample(random);
    NoisySphereConfig.RadiusSettings radiusSettings = config.radiusSettings();
    int xRadius = radiusSettings.xRadius().sample(random) / 2;
    int yRadius = radiusSettings.yRadius().sample(random) / 2;
    int zRadius = radiusSettings.zRadius().sample(random) / 2;
    fastNoise.SetFrequency(config.noiseFrequency());
    double radiusDivisorPerStack = config.radiusDivisorPerStack();
    ArrayList<BlockPos> caveAir = new ArrayList<>();
    for (int stackIDX = 0; stackIDX < stackHeight; stackIDX++) {
        for (int x = -xRadius; x <= xRadius; x++) {
            for (int z = -zRadius; z <= zRadius; z++) {
                for (int y = -yRadius; y <= yRadius; y++) {
                    mutable2.set(mutable).move(x, y, z);
                    // Credits to Hex_26 for this equation!
                    double equationResult = Math.pow(x, 2) / Math.pow(xRadius, 2) + Math.pow(y, 2) / Math.pow(yRadius, 2) + Math.pow(z, 2) / Math.pow(zRadius, 2);
                    double threshold = 1 + 0.7 * fastNoise.GetNoise(mutable2.getX(), mutable2.getY(), mutable2.getZ());
                    if (equationResult >= threshold)
                        continue;
                    if (world.getBlockState(mutable2).canOcclude()) {
                        if (mutable2.getY() <= 30) {
                            placeFluid(world, config.fluidState(), mutable2);
                        } else {
                            BlockState state = config.blockProvider().getState(random, mutable2);
                            if (state.isAir()) {
                                caveAir.add(mutable2.immutable());
                            }
                            world.setBlock(mutable2, state, 2);
                            // Remove non solids
                            for (int i = 0; i < 8; i++) {
                                BlockState blockState = world.getBlockState(mutable2);
                                if ((!blockState.canOcclude() && !blockState.isAir()) || blockState.is(BYGBlocks.CRYPTIC_VENT) || blockState.is(BYGBlocks.TALL_CRYPTIC_VENT) || blockState.is(BYGBlocks.CRYPTIC_FIRE)) {
                                    world.removeBlock(mutable2, false);
                                }
                                mutable2.move(Direction.UP);
                            }
                        }
                    }
                }
                xRadius = (int) (xRadius / radiusDivisorPerStack);
                yRadius = (int) (yRadius / radiusDivisorPerStack);
                zRadius = (int) (zRadius / radiusDivisorPerStack);
            }
        }
        for (BlockPos blockPos : caveAir) {
            for (Holder<PlacedFeature> spawningFeature : config.spawningFeatures()) {
                spawningFeature.value().place(world, chunkGenerator, random, blockPos);
            }
        }
    }
    return true;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) NoisySphereConfig(potionstudios.byg.common.world.feature.config.NoisySphereConfig) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.core.BlockPos) PlacedFeature(net.minecraft.world.level.levelgen.placement.PlacedFeature)

Example 2 with PlacedFeature

use of net.minecraft.world.level.levelgen.placement.PlacedFeature in project TutorialV3 by McJty.

the class DimensionBiomeFilter method shouldPlace.

@Override
protected boolean shouldPlace(PlacementContext context, Random random, BlockPos pos) {
    if (levelTest.test(context.getLevel().getLevel().dimension())) {
        PlacedFeature placedfeature = context.topFeature().orElseThrow(() -> new IllegalStateException("Tried to biome check an unregistered feature"));
        Holder<Biome> biome = context.getLevel().getBiome(pos);
        return biome.value().getGenerationSettings().hasFeature(placedfeature);
    } else {
        return false;
    }
}
Also used : Biome(net.minecraft.world.level.biome.Biome) PlacedFeature(net.minecraft.world.level.levelgen.placement.PlacedFeature)

Example 3 with PlacedFeature

use of net.minecraft.world.level.levelgen.placement.PlacedFeature in project excavated_variants by lukebemish.

the class MainPlatformTargetImpl method registerFeatures.

public void registerFeatures() {
    if (ORE_REPLACER == null) {
        ORE_REPLACER = new OreReplacer();
    }
    if (ORE_REPLACER_CONFIGURED == null) {
        ORE_REPLACER_CONFIGURED = new ConfiguredFeature<>(ORE_REPLACER, FeatureConfiguration.NONE);
    }
    if (ORE_REPLACER_PLACED == null) {
        ORE_REPLACER_PLACED = new PlacedFeature(Holder.direct(ORE_REPLACER_CONFIGURED), List.of());
    }
    Registry.register(Registry.FEATURE, new ResourceLocation(ExcavatedVariants.MOD_ID, "ore_replacer"), ORE_REPLACER);
    Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new ResourceLocation(ExcavatedVariants.MOD_ID, "ore_replacer"), ORE_REPLACER_CONFIGURED);
    Registry.register(BuiltinRegistries.PLACED_FEATURE, new ResourceLocation(ExcavatedVariants.MOD_ID, "ore_replacer"), ORE_REPLACER_PLACED);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) OreReplacer(io.github.lukebemish.excavated_variants.worldgen.OreReplacer) PlacedFeature(net.minecraft.world.level.levelgen.placement.PlacedFeature)

Example 4 with PlacedFeature

use of net.minecraft.world.level.levelgen.placement.PlacedFeature in project excavated_variants by lukebemish.

the class ExcavatedVariantsFabric method onInitialize.

@Override
public void onInitialize() {
    ExcavatedVariants.init();
    for (ExcavatedVariants.RegistryFuture b : ExcavatedVariants.getBlockList()) {
        if (ExcavatedVariants.loadedBlockRLs.contains(b.ore.block_id.get(0)) && ExcavatedVariants.loadedBlockRLs.contains(b.stone.block_id)) {
            ExcavatedVariants.registerBlockAndItem((rl, bl) -> Registry.register(Registry.BLOCK, rl, bl), (rl, i) -> {
                Item out = Registry.register(Registry.ITEM, rl, i.get());
                return () -> out;
            }, b);
        }
    }
    ServerLifecycleEvents.SERVER_STARTING.register(server -> {
        // Ore gen map setup
        Services.REGISTRY_UTIL.reset();
        ExcavatedVariants.oreStoneList = null;
        OreFinderUtil.setupBlocks();
        ExcavatedVariants.setupMap();
    });
    if (ExcavatedVariants.getConfig().attempt_ore_replacement) {
        ResourceKey<PlacedFeature> confKey = ResourceKey.create(Registry.PLACED_FEATURE_REGISTRY, new ResourceLocation(ExcavatedVariants.MOD_ID, "ore_replacer"));
        // A bit hacky, but will hopefully put it after existing stuff (like Unearthed's generation)
        BiomeModifications.create(confKey.location()).add(ModificationPhase.POST_PROCESSING, (x) -> true, context -> {
            context.getGenerationSettings().addFeature(GenerationStep.Decoration.TOP_LAYER_MODIFICATION, confKey);
        });
    }
    if (FabricLoader.getInstance().isModLoaded("unearthed") && ExcavatedVariants.setupMap()) {
        HyleCompat.init();
    }
}
Also used : Item(net.minecraft.world.item.Item) ExcavatedVariants(io.github.lukebemish.excavated_variants.ExcavatedVariants) ResourceLocation(net.minecraft.resources.ResourceLocation) PlacedFeature(net.minecraft.world.level.levelgen.placement.PlacedFeature)

Example 5 with PlacedFeature

use of net.minecraft.world.level.levelgen.placement.PlacedFeature in project excavated_variants by lukebemish.

the class MainPlatformTargetImpl method registerFeatures.

public void registerFeatures() {
    if (ORE_REPLACER == null) {
        ORE_REPLACER = new OreReplacer();
    }
    if (ORE_REPLACER_CONFIGURED == null) {
        ORE_REPLACER_CONFIGURED = new ConfiguredFeature<>(ORE_REPLACER, FeatureConfiguration.NONE);
    }
    if (ORE_REPLACER_PLACED == null) {
        ORE_REPLACER_PLACED = new PlacedFeature(Holder.direct(ORE_REPLACER_CONFIGURED), List.of());
    }
    Registry.register(Registry.FEATURE, new ResourceLocation(ExcavatedVariants.MOD_ID, "ore_replacer"), ORE_REPLACER);
    Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new ResourceLocation(ExcavatedVariants.MOD_ID, "ore_replacer"), ORE_REPLACER_CONFIGURED);
    Registry.register(BuiltinRegistries.PLACED_FEATURE, new ResourceLocation(ExcavatedVariants.MOD_ID, "ore_replacer"), ORE_REPLACER_PLACED);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) OreReplacer(io.github.lukebemish.excavated_variants.worldgen.OreReplacer) PlacedFeature(net.minecraft.world.level.levelgen.placement.PlacedFeature)

Aggregations

PlacedFeature (net.minecraft.world.level.levelgen.placement.PlacedFeature)23 ResourceLocation (net.minecraft.resources.ResourceLocation)9 BlockPos (net.minecraft.core.BlockPos)7 BlockState (net.minecraft.world.level.block.state.BlockState)6 OreConfiguration (net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration)4 ArrayList (java.util.ArrayList)3 ChunkGenerator (net.minecraft.world.level.chunk.ChunkGenerator)3 NoisySphereConfig (potionstudios.byg.common.world.feature.config.NoisySphereConfig)3 Pair (com.mojang.datafixers.util.Pair)2 Codec (com.mojang.serialization.Codec)2 ExcavatedVariants (io.github.lukebemish.excavated_variants.ExcavatedVariants)2 OreReplacer (io.github.lukebemish.excavated_variants.worldgen.OreReplacer)2 List (java.util.List)2 Random (java.util.Random)2 Holder (net.minecraft.core.Holder)2 WorldGenLevel (net.minecraft.world.level.WorldGenLevel)2 PlacementModifier (net.minecraft.world.level.levelgen.placement.PlacementModifier)2 RadiusMatcher (potionstudios.byg.common.world.feature.config.RadiusMatcher)2 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1