diff options
Diffstat (limited to 'patches/server/1031-DataComponent-API.patch')
-rw-r--r-- | patches/server/1031-DataComponent-API.patch | 107 |
1 files changed, 90 insertions, 17 deletions
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 |