/* * Decompiled with CFR 0.152. */ package net.minecraft.data.worldgen.placement; import java.util.List; import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; import net.minecraft.core.registries.Registries; import net.minecraft.data.worldgen.BootstrapContext; import net.minecraft.data.worldgen.placement.AquaticPlacements; import net.minecraft.data.worldgen.placement.CavePlacements; import net.minecraft.data.worldgen.placement.EndPlacements; import net.minecraft.data.worldgen.placement.MiscOverworldPlacements; import net.minecraft.data.worldgen.placement.NetherPlacements; import net.minecraft.data.worldgen.placement.OrePlacements; import net.minecraft.data.worldgen.placement.TreePlacements; import net.minecraft.data.worldgen.placement.VegetationPlacements; import net.minecraft.data.worldgen.placement.VillagePlacements; import net.minecraft.resources.Identifier; import net.minecraft.resources.ResourceKey; import net.minecraft.util.random.WeightedList; import net.minecraft.util.valueproviders.ConstantInt; import net.minecraft.util.valueproviders.IntProvider; import net.minecraft.util.valueproviders.WeightedListInt; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.levelgen.Heightmap; import net.minecraft.world.level.levelgen.VerticalAnchor; import net.minecraft.world.level.levelgen.blockpredicates.BlockPredicate; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.Feature; import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; import net.minecraft.world.level.levelgen.placement.BlockPredicateFilter; import net.minecraft.world.level.levelgen.placement.CountPlacement; import net.minecraft.world.level.levelgen.placement.HeightRangePlacement; import net.minecraft.world.level.levelgen.placement.HeightmapPlacement; import net.minecraft.world.level.levelgen.placement.PlacedFeature; import net.minecraft.world.level.levelgen.placement.PlacementFilter; import net.minecraft.world.level.levelgen.placement.PlacementModifier; public class PlacementUtils { public static final PlacementModifier HEIGHTMAP = HeightmapPlacement.onHeightmap(Heightmap.Types.MOTION_BLOCKING); public static final PlacementModifier HEIGHTMAP_NO_LEAVES = HeightmapPlacement.onHeightmap(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES); public static final PlacementModifier HEIGHTMAP_TOP_SOLID = HeightmapPlacement.onHeightmap(Heightmap.Types.OCEAN_FLOOR_WG); public static final PlacementModifier HEIGHTMAP_WORLD_SURFACE = HeightmapPlacement.onHeightmap(Heightmap.Types.WORLD_SURFACE_WG); public static final PlacementModifier HEIGHTMAP_OCEAN_FLOOR = HeightmapPlacement.onHeightmap(Heightmap.Types.OCEAN_FLOOR); public static final PlacementModifier FULL_RANGE = HeightRangePlacement.uniform(VerticalAnchor.bottom(), VerticalAnchor.top()); public static final PlacementModifier RANGE_10_10 = HeightRangePlacement.uniform(VerticalAnchor.aboveBottom(10), VerticalAnchor.belowTop(10)); public static final PlacementModifier RANGE_8_8 = HeightRangePlacement.uniform(VerticalAnchor.aboveBottom(8), VerticalAnchor.belowTop(8)); public static final PlacementModifier RANGE_4_4 = HeightRangePlacement.uniform(VerticalAnchor.aboveBottom(4), VerticalAnchor.belowTop(4)); public static final PlacementModifier RANGE_BOTTOM_TO_MAX_TERRAIN_HEIGHT = HeightRangePlacement.uniform(VerticalAnchor.bottom(), VerticalAnchor.absolute(256)); public static void bootstrap(BootstrapContext context) { AquaticPlacements.bootstrap(context); CavePlacements.bootstrap(context); EndPlacements.bootstrap(context); MiscOverworldPlacements.bootstrap(context); NetherPlacements.bootstrap(context); OrePlacements.bootstrap(context); TreePlacements.bootstrap(context); VegetationPlacements.bootstrap(context); VillagePlacements.bootstrap(context); } public static ResourceKey createKey(String name) { return ResourceKey.create(Registries.PLACED_FEATURE, Identifier.withDefaultNamespace(name)); } public static void register(BootstrapContext context, ResourceKey id, Holder> feature, List placementModifiers) { context.register(id, new PlacedFeature(feature, List.copyOf(placementModifiers))); } public static void register(BootstrapContext context, ResourceKey id, Holder> feature, PlacementModifier ... placementModifiers) { PlacementUtils.register(context, id, feature, List.of(placementModifiers)); } public static PlacementModifier countExtra(int count, float chance, int extra) { float weight = 1.0f / chance; if (Math.abs(weight - (float)((int)weight)) > 1.0E-5f) { throw new IllegalStateException("Chance data cannot be represented as list weight"); } WeightedList distribution = WeightedList.builder().add(ConstantInt.of(count), (int)weight - 1).add(ConstantInt.of(count + extra), 1).build(); return CountPlacement.of(new WeightedListInt(distribution)); } public static PlacementFilter isEmpty() { return BlockPredicateFilter.forPredicate(BlockPredicate.ONLY_IN_AIR_PREDICATE); } public static BlockPredicateFilter filteredByBlockSurvival(Block block) { return BlockPredicateFilter.forPredicate(BlockPredicate.wouldSurvive(block.defaultBlockState(), BlockPos.ZERO)); } public static Holder inlinePlaced(Holder> configuredFeature, PlacementModifier ... placedFeatures) { return Holder.direct(new PlacedFeature(configuredFeature, List.of(placedFeatures))); } public static > Holder inlinePlaced(F feature, FC config, PlacementModifier ... placedFeatures) { return PlacementUtils.inlinePlaced(Holder.direct(new ConfiguredFeature(feature, config)), placedFeatures); } public static > Holder onlyWhenEmpty(F feature, FC config) { return PlacementUtils.filtered(feature, config, BlockPredicate.ONLY_IN_AIR_PREDICATE); } public static > Holder filtered(F feature, FC config, BlockPredicate predicate) { return PlacementUtils.inlinePlaced(feature, config, BlockPredicateFilter.forPredicate(predicate)); } }