diff --git a/paper-api-generator/generated/io/papermc/paper/registry/keys/BiomeKeys.java b/paper-api-generator/generated/io/papermc/paper/registry/keys/BiomeKeys.java index fc62be44d6..3bd15016b0 100644 --- a/paper-api-generator/generated/io/papermc/paper/registry/keys/BiomeKeys.java +++ b/paper-api-generator/generated/io/papermc/paper/registry/keys/BiomeKeys.java @@ -6,7 +6,6 @@ import io.papermc.paper.generated.GeneratedFrom; import io.papermc.paper.registry.RegistryKey; import io.papermc.paper.registry.TypedKey; import net.kyori.adventure.key.Key; -import org.bukkit.MinecraftExperimental; import org.bukkit.block.Biome; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -249,8 +248,6 @@ public final class BiomeKeys { * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - @ApiStatus.Experimental - @MinecraftExperimental(MinecraftExperimental.Requires.UPDATE_1_21) public static final TypedKey MANGROVE_SWAMP = create(key("mangrove_swamp")); /** @@ -405,8 +402,6 @@ public final class BiomeKeys { * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - @ApiStatus.Experimental - @MinecraftExperimental(MinecraftExperimental.Requires.UPDATE_1_21) public static final TypedKey SWAMP = create(key("swamp")); /** diff --git a/paper-api-generator/src/main/java/io/papermc/generator/types/GeneratedKeyType.java b/paper-api-generator/src/main/java/io/papermc/generator/types/GeneratedKeyType.java index ba27aa640d..66c4a4b14f 100644 --- a/paper-api-generator/src/main/java/io/papermc/generator/types/GeneratedKeyType.java +++ b/paper-api-generator/src/main/java/io/papermc/generator/types/GeneratedKeyType.java @@ -1,5 +1,6 @@ package io.papermc.generator.types; +import com.google.common.collect.Sets; import com.squareup.javapoet.FieldSpec; import com.squareup.javapoet.JavaFile; import com.squareup.javapoet.MethodSpec; @@ -16,17 +17,18 @@ import io.papermc.paper.registry.RegistryKey; import io.papermc.paper.registry.TypedKey; import java.lang.reflect.Field; import java.lang.reflect.Modifier; -import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.List; +import java.util.IdentityHashMap; import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; import net.kyori.adventure.key.Key; import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.core.RegistrySetBuilder; import net.minecraft.data.registries.UpdateOneTwentyOneRegistries; +import net.minecraft.data.registries.VanillaRegistries; import net.minecraft.resources.ResourceKey; import org.bukkit.MinecraftExperimental; import org.checkerframework.checker.nullness.qual.NonNull; @@ -46,6 +48,9 @@ import static javax.lang.model.element.Modifier.STATIC; @DefaultQualifier(NonNull.class) public class GeneratedKeyType extends SimpleGenerator { + private static final Map>, RegistrySetBuilder.RegistryBootstrap> VANILLA_REGISTRY_ENTRIES = VanillaRegistries.BUILDER.entries.stream() + .collect(Collectors.toMap(RegistrySetBuilder.RegistryStub::key, RegistrySetBuilder.RegistryStub::bootstrap)); + private static final Map>, RegistrySetBuilder.RegistryBootstrap> EXPERIMENTAL_REGISTRY_ENTRIES = UpdateOneTwentyOneRegistries.BUILDER.entries.stream() .collect(Collectors.toMap(RegistrySetBuilder.RegistryStub::key, RegistrySetBuilder.RegistryStub::bootstrap)); @@ -120,7 +125,7 @@ public class GeneratedKeyType extends SimpleGenerator { final MethodSpec.Builder createMethod = this.createMethod(typedKey); final Registry registry = Main.REGISTRY_ACCESS.registryOrThrow(this.registryKey); - final List> experimental = this.collectExperimentalKeys(registry); + final Set> experimental = this.collectExperimentalKeys(registry); boolean allExperimental = true; for (final Holder.Reference reference : registry.holders().sorted(Formatting.alphabeticKeyOrder(reference -> reference.key().location().getPath())).toList()) { @@ -147,19 +152,27 @@ public class GeneratedKeyType extends SimpleGenerator { } @SuppressWarnings("unchecked") - private List> collectExperimentalKeys(final Registry registry) { - final RegistrySetBuilder.@Nullable RegistryBootstrap registryBootstrap = (RegistrySetBuilder.RegistryBootstrap) EXPERIMENTAL_REGISTRY_ENTRIES.get(this.registryKey); - if (registryBootstrap == null) { - return Collections.emptyList(); + private Set> collectExperimentalKeys(final Registry registry) { + final RegistrySetBuilder.@Nullable RegistryBootstrap experimentalBootstrap = (RegistrySetBuilder.RegistryBootstrap) EXPERIMENTAL_REGISTRY_ENTRIES.get(this.registryKey); + if (experimentalBootstrap == null) { + return Collections.emptySet(); + } + final Set> experimental = Collections.newSetFromMap(new IdentityHashMap<>()); + final CollectingContext experimentalCollector = new CollectingContext<>(experimental, registry); + experimentalBootstrap.run(experimentalCollector); + + final RegistrySetBuilder.@Nullable RegistryBootstrap vanillaBootstrap = (RegistrySetBuilder.RegistryBootstrap) VANILLA_REGISTRY_ENTRIES.get(this.registryKey); + if (vanillaBootstrap != null) { + final Set> vanilla = Collections.newSetFromMap(new IdentityHashMap<>()); + final CollectingContext vanillaCollector = new CollectingContext<>(vanilla, registry); + vanillaBootstrap.run(vanillaCollector); + return Sets.difference(experimental, vanilla); } - final List> experimental = new ArrayList<>(); - final CollectingContext context = new CollectingContext<>(experimental, registry); - registryBootstrap.run(context); return experimental; } @Override - protected JavaFile.Builder file(JavaFile.Builder builder) { + protected JavaFile.Builder file(final JavaFile.Builder builder) { return builder .skipJavaLangImports(true) .addStaticImport(Key.class, "key") diff --git a/paper-api-generator/src/main/java/io/papermc/generator/utils/CollectingContext.java b/paper-api-generator/src/main/java/io/papermc/generator/utils/CollectingContext.java index 614babf9e0..15cb4ac3e7 100644 --- a/paper-api-generator/src/main/java/io/papermc/generator/utils/CollectingContext.java +++ b/paper-api-generator/src/main/java/io/papermc/generator/utils/CollectingContext.java @@ -3,6 +3,7 @@ package io.papermc.generator.utils; import com.mojang.serialization.Lifecycle; import io.papermc.generator.Main; import java.util.List; +import java.util.Set; import net.minecraft.core.Holder; import net.minecraft.core.HolderGetter; import net.minecraft.core.Registry; @@ -12,7 +13,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.framework.qual.DefaultQualifier; @DefaultQualifier(NonNull.class) -public record CollectingContext(List> registered, +public record CollectingContext(Set> registered, Registry registry) implements BootstrapContext { @Override diff --git a/paper-api-generator/wideners.at b/paper-api-generator/wideners.at index 54524a165e..6928316973 100644 --- a/paper-api-generator/wideners.at +++ b/paper-api-generator/wideners.at @@ -4,3 +4,4 @@ public net/minecraft/server/WorldLoader loadAndReplaceLayer(Lnet/minecraft/serve public net/minecraft/core/RegistrySetBuilder entries public net/minecraft/core/RegistrySetBuilder$RegistryStub public net/minecraft/data/registries/UpdateOneTwentyOneRegistries BUILDER +public net/minecraft/data/registries/VanillaRegistries BUILDER