#822: Add experimental armor trim API

By: Parker Hawke <hawkeboyz2@hotmail.com>
This commit is contained in:
Bukkit/Spigot 2023-04-07 16:50:59 +10:00
parent bec81a9aff
commit 943a1d3dd9
7 changed files with 301 additions and 0 deletions

View File

@ -18,7 +18,10 @@ import org.bukkit.entity.Villager;
import org.bukkit.entity.memory.MemoryKey;
import org.bukkit.generator.structure.Structure;
import org.bukkit.generator.structure.StructureType;
import org.bukkit.inventory.meta.trim.TrimMaterial;
import org.bukkit.inventory.meta.trim.TrimPattern;
import org.bukkit.loot.LootTables;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -149,6 +152,22 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
* @see Sound
*/
Registry<Sound> SOUNDS = new SimpleRegistry<>(Sound.class);
/**
* Trim materials.
*
* @see TrimMaterial
*/
@MinecraftExperimental
@ApiStatus.Experimental
Registry<TrimMaterial> TRIM_MATERIAL = Bukkit.getRegistry(TrimMaterial.class);
/**
* Trim patterns.
*
* @see TrimPattern
*/
@MinecraftExperimental
@ApiStatus.Experimental
Registry<TrimPattern> TRIM_PATTERN = Bukkit.getRegistry(TrimPattern.class);
/**
* Villager profession.
*

View File

@ -0,0 +1,47 @@
package org.bukkit.inventory.meta;
import org.bukkit.MinecraftExperimental;
import org.bukkit.inventory.meta.trim.ArmorTrim;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Represents armor that an entity can equip.
* <p>
* <strong>Note: Armor trims are part of an experimental feature of Minecraft
* and hence subject to change.</strong>
*/
@MinecraftExperimental
@ApiStatus.Experimental
public interface ArmorMeta extends ItemMeta {
/**
* Check whether or not this item has an armor trim.
*
* @return true if has a trim, false otherwise
*/
boolean hasTrim();
/**
* Set the {@link ArmorTrim}.
* <p>
* While vanilla only allows for armor to be trimmed, trims may be applied
* to any item whether or not the client will actually render a trim.
*
* @param trim the trim to set, or null to remove it
*/
void setTrim(@Nullable ArmorTrim trim);
/**
* Get the {@link ArmorTrim}.
*
* @return the armor trim, or null if none
*/
@Nullable
ArmorTrim getTrim();
@Override
@NotNull
ArmorMeta clone();
}

View File

@ -0,0 +1,15 @@
package org.bukkit.inventory.meta;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
/**
* Represents armor that an entity can equip and can also be colored.
*/
@ApiStatus.Experimental
public interface ColorableArmorMeta extends ArmorMeta, LeatherArmorMeta {
@Override
@NotNull
ColorableArmorMeta clone();
}

View File

@ -0,0 +1,80 @@
package org.bukkit.inventory.meta.trim;
import com.google.common.base.Preconditions;
import java.util.Objects;
import org.bukkit.MinecraftExperimental;
import org.bukkit.inventory.meta.ArmorMeta;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
/**
* Represents an armor trim that may be applied to an item.
*
* @see ArmorMeta#setTrim(ArmorTrim)
* @apiNote Armor trims are part of an experimental feature of Minecraft and
* hence subject to change.
*/
@MinecraftExperimental
@ApiStatus.Experimental
public class ArmorTrim {
private final TrimMaterial material;
private final TrimPattern pattern;
/**
* Create a new {@link ArmorTrim} given a {@link TrimMaterial} and
* {@link TrimPattern}.
*
* @param material the material
* @param pattern the pattern
*/
public ArmorTrim(@NotNull TrimMaterial material, @NotNull TrimPattern pattern) {
Preconditions.checkArgument(material != null, "material must not be null");
Preconditions.checkArgument(pattern != null, "pattern must not be null");
this.material = material;
this.pattern = pattern;
}
/**
* Get the {@link TrimMaterial} for this armor trim.
*
* @return the material
*/
@NotNull
public TrimMaterial getMaterial() {
return material;
}
/**
* Get the {@link TrimPattern} for this armor trim.
*
* @return the pattern
*/
@NotNull
public TrimPattern getPattern() {
return pattern;
}
@Override
public int hashCode() {
int hash = 7;
hash = 31 * hash + Objects.hashCode(material);
hash = 31 * hash + Objects.hashCode(pattern);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof ArmorTrim)) {
return false;
}
ArmorTrim other = (ArmorTrim) obj;
return material == other.material && pattern == other.pattern;
}
}

