aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--patches/api/0480-WIP-DataComponent-API.patch123
-rw-r--r--patches/server/1026-WIP-DataComponent-API.patch114
2 files changed, 225 insertions, 12 deletions
diff --git a/patches/api/0480-WIP-DataComponent-API.patch b/patches/api/0480-WIP-DataComponent-API.patch
index a8f99daa38..2904a49259 100644
--- a/patches/api/0480-WIP-DataComponent-API.patch
+++ b/patches/api/0480-WIP-DataComponent-API.patch
@@ -4,6 +4,77 @@ Date: Sun, 28 Apr 2024 19:53:06 -0400
Subject: [PATCH] WIP DataComponent API
+diff --git a/src/main/java/io/papermc/paper/block/BlockPredicate.java b/src/main/java/io/papermc/paper/block/BlockPredicate.java
+new file mode 100644
+index 0000000000000000000000000000000000000000..abd1985275d59bc2377eb386a7f06c13dfa2ede0
+--- /dev/null
++++ b/src/main/java/io/papermc/paper/block/BlockPredicate.java
+@@ -0,0 +1,65 @@
++package io.papermc.paper.block;
++
++import io.papermc.paper.registry.RegistryBuilder;
++import io.papermc.paper.registry.data.EnchantmentRegistryEntry;
++import io.papermc.paper.registry.set.RegistryKeySet;
++import org.bukkit.Bukkit;
++import org.bukkit.Location;
++import org.bukkit.block.BlockType;
++import org.bukkit.enchantments.Enchantment;
++import org.bukkit.inventory.ItemType;
++import org.checkerframework.checker.nullness.qual.NonNull;
++import org.jetbrains.annotations.ApiStatus;
++import org.jetbrains.annotations.Contract;
++import org.jetbrains.annotations.NotNull;
++import org.jetbrains.annotations.Nullable;
++
++public interface BlockPredicate {
++
++ @NotNull
++ static Builder predicate() {
++ record BlockPredicateImpl(RegistryKeySet<BlockType> blocks) implements BlockPredicate {
++
++ @Override
++ public @Nullable RegistryKeySet<@NotNull BlockType> blocks() {
++ return this.blocks;
++ }
++ }
++
++ class BuilderImpl implements Builder {
++
++ private @Nullable RegistryKeySet<BlockType> blocks = null;
++
++ @Override
++ public @NonNull Builder blocks(@Nullable final RegistryKeySet<@NotNull BlockType> blocks) {
++ this.blocks = blocks;
++ return this;
++ }
++
++ @Override
++ public @NotNull BlockPredicate build() {
++ return new BlockPredicateImpl(this.blocks);
++ }
++ }
++
++ return new BuilderImpl();
++ }
++
++ @Nullable
++ RegistryKeySet<@org.jetbrains.annotations.NotNull BlockType> blocks();
++
++ @ApiStatus.Experimental
++ @ApiStatus.NonExtendable
++ interface Builder {
++
++ @Contract(value = "_ -> this", mutates = "this")
++ @NonNull
++ Builder blocks(@Nullable RegistryKeySet<@NotNull BlockType> blocks);
++
++ @NotNull
++ BlockPredicate build();
++ }
++
++}
diff --git a/src/main/java/io/papermc/paper/component/ComponentBuilder.java b/src/main/java/io/papermc/paper/component/ComponentBuilder.java
new file mode 100644
index 0000000000000000000000000000000000000000..3f5e6f7c6fb44898e8bfdb87c8d2569086025cba
@@ -67,10 +138,10 @@ index 0000000000000000000000000000000000000000..50d15b4e0ed5cd17fdc95476ee4650ef
+}
diff --git a/src/main/java/io/papermc/paper/component/DataComponentTypes.java b/src/main/java/io/papermc/paper/component/DataComponentTypes.java
new file mode 100644
-index 0000000000000000000000000000000000000000..d0ff39fe9fdd6ad011e83f17080d75659a6d07af
+index 0000000000000000000000000000000000000000..b404d32baa750f0a5d27a9a3fa1b454d1bd4e4f6
--- /dev/null
+++ b/src/main/java/io/papermc/paper/component/DataComponentTypes.java
-@@ -0,0 +1,115 @@
+@@ -0,0 +1,116 @@
+package io.papermc.paper.component;
+
+import io.papermc.paper.component.item.BannerPatternLayers;
@@ -81,6 +152,7 @@ index 0000000000000000000000000000000000000000..d0ff39fe9fdd6ad011e83f17080d7565
+import io.papermc.paper.component.item.DyedItemColor;
+import io.papermc.paper.component.item.Fireworks;
+import io.papermc.paper.component.item.FoodProperties;
++import io.papermc.paper.component.item.ItemAdventurePredicate;
+import io.papermc.paper.component.item.ItemArmorTrim;
+import io.papermc.paper.component.item.ItemAttributeModifiers;
+import io.papermc.paper.component.item.ItemContainerContents;
@@ -126,8 +198,8 @@ index 0000000000000000000000000000000000000000..d0ff39fe9fdd6ad011e83f17080d7565
+ public static final DataComponentType.Valued<ItemLore> LORE = valued("lore");
+ public static final DataComponentType.Valued<ItemRarity> RARITY = valued("rarity");
+ public static final DataComponentType.Valued<ItemEnchantments> ENCHANTMENTS = valued("enchantments");
-+ // can_place_on
-+ // can_break
++ public static final DataComponentType.Valued<ItemAdventurePredicate> CAN_PLACE_ON = valued("can_place_on");
++ public static final DataComponentType.Valued<ItemAdventurePredicate> CAN_BREAK = valued("can_break");
+ public static final DataComponentType.Valued<ItemAttributeModifiers> ATTRIBUTE_MODIFIERS = valued("attribute_modifiers");
+ public static final DataComponentType.Valued<CustomModelData> CUSTOM_MODEL_DATA = valued("custom_model_data");
+ public static final DataComponentType.NonValued HIDE_ADDITIONAL_TOOLTIP = unvalued("hide_additional_tooltip");
@@ -366,10 +438,10 @@ index 0000000000000000000000000000000000000000..48f5b0a3bceb4312a5a2e10ee27811ce
+}
diff --git a/src/main/java/io/papermc/paper/component/item/ComponentTypesBridge.java b/src/main/java/io/papermc/paper/component/item/ComponentTypesBridge.java
new file mode 100644
-index 0000000000000000000000000000000000000000..a0ba12928b1aed432351164dfeb5daa1c6d40b1b
+index 0000000000000000000000000000000000000000..f05ccb7973028c9853de57406a514113b4257079
--- /dev/null
+++ b/src/main/java/io/papermc/paper/component/item/ComponentTypesBridge.java
-@@ -0,0 +1,85 @@
+@@ -0,0 +1,87 @@
+package io.papermc.paper.component.item;
+
+import io.papermc.paper.registry.set.RegistryKeySet;
@@ -454,6 +526,8 @@ index 0000000000000000000000000000000000000000..a0ba12928b1aed432351164dfeb5daa1
+ Tool.Builder tool();
+
+ Tool.Rule rule(RegistryKeySet<BlockType> blockTypes, Float speed, TriState correctForDrops);
++
++ ItemAdventurePredicate.Builder itemAdventurePredicate();
+}
diff --git a/src/main/java/io/papermc/paper/component/item/CustomModelData.java b/src/main/java/io/papermc/paper/component/item/CustomModelData.java
new file mode 100644
@@ -654,6 +728,43 @@ index 0000000000000000000000000000000000000000..fec96d323477fdf8fb410629ac2d23cd
+ @NonNull Builder addAllEffects(@NonNull List<@NonNull PossibleEffect> effects);
+ }
+}
+diff --git a/src/main/java/io/papermc/paper/component/item/ItemAdventurePredicate.java b/src/main/java/io/papermc/paper/component/item/ItemAdventurePredicate.java
+new file mode 100644
+index 0000000000000000000000000000000000000000..65a2267ef0b0d8958ea54454f55a7c6d01fc0f33
+--- /dev/null
++++ b/src/main/java/io/papermc/paper/component/item/ItemAdventurePredicate.java
+@@ -0,0 +1,31 @@
++package io.papermc.paper.component.item;
++
++import io.papermc.paper.block.BlockPredicate;
++import io.papermc.paper.component.ComponentBuilder;
++import java.util.List;
++import org.bukkit.attribute.Attribute;
++import org.bukkit.attribute.AttributeModifier;
++import org.checkerframework.checker.nullness.qual.NonNull;
++import org.jetbrains.annotations.ApiStatus;
++import org.jetbrains.annotations.Contract;
++import org.jetbrains.annotations.Unmodifiable;
++
++public interface ItemAdventurePredicate extends ShownInTooltip<ItemAdventurePredicate> {
++
++ @Contract(value = "-> new", pure = true)
++ static ItemAdventurePredicate.@NonNull Builder itemAdventurePredicate() {
++ return ComponentTypesBridge.bridge().itemAdventurePredicate();
++ }
++
++ @Contract(pure = true)
++ @NonNull @Unmodifiable List<@NonNull BlockPredicate> modifiers();
++
++
++ @ApiStatus.NonExtendable
++ interface Builder extends ShownInTooltip.Builder<Builder>, ComponentBuilder<ItemAdventurePredicate> {
++
++ @Contract(value = "_, _ -> this", mutates = "this")
++ @NonNull Builder addPredicate(@NonNull BlockPredicate predicate);
++ }
++}
diff --git a/src/main/java/io/papermc/paper/component/item/ItemArmorTrim.java b/src/main/java/io/papermc/paper/component/item/ItemArmorTrim.java
new file mode 100644
index 0000000000000000000000000000000000000000..0d1ecd1e33a423df2ef07f1bf73334b06224b199
diff --git a/patches/server/1026-WIP-DataComponent-API.patch b/patches/server/1026-WIP-DataComponent-API.patch
index 43bbc87cdc..c6ff3b83df 100644
--- a/patches/server/1026-WIP-DataComponent-API.patch
+++ b/patches/server/1026-WIP-DataComponent-API.patch
@@ -40,10 +40,10 @@ index 0000000000000000000000000000000000000000..e538819c873a324c58bcd8e73f89510e
+}
diff --git a/src/main/java/io/papermc/paper/component/ComponentAdapters.java b/src/main/java/io/papermc/paper/component/ComponentAdapters.java
new file mode 100644
-index 0000000000000000000000000000000000000000..d8eaf4970a6531693e4ef18e4d5954322a3f8345
+index 0000000000000000000000000000000000000000..d5b1ef91d777cd207e51b4541cd0d7c7167c7be5
--- /dev/null
+++ b/src/main/java/io/papermc/paper/component/ComponentAdapters.java
-@@ -0,0 +1,184 @@
+@@ -0,0 +1,185 @@
+package io.papermc.paper.component;
+
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
@@ -56,6 +56,7 @@ index 0000000000000000000000000000000000000000..d8eaf4970a6531693e4ef18e4d595432
+import io.papermc.paper.component.item.PaperDyedItemColor;
+import io.papermc.paper.component.item.PaperFireworks;
+import io.papermc.paper.component.item.PaperFoodProperties;
++import io.papermc.paper.component.item.PaperItemAdventurePredicate;
+import io.papermc.paper.component.item.PaperItemArmorTrim;
+import io.papermc.paper.component.item.PaperItemAttributeModifiers;
+import io.papermc.paper.component.item.PaperItemContainerContents;
@@ -134,8 +135,8 @@ index 0000000000000000000000000000000000000000..d8eaf4970a6531693e4ef18e4d595432
+ register(DataComponents.LORE, PaperItemLore::new);
+ register(DataComponents.RARITY, nms -> ItemRarity.valueOf(nms.name()), api -> Rarity.valueOf(api.name()));
+ register(DataComponents.ENCHANTMENTS, PaperItemEnchantments::new);
-+ // can place on
-+ // can break
++ register(DataComponents.CAN_PLACE_ON, PaperItemAdventurePredicate::new);
++ register(DataComponents.CAN_BREAK, PaperItemAdventurePredicate::new);
+ register(DataComponents.ATTRIBUTE_MODIFIERS, PaperItemAttributeModifiers::new);
+ register(DataComponents.CUSTOM_MODEL_DATA, PaperCustomModelData::new);
+ registerUntyped(DataComponents.HIDE_ADDITIONAL_TOOLTIP);
@@ -354,10 +355,10 @@ index 0000000000000000000000000000000000000000..5639559368e6866e9b0afa6688f3b12c
+}
diff --git a/src/main/java/io/papermc/paper/component/item/ComponentTypesBridgesImpl.java b/src/main/java/io/papermc/paper/component/item/ComponentTypesBridgesImpl.java
new file mode 100644
-index 0000000000000000000000000000000000000000..da9fe244f027c7932d9ed73e25f9e585106b70bf
+index 0000000000000000000000000000000000000000..2e0996b652ecc01d4f53963e73340dc2828aecab
--- /dev/null
+++ b/src/main/java/io/papermc/paper/component/item/ComponentTypesBridgesImpl.java
-@@ -0,0 +1,168 @@
+@@ -0,0 +1,173 @@
+package io.papermc.paper.component.item;
+
+import io.papermc.paper.registry.set.RegistryKeySet;
@@ -482,6 +483,11 @@ index 0000000000000000000000000000000000000000..da9fe244f027c7932d9ed73e25f9e585
+ }
+
+ @Override
++ public ItemAdventurePredicate.Builder itemAdventurePredicate() {
++ return new PaperItemAdventurePredicate.BuilderImpl();
++ }
++
++ @Override
+ public WrittenBookContent.Builder writtenBookContent(final Filtered<String> title, final String author) {
+ return new PaperWrittenBookContent.BuilderImpl(title, author);
+ }
@@ -1155,6 +1161,102 @@ index 0000000000000000000000000000000000000000..faff33e3dc42cd52130c4896d939ae53
+ }
+ }
+}
+diff --git a/src/main/java/io/papermc/paper/component/item/PaperItemAdventurePredicate.java b/src/main/java/io/papermc/paper/component/item/PaperItemAdventurePredicate.java
+new file mode 100644
+index 0000000000000000000000000000000000000000..c0604b3d12e5299e602075cbdfa5a630b0ea52e6
+--- /dev/null
++++ b/src/main/java/io/papermc/paper/component/item/PaperItemAdventurePredicate.java
+@@ -0,0 +1,90 @@
++package io.papermc.paper.component.item;
++
++import com.google.common.base.Preconditions;
++import java.util.ArrayList;
++import java.util.Collections;
++import java.util.List;
++import java.util.Optional;
++import java.util.function.Function;
++import io.papermc.paper.block.BlockPredicate;
++import io.papermc.paper.registry.RegistryKey;
++import io.papermc.paper.registry.set.PaperRegistrySets;
++import io.papermc.paper.registry.set.RegistryKeySet;
++import net.minecraft.core.HolderSet;
++import net.minecraft.core.registries.BuiltInRegistries;
++import net.minecraft.core.registries.Registries;
++import net.minecraft.world.item.AdventureModePredicate;
++import net.minecraft.world.level.block.Block;
++import org.bukkit.attribute.Attribute;
++import org.bukkit.attribute.AttributeModifier;
++import org.bukkit.block.BlockType;
++import org.bukkit.craftbukkit.CraftEquipmentSlot;
++import org.bukkit.craftbukkit.attribute.CraftAttribute;
++import org.bukkit.craftbukkit.attribute.CraftAttributeInstance;
++import org.bukkit.craftbukkit.util.Handleable;
++import org.checkerframework.checker.nullness.qual.NonNull;
++import org.checkerframework.framework.qual.DefaultQualifier;
++import org.jetbrains.annotations.Unmodifiable;
++
++import static io.papermc.paper.component.item.ComponentUtils.transform;
++
++@DefaultQualifier(NonNull.class)
++public record PaperItemAdventurePredicate(
++ net.minecraft.world.item.AdventureModePredicate impl,
++ List<BlockPredicate> predicates
++) implements ItemAdventurePredicate, Handleable<net.minecraft.world.item.AdventureModePredicate> {
++
++ public PaperItemAdventurePredicate(final net.minecraft.world.item.AdventureModePredicate itemModifiers) {
++ this(itemModifiers, convert(itemModifiers));
++ }
++
++ private static List<BlockPredicate> convert(final net.minecraft.world.item.AdventureModePredicate nmsModifiers) {
++ return transform(nmsModifiers.predicates, nms -> BlockPredicate.predicate()
++ .blocks(nms.blocks().map(holders -> PaperRegistrySets.convertToApi(RegistryKey.BLOCK, holders)).orElse(null)).build());
++ }
++
++ @Override
++ public net.minecraft.world.item.AdventureModePredicate getHandle() {
++ return this.impl;
++ }
++
++ @Override
++ public boolean showInTooltip() {
++ return this.impl.showInTooltip();
++ }
++
++ @Override
++ public PaperItemAdventurePredicate showInTooltip(final boolean showInTooltip) {
++ return new PaperItemAdventurePredicate(this.impl.withTooltip(showInTooltip), this.predicates);
++ }
++
++ @Override
++ public @NonNull @Unmodifiable List<@NonNull BlockPredicate> modifiers() {
++ return this.predicates;
++ }
++
++ static final class BuilderImpl implements Builder {
++
++ private final List<net.minecraft.advancements.critereon.BlockPredicate> predicates = new ArrayList<>();
++ private boolean showInTooltip = net.minecraft.world.item.component.ItemAttributeModifiers.EMPTY.showInTooltip();
++
++ @Override
++ public @NonNull Builder addPredicate(@NonNull final BlockPredicate predicate) {
++ this.predicates.add(new net.minecraft.advancements.critereon.BlockPredicate(Optional.ofNullable(predicate.blocks()).map(
++ typedKeys -> PaperRegistrySets.convertToNms(Registries.BLOCK, BuiltInRegistries.BUILT_IN_CONVERSIONS.lookup(), typedKeys)
++ ), Optional.empty(), Optional.empty()));
++ return this;
++ }
++
++ @Override
++ public Builder showInTooltip(final boolean showInTooltip) {
++ this.showInTooltip = showInTooltip;
++ return this;
++ }
++
++ @Override
++ public @NonNull ItemAdventurePredicate build() {
++ return new PaperItemAdventurePredicate(new net.minecraft.world.item.AdventureModePredicate(Collections.unmodifiableList(this.predicates), this.showInTooltip));
++ }
++ }
++}
diff --git a/src/main/java/io/papermc/paper/component/item/PaperItemArmorTrim.java b/src/main/java/io/papermc/paper/component/item/PaperItemArmorTrim.java
new file mode 100644
index 0000000000000000000000000000000000000000..8d2f20225101a1134b9d89a03f2f1a704bd4d51f