Skip to content

Commit

Permalink
Item DataComponent API (PaperMC#10845)
Browse files Browse the repository at this point in the history

Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
Co-authored-by: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com>
Co-authored-by: Bjarne Koll <git@lynxplay.dev>
  • Loading branch information
4 people authored Nov 18, 2024
1 parent 6735c60 commit de6173b
Show file tree
Hide file tree
Showing 35 changed files with 9,063 additions and 17 deletions.
4,186 changes: 4,186 additions & 0 deletions patches/api/0495-DataComponent-API.patch

Large diffs are not rendered by default.

56 changes: 54 additions & 2 deletions patches/server/0009-MC-Utils.patch
Original file line number Diff line number Diff line change
Expand Up @@ -4691,16 +4691,21 @@ index 0000000000000000000000000000000000000000..197224e31175252d8438a8df585bbb65
+}
diff --git a/src/main/java/io/papermc/paper/util/MCUtil.java b/src/main/java/io/papermc/paper/util/MCUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..422bc104e5bdd4ae786b14d97eb779dc76bfad69
index 0000000000000000000000000000000000000000..e85e544506b4c762503a1cb490e6c0f5b1d563f4
--- /dev/null
+++ b/src/main/java/io/papermc/paper/util/MCUtil.java
@@ -0,0 +1,190 @@
@@ -0,0 +1,220 @@
+package io.papermc.paper.util;
+
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Lists;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import io.papermc.paper.adventure.PaperAdventure;
+import io.papermc.paper.math.BlockPosition;
+import io.papermc.paper.math.FinePosition;
+import io.papermc.paper.math.Position;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
Expand All @@ -4709,11 +4714,17 @@ index 0000000000000000000000000000000000000000..422bc104e5bdd4ae786b14d97eb779dc
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Supplier;
+import net.kyori.adventure.key.Key;
+import net.minecraft.core.BlockPos;
+import net.minecraft.core.Holder;
+import net.minecraft.core.Vec3i;
+import net.minecraft.core.registries.BuiltInRegistries;
+import net.minecraft.resources.ResourceKey;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.sounds.SoundEvent;
+import net.minecraft.world.level.ChunkPos;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.phys.Vec3;
Expand Down Expand Up @@ -4884,6 +4895,25 @@ index 0000000000000000000000000000000000000000..422bc104e5bdd4ae786b14d97eb779dc
+ public static NamespacedKey fromResourceKey(final ResourceKey<?> key) {
+ return CraftNamespacedKey.fromMinecraft(key.location());
+ }
+
+ public static Holder<SoundEvent> keyToSound(Key key) {
+ ResourceLocation soundId = PaperAdventure.asVanilla(key);
+ return BuiltInRegistries.SOUND_EVENT.wrapAsHolder(BuiltInRegistries.SOUND_EVENT.getOptional(soundId).orElse(SoundEvent.createVariableRangeEvent(soundId)));
+ }
+
+ public static <A, M> List<A> transformUnmodifiable(final List<? extends M> nms, final Function<? super M, ? extends A> converter) {
+ return Collections.unmodifiableList(Lists.transform(nms, converter::apply));
+ }
+
+ public static <A, M> Collection<A> transformUnmodifiable(final Collection<? extends M> nms, final Function<? super M, ? extends A> converter) {
+ return Collections.unmodifiableCollection(Collections2.transform(nms, converter::apply));
+ }
+
+ public static <A, M, C extends Collection<M>> void addAndConvert(final C target, final Collection<A> toAdd, final Function<? super A, ? extends M> converter) {
+ for (final A value : toAdd) {
+ target.add(converter.apply(value));
+ }
+ }
+}
diff --git a/src/main/java/io/papermc/paper/util/StackWalkerUtil.java b/src/main/java/io/papermc/paper/util/StackWalkerUtil.java
new file mode 100644
Expand Down Expand Up @@ -6309,6 +6339,28 @@ index f6e6f0ddef6693c58f28b89cf3df005a8d47e08d..101eea3452c9e387e770b716543c3a4f
public static net.minecraft.world.item.ItemStack asNMSCopy(ItemStack original) {
if (original instanceof CraftItemStack) {
CraftItemStack stack = (CraftItemStack) original;
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftLocation.java b/src/main/java/org/bukkit/craftbukkit/util/CraftLocation.java
index 097996d3955ab5126b71f7bff1dd2c62becb5ffd..a8b46ea5e4b6260c2728c67e8651b74fe6356605 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftLocation.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftLocation.java
@@ -40,6 +40,17 @@ public final class CraftLocation {
return new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
}

+ // Paper start
+ public static net.minecraft.core.GlobalPos toGlobalPos(Location location) {
+ return net.minecraft.core.GlobalPos.of(((org.bukkit.craftbukkit.CraftWorld) location.getWorld()).getHandle().dimension(), toBlockPosition(location));
+ }
+
+ public static Location fromGlobalPos(net.minecraft.core.GlobalPos globalPos) {
+ BlockPos pos = globalPos.pos();
+ return new org.bukkit.Location(net.minecraft.server.MinecraftServer.getServer().getLevel(globalPos.dimension()).getWorld(), pos.getX(), pos.getY(), pos.getZ());
+ }
+ // Paper end
+
public static Vec3 toVec3D(Location location) {
return new Vec3(location.getX(), location.getY(), location.getZ());
}
diff --git a/src/main/java/org/bukkit/craftbukkit/util/DelegatedGeneratorAccess.java b/src/main/java/org/bukkit/craftbukkit/util/DelegatedGeneratorAccess.java
index b8a865305cc61954aeebff4a7cd1d1973c5f46ab..e444662ee4d9405eeea7caa41b9cd6b36586d840 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/DelegatedGeneratorAccess.java
Expand Down
14 changes: 9 additions & 5 deletions patches/server/0010-Adventure.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1161,10 +1161,10 @@ index 0000000000000000000000000000000000000000..2fd6c3e65354071af71c7d8ebb97b559
+}
diff --git a/src/main/java/io/papermc/paper/adventure/PaperAdventure.java b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
new file mode 100644
index 0000000000000000000000000000000000000000..161bc8c577643094d824ea96fb6974c76e5e77f0
index 0000000000000000000000000000000000000000..610003a668c4a7fe53e3477accc6bafb8479b936
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
@@ -0,0 +1,479 @@
@@ -0,0 +1,483 @@
+package io.papermc.paper.adventure;
+
+import com.mojang.brigadier.StringReader;
Expand Down Expand Up @@ -1314,6 +1314,10 @@ index 0000000000000000000000000000000000000000..161bc8c577643094d824ea96fb6974c7
+
+ // Key
+
+ public static Key asAdventure(final ResourceLocation key) {
+ return Key.key(key.getNamespace(), key.getPath());
+ }
+
+ public static ResourceLocation asVanilla(final Key key) {
+ return ResourceLocation.fromNamespaceAndPath(key.namespace(), key.value());
+ }
Expand Down Expand Up @@ -2704,7 +2708,7 @@ index 709330ca9caa82a6de71767b3d5c32f97ea1d68b..daf20aa9a83a2583c0c61a4123cc2e52

public boolean logIPs() {
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 32e7c6e6f09e53fe8b5ade22dad8142cd09e0163..4303bde198050cd037f006234d269af406606eff 100644
index 785c7e11f92610be58b624d252d1858658496af7..99607edee9fba8df87f0525bf0eadee865ab38a4 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -190,6 +190,7 @@ import net.minecraft.world.item.trading.MerchantOffers;
Expand Down Expand Up @@ -3639,7 +3643,7 @@ index 8b58884d6cb1088a2fffb36a99bfe4dc568326d1..9a79b948264150d0f7a843a8ddd2ea92
// Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java
index 94004204b6cdbbbf35263faae56e3e06cb6b650c..2e33acc428dbfd3e123dfd6ef90bc020b8a08daf 100644
index 39126769594a535ebd4bf7052f42e9eda9d3e10a..41ceea1093edbf777f9ebe252114be7f75438420 100644
--- a/src/main/java/org/bukkit/craftbukkit/Main.java
+++ b/src/main/java/org/bukkit/craftbukkit/Main.java
@@ -20,6 +20,12 @@ public class Main {
Expand Down Expand Up @@ -5202,7 +5206,7 @@ index c71a4971f127fdfc753306019313ce1a31201120..fd3b12477c30d1eabdbe57ea77902793
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
index 5dea83c1a0de4e5123430bf2f902a78969021167..2e524520308dda7ce7df98d91c89a9cfe7542862 100644
index 2d68086ef09b5f2d6b3d3e6200e621c23747b25a..f3789ea732b17a311d8203a58a97d11370ec7863 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
@@ -1097,6 +1097,18 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
Expand Down
Loading

0 comments on commit de6173b

Please sign in to comment.