mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-12-22 22:45:04 +01:00
Anvil renaming
This commit is contained in:
parent
c963503fef
commit
dacacc6df8
4 changed files with 13 additions and 10 deletions
|
@ -25,6 +25,7 @@
|
|||
|
||||
package org.geysermc.geyser.inventory;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.inventory.ContainerType;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundRenameItemPacket;
|
||||
import lombok.Getter;
|
||||
|
@ -72,10 +73,9 @@ public class AnvilContainer extends Container {
|
|||
String correctRename;
|
||||
newName = rename;
|
||||
|
||||
// TODO 1.20.5 fix properly - this name is apparently nullable??
|
||||
String originalName = MessageTranslator.convertMessage(ItemUtils.getCustomName(getInput().getComponents()));
|
||||
Component originalName = ItemUtils.getCustomName(getInput().getComponents());
|
||||
|
||||
String plainOriginalName = MessageTranslator.convertToPlainTextLenient(originalName, session.locale());
|
||||
String plainOriginalName = MessageTranslator.convertToPlainText(originalName, session.locale());
|
||||
String plainNewName = MessageTranslator.convertToPlainText(rename);
|
||||
if (!plainOriginalName.equals(plainNewName)) {
|
||||
// Strip out formatting since Java Edition does not allow it
|
||||
|
@ -85,7 +85,7 @@ public class AnvilContainer extends Container {
|
|||
session.sendDownstreamGamePacket(renameItemPacket);
|
||||
} else {
|
||||
// Restore formatting for item since we're not renaming
|
||||
correctRename = MessageTranslator.convertMessageLenient(originalName);
|
||||
correctRename = MessageTranslator.convertMessage(originalName, session.locale());
|
||||
// Java Edition sends the original custom name when not renaming,
|
||||
// if there isn't a custom name an empty string is sent
|
||||
ServerboundRenameItemPacket renameItemPacket = new ServerboundRenameItemPacket(plainOriginalName);
|
||||
|
|
|
@ -118,8 +118,7 @@ public class AnvilInventoryUpdater extends InventoryUpdater {
|
|||
|
||||
// Changing the item in the input slot resets the name field on Bedrock, but
|
||||
// does not result in a FilterTextPacket
|
||||
// TODO test
|
||||
String originalName = MessageTranslator.convertToPlainText(ItemUtils.getCustomName(input.getComponents()));
|
||||
String originalName = MessageTranslator.convertToPlainText(ItemUtils.getCustomName(input.getComponents()), session.locale());
|
||||
ServerboundRenameItemPacket renameItemPacket = new ServerboundRenameItemPacket(originalName);
|
||||
session.sendDownstreamGamePacket(renameItemPacket);
|
||||
|
||||
|
|
|
@ -260,13 +260,17 @@ public class MessageTranslator {
|
|||
}
|
||||
|
||||
/**
|
||||
* Convert legacy format message to plain text
|
||||
* Convert a Java message to plain text
|
||||
*
|
||||
* @param message Message to convert
|
||||
* @param locale Locale to use for translation strings
|
||||
* @return The plain text of the message
|
||||
*/
|
||||
public static String convertToPlainText(Component message) {
|
||||
return PlainTextComponentSerializer.plainText().serialize(message);
|
||||
public static String convertToPlainText(Component message, String locale) {
|
||||
if (message == null) {
|
||||
return "";
|
||||
}
|
||||
return PlainTextComponentSerializer.plainText().serialize(RENDERER.render(message, locale));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,7 +15,7 @@ protocol-connection = "3.0.0.Beta1-20240411.165033-128"
|
|||
raknet = "1.0.0.CR3-20240416.144209-1"
|
||||
blockstateupdater="1.20.80-20240411.142413-1"
|
||||
mcauthlib = "d9d773e"
|
||||
mcprotocollib = "400f1b4" # Revert from jitpack after release
|
||||
mcprotocollib = "bc8526b" # Revert from jitpack after release
|
||||
adventure = "4.14.0"
|
||||
adventure-platform = "4.3.0"
|
||||
junit = "5.9.2"
|
||||
|
|
Loading…
Reference in a new issue