Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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;

/**
* A data-centric version-specific registry entry for the {@link PatternType} type.
*/
@ApiStatus.Experimental
@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);

}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.papermc.paper.registry.event;

import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.BannerPatternRegistryEntry;
import io.papermc.paper.registry.data.EnchantmentRegistryEntry;
import io.papermc.paper.registry.data.GameEventRegistryEntry;
import io.papermc.paper.registry.data.PaintingVariantRegistryEntry;
import org.bukkit.Art;
import org.bukkit.GameEvent;
import org.bukkit.block.banner.PatternType;
import org.bukkit.enchantments.Enchantment;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
Expand All @@ -23,6 +25,7 @@ public final class RegistryEvents {
public static final RegistryEventProvider<GameEvent, GameEventRegistryEntry.Builder> GAME_EVENT = create(RegistryKey.GAME_EVENT);
public static final RegistryEventProvider<Enchantment, EnchantmentRegistryEntry.Builder> ENCHANTMENT = create(RegistryKey.ENCHANTMENT);
public static final RegistryEventProvider<Art, PaintingVariantRegistryEntry.Builder> PAINTING_VARIANT = create(RegistryKey.PAINTING_VARIANT);
public static final RegistryEventProvider<PatternType, BannerPatternRegistryEntry.Builder> BANNER_PATTERN = create(RegistryKey.BANNER_PATTERN);

private RegistryEvents() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand Down Expand Up @@ -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(),

Expand Down
Original file line number Diff line number Diff line change
@@ -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()
);
}
}
}
Loading