Banner pattern registry modification API

This commit is contained in:
kokiriglade 2024-12-24 02:24:32 +00:00
parent d0d0efee02
commit 4ebf803df1
No known key found for this signature in database
3 changed files with 134 additions and 1 deletions

View file

@ -0,0 +1,67 @@
package io.papermc.paper.registry.data;
import io.papermc.paper.registry.RegistryBuilder;
import net.kyori.adventure.key.Key;
import org.bukkit.block.banner.PatternType;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jspecify.annotations.NullMarked;
/**
* A data-centric version-specific registry entry for the {@link PatternType} type.
*/
@ApiStatus.Experimental
@NullMarked
@ApiStatus.NonExtendable
public interface BannerPatternRegistryEntry {
/**
* Provides the asset id of the pattern type, which is the location of the sprite to use.
*
* @return the asset id.
*/
Key assetId();
/**
* Provides the translation key for displaying the pattern inside the banner's tooltip.
*
* @return the translation key.
*/
String translationKey();
/**
* A mutable builder for the {@link BannerPatternRegistryEntry} plugins may change in applicable registry events.
* <p>
* The following values are required for each builder:
* <ul>
* <li>{@link #assetId(Key)}</li>
* <li>{@link #translationKey(String)}</li>
* </ul>
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
interface Builder extends BannerPatternRegistryEntry, RegistryBuilder<PatternType> {
/**
* Sets the asset id of the pattern type, which is the location of the sprite to use.
*
* @param assetId the asset id.
* @return this builder instance.
* @see BannerPatternRegistryEntry#assetId()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder assetId(Key assetId);
/**
* Sets the translation key for displaying the pattern inside the banner's tooltip.
*
* @param translationKey the translation key.
* @return this builder instance.
* @see BannerPatternRegistryEntry#translationKey()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder translationKey(String translationKey);
}
}

View file

@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
import io.papermc.paper.adventure.PaperAdventure;
import io.papermc.paper.datacomponent.DataComponentTypes;
import io.papermc.paper.datacomponent.PaperDataComponentType;
import io.papermc.paper.registry.data.PaperBannerPatternRegistryEntry;
import io.papermc.paper.registry.data.PaperEnchantmentRegistryEntry;
import io.papermc.paper.registry.data.PaperGameEventRegistryEntry;
import io.papermc.paper.registry.data.PaperPaintingVariantRegistryEntry;
@ -106,7 +107,7 @@ public final class PaperRegistries {
start(Registries.WOLF_VARIANT, RegistryKey.WOLF_VARIANT).craft(Wolf.Variant.class, CraftWolf.CraftVariant::new).build().delayed(),
start(Registries.ENCHANTMENT, RegistryKey.ENCHANTMENT).craft(Enchantment.class, CraftEnchantment::new).serializationUpdater(FieldRename.ENCHANTMENT_RENAME).writable(PaperEnchantmentRegistryEntry.PaperBuilder::new).delayed(),
start(Registries.JUKEBOX_SONG, RegistryKey.JUKEBOX_SONG).craft(JukeboxSong.class, CraftJukeboxSong::new).build().delayed(),
start(Registries.BANNER_PATTERN, RegistryKey.BANNER_PATTERN).craft(PatternType.class, CraftPatternType::new).build().delayed(),
start(Registries.BANNER_PATTERN, RegistryKey.BANNER_PATTERN).craft(PatternType.class, CraftPatternType::new).writable(PaperBannerPatternRegistryEntry.PaperBuilder::new).delayed(),
start(Registries.PAINTING_VARIANT, RegistryKey.PAINTING_VARIANT).craft(Art.class, CraftArt::new).writable(PaperPaintingVariantRegistryEntry.PaperBuilder::new).delayed(),
start(Registries.INSTRUMENT, RegistryKey.INSTRUMENT).craft(MusicInstrument.class, CraftMusicInstrument::new).build().delayed(),

View file

@ -0,0 +1,65 @@
package io.papermc.paper.registry.data;
import io.papermc.paper.adventure.PaperAdventure;
import io.papermc.paper.registry.PaperRegistryBuilder;
import io.papermc.paper.registry.data.util.Conversions;
import net.kyori.adventure.key.Key;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.entity.BannerPattern;
import org.bukkit.block.banner.PatternType;
import org.jspecify.annotations.Nullable;
import static io.papermc.paper.registry.data.util.Checks.*;
public class PaperBannerPatternRegistryEntry implements BannerPatternRegistryEntry {
protected @Nullable ResourceLocation assetId;
protected @Nullable String translationKey;
public PaperBannerPatternRegistryEntry(
final Conversions ignoredConversions,
final @Nullable BannerPattern internal
) {
if (internal == null) return;
this.assetId = internal.assetId();
this.translationKey = internal.translationKey();
}
@Override
public Key assetId() {
return PaperAdventure.asAdventure(asConfigured(this.assetId, "assetId"));
}
@Override
public String translationKey() {
return asConfigured(this.translationKey, "translationKey");
}
public static final class PaperBuilder extends PaperBannerPatternRegistryEntry implements Builder, PaperRegistryBuilder<BannerPattern, PatternType> {
public PaperBuilder(final Conversions conversions, final @Nullable BannerPattern internal) {
super(conversions, internal);
}
@Override
public Builder assetId(final Key assetId) {
this.assetId = PaperAdventure.asVanilla(asArgument(assetId, "assetId"));
return this;
}
@Override
public Builder translationKey(final String translationKey) {
this.translationKey = asArgument(translationKey, "translationKey");
return this;
}
@Override
public BannerPattern build() {
return new BannerPattern(
asConfigured(this.assetId, "assetId"),
this.translationKey()
);
}
}
}