View File

@ -0,0 +1,66 @@
package org.bukkit.inventory.meta.trim;
import org.bukkit.Keyed;
import org.bukkit.Material;
import org.bukkit.MinecraftExperimental;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
/**
* Represents a material that may be used in an {@link ArmorTrim}.
*
* @apiNote Armor trims are part of an experimental feature of Minecraft and
* hence subject to change. Constants in this class may be null if a data pack
* is not present to enable these features.
*/
@MinecraftExperimental
@ApiStatus.Experimental
public interface TrimMaterial extends Keyed {
/**
* {@link Material#QUARTZ}.
*/
public static final TrimMaterial QUARTZ = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("quartz"));
/**
* {@link Material#IRON_INGOT}.
*/
public static final TrimMaterial IRON = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("iron"));
/**
* {@link Material#NETHERITE_INGOT}.
*/
public static final TrimMaterial NETHERITE = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("netherite"));
/**
* {@link Material#REDSTONE}.
*/
public static final TrimMaterial REDSTONE = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("redstone"));
/**
* {@link Material#COPPER_INGOT}.
*/
public static final TrimMaterial COPPER = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("copper"));
/**
* {@link Material#GOLD_INGOT}.
*/
public static final TrimMaterial GOLD = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("gold"));
/**
* {@link Material#EMERALD}.
*/
public static final TrimMaterial EMERALD = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("emerald"));
/**
* {@link Material#DIAMOND}.
*/
public static final TrimMaterial DIAMOND = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("diamond"));
/**
* {@link Material#LAPIS_LAZULI}.
*/
public static final TrimMaterial LAPIS = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("lapis"));
/**
* {@link Material#AMETHYST_SHARD}.
*/
public static final TrimMaterial AMETHYST = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("amethyst"));
@NotNull
@Override
public NamespacedKey getKey(); // Satisfies Checkstyle for now
}

View File

@ -0,0 +1,70 @@
package org.bukkit.inventory.meta.trim;
import org.bukkit.Keyed;
import org.bukkit.Material;
import org.bukkit.MinecraftExperimental;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
/**
* Represents a pattern that may be used in an {@link ArmorTrim}.
*
* @apiNote Armor trims are part of an experimental feature of Minecraft and
* hence subject to change. Constants in this class may be null if a data pack
* is not present to enable these features.
*/
@MinecraftExperimental
@ApiStatus.Experimental
public interface TrimPattern extends Keyed {
/**
* {@link Material#SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE}.
*/
public static final TrimPattern SENTRY = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("sentry"));
/**
* {@link Material#DUNE_ARMOR_TRIM_SMITHING_TEMPLATE}.
*/
public static final TrimPattern DUNE = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("dune"));
/**
* {@link Material#COAST_ARMOR_TRIM_SMITHING_TEMPLATE}.
*/
public static final TrimPattern COAST = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("coast"));
/**
* {@link Material#WILD_ARMOR_TRIM_SMITHING_TEMPLATE}.
*/
public static final TrimPattern WILD = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("wild"));
/**
* {@link Material#WARD_ARMOR_TRIM_SMITHING_TEMPLATE}.
*/
public static final TrimPattern WARD = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("ward"));
/**
* {@link Material#EYE_ARMOR_TRIM_SMITHING_TEMPLATE}.
*/
public static final TrimPattern EYE = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("eye"));
/**
* {@link Material#VEX_ARMOR_TRIM_SMITHING_TEMPLATE}.
*/
public static final TrimPattern VEX = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("vex"));
/**
* {@link Material#TIDE_ARMOR_TRIM_SMITHING_TEMPLATE}.
*/
public static final TrimPattern TIDE = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("tide"));
/**
* {@link Material#SNOUT_ARMOR_TRIM_SMITHING_TEMPLATE}.
*/
public static final TrimPattern SNOUT = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("snout"));
/**
* {@link Material#RIB_ARMOR_TRIM_SMITHING_TEMPLATE}.
*/
public static final TrimPattern RIB = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("rib"));
/**
* {@link Material#SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE}.
*/
public static final TrimPattern SPIRE = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("spire"));
@NotNull
@Override
public NamespacedKey getKey(); // Satisfies Checkstyle for now
}

View File

@ -0,0 +1,4 @@
/**
* Armor trim meta types.
*/
package org.bukkit.inventory.meta.trim;