diff options
author | Jake Potrebic <[email protected]> | 2024-06-03 13:18:17 -0700 |
---|---|---|
committer | Owen1212055 <[email protected]> | 2024-11-18 14:50:37 -0500 |
commit | 04df425a8483d35eb8e356d032e208bcfeb90dbe (patch) | |
tree | 006f3c29c578412402bb9baf568464f702e02c31 | |
parent | 09b7e3b9cf0002f1538fddcae1df53f16a73ad48 (diff) | |
download | Paper-04df425a8483d35eb8e356d032e208bcfeb90dbe.tar.gz Paper-04df425a8483d35eb8e356d032e208bcfeb90dbe.zip |
add DataComponentType#isPersistent
-rw-r--r-- | patches/api/0485-WIP-DataComponent-API.patch | 12 | ||||
-rw-r--r-- | patches/server/1054-WIP-DataComponent-API.patch | 21 |
2 files changed, 23 insertions, 10 deletions
diff --git a/patches/api/0485-WIP-DataComponent-API.patch b/patches/api/0485-WIP-DataComponent-API.patch index 8fb35c5a5a..d3de7b1237 100644 --- a/patches/api/0485-WIP-DataComponent-API.patch +++ b/patches/api/0485-WIP-DataComponent-API.patch @@ -6,10 +6,10 @@ Subject: [PATCH] WIP DataComponent API diff --git a/src/main/java/io/papermc/paper/component/DataComponentType.java b/src/main/java/io/papermc/paper/component/DataComponentType.java new file mode 100644 -index 0000000000000000000000000000000000000000..8185d943d95153bdff00629af8ace46f4ffb65fe +index 0000000000000000000000000000000000000000..50d15b4e0ed5cd17fdc95476ee4650ef918af62c --- /dev/null +++ b/src/main/java/io/papermc/paper/component/DataComponentType.java -@@ -0,0 +1,19 @@ +@@ -0,0 +1,27 @@ +package io.papermc.paper.component; + +import org.bukkit.Keyed; @@ -18,6 +18,14 @@ index 0000000000000000000000000000000000000000..8185d943d95153bdff00629af8ace46f +public interface DataComponentType extends Keyed { + ++ /** ++ * Checks if this data component type is persistent, or ++ * that it will be saved with any itemstack it's attached to. ++ * ++ * @return true if persistent, false otherwise ++ */ ++ boolean isPersistent(); ++ + @SuppressWarnings("unused") + @ApiStatus.NonExtendable + interface Valued<T> extends DataComponentType { diff --git a/patches/server/1054-WIP-DataComponent-API.patch b/patches/server/1054-WIP-DataComponent-API.patch index c195949054..deecca7ddc 100644 --- a/patches/server/1054-WIP-DataComponent-API.patch +++ b/patches/server/1054-WIP-DataComponent-API.patch @@ -174,10 +174,10 @@ index 0000000000000000000000000000000000000000..ca621dd53bee70a2f383517a4f1f4c15 +} diff --git a/src/main/java/io/papermc/paper/component/PaperComponentType.java b/src/main/java/io/papermc/paper/component/PaperComponentType.java new file mode 100644 -index 0000000000000000000000000000000000000000..4f2dc5add01a3998b4d46af0a663a6fe539f6b0c +index 0000000000000000000000000000000000000000..5639559368e6866e9b0afa6688f3b12cde4254f8 --- /dev/null +++ b/src/main/java/io/papermc/paper/component/PaperComponentType.java -@@ -0,0 +1,113 @@ +@@ -0,0 +1,118 @@ +package io.papermc.paper.component; + +import java.util.Collections; @@ -247,6 +247,11 @@ index 0000000000000000000000000000000000000000..4f2dc5add01a3998b4d46af0a663a6fe + return this.key; + } + ++ @Override ++ public boolean isPersistent() { ++ return !this.getHandle().isTransient(); ++ } ++ + public ComponentAdapter<NMS, T> getAdapter() { + return this.adapter; + } @@ -1779,7 +1784,7 @@ index 0000000000000000000000000000000000000000..a2c02206254a18e089cb2b40eab5c59e +io.papermc.paper.component.item.ComponentTypesBridgesImpl diff --git a/src/test/java/io/papermc/paper/item/ItemStackDataComponentTest.java b/src/test/java/io/papermc/paper/item/ItemStackDataComponentTest.java new file mode 100644 -index 0000000000000000000000000000000000000000..40c77423134931083913e871b80dae8e6e5f2194 +index 0000000000000000000000000000000000000000..f5c652d47bfa539bd5ecb8b8f7107e1675d3ec3b --- /dev/null +++ b/src/test/java/io/papermc/paper/item/ItemStackDataComponentTest.java @@ -0,0 +1,127 @@ @@ -1844,7 +1849,7 @@ index 0000000000000000000000000000000000000000..40c77423134931083913e871b80dae8e + stack.setData(DataComponentTypes.HIDE_ADDITIONAL_TOOLTIP); + + Assertions.assertTrue(stack.getItemMeta().getItemFlags().contains(ItemFlag.HIDE_ADDITIONAL_TOOLTIP)); -+ stack.removeData(DataComponentTypes.HIDE_ADDITIONAL_TOOLTIP); ++ stack.unsetData(DataComponentTypes.HIDE_ADDITIONAL_TOOLTIP); + Assertions.assertFalse(stack.getItemMeta().getItemFlags().contains(ItemFlag.HIDE_ADDITIONAL_TOOLTIP)); + } + @@ -1855,11 +1860,11 @@ index 0000000000000000000000000000000000000000..40c77423134931083913e871b80dae8e + + Assertions.assertEquals(stack.getItemMeta().isHideTooltip(), stack.hasData(DataComponentTypes.HIDE_TOOLTIP)); + Assertions.assertTrue(stack.getItemMeta().isHideTooltip()); -+ stack.removeData(DataComponentTypes.HIDE_TOOLTIP); ++ stack.unsetData(DataComponentTypes.HIDE_TOOLTIP); + Assertions.assertFalse(stack.getItemMeta().isHideTooltip()); + stack = new ItemStack(Material.STONE); + -+ stack.removeData(DataComponentTypes.HIDE_TOOLTIP); ++ stack.unsetData(DataComponentTypes.HIDE_TOOLTIP); + Assertions.assertFalse(stack.getItemMeta().isHideTooltip()); + Assertions.assertEquals(stack.getItemMeta().isHideTooltip(), stack.hasData(DataComponentTypes.HIDE_TOOLTIP)); + } @@ -1879,7 +1884,7 @@ index 0000000000000000000000000000000000000000..40c77423134931083913e871b80dae8e + CrossbowMeta meta = (CrossbowMeta) stack.getItemMeta(); + Assertions.assertEquals(meta.getChargedProjectiles().getFirst(), projectile); + -+ stack.removeData(DataComponentTypes.CHARGED_PROJECTILES); ++ stack.unsetData(DataComponentTypes.CHARGED_PROJECTILES); + meta = (CrossbowMeta) stack.getItemMeta(); + Assertions.assertTrue(meta.getChargedProjectiles().isEmpty()); + } @@ -1893,7 +1898,7 @@ index 0000000000000000000000000000000000000000..40c77423134931083913e871b80dae8e + DecoratedPot decoratedPot = (DecoratedPot) state; + + Assertions.assertEquals(decoratedPot.getSherd(DecoratedPot.Side.BACK), Material.DANGER_POTTERY_SHERD); -+ stack.removeData(DataComponentTypes.POT_DECORATIONS); ++ stack.unsetData(DataComponentTypes.POT_DECORATIONS); + decoratedPot = (DecoratedPot) ((BlockStateMeta) stack.getItemMeta()).getBlockState(); + Assertions.assertTrue(decoratedPot.getSherds().values().stream().allMatch((m) -> m == Material.BRICK)); + } |