mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 10:35:38 +01:00
some work on adventure
This commit is contained in:
parent
c95db4fcaa
commit
bb1351cb8d
@ -14,10 +14,10 @@ Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/adventure/AdventureCodecs.java b/src/main/java/io/papermc/paper/adventure/AdventureCodecs.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..b33e394d88517c7afc2f549bae5a2063316ada73
|
||||
index 0000000000000000000000000000000000000000..87391401d1627009e5f2be3847f59c9a752fe52a
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/adventure/AdventureCodecs.java
|
||||
@@ -0,0 +1,458 @@
|
||||
@@ -0,0 +1,459 @@
|
||||
+package io.papermc.paper.adventure;
|
||||
+
|
||||
+import com.google.gson.JsonElement;
|
||||
@ -152,7 +152,7 @@ index 0000000000000000000000000000000000000000..b33e394d88517c7afc2f549bae5a2063
|
||||
+ static Codec<HoverEvent.ShowItem> showItemCodec(final Codec<Component> componentCodec) {
|
||||
+ return net.minecraft.network.chat.HoverEvent.ItemStackInfo.CODEC.xmap(isi -> {
|
||||
+ @Subst("key") final String typeKey = isi.item.unwrapKey().orElseThrow().toString();
|
||||
+ return HoverEvent.ShowItem.showItem(Key.key(typeKey), isi.count, PaperAdventure.asBinaryTagHolder(isi.tag.orElse(null)));
|
||||
+ return HoverEvent.ShowItem.showItem(Key.key(typeKey), isi.count, PaperAdventure.dataComponents(isi.getItemStack()));
|
||||
+ }, si -> {
|
||||
+ final Item itemType = BuiltInRegistries.ITEM.get(PaperAdventure.asVanilla(si.item()));
|
||||
+ final ItemStack stack;
|
||||
@ -168,7 +168,7 @@ index 0000000000000000000000000000000000000000..b33e394d88517c7afc2f549bae5a2063
|
||||
+
|
||||
+ static final HoverEventType<HoverEvent.ShowEntity> SHOW_ENTITY_HOVER_EVENT_TYPE = new HoverEventType<>(AdventureCodecs::showEntityCodec, HoverEvent.Action.SHOW_ENTITY, "show_entity", AdventureCodecs::legacyDeserializeEntity);
|
||||
+ static final HoverEventType<HoverEvent.ShowItem> SHOW_ITEM_HOVER_EVENT_TYPE = new HoverEventType<>(AdventureCodecs::showItemCodec, HoverEvent.Action.SHOW_ITEM, "show_item", AdventureCodecs::legacyDeserializeItem);
|
||||
+ static final HoverEventType<Component> SHOW_TEXT_HOVER_EVENT_TYPE = new HoverEventType<>(identity(), HoverEvent.Action.SHOW_TEXT, "show_text", DataResult::success);
|
||||
+ static final HoverEventType<Component> SHOW_TEXT_HOVER_EVENT_TYPE = new HoverEventType<>(identity(), HoverEvent.Action.SHOW_TEXT, "show_text", (component, registryOps, codec) -> DataResult.success(component));
|
||||
+ static final Codec<HoverEventType<?>> HOVER_EVENT_TYPE_CODEC = StringRepresentable.fromValues(() -> new HoverEventType<?>[]{ SHOW_ENTITY_HOVER_EVENT_TYPE, SHOW_ITEM_HOVER_EVENT_TYPE, SHOW_TEXT_HOVER_EVENT_TYPE });
|
||||
+
|
||||
+ static DataResult<HoverEvent.ShowEntity> legacyDeserializeEntity(final Component component, final @Nullable RegistryOps<?> ops, final Codec<Component> componentCodec) {
|
||||
@ -188,11 +188,12 @@ index 0000000000000000000000000000000000000000..b33e394d88517c7afc2f549bae5a2063
|
||||
+ try {
|
||||
+ final CompoundTag tag = TagParser.parseTag(PlainTextComponentSerializer.plainText().serialize(component));
|
||||
+ final DynamicOps<Tag> dynamicOps = ops != null ? ops.withParent(NbtOps.INSTANCE) : NbtOps.INSTANCE;
|
||||
+ final DataResult<org.bukkit.inventory.ItemStack> stackResult = ItemStack.CODEC.parse(dynamicOps, tag).map(CraftItemStack::asCraftMirror);
|
||||
+ final DataResult<ItemStack> stackResult = ItemStack.CODEC.parse(dynamicOps, tag);
|
||||
+ return stackResult.map(stack -> {
|
||||
+ return HoverEvent.ShowItem.showItem(stack.getType().key(), stack.getAmount(), /* TODO */);
|
||||
+ final CraftItemStack craft = CraftItemStack.asCraftMirror(stack);
|
||||
+ return HoverEvent.ShowItem.showItem(craft.getType().key(), stack.getCount(), PaperAdventure.dataComponents(stack));
|
||||
+ });
|
||||
+ } catch (final CommandSyntaxException | IOException ex) {
|
||||
+ } catch (final CommandSyntaxException ex) {
|
||||
+ return DataResult.error(() -> "Failed to parse item tag: " + ex.getMessage());
|
||||
+ }
|
||||
+ }
|
||||
@ -1159,16 +1160,17 @@ 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..5bacfadf01777171e51858d450a68135d422bf0f
|
||||
index 0000000000000000000000000000000000000000..0a428c392fec7c088648ab2633c92f0600f404b3
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
|
||||
@@ -0,0 +1,421 @@
|
||||
@@ -0,0 +1,445 @@
|
||||
+package io.papermc.paper.adventure;
|
||||
+
|
||||
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
+import io.netty.util.AttributeKey;
|
||||
+import java.io.IOException;
|
||||
+import java.util.ArrayList;
|
||||
+import java.util.HashMap;
|
||||
+import java.util.List;
|
||||
+import java.util.Locale;
|
||||
+import java.util.Map;
|
||||
@ -1186,6 +1188,7 @@ index 0000000000000000000000000000000000000000..5bacfadf01777171e51858d450a68135
|
||||
+import net.kyori.adventure.text.Component;
|
||||
+import net.kyori.adventure.text.TranslatableComponent;
|
||||
+import net.kyori.adventure.text.TranslationArgument;
|
||||
+import net.kyori.adventure.text.event.DataComponentValue;
|
||||
+import net.kyori.adventure.text.flattener.ComponentFlattener;
|
||||
+import net.kyori.adventure.text.format.Style;
|
||||
+import net.kyori.adventure.text.format.TextColor;
|
||||
@ -1201,11 +1204,14 @@ index 0000000000000000000000000000000000000000..5bacfadf01777171e51858d450a68135
|
||||
+import net.minecraft.Util;
|
||||
+import net.minecraft.commands.CommandSourceStack;
|
||||
+import net.minecraft.core.Holder;
|
||||
+import net.minecraft.core.component.TypedDataComponent;
|
||||
+import net.minecraft.core.registries.BuiltInRegistries;
|
||||
+import net.minecraft.locale.Language;
|
||||
+import net.minecraft.nbt.CompoundTag;
|
||||
+import net.minecraft.nbt.ListTag;
|
||||
+import net.minecraft.nbt.NbtOps;
|
||||
+import net.minecraft.nbt.StringTag;
|
||||
+import net.minecraft.nbt.Tag;
|
||||
+import net.minecraft.nbt.TagParser;
|
||||
+import net.minecraft.network.chat.ComponentUtils;
|
||||
+import net.minecraft.network.protocol.Packet;
|
||||
@ -1541,6 +1547,25 @@ index 0000000000000000000000000000000000000000..5bacfadf01777171e51858d450a68135
|
||||
+
|
||||
+ // NBT
|
||||
+
|
||||
+ public static Map<Key, ? extends DataComponentValue> dataComponents(
|
||||
+ final ItemStack stack
|
||||
+ ) {
|
||||
+ final Map<Key, DataComponentValue> map = new HashMap<>();
|
||||
+ for (final TypedDataComponent<?> component : stack.getComponents()) {
|
||||
+ final ResourceLocation key = BuiltInRegistries.DATA_COMPONENT_TYPE.getKey(component.type());
|
||||
+ final DataComponentValue value = new DataComponentValue.TagSerializable() {
|
||||
+ @Override
|
||||
+ public @NotNull BinaryTagHolder asBinaryTag() {
|
||||
+ return BinaryTagHolder.binaryTagHolder(
|
||||
+ component.encodeValue(NbtOps.INSTANCE).map(Tag::getAsString).getOrThrow()
|
||||
+ );
|
||||
+ }
|
||||
+ };
|
||||
+ map.put(Key.key(key.toString()), value);
|
||||
+ }
|
||||
+ return map;
|
||||
+ }
|
||||
+
|
||||
+ public static @Nullable BinaryTagHolder asBinaryTagHolder(final @Nullable CompoundTag tag) {
|
||||
+ if (tag == null) {
|
||||
+ return null;
|
||||
@ -4609,10 +4634,10 @@ index 4dd9a80af9901287ab6740b072f2b89678c3d0cb..b2586684295b295a3196a2a9cf724cec
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
index 01963ef944da9251c038208c20012939afc77830..e5ee4a2e5cca2fd3a74ac58335ccf589ab87c9c5 100644
|
||||
index 01963ef944da9251c038208c20012939afc77830..cc142d8c3736f8f6817256865e9166b471de0344 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
@@ -501,4 +501,17 @@ public final class CraftItemFactory implements ItemFactory {
|
||||
@@ -501,4 +501,16 @@ public final class CraftItemFactory implements ItemFactory {
|
||||
CraftItemStack craft = (CraftItemStack) itemStack;
|
||||
return CraftItemStack.asCraftMirror(EnchantmentHelper.enchantItem(MinecraftServer.getServer().getWorldData().enabledFeatures(), source, craft.handle, level, allowTreasures));
|
||||
}
|
||||
@ -4620,8 +4645,7 @@ index 01963ef944da9251c038208c20012939afc77830..e5ee4a2e5cca2fd3a74ac58335ccf589
|
||||
+ // Paper start - Adventure
|
||||
+ @Override
|
||||
+ public net.kyori.adventure.text.event.HoverEvent<net.kyori.adventure.text.event.HoverEvent.ShowItem> asHoverEvent(final ItemStack item, final java.util.function.UnaryOperator<net.kyori.adventure.text.event.HoverEvent.ShowItem> op) {
|
||||
+ final net.minecraft.nbt.CompoundTag tag = CraftItemStack.asNMSCopy(item).getTag();
|
||||
+ return net.kyori.adventure.text.event.HoverEvent.showItem(op.apply(net.kyori.adventure.text.event.HoverEvent.ShowItem.showItem(item.getType().getKey(), item.getAmount(), io.papermc.paper.adventure.PaperAdventure.asBinaryTagHolder(tag))));
|
||||
+ return net.kyori.adventure.text.event.HoverEvent.showItem(op.apply(net.kyori.adventure.text.event.HoverEvent.ShowItem.showItem(item.getType().getKey(), item.getAmount(), io.papermc.paper.adventure.PaperAdventure.dataComponents(CraftItemStack.asNMSCopy(item)))));
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
|
@ -206,10 +206,10 @@ index 0000000000000000000000000000000000000000..8f07539a82f449ad217e316a7513a170
|
||||
+
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/adventure/PaperAdventure.java b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
|
||||
index 5bacfadf01777171e51858d450a68135d422bf0f..41a87166d453ea4977ff0c15dab94c93715ade46 100644
|
||||
index 0a428c392fec7c088648ab2633c92f0600f404b3..7abf0424be2d61adc4018dd6d6b44fc63e365a3d 100644
|
||||
--- a/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
|
||||
+++ b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
|
||||
@@ -25,6 +25,7 @@ import net.kyori.adventure.text.flattener.ComponentFlattener;
|
||||
@@ -27,6 +27,7 @@ import net.kyori.adventure.text.flattener.ComponentFlattener;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.serializer.ComponentSerializer;
|
||||
@ -217,7 +217,7 @@ index 5bacfadf01777171e51858d450a68135d422bf0f..41a87166d453ea4977ff0c15dab94c93
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
@@ -113,6 +114,7 @@ public final class PaperAdventure {
|
||||
@@ -118,6 +119,7 @@ public final class PaperAdventure {
|
||||
public static final AttributeKey<Locale> LOCALE_ATTRIBUTE = AttributeKey.valueOf("adventure:locale"); // init after FLATTENER because classloading triggered here might create a logger
|
||||
@Deprecated
|
||||
public static final PlainComponentSerializer PLAIN = PlainComponentSerializer.builder().flattener(FLATTENER).build();
|
||||
|
@ -7,10 +7,10 @@ This will take a Bukkit ItemStack and run it through any conversions a server pr
|
||||
to ensure it meets latest minecraft expectations.
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
index e5ee4a2e5cca2fd3a74ac58335ccf589ab87c9c5..74c8f8540340be6d7d26bbecfe07c6ce3ed019ad 100644
|
||||
index cc142d8c3736f8f6817256865e9166b471de0344..034e46437d13e2b234c8afb1c2cccd9eff1fc580 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
@@ -514,4 +514,12 @@ public final class CraftItemFactory implements ItemFactory {
|
||||
@@ -513,4 +513,12 @@ public final class CraftItemFactory implements ItemFactory {
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(CraftItemStack.asNMSCopy(itemStack).getDisplayName());
|
||||
}
|
||||
// Paper end - Adventure
|
||||
|
@ -8,10 +8,10 @@ Currently the server only supports the English language. To override this,
|
||||
You must replace the language file embedded in the server jar.
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
index 74c8f8540340be6d7d26bbecfe07c6ce3ed019ad..fc51a93785ffc464d2719b440f49022f24b3983a 100644
|
||||
index 034e46437d13e2b234c8afb1c2cccd9eff1fc580..0fa1f4324cf1e7f13976ddab2cc8f760645a0e5a 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
@@ -522,4 +522,19 @@ public final class CraftItemFactory implements ItemFactory {
|
||||
@@ -521,4 +521,19 @@ public final class CraftItemFactory implements ItemFactory {
|
||||
return CraftItemStack.asCraftMirror(CraftItemStack.asNMSCopy(item));
|
||||
}
|
||||
// Paper end - ensure server conversions API
|
||||
|
@ -5,10 +5,10 @@ Subject: [PATCH] Create HoverEvent from ItemStack Entity
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
index fc51a93785ffc464d2719b440f49022f24b3983a..3ebba8af1cf2d2eaf6670860b011c7dc1da62890 100644
|
||||
index 0fa1f4324cf1e7f13976ddab2cc8f760645a0e5a..7ce33d2f16d4431d9ff1818f1f8e292ca4d76c35 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
@@ -537,4 +537,41 @@ public final class CraftItemFactory implements ItemFactory {
|
||||
@@ -536,4 +536,41 @@ public final class CraftItemFactory implements ItemFactory {
|
||||
return nms != null ? net.minecraft.locale.Language.getInstance().getOrDefault(nms.getItem().getDescriptionId(nms)) : null;
|
||||
}
|
||||
// Paper end - add getI18NDisplayName
|
||||
|
@ -5,10 +5,10 @@ Subject: [PATCH] Add ItemFactory#getSpawnEgg API
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
index 3ebba8af1cf2d2eaf6670860b011c7dc1da62890..acf57732dd902bd23166e60788477b69e023cb35 100644
|
||||
index 7ce33d2f16d4431d9ff1818f1f8e292ca4d76c35..85de36c0d2aee41f1ed05ed6c4a71adaf61c6168 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
@@ -574,4 +574,19 @@ public final class CraftItemFactory implements ItemFactory {
|
||||
@@ -573,4 +573,19 @@ public final class CraftItemFactory implements ItemFactory {
|
||||
new net.md_5.bungee.api.chat.TextComponent(customName));
|
||||
}
|
||||
// Paper end - bungee hover events
|
||||
|
@ -5,10 +5,10 @@ Subject: [PATCH] Implement enchantWithLevels API
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
index acf57732dd902bd23166e60788477b69e023cb35..071f4fe53fbea333b5db52ac719c5e6b833ffe19 100644
|
||||
index 85de36c0d2aee41f1ed05ed6c4a71adaf61c6168..d412859b8308f62068bd6bdbd57f51bc0bea1607 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
@@ -589,4 +589,20 @@ public final class CraftItemFactory implements ItemFactory {
|
||||
@@ -588,4 +588,20 @@ public final class CraftItemFactory implements ItemFactory {
|
||||
return eggItem == null ? null : new net.minecraft.world.item.ItemStack(eggItem).asBukkitMirror();
|
||||
}
|
||||
// Paper end - old getSpawnEgg API
|
||||
|
@ -5,7 +5,7 @@ Subject: [PATCH] fix item meta for tadpole buckets
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
index 071f4fe53fbea333b5db52ac719c5e6b833ffe19..4cc5f39ee20948e2369b21041b663a7e50d15ac1 100644
|
||||
index d412859b8308f62068bd6bdbd57f51bc0bea1607..4538cb1a36e2589ea04ee60bcd09181065108f4f 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
@@ -364,6 +364,7 @@ public final class CraftItemFactory implements ItemFactory {
|
||||
|
Loading…
Reference in New Issue
Block a user