fix adventure translations

This commit is contained in:
Jake Potrebic 2024-04-26 15:08:35 -07:00
parent e856d17ec5
commit 882ea0a430
No known key found for this signature in database
GPG Key ID: ECE0B3C133C016C5
13 changed files with 60 additions and 49 deletions

View File

@ -2200,18 +2200,26 @@ index d120fff432d9c4fc7a35ddffdc4186459e45e950..676a1499747b07151547913087515726
}
}
diff --git a/src/main/java/net/minecraft/network/FriendlyByteBuf.java b/src/main/java/net/minecraft/network/FriendlyByteBuf.java
index a7419bcb0954f0adbf7ce2d1e9738e690c265f4d..6ad38756cbc532b18de0793c784b9c7f2a10a88f 100644
index a7419bcb0954f0adbf7ce2d1e9738e690c265f4d..aafeb9c61ddba6a8671f0238eda47b227619f1af 100644
--- a/src/main/java/net/minecraft/network/FriendlyByteBuf.java
+++ b/src/main/java/net/minecraft/network/FriendlyByteBuf.java
@@ -72,6 +72,7 @@ public class FriendlyByteBuf extends ByteBuf {
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;
@@ -120,11 +121,16 @@ public class FriendlyByteBuf extends ByteBuf {
@@ -80,6 +81,7 @@ 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;
}
@@ -120,11 +122,16 @@ public class FriendlyByteBuf extends ByteBuf {
}
public <T> void writeJsonWithCodec(Codec<T> codec, T value) {
@ -2230,17 +2238,22 @@ index a7419bcb0954f0adbf7ce2d1e9738e690c265f4d..6ad38756cbc532b18de0793c784b9c7f
public static <T> IntFunction<T> limitValue(IntFunction<T> applier, int max) {
diff --git a/src/main/java/net/minecraft/network/PacketEncoder.java b/src/main/java/net/minecraft/network/PacketEncoder.java
index a58f67973b4ed986065860263c7a42214640520d..15783d102208f6ab824ac50ed7969204b80a22c9 100644
index a58f67973b4ed986065860263c7a42214640520d..046bfc212b640de174b300e7a05cc30bb3cac93e 100644
--- a/src/main/java/net/minecraft/network/PacketEncoder.java
+++ b/src/main/java/net/minecraft/network/PacketEncoder.java
@@ -20,6 +20,7 @@ public class PacketEncoder<T extends PacketListener> extends MessageToByteEncode
@@ -17,10 +17,12 @@ 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 e4624d696dcf0ddb6d42a80701dfc47ec6877540..6b8dc1eb490098cc14673c9ab0aa16fe3471325b 100644
--- a/src/main/java/net/minecraft/network/chat/ChatDecorator.java
@ -3208,27 +3221,25 @@ index ed54c81a3269360acce674aa4e1d54ccb2461841..c9c849534c3998cfcab7ddcb12a71ccb
}
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index 2b8b220bf1e132b230abe14770da53de84db9818..7ca60db3a639e68456933f8e5af900dc4aade575 100644
index 2b8b220bf1e132b230abe14770da53de84db9818..96da768f55ad835a1a55bf359f0d7278bc232304 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -164,7 +164,16 @@ 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);
@@ -186,7 +186,15 @@ public final class ItemStack implements DataComponentHolder {
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 8ec376f453ac1f4c9423483f5ae1625b295858c7..e535fb3b5194b8412c0c26c0799340916c7542eb 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java

View File

@ -5,10 +5,10 @@ Subject: [PATCH] Remove unnecessary itemmeta handling
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index 7ca60db3a639e68456933f8e5af900dc4aade575..836a9bb57fa6e916ed8a24c35426c6432f73be88 100644
index 96da768f55ad835a1a55bf359f0d7278bc232304..aca1e4ef1593c5a506a37349274cd81b1dc81ea8 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -177,7 +177,7 @@ public final class ItemStack implements DataComponentHolder {
@@ -168,7 +168,7 @@ public final class ItemStack implements DataComponentHolder {
// CraftBukkit start
ItemStack itemstack = new ItemStack(holder, i, datacomponentpatch);
@ -17,7 +17,7 @@ index 7ca60db3a639e68456933f8e5af900dc4aade575..836a9bb57fa6e916ed8a24c35426c643
CraftItemStack.setItemMeta(itemstack, CraftItemStack.getItemMeta(itemstack));
}
return itemstack;
@@ -192,7 +192,7 @@ public final class ItemStack implements DataComponentHolder {
@@ -183,7 +183,7 @@ public final class ItemStack implements DataComponentHolder {
registryfriendlybytebuf.writeVarInt(itemstack.getCount());
// Spigot start - filter
itemstack = itemstack.copy();
@ -25,4 +25,4 @@ index 7ca60db3a639e68456933f8e5af900dc4aade575..836a9bb57fa6e916ed8a24c35426c643
+ // 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

View File

@ -5,10 +5,10 @@ Subject: [PATCH] Allow chests to be placed with NBT data
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index 836a9bb57fa6e916ed8a24c35426c6432f73be88..72ce219546306fc50da37468f37cec8e6bf551fe 100644
index aca1e4ef1593c5a506a37349274cd81b1dc81ea8..c834212d0e6a09c0f73abeb545b60dec26e726a5 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -470,6 +470,7 @@ public final class ItemStack implements DataComponentHolder {
@@ -469,6 +469,7 @@ public final class ItemStack implements DataComponentHolder {
enuminteractionresult = InteractionResult.FAIL; // cancel placement
// PAIL: Remove this when MC-99075 fixed
placeEvent.getPlayer().updateInventory();

View File

@ -5,10 +5,10 @@ Subject: [PATCH] PortalCreateEvent needs to know its entity
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index 72ce219546306fc50da37468f37cec8e6bf551fe..d95272b1765368a4cd968fa566ad68844dced4c8 100644
index c834212d0e6a09c0f73abeb545b60dec26e726a5..db78a1948df2f8a5bce37a7566e9af9cd7c8b485 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -502,7 +502,7 @@ public final class ItemStack implements DataComponentHolder {
@@ -501,7 +501,7 @@ public final class ItemStack implements DataComponentHolder {
net.minecraft.world.level.block.state.BlockState block = world.getBlockState(newblockposition);
if (!(block.getBlock() instanceof BaseEntityBlock)) { // Containers get placed automatically

View File

@ -5,10 +5,10 @@ Subject: [PATCH] Add EntityDamageItemEvent
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index d95272b1765368a4cd968fa566ad68844dced4c8..081d0241692078516a4554ccbda17f4539dc5ed6 100644
index db78a1948df2f8a5bce37a7566e9af9cd7c8b485..87208b14b3f31f372c1d5f4b759f4ced8cc992c9 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -648,7 +648,7 @@ public final class ItemStack implements DataComponentHolder {
@@ -647,7 +647,7 @@ public final class ItemStack implements DataComponentHolder {
return (Integer) this.getOrDefault(DataComponents.MAX_DAMAGE, 0);
}
@ -17,7 +17,7 @@ index d95272b1765368a4cd968fa566ad68844dced4c8..081d0241692078516a4554ccbda17f45
if (this.isDamageableItem()) {
int j;
@@ -664,8 +664,8 @@ public final class ItemStack implements DataComponentHolder {
@@ -663,8 +663,8 @@ public final class ItemStack implements DataComponentHolder {
amount -= k;
// CraftBukkit start
@ -28,7 +28,7 @@ index d95272b1765368a4cd968fa566ad68844dced4c8..081d0241692078516a4554ccbda17f45
event.getPlayer().getServer().getPluginManager().callEvent(event);
if (amount != event.getDamage() || event.isCancelled()) {
@@ -676,6 +676,14 @@ public final class ItemStack implements DataComponentHolder {
@@ -675,6 +675,14 @@ public final class ItemStack implements DataComponentHolder {
}
amount = event.getDamage();
@ -43,7 +43,7 @@ index d95272b1765368a4cd968fa566ad68844dced4c8..081d0241692078516a4554ccbda17f45
}
// CraftBukkit end
if (amount <= 0) {
@@ -683,8 +691,8 @@ public final class ItemStack implements DataComponentHolder {
@@ -682,8 +690,8 @@ public final class ItemStack implements DataComponentHolder {
}
}
@ -54,7 +54,7 @@ index d95272b1765368a4cd968fa566ad68844dced4c8..081d0241692078516a4554ccbda17f45
}
j = this.getDamageValue() + amount;
@@ -717,7 +725,7 @@ public final class ItemStack implements DataComponentHolder {
@@ -716,7 +724,7 @@ public final class ItemStack implements DataComponentHolder {
entityplayer = null;
}

View File

@ -8,10 +8,10 @@ snow bucket didn't revert grass that became snowy because of the
placement.
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index 081d0241692078516a4554ccbda17f4539dc5ed6..8f4ca2479bf185cb2409d1da20dfc7de0f0ce550 100644
index 87208b14b3f31f372c1d5f4b759f4ced8cc992c9..db94bbbd7f93afef46586e6314ebc666b7e6087c 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -402,7 +402,7 @@ public final class ItemStack implements DataComponentHolder {
@@ -401,7 +401,7 @@ public final class ItemStack implements DataComponentHolder {
int oldCount = this.getCount();
ServerLevel world = (ServerLevel) context.getLevel();
@ -20,7 +20,7 @@ index 081d0241692078516a4554ccbda17f4539dc5ed6..8f4ca2479bf185cb2409d1da20dfc7de
world.captureBlockStates = true;
// special case bonemeal
if (item == Items.BONE_MEAL) {
@@ -462,7 +462,7 @@ public final class ItemStack implements DataComponentHolder {
@@ -461,7 +461,7 @@ public final class ItemStack implements DataComponentHolder {
world.capturedBlockStates.clear();
if (blocks.size() > 1) {
placeEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callBlockMultiPlaceEvent(world, entityhuman, enumhand, blocks, blockposition.getX(), blockposition.getY(), blockposition.getZ());

View File

@ -5,10 +5,10 @@ Subject: [PATCH] Expand PlayerItemDamageEvent
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index 8f4ca2479bf185cb2409d1da20dfc7de0f0ce550..179932c624912a39d6c4e53187ba9f9c23df42e5 100644
index db94bbbd7f93afef46586e6314ebc666b7e6087c..9d43c37e345689d5e4c6cfcb00ab2b4da01eef56 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -662,10 +662,11 @@ public final class ItemStack implements DataComponentHolder {
@@ -661,10 +661,11 @@ public final class ItemStack implements DataComponentHolder {
}
}

View File

@ -22,10 +22,10 @@ index 7d76cdc59984b156628273c8357485eb10046007..7180996027f70aef7afe32fb2adfce64
itemstack.consume(1, entityhuman);
return InteractionResult.sidedSuccess(world.isClientSide);
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index 179932c624912a39d6c4e53187ba9f9c23df42e5..144bcbcfc44d0c3467f30046889e225afc42e781 100644
index 9d43c37e345689d5e4c6cfcb00ab2b4da01eef56..be2a229903efe80d318e2b94911fa10ed8134690 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -516,13 +516,7 @@ public final class ItemStack implements DataComponentHolder {
@@ -515,13 +515,7 @@ public final class ItemStack implements DataComponentHolder {
if (tileentity instanceof JukeboxBlockEntity) {
JukeboxBlockEntity tileentityjukebox = (JukeboxBlockEntity) tileentity;

View File

@ -5,10 +5,10 @@ Subject: [PATCH] Fix spigot sound playing for BlockItem ItemStacks
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index 144bcbcfc44d0c3467f30046889e225afc42e781..a11bb28b2b85057418d80db33c2568218ef8db99 100644
index be2a229903efe80d318e2b94911fa10ed8134690..83976d1b9e6f9fe696f58526cbab9b0f607f3bdc 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -567,7 +567,11 @@ public final class ItemStack implements DataComponentHolder {
@@ -566,7 +566,11 @@ public final class ItemStack implements DataComponentHolder {
// SPIGOT-1288 - play sound stripped from ItemBlock
if (this.item instanceof BlockItem) {

View File

@ -5,10 +5,10 @@ Subject: [PATCH] Add event for player editing sign
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index a11bb28b2b85057418d80db33c2568218ef8db99..b00cf6f02bf1e85dbbbbb5b5c1201c643385576f 100644
index 83976d1b9e6f9fe696f58526cbab9b0f607f3bdc..05b4762c9a8ceb2faf21efe534ba609b6e76a968 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -546,7 +546,7 @@ public final class ItemStack implements DataComponentHolder {
@@ -545,7 +545,7 @@ public final class ItemStack implements DataComponentHolder {
try {
if (world.getBlockEntity(SignItem.openSign) instanceof SignBlockEntity tileentitysign) {
if (world.getBlockState(SignItem.openSign).getBlock() instanceof SignBlock blocksign) {

View File

@ -17,10 +17,10 @@ index 5bbadc890a72f1cb22c6881ebcc163b0c06a367a..4fa838bf97ede6e1c893ba64f53aa7af
}
}
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index b00cf6f02bf1e85dbbbbb5b5c1201c643385576f..fb85a7da9da8063c2b781377f62e7db34c467859 100644
index 05b4762c9a8ceb2faf21efe534ba609b6e76a968..6f5e5c5b4af7e16f4a7c5429208fc85014f9e302 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -446,6 +446,7 @@ public final class ItemStack implements DataComponentHolder {
@@ -445,6 +445,7 @@ public final class ItemStack implements DataComponentHolder {
for (CraftBlockState blockstate : blocks) {
// SPIGOT-7572 - Move fix for SPIGOT-7248 to CapturedBlockState, to allow bees in bee nest
CapturedBlockState.setBlockState(blockstate);

View File

@ -149,10 +149,10 @@ index 6d494b80ae002aea00afa44adf83dad1ae5bbbc1..49557d6f22c5725c663a231deab019d4
return false;
}
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index fb85a7da9da8063c2b781377f62e7db34c467859..2d2b436cae5693051df14e5777d385d38d5f4dd6 100644
index 6f5e5c5b4af7e16f4a7c5429208fc85014f9e302..fef96852bd95ad24d1e0daff17c3e117524efc69 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -480,10 +480,12 @@ public final class ItemStack implements DataComponentHolder {
@@ -479,10 +479,12 @@ public final class ItemStack implements DataComponentHolder {
world.preventPoiUpdated = false;
// Brute force all possible updates

View File

@ -62,10 +62,10 @@ index 81d0a0c79958a137ac8bc703eb97f30cd10864e3..b12f69931e5b247c42bb4e56bcf1ef24
this.profiler.push(() -> {
String s = String.valueOf(worldserver);
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index 2d2b436cae5693051df14e5777d385d38d5f4dd6..3d6ea1a9bd87ee9ce34cf95db8835e5729b1ade0 100644
index fef96852bd95ad24d1e0daff17c3e117524efc69..4ef83f6d48a939f883bac49d6527f95f108a91e5 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -795,7 +795,13 @@ public final class ItemStack implements DataComponentHolder {
@@ -794,7 +794,13 @@ public final class ItemStack implements DataComponentHolder {
}
public ItemStack copy() {