mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-18 12:48:53 +01:00
Implement new CustomModelData
This commit is contained in:
parent
cbd578c7b5
commit
7e601ad916
2 changed files with 189 additions and 23 deletions
|
@ -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
|
|||
+@ApiStatus.NonExtendable
|
||||
+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);
|
||||
+
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue