aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOwen1212055 <[email protected]>2024-12-04 00:26:31 -0500
committerOwen1212055 <[email protected]>2024-12-04 00:26:31 -0500
commit7e601ad916eb6e6e2635e6a0b87852af40e63eae (patch)
tree43a5701d1e70f4f6cd2c490df439102d7efe6352
parentcbd578c7b541240f4e9405d4db0fe4270125e873 (diff)
downloadPaper-7e601ad916eb6e6e2635e6a0b87852af40e63eae.tar.gz
Paper-7e601ad916eb6e6e2635e6a0b87852af40e63eae.zip
Implement new CustomModelData
-rw-r--r--patches/api/0495-DataComponent-API.patch105
-rw-r--r--patches/server/1031-DataComponent-API.patch107
2 files changed, 189 insertions, 23 deletions
diff --git a/patches/api/0495-DataComponent-API.patch b/patches/api/0495-DataComponent-API.patch
index 550b81d926..7b2b1bc9e4 100644
--- a/patches/api/0495-DataComponent-API.patch
+++ b/patches/api/0495-DataComponent-API.patch
@@ -853,13 +853,15 @@ index 0000000000000000000000000000000000000000..8c88bbbeef179e6c6666d07c8b28157e
+}
diff --git a/src/main/java/io/papermc/paper/datacomponent/item/CustomModelData.java b/src/main/java/io/papermc/paper/datacomponent/item/CustomModelData.java
new file mode 100644
-index 0000000000000000000000000000000000000000..31921e8d94ea117dce298fd97e95ad9608158a1d
+index 0000000000000000000000000000000000000000..734b1750a00f711a57186f15285cfc4c2563b1a2
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datacomponent/item/CustomModelData.java
-@@ -0,0 +1,51 @@
+@@ -0,0 +1,144 @@
+package io.papermc.paper.datacomponent.item;
+
+import java.util.List;
++import io.papermc.paper.datacomponent.DataComponentBuilder;
++import org.bukkit.Color;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.Contract;
+import org.jspecify.annotations.NullMarked;
@@ -874,7 +876,10 @@ index 0000000000000000000000000000000000000000..31921e8d94ea117dce298fd97e95ad96
+public interface CustomModelData {
+
-+ // TODO
++ @Contract(value = "-> new", pure = true)
++ static CustomModelData.Builder customModelData() {
++ return ItemComponentTypesBridge.bridge().customModelData();
++ }
+
+ /**
+ * Gets the custom model data float values.
@@ -906,7 +911,95 @@ index 0000000000000000000000000000000000000000..31921e8d94ea117dce298fd97e95ad96
+ * @return the color values
+ */
+ @Contract(pure = true)
-+ List<Integer> colors();
++ List<Color> colors();
++
++ /**
++ * Builder for {@link CustomModelData}.
++ */
++ @ApiStatus.Experimental
++ @ApiStatus.NonExtendable
++ interface Builder extends DataComponentBuilder<CustomModelData> {
++
++ /**
++ * Adds a float to this custom model data.
++ *
++ * @param num the float
++ * @return the builder for chaining
++ * @see #floats()
++ */
++ @Contract(value = "_ -> this", mutates = "this")
++ CustomModelData.Builder addFloat(float num);
++
++ /**
++ * Adds multiple floats to this custom model data.
++ *
++ * @param nums the floats
++ * @return the builder for chaining
++ * @see #floats()
++ */
++ @Contract(value = "_ -> this", mutates = "this")
++ CustomModelData.Builder addFloats(List<Float> nums);
++
++ /**
++ * Adds a flag to this custom model data.
++ *
++ * @param flag the flag
++ * @return the builder for chaining
++ * @see #floats()
++ */
++ @Contract(value = "_ -> this", mutates = "this")
++ CustomModelData.Builder addFlag(boolean flag);
++
++ /**
++ * Adds multiple flags to this custom model data.
++ *
++ * @param flags the flags
++ * @return the builder for chaining
++ * @see #flags()
++ */
++ @Contract(value = "_ -> this", mutates = "this")
++ CustomModelData.Builder addFlags(List<Boolean> flags);
++
++ /**
++ * Adds a string to this custom model data.
++ *
++ * @param string the string
++ * @return the builder for chaining
++ * @see #strings()
++ */
++ @Contract(value = "_ -> this", mutates = "this")
++ CustomModelData.Builder addString(String string);
++
++ /**
++ * Adds multiple strings to this custom model data.
++ *
++ * @param strings the strings
++ * @return the builder for chaining
++ * @see #strings()
++ */
++ @Contract(value = "_ -> this", mutates = "this")
++ CustomModelData.Builder addStrings(List<String> strings);
++
++ /**
++ * Adds a color to this custom model data.
++ *
++ * @param color the float
++ * @return the builder for chaining
++ * @see #colors()
++ */
++ @Contract(value = "_ -> this", mutates = "this")
++ CustomModelData.Builder addColor(Color color);
++
++ /**
++ * Adds multiple colors to this custom model data.
++ *
++ * @param colors the colors
++ * @return the builder for chaining
++ * @see #colors()
++ */
++ @Contract(value = "_ -> this", mutates = "this")
++ CustomModelData.Builder addColors(List<Color> colors);
++ }
+}
diff --git a/src/main/java/io/papermc/paper/datacomponent/item/DamageResistant.java b/src/main/java/io/papermc/paper/datacomponent/item/DamageResistant.java
new file mode 100644
@@ -1684,7 +1777,7 @@ index 0000000000000000000000000000000000000000..56a3e678c6658dd617da4974d9392006
+}
diff --git a/src/main/java/io/papermc/paper/datacomponent/item/ItemComponentTypesBridge.java b/src/main/java/io/papermc/paper/datacomponent/item/ItemComponentTypesBridge.java
new file mode 100644
-index 0000000000000000000000000000000000000000..1ce34642371a65590ce1ac74b402ccfc301671d7
+index 0000000000000000000000000000000000000000..12df050d35a8470d9a111c98d9c0e22a52b684d1
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datacomponent/item/ItemComponentTypesBridge.java
@@ -0,0 +1,112 @@
@@ -1778,7 +1871,7 @@ index 0000000000000000000000000000000000000000..1ce34642371a65590ce1ac74b402ccfc
+
+ ItemAdventurePredicate.Builder itemAdventurePredicate();
+
-+ CustomModelData customModelData(int id);
++ CustomModelData.Builder customModelData();
+
+ MapId mapId(int id);
+
diff --git a/patches/server/1031-DataComponent-API.patch b/patches/server/1031-DataComponent-API.patch
index 9f3257ced1..af60a90785 100644
--- a/patches/server/1031-DataComponent-API.patch
+++ b/patches/server/1031-DataComponent-API.patch
@@ -348,10 +348,10 @@ index 0000000000000000000000000000000000000000..e2fcf870b2256e3df90372c3208f3ed2
+}
diff --git a/src/main/java/io/papermc/paper/datacomponent/item/ItemComponentTypesBridgesImpl.java b/src/main/java/io/papermc/paper/datacomponent/item/ItemComponentTypesBridgesImpl.java
new file mode 100644
-index 0000000000000000000000000000000000000000..e015b9c1fc5414afe0e040438fd95ef082c69a30
+index 0000000000000000000000000000000000000000..15c66b0186ffede98a196f63e0e616b125bac35a
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datacomponent/item/ItemComponentTypesBridgesImpl.java
-@@ -0,0 +1,240 @@
+@@ -0,0 +1,239 @@
+package io.papermc.paper.datacomponent.item;
+
+import com.destroystokyo.paper.profile.PlayerProfile;
@@ -577,9 +577,8 @@ index 0000000000000000000000000000000000000000..e015b9c1fc5414afe0e040438fd95ef0
+ }
+
+ @Override
-+ public CustomModelData customModelData(final int id) {
-+ throw new UnsupportedOperationException("Not implemented yet");
-+ //return new PaperCustomModelData(new net.minecraft.world.item.component.CustomModelData(id));
++ public CustomModelData.Builder customModelData() {
++ return new PaperCustomModelData.BuilderImpl();
+ }
+
+ @Override
@@ -964,13 +963,17 @@ index 0000000000000000000000000000000000000000..0bc2bad71d6945ca24f37008effc903a
+}
diff --git a/src/main/java/io/papermc/paper/datacomponent/item/PaperCustomModelData.java b/src/main/java/io/papermc/paper/datacomponent/item/PaperCustomModelData.java
new file mode 100644
-index 0000000000000000000000000000000000000000..f361f026acba97efb0482d4d792fefb33a4faf47
+index 0000000000000000000000000000000000000000..a47fe18c1b619df9ff3adacf5c7c670dece84179
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datacomponent/item/PaperCustomModelData.java
-@@ -0,0 +1,34 @@
+@@ -0,0 +1,109 @@
+package io.papermc.paper.datacomponent.item;
+
++import java.util.ArrayList;
++import java.util.Collections;
+import java.util.List;
++import io.papermc.paper.util.MCUtil;
++import org.bukkit.Color;
+import org.bukkit.craftbukkit.util.Handleable;
+
+public record PaperCustomModelData(
@@ -984,22 +987,93 @@ index 0000000000000000000000000000000000000000..f361f026acba97efb0482d4d792fefb3
+
+ @Override
+ public List<Float> floats() {
-+ return this.impl.floats();
++ return Collections.unmodifiableList(this.impl.floats());
+ }
+
+ @Override
+ public List<Boolean> flags() {
-+ return this.impl.flags();
++ return Collections.unmodifiableList(this.impl.flags());
+ }
+
+ @Override
+ public List<String> strings() {
-+ return this.impl.strings();
++ return Collections.unmodifiableList(this.impl.strings());
+ }
+
+ @Override
-+ public List<Integer> colors() {
-+ return this.impl.colors();
++ public List<Color> colors() {
++ return MCUtil.transformUnmodifiable(this.impl.colors(), Color::fromRGB);
++ }
++
++ static final class BuilderImpl implements CustomModelData.Builder {
++
++ private final List<Float> floats = new ArrayList<>();
++ private final List<Boolean> flags = new ArrayList<>();
++ private final List<String> strings = new ArrayList<>();
++ private final List<Integer> colors = new ArrayList<>();
++
++ @Override
++ public Builder addFloat(final float num) {
++ this.floats.add(num);
++ return this;
++ }
++
++ @Override
++ public Builder addFloats(final List<Float> nums) {
++ this.floats.addAll(nums);
++ return this;
++ }
++
++ @Override
++ public Builder addFlag(final boolean flag) {
++ this.flags.add(flag);
++ return this;
++ }
++
++ @Override
++ public Builder addFlags(final List<Boolean> flags) {
++ this.flags.addAll(flags);
++ return this;
++ }
++
++ @Override
++ public Builder addString(final String string) {
++ this.strings.add(string);
++ return this;
++ }
++
++ @Override
++ public Builder addStrings(final List<String> strings) {
++ this.strings.addAll(strings);
++ return this;
++ }
++
++ @Override
++ public Builder addColor(final Color color) {
++ this.colors.add(color.asRGB());
++ return this;
++ }
++
++ @Override
++ public Builder addColors(final List<Color> colors) {
++ for (Color color : colors) {
++ this.addColor(color);
++ }
++ return this;
++ }
++
++ @Override
++ public CustomModelData build() {
++ return new PaperCustomModelData(
++ new net.minecraft.world.item.component.CustomModelData(
++ this.floats,
++ this.flags,
++ this.strings,
++ this.colors
++ )
++ );
++ }
++
+ }
+}
diff --git a/src/main/java/io/papermc/paper/datacomponent/item/PaperDamageResistant.java b/src/main/java/io/papermc/paper/datacomponent/item/PaperDamageResistant.java
@@ -4090,10 +4164,10 @@ index 0000000000000000000000000000000000000000..4ee0491763341232844a99aa528310a3
+}
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..d868505098533dc62436767416f1ece0f7067f57
+index 0000000000000000000000000000000000000000..00133403f878d238fba84743b2d76a16d7a5e32f
--- /dev/null
+++ b/src/test/java/io/papermc/paper/item/ItemStackDataComponentTest.java
-@@ -0,0 +1,417 @@
+@@ -0,0 +1,416 @@
+package io.papermc.paper.item;
+
+import io.papermc.paper.datacomponent.DataComponentType;
@@ -4276,9 +4350,8 @@ index 0000000000000000000000000000000000000000..d868505098533dc62436767416f1ece0
+ }
+
+ @Test
-+ void testCustomModelData() {
-+ // TODO
-+ //testWithMeta(new ItemStack(Material.STONE), DataComponentTypes.CUSTOM_MODEL_DATA, CustomModelData.customModelData(1), CustomModelData::id, ItemMeta.class, ItemMeta::getCustomModelData, ItemMeta::setCustomModelData);
++ void testLegacyCustomModelData() {
++ testWithMeta(new ItemStack(Material.STONE), DataComponentTypes.CUSTOM_MODEL_DATA, CustomModelData.customModelData().addFloat(1).build(), customModelData -> customModelData.floats().get(0).intValue(), ItemMeta.class, ItemMeta::getCustomModelData, ItemMeta::setCustomModelData);
+ }
+
+ @Test