mirror of
https://github.com/PaperMC/Paper.git
synced 2025-07-26 01:32:02 -07:00
Add registry api for trim patterns and materials
This commit is contained in:
@@ -32,7 +32,7 @@ public interface Dialog extends Keyed, DialogLike {
|
||||
}
|
||||
|
||||
// Start generate - Dialog
|
||||
// @GeneratedFrom 1.21.7-rc2
|
||||
// @GeneratedFrom 1.21.7
|
||||
Dialog CUSTOM_OPTIONS = getDialog("custom_options");
|
||||
|
||||
Dialog QUICK_ACTIONS = getDialog("quick_actions");
|
||||
|
@@ -59,7 +59,5 @@ public interface BannerPatternRegistryEntry {
|
||||
*/
|
||||
@Contract(value = "_ -> this", mutates = "this")
|
||||
Builder translationKey(String translationKey);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -7,6 +7,8 @@ import java.util.Optional;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.function.Consumer;
|
||||
import org.bukkit.MusicInstrument;
|
||||
import org.bukkit.inventory.meta.trim.TrimMaterial;
|
||||
import org.bukkit.inventory.meta.trim.TrimPattern;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ApiStatus.Internal
|
||||
@@ -23,4 +25,8 @@ public interface InlinedRegistryBuilderProvider {
|
||||
MusicInstrument createInstrument(Consumer<RegistryBuilderFactory<MusicInstrument, ? extends InstrumentRegistryEntry.Builder>> value);
|
||||
|
||||
Dialog createDialog(Consumer<RegistryBuilderFactory<Dialog, ? extends DialogRegistryEntry.Builder>> value);
|
||||
|
||||
TrimMaterial createTrimMaterial(Consumer<RegistryBuilderFactory<TrimMaterial, ? extends TrimMaterialRegistryEntry.Builder>> value);
|
||||
|
||||
TrimPattern createTrimPattern(Consumer<RegistryBuilderFactory<TrimPattern, ? extends TrimPatternRegistryEntry.Builder>> value);
|
||||
}
|
||||
|
@@ -0,0 +1,91 @@
|
||||
package io.papermc.paper.registry.data;
|
||||
|
||||
import io.papermc.paper.datacomponent.item.Equippable;
|
||||
import io.papermc.paper.registry.RegistryBuilder;
|
||||
import java.util.Map;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.key.KeyPattern;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.inventory.meta.trim.TrimMaterial;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
/**
|
||||
* A data-centric version-specific registry entry for the {@link org.bukkit.inventory.meta.trim.TrimMaterial} type.
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
@ApiStatus.NonExtendable
|
||||
public interface TrimMaterialRegistryEntry {
|
||||
|
||||
/**
|
||||
* The base asset path for the trim material.
|
||||
*
|
||||
* @return the base asset path
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@KeyPattern.Value String baseAssetPath();
|
||||
|
||||
/**
|
||||
* An immutable map of asset path overrides for the trim material.
|
||||
* <p>
|
||||
* The key is the identifier of the asset, and the value is the path to the asset.
|
||||
*
|
||||
* @return the asset path overrides
|
||||
* @see Equippable#assetId()
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@Unmodifiable Map<Key, String> assetPathOverrides();
|
||||
|
||||
/**
|
||||
* The description of the trim material.
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
Component description();
|
||||
|
||||
/**
|
||||
* A mutable builder for {@link TrimMaterialRegistryEntry} plugins may change in applicable registry events.
|
||||
* <p>
|
||||
* The following values are required for each builder:
|
||||
* <ul>
|
||||
* <li>{@link #baseAssetPath(String)}</li>
|
||||
* <li>{@link #description(Component)}</li>
|
||||
* </ul>
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
@ApiStatus.NonExtendable
|
||||
interface Builder extends TrimMaterialRegistryEntry, RegistryBuilder<TrimMaterial> {
|
||||
|
||||
/**
|
||||
* Sets the base asset path for the trim material.
|
||||
*
|
||||
* @param baseAssetPath the base asset path
|
||||
* @return the builder
|
||||
* @see #baseAssetPath()
|
||||
*/
|
||||
@Contract(value = "_ -> this", mutates = "this")
|
||||
Builder baseAssetPath(@KeyPattern.Value String baseAssetPath);
|
||||
|
||||
/**
|
||||
* Sets the asset path overrides for the trim material.
|
||||
*
|
||||
* @param assetPathOverrides the asset path overrides
|
||||
* @return the builder
|
||||
* @see #assetPathOverrides()
|
||||
*/
|
||||
@Contract(value = "_ -> this", mutates = "this")
|
||||
Builder assetPathOverrides(Map<Key, String> assetPathOverrides);
|
||||
|
||||
/**
|
||||
* Sets the description for the trim material.
|
||||
*
|
||||
* @param description the description
|
||||
* @return the builder
|
||||
* @see #description()
|
||||
*/
|
||||
@Contract(value = "_ -> this", mutates = "this")
|
||||
Builder description(Component description);
|
||||
}
|
||||
}
|
@@ -0,0 +1,84 @@
|
||||
package io.papermc.paper.registry.data;
|
||||
|
||||
import io.papermc.paper.registry.RegistryBuilder;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.inventory.meta.trim.TrimPattern;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
/**
|
||||
* A data-centric version-specific registry entry for the {@link org.bukkit.inventory.meta.trim.TrimMaterial} type.
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
@ApiStatus.NonExtendable
|
||||
public interface TrimPatternRegistryEntry {
|
||||
|
||||
/**
|
||||
* The asset ID of the trim pattern.
|
||||
*
|
||||
* @return the asset ID
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
Key assetId();
|
||||
|
||||
/**
|
||||
* The description of the trim pattern.
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
Component description();
|
||||
|
||||
/**
|
||||
* Checks if the trim pattern is a decal.
|
||||
*
|
||||
* @return true if decal, false otherwise
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
boolean decal();
|
||||
|
||||
/**
|
||||
* A mutable builder for {@link TrimPatternRegistryEntry} plugins may change in applicable registry events.
|
||||
* <p>
|
||||
* The following values are required for each builder:
|
||||
* <ul>
|
||||
* <li>{@link #assetId(Key)}</li>
|
||||
* <li>{@link #description(Component)}</li>
|
||||
* </ul>
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
@ApiStatus.NonExtendable
|
||||
interface Builder extends TrimPatternRegistryEntry, RegistryBuilder<TrimPattern> {
|
||||
|
||||
/**
|
||||
* Sets the asset ID for the trim pattern.
|
||||
*
|
||||
* @param key the asset ID
|
||||
* @return the builder
|
||||
* @see #assetId()
|
||||
*/
|
||||
@Contract(value = "_ -> this", mutates = "this")
|
||||
Builder assetId(Key key);
|
||||
|
||||
/**
|
||||
* Sets the description for the trim pattern.
|
||||
*
|
||||
* @param description the description
|
||||
* @return the builder
|
||||
* @see #description()
|
||||
*/
|
||||
@Contract(value = "_ -> this", mutates = "this")
|
||||
Builder description(Component description);
|
||||
|
||||
/**
|
||||
* Sets whether the trim pattern is a decal.
|
||||
*
|
||||
* @param decal true if decal, false otherwise
|
||||
* @return the builder
|
||||
* @see #decal()
|
||||
*/
|
||||
@Contract(value = "_ -> this", mutates = "this")
|
||||
Builder decal(boolean decal);
|
||||
}
|
||||
}
|
@@ -14,6 +14,8 @@ import io.papermc.paper.registry.data.InstrumentRegistryEntry;
|
||||
import io.papermc.paper.registry.data.JukeboxSongRegistryEntry;
|
||||
import io.papermc.paper.registry.data.PaintingVariantRegistryEntry;
|
||||
import io.papermc.paper.registry.data.PigVariantRegistryEntry;
|
||||
import io.papermc.paper.registry.data.TrimMaterialRegistryEntry;
|
||||
import io.papermc.paper.registry.data.TrimPatternRegistryEntry;
|
||||
import io.papermc.paper.registry.data.WolfVariantRegistryEntry;
|
||||
import io.papermc.paper.registry.data.dialog.DialogRegistryEntry;
|
||||
import org.bukkit.Art;
|
||||
@@ -29,6 +31,8 @@ import org.bukkit.entity.Cow;
|
||||
import org.bukkit.entity.Frog;
|
||||
import org.bukkit.entity.Pig;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.inventory.meta.trim.TrimMaterial;
|
||||
import org.bukkit.inventory.meta.trim.TrimPattern;
|
||||
|
||||
import static io.papermc.paper.registry.event.RegistryEventProviderImpl.create;
|
||||
|
||||
@@ -41,6 +45,8 @@ public final class RegistryEvents {
|
||||
// Start generate - RegistryEvents
|
||||
// @GeneratedFrom 1.21.7
|
||||
public static final RegistryEventProvider<GameEvent, GameEventRegistryEntry.Builder> GAME_EVENT = create(RegistryKey.GAME_EVENT);
|
||||
public static final RegistryEventProvider<TrimMaterial, TrimMaterialRegistryEntry.Builder> TRIM_MATERIAL = create(RegistryKey.TRIM_MATERIAL);
|
||||
public static final RegistryEventProvider<TrimPattern, TrimPatternRegistryEntry.Builder> TRIM_PATTERN = create(RegistryKey.TRIM_PATTERN);
|
||||
public static final RegistryEventProvider<DamageType, DamageTypeRegistryEntry.Builder> DAMAGE_TYPE = create(RegistryKey.DAMAGE_TYPE);
|
||||
public static final RegistryEventProvider<Wolf.Variant, WolfVariantRegistryEntry.Builder> WOLF_VARIANT = create(RegistryKey.WOLF_VARIANT);
|
||||
public static final RegistryEventProvider<Enchantment, EnchantmentRegistryEntry.Builder> ENCHANTMENT = create(RegistryKey.ENCHANTMENT);
|
||||
|
@@ -1,19 +1,38 @@
|
||||
package org.bukkit.inventory.meta.trim;
|
||||
|
||||
import io.papermc.paper.registry.RegistryAccess;
|
||||
import io.papermc.paper.registry.RegistryBuilderFactory;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import io.papermc.paper.registry.data.InlinedRegistryBuilderProvider;
|
||||
import io.papermc.paper.registry.data.TrimMaterialRegistryEntry;
|
||||
import java.util.function.Consumer;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.key.KeyPattern;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.Translatable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* Represents a material that may be used in an {@link ArmorTrim}.
|
||||
*/
|
||||
@NullMarked
|
||||
public interface TrimMaterial extends Keyed, Translatable {
|
||||
|
||||
/**
|
||||
* Creates an inlined trim material.
|
||||
*
|
||||
* @param value a consumer for the builder factory
|
||||
* @return the created trim material
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
static TrimMaterial create(final Consumer<RegistryBuilderFactory<TrimMaterial, ? extends TrimMaterialRegistryEntry.Builder>> value) {
|
||||
return InlinedRegistryBuilderProvider.instance().createTrimMaterial(value);
|
||||
}
|
||||
|
||||
// Start generate - TrimMaterial
|
||||
// @GeneratedFrom 1.21.7
|
||||
TrimMaterial AMETHYST = getTrimMaterial("amethyst");
|
||||
@@ -39,18 +58,16 @@ public interface TrimMaterial extends Keyed, Translatable {
|
||||
TrimMaterial RESIN = getTrimMaterial("resin");
|
||||
// End generate - TrimMaterial
|
||||
|
||||
@NotNull
|
||||
private static TrimMaterial getTrimMaterial(@NotNull String key) {
|
||||
return RegistryAccess.registryAccess().getRegistry(RegistryKey.TRIM_MATERIAL).getOrThrow(NamespacedKey.minecraft(key));
|
||||
private static TrimMaterial getTrimMaterial(@KeyPattern.Value final String key) {
|
||||
return RegistryAccess.registryAccess().getRegistry(RegistryKey.TRIM_MATERIAL).getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
|
||||
}
|
||||
|
||||
// Paper start - adventure
|
||||
/**
|
||||
* Get the description of this {@link TrimMaterial}.
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component description();
|
||||
Component description();
|
||||
|
||||
/**
|
||||
* @deprecated this method assumes that {@link #description()} will
|
||||
@@ -58,17 +75,7 @@ public interface TrimMaterial extends Keyed, Translatable {
|
||||
*/
|
||||
@Override
|
||||
@Deprecated(forRemoval = true)
|
||||
@org.jetbrains.annotations.NotNull String getTranslationKey();
|
||||
// Paper end - adventure
|
||||
|
||||
// Paper start - Registry#getKey
|
||||
/**
|
||||
* @deprecated use {@link Registry#getKey(Keyed)}, {@link io.papermc.paper.registry.RegistryAccess#getRegistry(io.papermc.paper.registry.RegistryKey)},
|
||||
* and {@link io.papermc.paper.registry.RegistryKey#TRIM_MATERIAL}. TrimMaterials can exist without a key.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.20.4")
|
||||
@Override
|
||||
org.bukkit.@org.jetbrains.annotations.NotNull NamespacedKey getKey();
|
||||
String getTranslationKey();
|
||||
|
||||
/**
|
||||
* @deprecated use {@link Registry#getKey(Keyed)}, {@link io.papermc.paper.registry.RegistryAccess#getRegistry(io.papermc.paper.registry.RegistryKey)},
|
||||
@@ -76,8 +83,15 @@ public interface TrimMaterial extends Keyed, Translatable {
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.20.4")
|
||||
@Override
|
||||
default net.kyori.adventure.key.@org.jetbrains.annotations.NotNull Key key() {
|
||||
return org.bukkit.Keyed.super.key();
|
||||
NamespacedKey getKey();
|
||||
|
||||
/**
|
||||
* @deprecated use {@link Registry#getKey(Keyed)}, {@link io.papermc.paper.registry.RegistryAccess#getRegistry(io.papermc.paper.registry.RegistryKey)},
|
||||
* and {@link io.papermc.paper.registry.RegistryKey#TRIM_MATERIAL}. TrimMaterials can exist without a key.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.20.4")
|
||||
@Override
|
||||
default Key key() {
|
||||
return Keyed.super.key();
|
||||
}
|
||||
// Paper end - Registry#getKey
|
||||
}
|
||||
|
@@ -1,19 +1,38 @@
|
||||
package org.bukkit.inventory.meta.trim;
|
||||
|
||||
import io.papermc.paper.registry.RegistryAccess;
|
||||
import io.papermc.paper.registry.RegistryBuilderFactory;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import io.papermc.paper.registry.data.InlinedRegistryBuilderProvider;
|
||||
import io.papermc.paper.registry.data.TrimPatternRegistryEntry;
|
||||
import java.util.function.Consumer;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.key.KeyPattern;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.Translatable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* Represents a pattern that may be used in an {@link ArmorTrim}.
|
||||
*/
|
||||
@NullMarked
|
||||
public interface TrimPattern extends Keyed, Translatable {
|
||||
|
||||
/**
|
||||
* Creates an inlined trim pattern.
|
||||
*
|
||||
* @param value a consumer for the builder factory
|
||||
* @return the created trim pattern
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
static TrimPattern create(final Consumer<RegistryBuilderFactory<TrimPattern, ? extends TrimPatternRegistryEntry.Builder>> value) {
|
||||
return InlinedRegistryBuilderProvider.instance().createTrimPattern(value);
|
||||
}
|
||||
|
||||
// Start generate - TrimPattern
|
||||
// @GeneratedFrom 1.21.7
|
||||
TrimPattern BOLT = getTrimPattern("bolt");
|
||||
@@ -53,9 +72,8 @@ public interface TrimPattern extends Keyed, Translatable {
|
||||
TrimPattern WILD = getTrimPattern("wild");
|
||||
// End generate - TrimPattern
|
||||
|
||||
@NotNull
|
||||
private static TrimPattern getTrimPattern(@NotNull String key) {
|
||||
return RegistryAccess.registryAccess().getRegistry(RegistryKey.TRIM_PATTERN).getOrThrow(NamespacedKey.minecraft(key));
|
||||
private static TrimPattern getTrimPattern(@KeyPattern.Value final String key) {
|
||||
return RegistryAccess.registryAccess().getRegistry(RegistryKey.TRIM_PATTERN).getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
|
||||
}
|
||||
|
||||
// Paper start - adventure
|
||||
@@ -64,7 +82,7 @@ public interface TrimPattern extends Keyed, Translatable {
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component description();
|
||||
Component description();
|
||||
|
||||
/**
|
||||
* @deprecated this method assumes that {@link #description()} will
|
||||
@@ -72,7 +90,7 @@ public interface TrimPattern extends Keyed, Translatable {
|
||||
*/
|
||||
@Override
|
||||
@Deprecated(forRemoval = true)
|
||||
@org.jetbrains.annotations.NotNull String getTranslationKey();
|
||||
String getTranslationKey();
|
||||
// Paper end - adventure
|
||||
|
||||
// Paper start - Registry#getKey
|
||||
@@ -82,7 +100,7 @@ public interface TrimPattern extends Keyed, Translatable {
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.20.4")
|
||||
@Override
|
||||
org.bukkit.@org.jetbrains.annotations.NotNull NamespacedKey getKey();
|
||||
NamespacedKey getKey();
|
||||
|
||||
/**
|
||||
* @deprecated use {@link Registry#getKey(Keyed)}, {@link io.papermc.paper.registry.RegistryAccess#getRegistry(io.papermc.paper.registry.RegistryKey)},
|
||||
@@ -90,8 +108,8 @@ public interface TrimPattern extends Keyed, Translatable {
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.20.4")
|
||||
@Override
|
||||
default net.kyori.adventure.key.@org.jetbrains.annotations.NotNull Key key() {
|
||||
return org.bukkit.Keyed.super.key();
|
||||
default Key key() {
|
||||
return Keyed.super.key();
|
||||
}
|
||||
// Paper end - Registry#getKey
|
||||
}
|
||||
|
@@ -17,6 +17,8 @@ import io.papermc.paper.registry.data.JukeboxSongRegistryEntry;
|
||||
import io.papermc.paper.registry.data.PaintingVariantRegistryEntry;
|
||||
import io.papermc.paper.registry.data.PigVariantRegistryEntry;
|
||||
import io.papermc.paper.registry.data.SoundEventRegistryEntry;
|
||||
import io.papermc.paper.registry.data.TrimMaterialRegistryEntry;
|
||||
import io.papermc.paper.registry.data.TrimPatternRegistryEntry;
|
||||
import io.papermc.paper.registry.data.WolfVariantRegistryEntry;
|
||||
import io.papermc.paper.registry.data.dialog.DialogRegistryEntry;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -170,8 +172,8 @@ public final class RegistryEntries {
|
||||
public static final List<RegistryEntry<?>> DATA_DRIVEN = List.of(
|
||||
entry(Registries.BIOME, Biomes.class, Biome.class).delayed(),
|
||||
entry(Registries.STRUCTURE, BuiltinStructures.class, Structure.class).delayed(),
|
||||
entry(Registries.TRIM_MATERIAL, TrimMaterials.class, TrimMaterial.class).allowDirect().delayed(),
|
||||
entry(Registries.TRIM_PATTERN, TrimPatterns.class, TrimPattern.class).allowDirect().delayed(),
|
||||
entry(Registries.TRIM_MATERIAL, TrimMaterials.class, TrimMaterial.class).writableApiRegistryBuilder(TrimMaterialRegistryEntry.Builder.class, "PaperTrimMaterialRegistryEntry.PaperBuilder").allowDirect().delayed(),
|
||||
entry(Registries.TRIM_PATTERN, TrimPatterns.class, TrimPattern.class).writableApiRegistryBuilder(TrimPatternRegistryEntry.Builder.class, "PaperTrimPatternRegistryEntry.PaperBuilder").allowDirect().delayed(),
|
||||
entry(Registries.DAMAGE_TYPE, DamageTypes.class, DamageType.class).writableApiRegistryBuilder(DamageTypeRegistryEntry.Builder.class, "PaperDamageTypeRegistryEntry.PaperBuilder").delayed(),
|
||||
entry(Registries.WOLF_VARIANT, WolfVariants.class, Wolf.Variant.class).writableApiRegistryBuilder(WolfVariantRegistryEntry.Builder.class, "PaperWolfVariantRegistryEntry.PaperBuilder").delayed(),
|
||||
entry(Registries.WOLF_SOUND_VARIANT, WolfSoundVariants.class, Wolf.SoundVariant.class),
|
||||
|
@@ -19,6 +19,8 @@ import io.papermc.paper.registry.data.PaperJukeboxSongRegistryEntry;
|
||||
import io.papermc.paper.registry.data.PaperPaintingVariantRegistryEntry;
|
||||
import io.papermc.paper.registry.data.PaperPigVariantRegistryEntry;
|
||||
import io.papermc.paper.registry.data.PaperSoundEventRegistryEntry;
|
||||
import io.papermc.paper.registry.data.PaperTrimMaterialRegistryEntry;
|
||||
import io.papermc.paper.registry.data.PaperTrimPatternRegistryEntry;
|
||||
import io.papermc.paper.registry.data.PaperWolfVariantRegistryEntry;
|
||||
import io.papermc.paper.registry.data.dialog.PaperDialogRegistryEntry;
|
||||
import io.papermc.paper.registry.entry.RegistryEntry;
|
||||
@@ -120,8 +122,8 @@ public final class PaperRegistries {
|
||||
// data-driven
|
||||
start(Registries.BIOME, RegistryKey.BIOME).craft(Biome.class, CraftBiome::new).build().delayed(),
|
||||
start(Registries.STRUCTURE, RegistryKey.STRUCTURE).craft(Structure.class, CraftStructure::new).build().delayed(),
|
||||
start(Registries.TRIM_MATERIAL, RegistryKey.TRIM_MATERIAL).craft(TrimMaterial.class, CraftTrimMaterial::new, true).build().delayed(),
|
||||
start(Registries.TRIM_PATTERN, RegistryKey.TRIM_PATTERN).craft(TrimPattern.class, CraftTrimPattern::new, true).build().delayed(),
|
||||
start(Registries.TRIM_MATERIAL, RegistryKey.TRIM_MATERIAL).craft(TrimMaterial.class, CraftTrimMaterial::new, true).writable(PaperTrimMaterialRegistryEntry.PaperBuilder::new).delayed(),
|
||||
start(Registries.TRIM_PATTERN, RegistryKey.TRIM_PATTERN).craft(TrimPattern.class, CraftTrimPattern::new, true).writable(PaperTrimPatternRegistryEntry.PaperBuilder::new).delayed(),
|
||||
start(Registries.DAMAGE_TYPE, RegistryKey.DAMAGE_TYPE).craft(DamageType.class, CraftDamageType::new).writable(PaperDamageTypeRegistryEntry.PaperBuilder::new).delayed(),
|
||||
start(Registries.WOLF_VARIANT, RegistryKey.WOLF_VARIANT).craft(Wolf.Variant.class, CraftWolf.CraftVariant::new).writable(PaperWolfVariantRegistryEntry.PaperBuilder::new).delayed(),
|
||||
start(Registries.WOLF_SOUND_VARIANT, RegistryKey.WOLF_SOUND_VARIANT).craft(Wolf.SoundVariant.class, CraftWolf.CraftSoundVariant::new).build(),
|
||||
|
@@ -7,6 +7,8 @@ import io.papermc.paper.registry.data.dialog.DialogRegistryEntry;
|
||||
import io.papermc.paper.registry.data.util.Conversions;
|
||||
import java.util.function.Consumer;
|
||||
import org.bukkit.MusicInstrument;
|
||||
import org.bukkit.inventory.meta.trim.TrimMaterial;
|
||||
import org.bukkit.inventory.meta.trim.TrimPattern;
|
||||
|
||||
public final class InlinedRegistryBuilderProviderImpl implements InlinedRegistryBuilderProvider {
|
||||
|
||||
@@ -19,4 +21,14 @@ public final class InlinedRegistryBuilderProviderImpl implements InlinedRegistry
|
||||
public Dialog createDialog(final Consumer<RegistryBuilderFactory<Dialog, ? extends DialogRegistryEntry.Builder>> value) {
|
||||
return Conversions.global().createApiInstanceFromBuilder(RegistryKey.DIALOG, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrimMaterial createTrimMaterial(final Consumer<RegistryBuilderFactory<TrimMaterial, ? extends TrimMaterialRegistryEntry.Builder>> value) {
|
||||
return Conversions.global().createApiInstanceFromBuilder(RegistryKey.TRIM_MATERIAL, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrimPattern createTrimPattern(final Consumer<RegistryBuilderFactory<TrimPattern, ? extends TrimPatternRegistryEntry.Builder>> value) {
|
||||
return Conversions.global().createApiInstanceFromBuilder(RegistryKey.TRIM_PATTERN, value);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,112 @@
|
||||
package io.papermc.paper.registry.data;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.papermc.paper.adventure.PaperAdventure;
|
||||
import io.papermc.paper.registry.PaperRegistryBuilder;
|
||||
import io.papermc.paper.registry.data.util.Conversions;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.key.KeyPattern;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.item.equipment.EquipmentAsset;
|
||||
import net.minecraft.world.item.equipment.EquipmentAssets;
|
||||
import net.minecraft.world.item.equipment.trim.MaterialAssetGroup;
|
||||
import net.minecraft.world.item.equipment.trim.TrimMaterial;
|
||||
import org.intellij.lang.annotations.Subst;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.asArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.asConfigured;
|
||||
|
||||
public class PaperTrimMaterialRegistryEntry implements TrimMaterialRegistryEntry {
|
||||
|
||||
protected MaterialAssetGroup.@Nullable AssetInfo baseAssetPath;
|
||||
protected Map<ResourceKey<EquipmentAsset>, MaterialAssetGroup.AssetInfo> assetPathOverrides = Collections.emptyMap();
|
||||
protected net.minecraft.network.chat.@Nullable Component description;
|
||||
|
||||
protected final Conversions conversions;
|
||||
|
||||
public PaperTrimMaterialRegistryEntry(final Conversions conversions, final @Nullable TrimMaterial internal) {
|
||||
this.conversions = conversions;
|
||||
if (internal == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.baseAssetPath = internal.assets().base();
|
||||
this.assetPathOverrides = internal.assets().overrides();
|
||||
this.description = internal.description();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@KeyPattern.Value
|
||||
public String baseAssetPath() {
|
||||
@Subst("suffix") final String path = asConfigured(this.baseAssetPath, "baseAssetPath").suffix();
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Unmodifiable Map<Key, String> assetPathOverrides() {
|
||||
if (this.assetPathOverrides.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
final ImmutableMap.Builder<Key, String> builder = ImmutableMap.builder();
|
||||
this.assetPathOverrides.forEach((key, value) -> {
|
||||
builder.put(PaperAdventure.asAdventureKey(key), value.suffix());
|
||||
});
|
||||
return builder.buildOrThrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component description() {
|
||||
return this.conversions.asAdventure(asConfigured(this.description, "description"));
|
||||
}
|
||||
|
||||
public static final class PaperBuilder extends PaperTrimMaterialRegistryEntry implements Builder, PaperRegistryBuilder<TrimMaterial, org.bukkit.inventory.meta.trim.TrimMaterial> {
|
||||
|
||||
public PaperBuilder(final Conversions conversions, final @Nullable TrimMaterial internal) {
|
||||
super(conversions, internal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder baseAssetPath(final String baseAssetPath) {
|
||||
this.baseAssetPath = new MaterialAssetGroup.AssetInfo(asArgument(baseAssetPath, "baseAssetPath"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder assetPathOverrides(final Map<Key, String> assetPathOverrides) {
|
||||
final Map<Key, String> input = asArgument(assetPathOverrides, "assetPathOverrides");
|
||||
if (input.isEmpty()) {
|
||||
this.assetPathOverrides = Collections.emptyMap();
|
||||
} else {
|
||||
final ImmutableMap.Builder<ResourceKey<EquipmentAsset>, MaterialAssetGroup.AssetInfo> builder = ImmutableMap.builder();
|
||||
input.forEach((key, value) -> {
|
||||
builder.put(PaperAdventure.asVanilla(EquipmentAssets.ROOT_ID, key), new MaterialAssetGroup.AssetInfo(value));
|
||||
});
|
||||
this.assetPathOverrides = builder.buildOrThrow();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder description(final Component description) {
|
||||
this.description = this.conversions.asVanilla(asArgument(description, "description"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrimMaterial build() {
|
||||
return new TrimMaterial(
|
||||
new MaterialAssetGroup(
|
||||
asConfigured(this.baseAssetPath, "baseAssetPath"),
|
||||
asConfigured(this.assetPathOverrides, "assetPathOverrides")
|
||||
),
|
||||
asConfigured(this.description, "description")
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,82 @@
|
||||
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.kyori.adventure.text.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.equipment.trim.TrimPattern;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.asArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.asConfigured;
|
||||
|
||||
public class PaperTrimPatternRegistryEntry implements TrimPatternRegistryEntry {
|
||||
|
||||
protected @Nullable ResourceLocation assetId;
|
||||
protected net.minecraft.network.chat.@Nullable Component description;
|
||||
protected boolean decal = false;
|
||||
|
||||
protected final Conversions conversions;
|
||||
|
||||
public PaperTrimPatternRegistryEntry(final Conversions conversions, final @Nullable TrimPattern internal) {
|
||||
this.conversions = conversions;
|
||||
if (internal == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.assetId = internal.assetId();
|
||||
this.description = internal.description();
|
||||
this.decal = internal.decal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key assetId() {
|
||||
return PaperAdventure.asAdventure(asConfigured(this.assetId, "assetId"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component description() {
|
||||
return this.conversions.asAdventure(asConfigured(this.description, "description"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean decal() {
|
||||
return this.decal;
|
||||
}
|
||||
|
||||
public static final class PaperBuilder extends PaperTrimPatternRegistryEntry implements Builder, PaperRegistryBuilder<TrimPattern, org.bukkit.inventory.meta.trim.TrimPattern> {
|
||||
|
||||
public PaperBuilder(final Conversions conversions, final @Nullable TrimPattern internal) {
|
||||
super(conversions, internal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder assetId(final Key key) {
|
||||
this.assetId = PaperAdventure.asVanilla(asArgument(key, "assetId"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder description(final Component description) {
|
||||
this.description = this.conversions.asVanilla(asArgument(description, "description"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder decal(final boolean decal) {
|
||||
this.decal = decal;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrimPattern build() {
|
||||
return new TrimPattern(
|
||||
asConfigured(this.assetId, "assetId"),
|
||||
asConfigured(this.description, "description"),
|
||||
this.decal
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user