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;
}
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;
}
}
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);
}
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();
}
}
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);
}
Aggregations