diff options
author | Jake Potrebic <[email protected]> | 2024-06-03 12:27:34 -0700 |
---|---|---|
committer | Owen1212055 <[email protected]> | 2024-11-18 14:50:37 -0500 |
commit | 09b7e3b9cf0002f1538fddcae1df53f16a73ad48 (patch) | |
tree | 99ba7215cc9ad4e848d4047d1aafe2f682412837 | |
parent | a9a35ffe103cb3a428806e47522e10e12833fc3b (diff) | |
download | Paper-09b7e3b9cf0002f1538fddcae1df53f16a73ad48.tar.gz Paper-09b7e3b9cf0002f1538fddcae1df53f16a73ad48.zip |
complete javadocs and add to Material
-rw-r--r-- | patches/api/0485-WIP-DataComponent-API.patch | 114 | ||||
-rw-r--r-- | patches/server/1054-WIP-DataComponent-API.patch | 24 |
2 files changed, 119 insertions, 19 deletions
diff --git a/patches/api/0485-WIP-DataComponent-API.patch b/patches/api/0485-WIP-DataComponent-API.patch index 11143445af..8fb35c5a5a 100644 --- a/patches/api/0485-WIP-DataComponent-API.patch +++ b/patches/api/0485-WIP-DataComponent-API.patch @@ -943,7 +943,7 @@ index 7b79bf33074355020e0b3b5ef40c7f2e6ba644b4..5cf3aa4641822c91adfbd70a847ca529 + RegistryKey<DataComponentType> DATA_COMPONENT_TYPE = create("data_component_type"); } diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java -index 7509b61dfdc0a6675256970cb850b08f9e814580..35127ef25494f70a0d57ff8b8d0c3be5e14286cd 100644 +index 7509b61dfdc0a6675256970cb850b08f9e814580..28e2628d8d0a6af742b2fa89e5581e6b0d1a38a4 100644 --- a/src/main/java/org/bukkit/Material.java +++ b/src/main/java/org/bukkit/Material.java @@ -131,7 +131,7 @@ import org.jetbrains.annotations.Nullable; @@ -955,6 +955,66 @@ index 7509b61dfdc0a6675256970cb850b08f9e814580..35127ef25494f70a0d57ff8b8d0c3be5 STONE(22948), GRANITE(21091), POLISHED_GRANITE(5477), +@@ -5710,6 +5710,7 @@ public enum Material implements Keyed, Translatable, net.kyori.adventure.transla + */ + @ApiStatus.Internal + @Nullable ++ @org.jetbrains.annotations.Contract(pure = true) // Paper + public ItemType asItemType() { + Material material = this; + if (isLegacy()) { +@@ -5726,6 +5727,7 @@ public enum Material implements Keyed, Translatable, net.kyori.adventure.transla + */ + @ApiStatus.Internal + @Nullable ++ @org.jetbrains.annotations.Contract(pure = true) // Paper + public BlockType asBlockType() { + Material material = this; + if (isLegacy()) { +@@ -5733,4 +5735,43 @@ public enum Material implements Keyed, Translatable, net.kyori.adventure.transla + } + return Registry.BLOCK.get(material.key); + } ++ ++ // Paper start - data component API ++ /** ++ * Gets the default data component value for the data type for this ItemType. ++ * ++ * @param dataComponentType the data component type ++ * @return the default value or null if there is none ++ * @param <T> the value type ++ * @see #hasDefaultData(io.papermc.paper.component.DataComponentType) for DataComponentType.NonValued ++ * @throws IllegalArgumentException if {@link #isItem()} is false ++ */ ++ public @Nullable <T> T getDefaultData(final io.papermc.paper.component.DataComponentType.@NotNull Valued<T> dataComponentType) { ++ Preconditions.checkArgument(this.asItemType() != null); ++ return this.asItemType().getDefaultData(dataComponentType); ++ } ++ ++ /** ++ * Checks if the data component type has a default value for this ItemType. ++ * ++ * @param dataComponentType the data component type ++ * @return true if there is a default value ++ * @throws IllegalArgumentException if {@link #isItem()} is false ++ */ ++ public boolean hasDefaultData(final io.papermc.paper.component.@NotNull DataComponentType dataComponentType) { ++ Preconditions.checkArgument(this.asItemType() != null); ++ return this.asItemType().hasDefaultData(dataComponentType); ++ } ++ ++ /** ++ * Gets the default data component types for this ItemType. ++ * ++ * @return an immutable set of data component types ++ * @throws IllegalArgumentException if {@link #isItem()} is false ++ */ ++ public [email protected] @NotNull Set<io.papermc.paper.component.DataComponentType> getDefaultDataTypes() { ++ Preconditions.checkArgument(this.asItemType() != null); ++ return this.asItemType().getDefaultDataTypes(); ++ } ++ // Paper end - data component API + } diff --git a/src/main/java/org/bukkit/Registry.java b/src/main/java/org/bukkit/Registry.java index 88bb3b9ae99fae97ec21972b75ec43cb6b7b22b5..ca3a0a268a80ea3d342ec1c2c9d8ae105d271c88 100644 --- a/src/main/java/org/bukkit/Registry.java @@ -981,10 +1041,10 @@ index e20f64828548c647a29dad5a475f4596cad88cd8..80c10ab30ca6ea6e2a80a916d8a5831a /** diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java -index 15a59a27f0854ff6f4038349d3a0d00347130140..44951ecb5ae4713cce515e2952c8c7e8c8d4eac4 100644 +index 15a59a27f0854ff6f4038349d3a0d00347130140..82574d096ac8f35ee69b0e9c248ec498c0655332 100644 --- a/src/main/java/org/bukkit/inventory/ItemStack.java +++ b/src/main/java/org/bukkit/inventory/ItemStack.java -@@ -1029,4 +1029,96 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat +@@ -1029,4 +1029,107 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat return Bukkit.getUnsafe().computeTooltipLines(this, tooltipContext, player); } // Paper end - expose itemstack tooltip lines @@ -996,7 +1056,7 @@ index 15a59a27f0854ff6f4038349d3a0d00347130140..44951ecb5ae4713cce515e2952c8c7e8 + * @param type the data component type + * @return the value for the data component type, or null if not set or marked as removed + * @param <T> the value type -+ * @see #hasData(io.papermc.paper.component.DataComponentType) for non-valued data component types ++ * @see #hasData(io.papermc.paper.component.DataComponentType) for DataComponentType.NonValued + */ + @org.jetbrains.annotations.Contract(pure = true) + public <T> @Nullable T getData(final io.papermc.paper.component.DataComponentType.@NotNull Valued<T> type) { @@ -1036,8 +1096,8 @@ index 15a59a27f0854ff6f4038349d3a0d00347130140..44951ecb5ae4713cce515e2952c8c7e8 + * @return an immutable set of data component types + */ + @org.jetbrains.annotations.Contract("-> new") -+ public [email protected] Set<io.papermc.paper.component.@NotNull DataComponentType> getDataComponents() { -+ return this.craftDelegate.getDataComponents(); ++ public [email protected] Set<io.papermc.paper.component.@NotNull DataComponentType> getDataTypes() { ++ return this.craftDelegate.getDataTypes(); + } + + /** @@ -1073,28 +1133,58 @@ index 15a59a27f0854ff6f4038349d3a0d00347130140..44951ecb5ae4713cce515e2952c8c7e8 + + /** + * Resets the value of this component to be the default -+ * value for the item type from {@link ItemType#getDefaultDataComponent(io.papermc.paper.component.DataComponentType.Valued)} ++ * value for the item type from {@link Material#getDefaultData(io.papermc.paper.component.DataComponentType.Valued)} + * @param type data component type to reset + */ + public void resetData(final io.papermc.paper.component.@NotNull DataComponentType type) { + this.craftDelegate.resetData(type); + } ++ ++ /** ++ * Checks if the data component type is overridden from the default for the ++ * item type. ++ * ++ * @param type the data component type ++ * @return true if the data type is overridden ++ */ ++ public boolean isOverridden(final io.papermc.paper.component.@NotNull DataComponentType type) { ++ return this.craftDelegate.isOverridden(type); ++ } + // Paper end - data component API } diff --git a/src/main/java/org/bukkit/inventory/ItemType.java b/src/main/java/org/bukkit/inventory/ItemType.java -index 077bd4d4e50169780f27e8502104e9e4b2ecdae6..173fdeac69729e3a4bc75d2dae1b1db588bb6c5b 100644 +index 077bd4d4e50169780f27e8502104e9e4b2ecdae6..a202cede658cb6fb5c12c80dceac7a514a31d46c 100644 --- a/src/main/java/org/bukkit/inventory/ItemType.java +++ b/src/main/java/org/bukkit/inventory/ItemType.java -@@ -2443,4 +2443,12 @@ public interface ItemType extends Keyed, Translatable, net.kyori.adventure.trans +@@ -2443,4 +2443,31 @@ public interface ItemType extends Keyed, Translatable, net.kyori.adventure.trans @Override @NotNull String getTranslationKey(); // Paper end - add Translatable + + // Paper start - data component API -+ @Nullable <T> T getDefaultDataComponent(io.papermc.paper.component.DataComponentType.@NotNull Valued<T> dataComponentType); ++ /** ++ * Gets the default data component value for the data type for this ItemType. ++ * ++ * @param dataComponentType the data component type ++ * @return the default value or null if there is none ++ * @param <T> the value type ++ * @see #hasDefaultData(io.papermc.paper.component.DataComponentType) for DataComponentType.NonValued ++ */ ++ @Nullable <T> T getDefaultData(io.papermc.paper.component.DataComponentType.@NotNull Valued<T> dataComponentType); + -+ boolean hasDefaultDataComponent(io.papermc.paper.component.@NotNull DataComponentType dataComponentType); ++ /** ++ * Checks if the data component type has a default value for this ItemType. ++ * ++ * @param dataComponentType the data component type ++ * @return true if there is a default value ++ */ ++ boolean hasDefaultData(io.papermc.paper.component.@NotNull DataComponentType dataComponentType); + -+ [email protected] @NotNull Set<io.papermc.paper.component.DataComponentType> getDefaultDataComponentTypes(); ++ /** ++ * Gets the default data component types for this ItemType. ++ * ++ * @return an immutable set of data component types ++ */ ++ [email protected] @NotNull Set<io.papermc.paper.component.DataComponentType> getDefaultDataTypes(); + // Paper end - data component API } diff --git a/patches/server/1054-WIP-DataComponent-API.patch b/patches/server/1054-WIP-DataComponent-API.patch index 6867fa7d85..c195949054 100644 --- a/patches/server/1054-WIP-DataComponent-API.patch +++ b/patches/server/1054-WIP-DataComponent-API.patch @@ -1573,7 +1573,7 @@ index af18de11dd55938b6091f5ab183bd3fe4e8df152..dad6cb4bbb52f4ce7e8f40131ee0bd37 ItemEnchantments(Object2IntAVLTreeMap<Holder<Enchantment>> enchantments, boolean showInTooltip) { // Paper diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java -index 3496b98ff0b984dbfec4f0983459a273dc0e3471..d14d0b4a0edbff19d6b5ce0674aa70ba7af902d6 100644 +index 3496b98ff0b984dbfec4f0983459a273dc0e3471..c640f5f36fb0d3935ac4decd61a458b7c74a6f54 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java @@ -167,7 +167,7 @@ public final class CraftItemStack extends ItemStack { @@ -1612,7 +1612,7 @@ index 3496b98ff0b984dbfec4f0983459a273dc0e3471..d14d0b4a0edbff19d6b5ce0674aa70ba item.set(DataComponents.PROFILE, new net.minecraft.world.item.component.ResolvableProfile(gameProfile)); } }; -@@ -768,4 +768,79 @@ public final class CraftItemStack extends ItemStack { +@@ -768,4 +768,89 @@ public final class CraftItemStack extends ItemStack { return mirrored; } // Paper end @@ -1635,7 +1635,7 @@ index 3496b98ff0b984dbfec4f0983459a273dc0e3471..d14d0b4a0edbff19d6b5ce0674aa70ba + } + + @Override -+ public java.util.Set<io.papermc.paper.component.DataComponentType> getDataComponents() { ++ public java.util.Set<io.papermc.paper.component.DataComponentType> getDataTypes() { + if (this.isEmpty()) { + return java.util.Collections.emptySet(); + } @@ -1690,10 +1690,20 @@ index 3496b98ff0b984dbfec4f0983459a273dc0e3471..d14d0b4a0edbff19d6b5ce0674aa70ba + // if nmsValue is not null, it will still clear any set patch because it will equal the default value + this.handle.set(nms, nmsValue); + } ++ ++ @Override ++ public boolean isOverridden(final io.papermc.paper.component.DataComponentType type) { ++ if (this.isEmpty()) { ++ return false; ++ } ++ final net.minecraft.core.component.DataComponentType<?> nms = io.papermc.paper.component.PaperComponentType.bukkitToMinecraft(type); ++ // maybe a more efficient way is to expose the "patch" map in PatchedDataComponentMap and just check if the type exists as a key ++ return java.util.Objects.equals(this.handle.get(nms), this.handle.getPrototype().get(nms)); ++ } + // Paper end - data component API } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java -index b54be1122af2b303c0f063ff6b61bf8e2478b0df..f0c394741c56b23df47c1b3e6790d4d41b9d851b 100644 +index b54be1122af2b303c0f063ff6b61bf8e2478b0df..a66775b21e829f76de9cf234b702f5f03857bac8 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java @@ -253,4 +253,21 @@ public class CraftItemType<M extends ItemMeta> implements ItemType.Typed<M>, Han @@ -1703,17 +1713,17 @@ index b54be1122af2b303c0f063ff6b61bf8e2478b0df..f0c394741c56b23df47c1b3e6790d4d4 + + // Paper start - data component API + @Override -+ public <T> T getDefaultDataComponent(final io.papermc.paper.component.DataComponentType.Valued<T> dataComponentType) { ++ public <T> T getDefaultData(final io.papermc.paper.component.DataComponentType.Valued<T> dataComponentType) { + return io.papermc.paper.component.PaperComponentType.convertDataComponentValue(this.item.components(), ((io.papermc.paper.component.PaperComponentType.ValuedImpl<T, ?>) dataComponentType)); + } + + @Override -+ public boolean hasDefaultDataComponent(final io.papermc.paper.component.DataComponentType dataComponentType) { ++ public boolean hasDefaultData(final io.papermc.paper.component.DataComponentType dataComponentType) { + return this.item.components().has(io.papermc.paper.component.PaperComponentType.bukkitToMinecraft(dataComponentType)); + } + + @Override -+ public java.util.Set<io.papermc.paper.component.DataComponentType> getDefaultDataComponentTypes() { ++ public java.util.Set<io.papermc.paper.component.DataComponentType> getDefaultDataTypes() { + return io.papermc.paper.component.PaperComponentType.minecraftToBukkit(this.item.components().keySet()); + } + // Paper end - data component API |