/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.google.common.base.Suppliers * com.google.common.collect.ImmutableList * com.google.common.collect.Lists * com.mojang.datafixers.kinds.App * com.mojang.datafixers.kinds.Applicative * com.mojang.logging.LogUtils * com.mojang.serialization.MapCodec * com.mojang.serialization.codecs.RecordCodecBuilder * org.slf4j.Logger */ package net.minecraft.world.level.biome; import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.mojang.datafixers.kinds.App; import com.mojang.datafixers.kinds.Applicative; import com.mojang.logging.LogUtils; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.function.Supplier; import java.util.stream.Collectors; import net.minecraft.core.Holder; import net.minecraft.core.HolderGetter; import net.minecraft.core.HolderSet; import net.minecraft.resources.ResourceKey; import net.minecraft.util.Util; import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.Feature; import net.minecraft.world.level.levelgen.placement.PlacedFeature; import org.slf4j.Logger; public class BiomeGenerationSettings { private static final Logger LOGGER = LogUtils.getLogger(); public static final BiomeGenerationSettings EMPTY = new BiomeGenerationSettings(HolderSet.direct(new Holder[0]), List.of()); public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(i -> i.group((App)ConfiguredWorldCarver.LIST_CODEC.promotePartial(Util.prefix("Carver: ", arg_0 -> ((Logger)LOGGER).error(arg_0))).fieldOf("carvers").forGetter(b -> b.carvers), (App)PlacedFeature.LIST_OF_LISTS_CODEC.promotePartial(Util.prefix("Features: ", arg_0 -> ((Logger)LOGGER).error(arg_0))).fieldOf("features").forGetter(b -> b.features)).apply((Applicative)i, BiomeGenerationSettings::new)); private final HolderSet> carvers; private final List> features; private final Supplier>> flowerFeatures; private final Supplier> featureSet; private BiomeGenerationSettings(HolderSet> carvers, List> features) { this.carvers = carvers; this.features = features; this.flowerFeatures = Suppliers.memoize(() -> (List)features.stream().flatMap(HolderSet::stream).map(Holder::value).flatMap(PlacedFeature::getFeatures).filter(f -> f.feature() == Feature.FLOWER).collect(ImmutableList.toImmutableList())); this.featureSet = Suppliers.memoize(() -> features.stream().flatMap(HolderSet::stream).map(Holder::value).collect(Collectors.toSet())); } public Iterable>> getCarvers() { return this.carvers; } public List> getFlowerFeatures() { return this.flowerFeatures.get(); } public List> features() { return this.features; } public boolean hasFeature(PlacedFeature feature) { return this.featureSet.get().contains(feature); } public static class Builder extends PlainBuilder { private final HolderGetter placedFeatures; private final HolderGetter> worldCarvers; public Builder(HolderGetter placedFeatures, HolderGetter> worldCarvers) { this.placedFeatures = placedFeatures; this.worldCarvers = worldCarvers; } public Builder addFeature(GenerationStep.Decoration step, ResourceKey feature) { this.addFeature(step.ordinal(), this.placedFeatures.getOrThrow(feature)); return this; } public Builder addCarver(ResourceKey> carver) { this.addCarver(this.worldCarvers.getOrThrow(carver)); return this; } } public static class PlainBuilder { private final List>> carvers = new ArrayList(); private final List>> features = new ArrayList>>(); public PlainBuilder addFeature(GenerationStep.Decoration step, Holder feature) { return this.addFeature(step.ordinal(), feature); } public PlainBuilder addFeature(int index, Holder feature) { this.addFeatureStepsUpTo(index); this.features.get(index).add(feature); return this; } public PlainBuilder addCarver(Holder> carver) { this.carvers.add(carver); return this; } private void addFeatureStepsUpTo(int index) { while (this.features.size() <= index) { this.features.add(Lists.newArrayList()); } } public BiomeGenerationSettings build() { return new BiomeGenerationSettings(HolderSet.direct(this.carvers), (List)this.features.stream().map(HolderSet::direct).collect(ImmutableList.toImmutableList())); } } }