BiomeModifications.java 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * This file is part of architectury.
  3. * Copyright (C) 2020, 2021 architectury
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 3 of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with this program; if not, write to the Free Software Foundation,
  17. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. package me.shedaniel.architectury.registry;
  20. import com.google.common.base.Predicates;
  21. import me.shedaniel.architectury.annotations.ExpectPlatform;
  22. import me.shedaniel.architectury.hooks.biome.BiomeProperties;
  23. import net.minecraft.resources.ResourceLocation;
  24. import java.util.function.BiConsumer;
  25. import java.util.function.Predicate;
  26. /**
  27. * This class provides a cross-platform API to modify Biome features and properties.
  28. *
  29. * <p> Changes to the biomes are hereby done in four distinct "phases", akin to Fabric API's
  30. * {@link net.fabricmc.fabric.api.biome.v1.ModificationPhase} enum.
  31. *
  32. * <p> The order in which these phases get processed is as follows,
  33. * with the corresponding Forge EventPriority shown in brackets:
  34. *
  35. * <ol>
  36. * <li>{@link #addProperties(Predicate, BiConsumer) Adding} new features to biomes. [HIGH]</li>
  37. * <li>{@link #removeProperties(Predicate, BiConsumer) Removing} existing features from biomes. [NORMAL]</li>
  38. * <li>{@link #replaceProperties(Predicate, BiConsumer) Replacing} existing features with new ones. [LOW]</li>
  39. * <li>Generic {@link #postProcessProperties(Predicate, BiConsumer) Post-Processing} of already modified biome features. [LOWEST]</li>
  40. * </ol>
  41. *
  42. * Keep in mind that it isn't strictly <b>required</b> that you use these phases accordingly
  43. * (i.e., you may also add features during Post-Processing, for example); they mostly serve to
  44. * add a predictable order to biome modifications.
  45. */
  46. public final class BiomeModifications {
  47. public static void addProperties(BiConsumer<BiomeContext, BiomeProperties.Mutable> modifier) {
  48. BiomeModifications.addProperties(Predicates.alwaysTrue(), modifier);
  49. }
  50. @ExpectPlatform
  51. public static void addProperties(Predicate<BiomeContext> predicate, BiConsumer<BiomeContext, BiomeProperties.Mutable> modifier) {
  52. throw new AssertionError();
  53. }
  54. public static void postProcessProperties(BiConsumer<BiomeContext, BiomeProperties.Mutable> modifier) {
  55. BiomeModifications.postProcessProperties(Predicates.alwaysTrue(), modifier);
  56. }
  57. @ExpectPlatform
  58. public static void postProcessProperties(Predicate<BiomeContext> predicate, BiConsumer<BiomeContext, BiomeProperties.Mutable> modifier) {
  59. throw new AssertionError();
  60. }
  61. public static void removeProperties(BiConsumer<BiomeContext, BiomeProperties.Mutable> modifier) {
  62. BiomeModifications.removeProperties(Predicates.alwaysTrue(), modifier);
  63. }
  64. @ExpectPlatform
  65. public static void removeProperties(Predicate<BiomeContext> predicate, BiConsumer<BiomeContext, BiomeProperties.Mutable> modifier) {
  66. throw new AssertionError();
  67. }
  68. public static void replaceProperties(BiConsumer<BiomeContext, BiomeProperties.Mutable> modifier) {
  69. BiomeModifications.replaceProperties(Predicates.alwaysTrue(), modifier);
  70. }
  71. @ExpectPlatform
  72. public static void replaceProperties(Predicate<BiomeContext> predicate, BiConsumer<BiomeContext, BiomeProperties.Mutable> modifier) {
  73. throw new AssertionError();
  74. }
  75. public interface BiomeContext {
  76. ResourceLocation getKey();
  77. BiomeProperties getProperties();
  78. }
  79. }