mirror of https://github.com/PaperMC/Paper.git
Biome, Pose, Sound
This commit is contained in:
parent
484827f463
commit
359ae082f3
|
@ -1,7 +1,6 @@
|
|||
package org.bukkit;
|
||||
|
||||
import io.papermc.paper.generated.GeneratedFrom;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -1060,7 +1059,7 @@ public enum Sound implements Keyed, net.kyori.adventure.sound.Sound.Type {
|
|||
|
||||
BLOCK_POLISHED_DEEPSLATE_STEP("block.polished_deepslate.step"),
|
||||
|
||||
@ApiStatus.Experimental
|
||||
@ApiStatus.Experimental
|
||||
@MinecraftExperimental
|
||||
BLOCK_POLISHED_TUFF_BREAK("block.polished_tuff.break"),
|
||||
|
||||
|
@ -3208,12 +3207,6 @@ public enum Sound implements Keyed, net.kyori.adventure.sound.Sound.Type {
|
|||
this.key = NamespacedKey.minecraft(key);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Key key() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public NamespacedKey getKey() {
|
||||
|
|
|
@ -0,0 +1,171 @@
|
|||
package org.bukkit.block;
|
||||
|
||||
import io.papermc.paper.generated.GeneratedFrom;
|
||||
import net.kyori.adventure.translation.Translatable;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Vanilla keys for Biomes.
|
||||
*
|
||||
* @apiNote The fields provided here are a direct representation of
|
||||
* what is available from the vanilla game source. They may be
|
||||
* changed (including removals) on any Minecraft version
|
||||
* bump, so cross-version compatibility is not provided on the
|
||||
* same level as it is on most of the other API.
|
||||
*/
|
||||
@SuppressWarnings({
|
||||
"unused",
|
||||
"SpellCheckingInspection"
|
||||
})
|
||||
@GeneratedFrom("1.20.4")
|
||||
public enum Biome implements Keyed, Translatable {
|
||||
BADLANDS("badlands"),
|
||||
|
||||
BAMBOO_JUNGLE("bamboo_jungle"),
|
||||
|
||||
BASALT_DELTAS("basalt_deltas"),
|
||||
|
||||
BEACH("beach"),
|
||||
|
||||
BIRCH_FOREST("birch_forest"),
|
||||
|
||||
CHERRY_GROVE("cherry_grove"),
|
||||
|
||||
COLD_OCEAN("cold_ocean"),
|
||||
|
||||
CRIMSON_FOREST("crimson_forest"),
|
||||
|
||||
DARK_FOREST("dark_forest"),
|
||||
|
||||
DEEP_COLD_OCEAN("deep_cold_ocean"),
|
||||
|
||||
DEEP_DARK("deep_dark"),
|
||||
|
||||
DEEP_FROZEN_OCEAN("deep_frozen_ocean"),
|
||||
|
||||
DEEP_LUKEWARM_OCEAN("deep_lukewarm_ocean"),
|
||||
|
||||
DEEP_OCEAN("deep_ocean"),
|
||||
|
||||
DESERT("desert"),
|
||||
|
||||
DRIPSTONE_CAVES("dripstone_caves"),
|
||||
|
||||
END_BARRENS("end_barrens"),
|
||||
|
||||
END_HIGHLANDS("end_highlands"),
|
||||
|
||||
END_MIDLANDS("end_midlands"),
|
||||
|
||||
ERODED_BADLANDS("eroded_badlands"),
|
||||
|
||||
FLOWER_FOREST("flower_forest"),
|
||||
|
||||
FOREST("forest"),
|
||||
|
||||
FROZEN_OCEAN("frozen_ocean"),
|
||||
|
||||
FROZEN_PEAKS("frozen_peaks"),
|
||||
|
||||
FROZEN_RIVER("frozen_river"),
|
||||
|
||||
GROVE("grove"),
|
||||
|
||||
ICE_SPIKES("ice_spikes"),
|
||||
|
||||
JAGGED_PEAKS("jagged_peaks"),
|
||||
|
||||
JUNGLE("jungle"),
|
||||
|
||||
LUKEWARM_OCEAN("lukewarm_ocean"),
|
||||
|
||||
LUSH_CAVES("lush_caves"),
|
||||
|
||||
MANGROVE_SWAMP("mangrove_swamp"),
|
||||
|
||||
MEADOW("meadow"),
|
||||
|
||||
MUSHROOM_FIELDS("mushroom_fields"),
|
||||
|
||||
NETHER_WASTES("nether_wastes"),
|
||||
|
||||
OCEAN("ocean"),
|
||||
|
||||
OLD_GROWTH_BIRCH_FOREST("old_growth_birch_forest"),
|
||||
|
||||
OLD_GROWTH_PINE_TAIGA("old_growth_pine_taiga"),
|
||||
|
||||
OLD_GROWTH_SPRUCE_TAIGA("old_growth_spruce_taiga"),
|
||||
|
||||
PLAINS("plains"),
|
||||
|
||||
RIVER("river"),
|
||||
|
||||
SAVANNA("savanna"),
|
||||
|
||||
SAVANNA_PLATEAU("savanna_plateau"),
|
||||
|
||||
SMALL_END_ISLANDS("small_end_islands"),
|
||||
|
||||
SNOWY_BEACH("snowy_beach"),
|
||||
|
||||
SNOWY_PLAINS("snowy_plains"),
|
||||
|
||||
SNOWY_SLOPES("snowy_slopes"),
|
||||
|
||||
SNOWY_TAIGA("snowy_taiga"),
|
||||
|
||||
SOUL_SAND_VALLEY("soul_sand_valley"),
|
||||
|
||||
SPARSE_JUNGLE("sparse_jungle"),
|
||||
|
||||
STONY_PEAKS("stony_peaks"),
|
||||
|
||||
STONY_SHORE("stony_shore"),
|
||||
|
||||
SUNFLOWER_PLAINS("sunflower_plains"),
|
||||
|
||||
SWAMP("swamp"),
|
||||
|
||||
TAIGA("taiga"),
|
||||
|
||||
THE_END("the_end"),
|
||||
|
||||
THE_VOID("the_void"),
|
||||
|
||||
WARM_OCEAN("warm_ocean"),
|
||||
|
||||
WARPED_FOREST("warped_forest"),
|
||||
|
||||
WINDSWEPT_FOREST("windswept_forest"),
|
||||
|
||||
WINDSWEPT_GRAVELLY_HILLS("windswept_gravelly_hills"),
|
||||
|
||||
WINDSWEPT_HILLS("windswept_hills"),
|
||||
|
||||
WINDSWEPT_SAVANNA("windswept_savanna"),
|
||||
|
||||
WOODED_BADLANDS("wooded_badlands"),
|
||||
|
||||
CUSTOM("custom");
|
||||
|
||||
private NamespacedKey key;
|
||||
|
||||
Biome(String key) {
|
||||
this.key = NamespacedKey.minecraft(key);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public NamespacedKey getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String translationKey() {
|
||||
return "biome.minecraft." + this.key.getKey();
|
||||
}
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
package io.papermc.generator;
|
||||
|
||||
import io.papermc.generator.types.GeneratedKeyType;
|
||||
import io.papermc.generator.types.SoundGenerator;
|
||||
import io.papermc.generator.types.SourceGenerator;
|
||||
import io.papermc.generator.types.enumgen.BiomeGenerator;
|
||||
import io.papermc.generator.types.enumgen.PoseGenerator;
|
||||
import io.papermc.generator.types.enumgen.SoundGenerator;
|
||||
import io.papermc.generator.types.goal.MobGoalGenerator;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import net.minecraft.core.Registry;
|
||||
|
@ -35,7 +37,9 @@ public interface Generators {
|
|||
simpleKey("DamageTypeKeys", DamageType.class, Registries.DAMAGE_TYPE, RegistryKey.DAMAGE_TYPE, true),
|
||||
simpleKey("WolfVariantKeys", Wolf.Variant.class, Registries.WOLF_VARIANT, RegistryKey.WOLF_VARIANT, true),
|
||||
new MobGoalGenerator("VanillaGoal", "com.destroystokyo.paper.entity.ai"),
|
||||
new SoundGenerator("Sound", "org.bukkit")
|
||||
new SoundGenerator("Sound", "org.bukkit"),
|
||||
new BiomeGenerator("Biome", "org.bukkit.block"),
|
||||
new PoseGenerator("Pose", "org.bukkit.entity")
|
||||
};
|
||||
|
||||
private static <T, A> SourceGenerator simpleKey(final String className, final Class<A> apiType, final ResourceKey<? extends Registry<T>> registryKey, final RegistryKey<A> apiRegistryKey, final boolean publicCreateKeyMethod) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
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;
|
||||
|
@ -10,32 +9,22 @@ import com.squareup.javapoet.TypeName;
|
|||
import com.squareup.javapoet.TypeSpec;
|
||||
import io.papermc.generator.Main;
|
||||
import io.papermc.generator.utils.Annotations;
|
||||
import io.papermc.generator.utils.CollectingContext;
|
||||
import io.papermc.generator.utils.Formatting;
|
||||
import io.papermc.generator.utils.Javadocs;
|
||||
import io.papermc.generator.utils.RegistryUtils;
|
||||
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.Collections;
|
||||
import java.util.HashMap;
|
||||
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.HolderLookup;
|
||||
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 net.minecraft.world.flag.FeatureElement;
|
||||
import net.minecraft.world.flag.FeatureFlags;
|
||||
import org.bukkit.MinecraftExperimental;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
import static com.squareup.javapoet.TypeSpec.classBuilder;
|
||||
|
@ -51,12 +40,6 @@ import static javax.lang.model.element.Modifier.STATIC;
|
|||
@DefaultQualifier(NonNull.class)
|
||||
public class GeneratedKeyType<T, A> extends SimpleGenerator {
|
||||
|
||||
private static final Map<ResourceKey<? extends Registry<?>>, RegistrySetBuilder.RegistryBootstrap<?>> VANILLA_REGISTRY_ENTRIES = VanillaRegistries.BUILDER.entries.stream()
|
||||
.collect(Collectors.toMap(RegistrySetBuilder.RegistryStub::key, RegistrySetBuilder.RegistryStub::bootstrap));
|
||||
|
||||
private static final Map<ResourceKey<? extends Registry<?>>, RegistrySetBuilder.RegistryBootstrap<?>> EXPERIMENTAL_REGISTRY_ENTRIES = UpdateOneTwentyOneRegistries.BUILDER.entries.stream()
|
||||
.collect(Collectors.toMap(RegistrySetBuilder.RegistryStub::key, RegistrySetBuilder.RegistryStub::bootstrap));
|
||||
|
||||
private static final Map<RegistryKey<?>, String> REGISTRY_KEY_FIELD_NAMES;
|
||||
static {
|
||||
final Map<RegistryKey<?>, String> map = new HashMap<>();
|
||||
|
@ -128,7 +111,7 @@ public class GeneratedKeyType<T, A> extends SimpleGenerator {
|
|||
final MethodSpec.Builder createMethod = this.createMethod(typedKey);
|
||||
|
||||
final Registry<T> registry = Main.REGISTRY_ACCESS.registryOrThrow(this.registryKey);
|
||||
final Set<ResourceKey<T>> experimental = this.collectExperimentalKeys(registry);
|
||||
final Set<ResourceKey<T>> experimental = RegistryUtils.collectExperimentalDataDrivenKeys(registry);
|
||||
|
||||
boolean allExperimental = true;
|
||||
for (final Holder.Reference<T> reference : registry.holders().sorted(Formatting.alphabeticKeyOrder(reference -> reference.key().location().getPath())).toList()) {
|
||||
|
@ -154,41 +137,6 @@ public class GeneratedKeyType<T, A> extends SimpleGenerator {
|
|||
return typeBuilder.addMethod(createMethod.build()).build();
|
||||
}
|
||||
|
||||
private Set<ResourceKey<T>> collectExperimentalKeys(final Registry<T> registry) {
|
||||
if (FeatureElement.FILTERED_REGISTRIES.contains(registry.key())) {
|
||||
return this.collectExperimentalKeysBuiltIn(registry);
|
||||
} else {
|
||||
return this.collectExperimentalKeysDataDriven(registry);
|
||||
}
|
||||
}
|
||||
|
||||
private Set<ResourceKey<T>> collectExperimentalKeysBuiltIn(final Registry<T> registry) {
|
||||
final HolderLookup.RegistryLookup<T> filteredLookup = registry.asLookup().filterElements(v -> {
|
||||
return ((FeatureElement) v).requiredFeatures().contains(FeatureFlags.UPDATE_1_21);
|
||||
});
|
||||
return filteredLookup.listElementIds().collect(Collectors.toUnmodifiableSet());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Set<ResourceKey<T>> collectExperimentalKeysDataDriven(final Registry<T> registry) {
|
||||
final RegistrySetBuilder.@Nullable RegistryBootstrap<T> experimentalBootstrap = (RegistrySetBuilder.RegistryBootstrap<T>) EXPERIMENTAL_REGISTRY_ENTRIES.get(this.registryKey);
|
||||
if (experimentalBootstrap == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
final Set<ResourceKey<T>> experimental = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||
final CollectingContext<T> experimentalCollector = new CollectingContext<>(experimental, registry);
|
||||
experimentalBootstrap.run(experimentalCollector);
|
||||
|
||||
final RegistrySetBuilder.@Nullable RegistryBootstrap<T> vanillaBootstrap = (RegistrySetBuilder.RegistryBootstrap<T>) VANILLA_REGISTRY_ENTRIES.get(this.registryKey);
|
||||
if (vanillaBootstrap != null) {
|
||||
final Set<ResourceKey<T>> vanilla = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||
final CollectingContext<T> vanillaCollector = new CollectingContext<>(vanilla, registry);
|
||||
vanillaBootstrap.run(vanillaCollector);
|
||||
return Sets.difference(experimental, vanilla);
|
||||
}
|
||||
return experimental;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JavaFile.Builder file(final JavaFile.Builder builder) {
|
||||
return builder
|
||||
|
|
|
@ -2,7 +2,6 @@ package io.papermc.generator.types;
|
|||
|
||||
import com.squareup.javapoet.JavaFile;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
|
|
|
@ -1,115 +0,0 @@
|
|||
package io.papermc.generator.types;
|
||||
|
||||
import com.squareup.javapoet.FieldSpec;
|
||||
import com.squareup.javapoet.JavaFile;
|
||||
import com.squareup.javapoet.MethodSpec;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import io.papermc.generator.Main;
|
||||
import io.papermc.generator.utils.Annotations;
|
||||
import io.papermc.generator.utils.Formatting;
|
||||
import io.papermc.generator.utils.Javadocs;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.lang.model.element.Modifier;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class SoundGenerator extends SimpleGenerator {
|
||||
|
||||
private static final String CLASS_HEADER = Javadocs.getVersionDependentClassHeader("Sounds");
|
||||
private static final List<Pattern> EXPERIMENTAL_REGEX = of(
|
||||
"block.copper_door.*",
|
||||
"block.copper_bulb.*",
|
||||
"block.copper_grate.*",
|
||||
"block.copper_grate.*",
|
||||
"block.copper_trapdoor.*",
|
||||
"block.polished_tuff.*",
|
||||
"block.trial_spawner.*",
|
||||
"block.tuff_bricks.*",
|
||||
"block.crafter.*",
|
||||
"entity.breeze.*",
|
||||
"entity.generic.wind_burst",
|
||||
"item.bundle.*"
|
||||
);
|
||||
|
||||
public SoundGenerator(final String keysClassName, final String pkg) {
|
||||
super(keysClassName, pkg);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeSpec getTypeSpec() {
|
||||
TypeSpec.Builder typeBuilder = TypeSpec.enumBuilder(this.className)
|
||||
.addSuperinterface(Keyed.class)
|
||||
.addSuperinterface(Sound.Type.class)
|
||||
.addModifiers(Modifier.PUBLIC)
|
||||
.addAnnotations(Annotations.CLASS_HEADER)
|
||||
.addJavadoc(CLASS_HEADER);
|
||||
|
||||
Registry<SoundEvent> event = Main.REGISTRY_ACCESS.registryOrThrow(Registries.SOUND_EVENT);
|
||||
List<String> paths = new ArrayList<>();
|
||||
event.entrySet().forEach(key -> paths.add(key.getKey().location().getPath()));
|
||||
paths.sort(Comparator.naturalOrder());
|
||||
|
||||
paths.forEach(key -> {
|
||||
String fieldName = Formatting.formatKeyAsField(key);
|
||||
boolean isExperimental = false;
|
||||
for (Pattern pattern : EXPERIMENTAL_REGEX) {
|
||||
if (pattern.matcher(key).find()) {
|
||||
isExperimental = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
TypeSpec.Builder builder = TypeSpec.anonymousClassBuilder("$S", key);
|
||||
if (isExperimental) {
|
||||
builder.addAnnotations(Annotations.experimentalAnnotations(null));
|
||||
}
|
||||
|
||||
typeBuilder.addEnumConstant(fieldName, builder.build());
|
||||
});
|
||||
|
||||
typeBuilder.addField(FieldSpec.builder(NamespacedKey.class, "key", Modifier.PRIVATE).build());
|
||||
typeBuilder.addMethod(MethodSpec.constructorBuilder()
|
||||
.addParameter(String.class, "key").addCode("this.key = NamespacedKey.minecraft(key);").build());
|
||||
|
||||
typeBuilder.addMethod(MethodSpec.methodBuilder("key")
|
||||
.returns(Key.class)
|
||||
.addModifiers(Modifier.PUBLIC)
|
||||
.addAnnotation(Annotations.NOT_NULL)
|
||||
.addAnnotation(Annotations.OVERRIDE)
|
||||
.addCode("return this.key;").build());
|
||||
|
||||
typeBuilder.addMethod(MethodSpec.methodBuilder("getKey")
|
||||
.returns(NamespacedKey.class)
|
||||
.addModifiers(Modifier.PUBLIC)
|
||||
.addAnnotation(Annotations.NOT_NULL)
|
||||
.addAnnotation(Annotations.OVERRIDE)
|
||||
.addCode("return this.key;").build());
|
||||
|
||||
return typeBuilder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JavaFile.Builder file(JavaFile.Builder builder) {
|
||||
return builder
|
||||
.skipJavaLangImports(true);
|
||||
}
|
||||
|
||||
private static List<Pattern> of(String... strings) {
|
||||
List<Pattern> patterns = new ArrayList<>(strings.length);
|
||||
for (String pattern : strings) {
|
||||
patterns.add(Pattern.compile(pattern));
|
||||
}
|
||||
|
||||
return patterns;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package io.papermc.generator.types.enumgen;
|
||||
|
||||
import com.squareup.javapoet.MethodSpec;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import io.papermc.generator.Main;
|
||||
import io.papermc.generator.utils.Annotations;
|
||||
import io.papermc.generator.utils.Javadocs;
|
||||
import io.papermc.generator.utils.RegistryUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.lang.model.element.Modifier;
|
||||
import net.kyori.adventure.translation.Translatable;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class BiomeGenerator extends EnumGenerator<Biome> {
|
||||
|
||||
|
||||
private static final String CLASS_HEADER = Javadocs.getVersionDependentClassHeader("Biomes");
|
||||
private final Set<ResourceKey<Biome>> experimental;
|
||||
|
||||
public BiomeGenerator(final String keysClassName, final String pkg) {
|
||||
super(keysClassName, pkg, Registries.BIOME);
|
||||
Registry<Biome> biomes = Main.REGISTRY_ACCESS.registryOrThrow(this.registryResourceKey);
|
||||
this.experimental = RegistryUtils.collectExperimentalDataDrivenKeys(biomes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras(final TypeSpec.Builder builder) {
|
||||
builder.addSuperinterface(Translatable.class);
|
||||
builder.addJavadoc(CLASS_HEADER);
|
||||
|
||||
builder.addMethod(MethodSpec.methodBuilder("translationKey")
|
||||
.returns(String.class)
|
||||
.addModifiers(Modifier.PUBLIC)
|
||||
.addAnnotation(Annotations.NOT_NULL)
|
||||
.addAnnotation(Annotations.OVERRIDE)
|
||||
.addCode("return $S + $L;", "biome.minecraft.", "this.key.getKey()").build());
|
||||
|
||||
builder.addEnumConstant("CUSTOM", TypeSpec.anonymousClassBuilder("$S", "custom").build());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isExperimental(final Map.Entry<ResourceKey<Biome>, Biome> entry) {
|
||||
return this.experimental.contains(entry.getKey());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package io.papermc.generator.types.enumgen;
|
||||
|
||||
import com.squareup.javapoet.FieldSpec;
|
||||
import com.squareup.javapoet.JavaFile;
|
||||
import com.squareup.javapoet.MethodSpec;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import io.papermc.generator.Main;
|
||||
import io.papermc.generator.types.SimpleGenerator;
|
||||
import io.papermc.generator.utils.Annotations;
|
||||
import io.papermc.generator.utils.Formatting;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.lang.model.element.Modifier;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public abstract class EnumGenerator<T> extends SimpleGenerator {
|
||||
|
||||
protected final ResourceKey<Registry<T>> registryResourceKey;
|
||||
|
||||
public EnumGenerator(final String keysClassName, final String pkg, ResourceKey<Registry<T>> registryResourceKey) {
|
||||
super(keysClassName, pkg);
|
||||
this.registryResourceKey = registryResourceKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeSpec getTypeSpec() {
|
||||
TypeSpec.Builder typeBuilder = TypeSpec.enumBuilder(this.className)
|
||||
.addSuperinterface(Keyed.class)
|
||||
.addModifiers(Modifier.PUBLIC)
|
||||
.addAnnotations(Annotations.CLASS_HEADER);
|
||||
|
||||
Registry<T> event = Main.REGISTRY_ACCESS.registryOrThrow(this.registryResourceKey);
|
||||
List<Map.Entry<ResourceKey<T>, T>> paths = new ArrayList<>(event.entrySet());
|
||||
paths.sort(Comparator.comparing(o -> o.getKey().location().getPath()));
|
||||
|
||||
paths.forEach(entry -> {
|
||||
String path = entry.getKey().location().getPath();
|
||||
|
||||
String fieldName = Formatting.formatKeyAsField(path);
|
||||
boolean isExperimental = this.isExperimental(entry);
|
||||
TypeSpec.Builder builder = TypeSpec.anonymousClassBuilder("$S", path);
|
||||
if (isExperimental) {
|
||||
builder.addAnnotations(Annotations.experimentalAnnotations(null));
|
||||
}
|
||||
|
||||
typeBuilder.addEnumConstant(fieldName, builder.build());
|
||||
});
|
||||
|
||||
typeBuilder.addField(FieldSpec.builder(NamespacedKey.class, "key", Modifier.PRIVATE).build());
|
||||
typeBuilder.addMethod(MethodSpec.constructorBuilder()
|
||||
.addParameter(String.class, "key").addCode("this.key = NamespacedKey.minecraft(key);").build());
|
||||
|
||||
typeBuilder.addMethod(MethodSpec.methodBuilder("getKey")
|
||||
.returns(NamespacedKey.class)
|
||||
.addModifiers(Modifier.PUBLIC)
|
||||
.addAnnotation(Annotations.NOT_NULL)
|
||||
.addAnnotation(Annotations.OVERRIDE)
|
||||
.addCode("return this.key;").build());
|
||||
|
||||
this.addExtras(typeBuilder);
|
||||
|
||||
return typeBuilder.build();
|
||||
}
|
||||
|
||||
public abstract void addExtras(TypeSpec.Builder builder);
|
||||
|
||||
@Override
|
||||
protected JavaFile.Builder file(JavaFile.Builder builder) {
|
||||
return builder
|
||||
.skipJavaLangImports(true);
|
||||
}
|
||||
|
||||
public abstract boolean isExperimental(Map.Entry<ResourceKey<T>, T> entry);
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package io.papermc.generator.types.enumgen;
|
||||
|
||||
import com.squareup.javapoet.JavaFile;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import io.papermc.generator.types.SimpleGenerator;
|
||||
import io.papermc.generator.utils.Annotations;
|
||||
import javax.lang.model.element.Modifier;
|
||||
import net.minecraft.world.entity.Pose;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class PoseGenerator extends SimpleGenerator {
|
||||
|
||||
public PoseGenerator(final String keysClassName, final String pkg) {
|
||||
super(keysClassName, pkg);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeSpec getTypeSpec() {
|
||||
TypeSpec.Builder typeBuilder = TypeSpec.enumBuilder(this.className)
|
||||
.addModifiers(Modifier.PUBLIC)
|
||||
.addAnnotations(Annotations.CLASS_HEADER);
|
||||
|
||||
for (Pose nmsPose : Pose.values()) {
|
||||
String fieldName = nmsPose.name();
|
||||
typeBuilder.addEnumConstant(fieldName);
|
||||
}
|
||||
|
||||
return typeBuilder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JavaFile.Builder file(JavaFile.Builder builder) {
|
||||
return builder
|
||||
.skipJavaLangImports(true);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package io.papermc.generator.types.enumgen;
|
||||
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import io.papermc.generator.utils.Javadocs;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class SoundGenerator extends EnumGenerator<SoundEvent> {
|
||||
|
||||
private static final String CLASS_HEADER = Javadocs.getVersionDependentClassHeader("Sounds");
|
||||
private static final List<Pattern> EXPERIMENTAL_REGEX = of(
|
||||
"block.copper_door.*",
|
||||
"block.copper_bulb.*",
|
||||
"block.copper_grate.*",
|
||||
"block.copper_grate.*",
|
||||
"block.copper_trapdoor.*",
|
||||
"block.polished_tuff.*",
|
||||
"block.trial_spawner.*",
|
||||
"block.tuff_bricks.*",
|
||||
"block.crafter.*",
|
||||
"entity.breeze.*",
|
||||
"entity.generic.wind_burst",
|
||||
"item.bundle.*"
|
||||
);
|
||||
|
||||
public SoundGenerator(final String keysClassName, final String pkg) {
|
||||
super(keysClassName, pkg, Registries.SOUND_EVENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addExtras(final TypeSpec.Builder builder) {
|
||||
builder.addSuperinterface(Sound.Type.class)
|
||||
.addJavadoc(CLASS_HEADER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExperimental(final Map.Entry<ResourceKey<SoundEvent>, SoundEvent> entry) {
|
||||
for (Pattern pattern : EXPERIMENTAL_REGEX) {
|
||||
if (pattern.matcher(entry.getKey().location().toString()).find()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static List<Pattern> of(String... strings) {
|
||||
List<Pattern> patterns = new ArrayList<>(strings.length);
|
||||
for (String pattern : strings) {
|
||||
patterns.add(Pattern.compile(pattern));
|
||||
}
|
||||
|
||||
return patterns;
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@ package io.papermc.generator.utils;
|
|||
|
||||
import com.squareup.javapoet.AnnotationSpec;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.generated.GeneratedFrom;
|
||||
import net.minecraft.SharedConstants;
|
||||
import org.bukkit.MinecraftExperimental;
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package io.papermc.generator.utils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import com.google.common.collect.Sets;
|
||||
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.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class RegistryUtils {
|
||||
|
||||
private static final Map<ResourceKey<? extends Registry<?>>, RegistrySetBuilder.RegistryBootstrap<?>> VANILLA_REGISTRY_ENTRIES = VanillaRegistries.BUILDER.entries.stream()
|
||||
.collect(Collectors.toMap(RegistrySetBuilder.RegistryStub::key, RegistrySetBuilder.RegistryStub::bootstrap));
|
||||
|
||||
private static final Map<ResourceKey<? extends Registry<?>>, RegistrySetBuilder.RegistryBootstrap<?>> EXPERIMENTAL_REGISTRY_ENTRIES = UpdateOneTwentyOneRegistries.BUILDER.entries.stream()
|
||||
.collect(Collectors.toMap(RegistrySetBuilder.RegistryStub::key, RegistrySetBuilder.RegistryStub::bootstrap));
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Set<ResourceKey<T>> collectExperimentalDataDrivenKeys(final Registry<T> registry) {
|
||||
final RegistrySetBuilder.@Nullable RegistryBootstrap<T> experimentalBootstrap = (RegistrySetBuilder.RegistryBootstrap<T>) EXPERIMENTAL_REGISTRY_ENTRIES.get(registry.key());
|
||||
if (experimentalBootstrap == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
final Set<ResourceKey<T>> experimental = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||
final CollectingContext<T> experimentalCollector = new CollectingContext<>(experimental, registry);
|
||||
experimentalBootstrap.run(experimentalCollector);
|
||||
|
||||
final RegistrySetBuilder.@Nullable RegistryBootstrap<T> vanillaBootstrap = (RegistrySetBuilder.RegistryBootstrap<T>) VANILLA_REGISTRY_ENTRIES.get(registry.key());
|
||||
if (vanillaBootstrap != null) {
|
||||
final Set<ResourceKey<T>> vanilla = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||
final CollectingContext<T> vanillaCollector = new CollectingContext<>(vanilla, registry);
|
||||
vanillaBootstrap.run(vanillaCollector);
|
||||
return Sets.difference(experimental, vanilla);
|
||||
}
|
||||
return experimental;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue