mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
Item DataComponent API (#10845)
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>
This commit is contained in:
parent
33bafcbf2d
commit
76403d796b
4186
patches/api/DataComponent-API.patch
Normal file
4186
patches/api/DataComponent-API.patch
Normal file
File diff suppressed because it is too large
Load Diff
@ -1314,6 +1314,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+
|
+
|
||||||
+ // Key
|
+ // Key
|
||||||
+
|
+
|
||||||
|
+ public static Key asAdventure(final ResourceLocation key) {
|
||||||
|
+ return Key.key(key.getNamespace(), key.getPath());
|
||||||
|
+ }
|
||||||
|
+
|
||||||
+ public static ResourceLocation asVanilla(final Key key) {
|
+ public static ResourceLocation asVanilla(final Key key) {
|
||||||
+ return ResourceLocation.fromNamespaceAndPath(key.namespace(), key.value());
|
+ return ResourceLocation.fromNamespaceAndPath(key.namespace(), key.value());
|
||||||
+ }
|
+ }
|
||||||
|
4804
patches/server/DataComponent-API.patch
Normal file
4804
patches/server/DataComponent-API.patch
Normal file
File diff suppressed because it is too large
Load Diff
@ -4697,10 +4697,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
@@ -0,0 +0,0 @@
|
@@ -0,0 +0,0 @@
|
||||||
+package io.papermc.paper.util;
|
+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 com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||||
|
+import io.papermc.paper.adventure.PaperAdventure;
|
||||||
+import io.papermc.paper.math.BlockPosition;
|
+import io.papermc.paper.math.BlockPosition;
|
||||||
+import io.papermc.paper.math.FinePosition;
|
+import io.papermc.paper.math.FinePosition;
|
||||||
+import io.papermc.paper.math.Position;
|
+import io.papermc.paper.math.Position;
|
||||||
|
+import java.util.Collection;
|
||||||
|
+import java.util.Collections;
|
||||||
+import java.util.List;
|
+import java.util.List;
|
||||||
+import java.util.concurrent.CompletableFuture;
|
+import java.util.concurrent.CompletableFuture;
|
||||||
+import java.util.concurrent.ExecutionException;
|
+import java.util.concurrent.ExecutionException;
|
||||||
@ -4709,11 +4714,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+import java.util.concurrent.TimeUnit;
|
+import java.util.concurrent.TimeUnit;
|
||||||
+import java.util.function.BiConsumer;
|
+import java.util.function.BiConsumer;
|
||||||
+import java.util.function.Consumer;
|
+import java.util.function.Consumer;
|
||||||
|
+import java.util.function.Function;
|
||||||
+import java.util.function.Supplier;
|
+import java.util.function.Supplier;
|
||||||
|
+import net.kyori.adventure.key.Key;
|
||||||
+import net.minecraft.core.BlockPos;
|
+import net.minecraft.core.BlockPos;
|
||||||
|
+import net.minecraft.core.Holder;
|
||||||
+import net.minecraft.core.Vec3i;
|
+import net.minecraft.core.Vec3i;
|
||||||
|
+import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
+import net.minecraft.resources.ResourceKey;
|
+import net.minecraft.resources.ResourceKey;
|
||||||
|
+import net.minecraft.resources.ResourceLocation;
|
||||||
+import net.minecraft.server.MinecraftServer;
|
+import net.minecraft.server.MinecraftServer;
|
||||||
|
+import net.minecraft.sounds.SoundEvent;
|
||||||
+import net.minecraft.world.level.ChunkPos;
|
+import net.minecraft.world.level.ChunkPos;
|
||||||
+import net.minecraft.world.level.Level;
|
+import net.minecraft.world.level.Level;
|
||||||
+import net.minecraft.world.phys.Vec3;
|
+import net.minecraft.world.phys.Vec3;
|
||||||
@ -4884,6 +4895,25 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ public static NamespacedKey fromResourceKey(final ResourceKey<?> key) {
|
+ public static NamespacedKey fromResourceKey(final ResourceKey<?> key) {
|
||||||
+ return CraftNamespacedKey.fromMinecraft(key.location());
|
+ 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
|
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
|
new file mode 100644
|
||||||
@ -6309,6 +6339,28 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
public static net.minecraft.world.item.ItemStack asNMSCopy(ItemStack original) {
|
public static net.minecraft.world.item.ItemStack asNMSCopy(ItemStack original) {
|
||||||
if (original instanceof CraftItemStack) {
|
if (original instanceof CraftItemStack) {
|
||||||
CraftItemStack stack = (CraftItemStack) original;
|
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftLocation.java
|
||||||
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftLocation.java
|
||||||
|
@@ -0,0 +0,0 @@ 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
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/DelegatedGeneratorAccess.java b/src/main/java/org/bukkit/craftbukkit/util/DelegatedGeneratorAccess.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/org/bukkit/craftbukkit/util/DelegatedGeneratorAccess.java
|
--- a/src/main/java/org/bukkit/craftbukkit/util/DelegatedGeneratorAccess.java
|
||||||
|
Loading…
Reference in New Issue
Block a user