mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
fix adventure translations
This commit is contained in:
parent
8cb49c8d67
commit
6ba0e1048f
@ -2207,10 +2207,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
|
||||
public static final int DEFAULT_NBT_QUOTA = 2097152;
|
||||
private final ByteBuf source;
|
||||
+ public java.util.Locale adventure$locale; // Paper - track player's locale for server-side translations
|
||||
+ @Nullable public final java.util.Locale adventure$locale; // Paper - track player's locale for server-side translations
|
||||
public static final short MAX_STRING_LENGTH = Short.MAX_VALUE;
|
||||
public static final int MAX_COMPONENT_STRING_LENGTH = 262144;
|
||||
private static final int PUBLIC_KEY_SIZE = 256;
|
||||
@@ -0,0 +0,0 @@ public class FriendlyByteBuf extends ByteBuf {
|
||||
private static final Gson GSON = new Gson();
|
||||
|
||||
public FriendlyByteBuf(ByteBuf parent) {
|
||||
+ this.adventure$locale = PacketEncoder.ADVENTURE_LOCALE.get(); // Paper - track player's locale for server-side translations
|
||||
this.source = parent;
|
||||
}
|
||||
|
||||
@@ -0,0 +0,0 @@ public class FriendlyByteBuf extends ByteBuf {
|
||||
}
|
||||
|
||||
@ -2234,13 +2242,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
--- a/src/main/java/net/minecraft/network/PacketEncoder.java
|
||||
+++ b/src/main/java/net/minecraft/network/PacketEncoder.java
|
||||
@@ -0,0 +0,0 @@ public class PacketEncoder<T extends PacketListener> extends MessageToByteEncode
|
||||
this.protocolInfo = state;
|
||||
}
|
||||
|
||||
+ static final ThreadLocal<java.util.Locale> ADVENTURE_LOCALE = ThreadLocal.withInitial(() -> null); // Paper - adventure; set player's locale
|
||||
protected void encode(ChannelHandlerContext channelHandlerContext, Packet<T> packet, ByteBuf byteBuf) throws Exception {
|
||||
PacketType<? extends Packet<? super T>> packetType = packet.type();
|
||||
|
||||
+ if (byteBuf instanceof FriendlyByteBuf friendlyByteBuf) friendlyByteBuf.adventure$locale = channelHandlerContext.channel().attr(io.papermc.paper.adventure.PaperAdventure.LOCALE_ATTRIBUTE).get(); // Paper - adventure; set player's locale
|
||||
try {
|
||||
+ ADVENTURE_LOCALE.set(channelHandlerContext.channel().attr(io.papermc.paper.adventure.PaperAdventure.LOCALE_ATTRIBUTE).get()); // Paper - adventure; set player's locale
|
||||
this.protocolInfo.codec().encode(byteBuf, packet);
|
||||
int i = byteBuf.readableBytes();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
diff --git a/src/main/java/net/minecraft/network/chat/ChatDecorator.java b/src/main/java/net/minecraft/network/chat/ChatDecorator.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/network/chat/ChatDecorator.java
|
||||
@ -3212,23 +3225,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
|
||||
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
|
||||
@@ -0,0 +0,0 @@ public final class ItemStack implements DataComponentHolder {
|
||||
return ItemStack.EMPTY;
|
||||
} else {
|
||||
Holder<Item> holder = (Holder) ITEM_STREAM_CODEC.decode(registryfriendlybytebuf); // CraftBukkit - decompile error
|
||||
- DataComponentPatch datacomponentpatch = (DataComponentPatch) DataComponentPatch.STREAM_CODEC.decode(registryfriendlybytebuf);
|
||||
CraftItemStack.setItemMeta(itemstack, CraftItemStack.getItemMeta(itemstack));
|
||||
// Spigot end
|
||||
ITEM_STREAM_CODEC.encode(registryfriendlybytebuf, itemstack.getItemHolder()); // CraftBukkit - decompile error
|
||||
+ // Paper start - adventure; conditionally render translatable components
|
||||
+ DataComponentPatch datacomponentpatch;
|
||||
+ boolean prev = net.minecraft.network.chat.ComponentSerialization.DONT_RENDER_TRANSLATABLES.get();
|
||||
+ try {
|
||||
+ net.minecraft.network.chat.ComponentSerialization.DONT_RENDER_TRANSLATABLES.set(true);
|
||||
+ datacomponentpatch = (DataComponentPatch) DataComponentPatch.STREAM_CODEC.decode(registryfriendlybytebuf);
|
||||
+ net.minecraft.network.chat.ComponentSerialization.DONT_RENDER_TRANSLATABLES.set(true);
|
||||
DataComponentPatch.STREAM_CODEC.encode(registryfriendlybytebuf, itemstack.components.asPatch());
|
||||
+ } finally {
|
||||
+ net.minecraft.network.chat.ComponentSerialization.DONT_RENDER_TRANSLATABLES.set(prev);
|
||||
+ }
|
||||
+ // Paper end - adventure; conditionally render translatable components
|
||||
|
||||
// CraftBukkit start
|
||||
ItemStack itemstack = new ItemStack(holder, i, datacomponentpatch);
|
||||
}
|
||||
}
|
||||
};
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java
|
||||
|
@ -25,4 +25,4 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ // CraftItemStack.setItemMeta(itemstack, CraftItemStack.getItemMeta(itemstack)); // Paper - This is no longer with raw NBT being handled in metadata
|
||||
// Spigot end
|
||||
ITEM_STREAM_CODEC.encode(registryfriendlybytebuf, itemstack.getItemHolder()); // CraftBukkit - decompile error
|
||||
DataComponentPatch.STREAM_CODEC.encode(registryfriendlybytebuf, itemstack.components.asPatch());
|
||||
// Paper start - adventure; conditionally render translatable components
|
||||
|
Loading…
Reference in New Issue
Block a user