From d1190734bc04d83635b7119d3848835e9de5f9f6 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sun, 8 Sep 2024 10:42:44 -0700 Subject: [PATCH] Enchantment is data-driven, so not FeatureDependant (#11377) --- patches/api/Add-FeatureFlag-API.patch | 19 +++---------------- patches/server/Add-FeatureFlag-API.patch | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/patches/api/Add-FeatureFlag-API.patch b/patches/api/Add-FeatureFlag-API.patch index aab25ce997..e37e1a72f0 100644 --- a/patches/api/Add-FeatureFlag-API.patch +++ b/patches/api/Add-FeatureFlag-API.patch @@ -21,8 +21,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +/** + * Implemented by types in built-in registries that are controlled by {@link FeatureFlag FeatureFlags}. + * Types in data-driven registries that are controlled by feature flags just will not exist in that registry. ++ * @apiNote When a type that currently implements this interface transitions to being data-drive, this ++ * interface will be removed from that type in the following major version. + */ -+@ApiStatus.Experimental +@ApiStatus.NonExtendable +public interface FeatureDependant { + @@ -79,7 +80,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * Implemented by types that hold {@link FeatureFlag FeatureFlags} like + * {@link org.bukkit.generator.WorldInfo} and {@link org.bukkit.RegionAccessor}. + */ -+@ApiStatus.Experimental +@ApiStatus.NonExtendable +public interface FeatureFlagSetHolder { + @@ -121,7 +121,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 - * Flags which are unavailable in the current version will be null and/or - * removed. */ - @ApiStatus.Experimental +-@ApiStatus.Experimental public interface FeatureFlag extends Keyed { - public static final FeatureFlag VANILLA = Bukkit.getUnsafe().getFeatureFlag(NamespacedKey.minecraft("vanilla")); @@ -253,19 +253,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 /** * Typed represents a subtype of {@link BlockType}s that have a known block -diff --git a/src/main/java/org/bukkit/enchantments/Enchantment.java b/src/main/java/org/bukkit/enchantments/Enchantment.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/org/bukkit/enchantments/Enchantment.java -+++ b/src/main/java/org/bukkit/enchantments/Enchantment.java -@@ -0,0 +0,0 @@ import org.jetbrains.annotations.Nullable; - /** - * The various type of enchantments that may be added to armour or weapons - */ --public abstract class Enchantment implements Keyed, Translatable, net.kyori.adventure.translation.Translatable { // Paper - Adventure translations -+public abstract class Enchantment implements Keyed, Translatable, net.kyori.adventure.translation.Translatable, io.papermc.paper.world.flag.FeatureDependant { // Paper - Adventure translations & feature flag API - /** - * Provides protection against environmental damage - */ diff --git a/src/main/java/org/bukkit/entity/EntityType.java b/src/main/java/org/bukkit/entity/EntityType.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/entity/EntityType.java diff --git a/patches/server/Add-FeatureFlag-API.patch b/patches/server/Add-FeatureFlag-API.patch index 7f4324c6c2..6e1d529acc 100644 --- a/patches/server/Add-FeatureFlag-API.patch +++ b/patches/server/Add-FeatureFlag-API.patch @@ -320,8 +320,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import io.papermc.paper.registry.PaperRegistries; +import io.papermc.paper.registry.RegistryAccess; +import io.papermc.paper.registry.RegistryKey; ++import io.papermc.paper.registry.entry.RegistryEntry; +import java.util.HashSet; +import java.util.Set; ++import java.util.stream.Stream; +import net.kyori.adventure.key.Key; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceKey; @@ -338,6 +340,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; ++import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; @@ -385,11 +388,28 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + @MethodSource("featureFilteredRegistries") + @ParameterizedTest -+ void testFeatureDependent(final RegistryKey registryKey) { ++ void testApiImplementsFeatureDependant(final RegistryKey registryKey) { + final org.bukkit.Registry registry = RegistryAccess.registryAccess().getRegistry(registryKey); + final T anyElement = registry.iterator().next(); + assertInstanceOf(FeatureDependant.class, anyElement, "Registry " + registryKey + " doesn't have feature dependent elements"); + final FeatureDependant dependant = ((FeatureDependant) anyElement); + assertDoesNotThrow(dependant::requiredFeatures, "Failed to get required features for " + anyElement + " in " + registryKey); + } ++ ++ static Stream> nonFeatureFilteredRegistries() { ++ return AbstractTestingBase.REGISTRY_CUSTOM.registries().filter(r -> { ++ final RegistryEntry entry = PaperRegistries.getEntry(r.key()); ++ // has an API registry and isn't a filtered registry ++ return entry != null && !FeatureElement.FILTERED_REGISTRIES.contains(r.key()); ++ }).map(r -> PaperRegistries.getEntry(r.key()).apiKey()); ++ } ++ ++ ++ @MethodSource("nonFeatureFilteredRegistries") ++ @ParameterizedTest ++ void testApiDoesntImplementFeatureDependant(final RegistryKey registryKey) { ++ final org.bukkit.Registry registry = RegistryAccess.registryAccess().getRegistry(registryKey); ++ final T anyElement = registry.iterator().next(); ++ assertFalse(anyElement instanceof FeatureDependant, "Registry " + registryKey + " has feature dependent elements"); ++ } +}