mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-28 03:56:59 -05:00
Add docs and util methods from #104 on top of previous PR
(I **completely** forgot I already implemented this for 1.16...) Signed-off-by: Max <maxh2709@gmail.com>
This commit is contained in:
@@ -362,6 +362,11 @@ public final class BiomeHooks {
|
||||
return settings.getCarvers(carving);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Supplier<PlacedFeature>> getFeatures(GenerationStep.Decoration decoration) {
|
||||
return settings.features().get(decoration.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<List<Supplier<PlacedFeature>>> getFeatures() {
|
||||
return settings.features();
|
||||
|
||||
@@ -30,6 +30,8 @@ import java.util.function.Supplier;
|
||||
public interface GenerationProperties {
|
||||
List<Supplier<ConfiguredWorldCarver<?>>> getCarvers(GenerationStep.Carving carving);
|
||||
|
||||
List<Supplier<PlacedFeature>> getFeatures(GenerationStep.Decoration decoration);
|
||||
|
||||
List<List<Supplier<PlacedFeature>>> getFeatures();
|
||||
|
||||
interface Mutable extends GenerationProperties {
|
||||
|
||||
@@ -27,6 +27,27 @@ import net.minecraft.resources.ResourceLocation;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* This class provides a cross-platform API to modify Biome features and properties.
|
||||
*
|
||||
* <p> Changes to the biomes are hereby done in four distinct "phases", akin to Fabric API's
|
||||
* {@link net.fabricmc.fabric.api.biome.v1.ModificationPhase} enum.
|
||||
*
|
||||
* <p> The order in which these phases get processed is as follows,
|
||||
* with the corresponding Forge EventPriority shown in brackets:
|
||||
*
|
||||
* <ol>
|
||||
* <li>{@linkplain #addProperties(Predicate, BiConsumer) Adding} new features to biomes. [HIGH]</li>
|
||||
* <li>{@linkplain #removeProperties(Predicate, BiConsumer) Removing} existing features from biomes. [NORMAL]</li>
|
||||
* <li>{@linkplain #replaceProperties(Predicate, BiConsumer) Replacing} existing features with new ones. [LOW]</li>
|
||||
* <li>Generic {@linkplain #postProcessProperties(Predicate, BiConsumer) Post-Processing} of already modified biome features. [LOWEST]</li>
|
||||
* </ol>
|
||||
*
|
||||
* Keep in mind that it isn't strictly <b>required</b> that you use these phases accordingly
|
||||
* (i.e., you may also add features during Post-Processing, for example); they mostly serve to
|
||||
* add a predictable order to biome modifications.
|
||||
*/
|
||||
@SuppressWarnings("JavadocReference")
|
||||
public final class BiomeModifications {
|
||||
public static void addProperties(BiConsumer<BiomeContext, BiomeProperties.Mutable> modifier) {
|
||||
BiomeModifications.addProperties(Predicates.alwaysTrue(), modifier);
|
||||
|
||||
@@ -153,7 +153,12 @@ public class BiomeModificationsImpl {
|
||||
public @NotNull List<Supplier<ConfiguredWorldCarver<?>>> getCarvers(GenerationStep.Carving carving) {
|
||||
return generation.getCarvers(carving);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Supplier<PlacedFeature>> getFeatures(GenerationStep.Decoration decoration) {
|
||||
return generation.getFeatures(decoration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<List<Supplier<PlacedFeature>>> getFeatures() {
|
||||
return generation.features;
|
||||
@@ -372,29 +377,29 @@ public class BiomeModificationsImpl {
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
public static void applyAdditions(BiomeLoadingEvent event) {
|
||||
modifyForPhase(event, ADDITIONS);
|
||||
public static void processAdditions(BiomeLoadingEvent event) {
|
||||
modifyBiome(event, ADDITIONS);
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.NORMAL)
|
||||
public static void applyRemovals(BiomeLoadingEvent event) {
|
||||
modifyForPhase(event, REMOVALS);
|
||||
public static void processRemovals(BiomeLoadingEvent event) {
|
||||
modifyBiome(event, REMOVALS);
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOW)
|
||||
public static void applyReplacements(BiomeLoadingEvent event) {
|
||||
modifyForPhase(event, REPLACEMENTS);
|
||||
public static void processReplacements(BiomeLoadingEvent event) {
|
||||
modifyBiome(event, REPLACEMENTS);
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
public static void applyPostProcessing(BiomeLoadingEvent event) {
|
||||
modifyForPhase(event, POST_PROCESSING);
|
||||
public static void postProcessBiomes(BiomeLoadingEvent event) {
|
||||
modifyBiome(event, POST_PROCESSING);
|
||||
}
|
||||
|
||||
private static void modifyForPhase(BiomeLoadingEvent event, List<Pair<Predicate<BiomeContext>, BiConsumer<BiomeContext, BiomeProperties.Mutable>>> phase) {
|
||||
private static void modifyBiome(BiomeLoadingEvent event, List<Pair<Predicate<BiomeContext>, BiConsumer<BiomeContext, BiomeProperties.Mutable>>> list) {
|
||||
BiomeContext biomeContext = wrapSelectionContext(event);
|
||||
BiomeProperties.Mutable mutableBiome = new MutableBiomeWrapped(event);
|
||||
for (var pair : phase) {
|
||||
for (var pair : list) {
|
||||
if (pair.getLeft().test(biomeContext)) {
|
||||
pair.getRight().accept(biomeContext, mutableBiome);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user