From cc25d48411f665f34a7e3a2c01d8e866304ea41f Mon Sep 17 00:00:00 2001 From: BugTeaON Date: Mon, 30 Dec 2024 20:56:07 +0800 Subject: [PATCH 1/7] Show custom effects information in HUD, and be able to hide it using hide_additional_tooltip component --- .../geysermc/geyser/item/type/PotionItem.java | 13 ----- .../geyser/item/type/TippedArrowItem.java | 14 ----- .../translator/item/ItemTranslator.java | 52 ++++++++++++++----- 3 files changed, 40 insertions(+), 39 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/item/type/PotionItem.java b/core/src/main/java/org/geysermc/geyser/item/type/PotionItem.java index 4cc3756cdf..89e60b3250 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/PotionItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/PotionItem.java @@ -34,9 +34,7 @@ import org.geysermc.geyser.registry.type.ItemMapping; import org.geysermc.geyser.registry.type.ItemMappings; import org.geysermc.geyser.session.GeyserSession; -import org.geysermc.geyser.translator.item.BedrockItemBuilder; import org.geysermc.geyser.translator.item.CustomItemTranslator; -import org.geysermc.geyser.translator.item.ItemTranslator; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents; import org.geysermc.mcprotocollib.protocol.data.game.item.component.PotionContents; @@ -70,17 +68,6 @@ public ItemData.Builder translateToBedrock(GeyserSession session, int count, Dat return super.translateToBedrock(session, count, components, mapping, mappings); } - @Override - public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) { - // Make custom effect information visible - PotionContents potionContents = components.get(DataComponentType.POTION_CONTENTS); - if (potionContents != null) { - ItemTranslator.addPotionEffectLore(potionContents, builder, session.locale()); - } - - super.translateComponentsToBedrock(session, components, builder); - } - @Override public @NonNull GeyserItemStack translateToJava(GeyserSession session, @NonNull ItemData itemData, @NonNull ItemMapping mapping, @NonNull ItemMappings mappings) { Potion potion = Potion.getByBedrockId(itemData.getDamage()); diff --git a/core/src/main/java/org/geysermc/geyser/item/type/TippedArrowItem.java b/core/src/main/java/org/geysermc/geyser/item/type/TippedArrowItem.java index 9e212ebef1..09e4ee21f9 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/TippedArrowItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/TippedArrowItem.java @@ -25,15 +25,12 @@ package org.geysermc.geyser.item.type; -import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.inventory.item.Potion; import org.geysermc.geyser.registry.type.ItemMapping; import org.geysermc.geyser.registry.type.ItemMappings; import org.geysermc.geyser.session.GeyserSession; -import org.geysermc.geyser.translator.item.BedrockItemBuilder; -import org.geysermc.geyser.translator.item.ItemTranslator; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents; import org.geysermc.mcprotocollib.protocol.data.game.item.component.PotionContents; @@ -60,15 +57,4 @@ public ItemData.Builder translateToBedrock(GeyserSession session, int count, Dat } return super.translateToBedrock(session, count, components, mapping, mappings); } - - @Override - public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) { - // Make custom effect information visible - PotionContents potionContents = components.get(DataComponentType.POTION_CONTENTS); - if (potionContents != null) { - ItemTranslator.addPotionEffectLore(potionContents, builder, session.locale()); - } - - super.translateComponentsToBedrock(session, components, builder); - } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java index b8959c7b8a..c870698d8e 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java @@ -41,6 +41,7 @@ import org.geysermc.geyser.api.block.custom.CustomBlockData; import org.geysermc.geyser.entity.attribute.GeyserAttributeType; import org.geysermc.geyser.inventory.GeyserItemStack; +import org.geysermc.geyser.inventory.item.Potion; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.components.Rarity; import org.geysermc.geyser.item.type.Item; @@ -175,6 +176,13 @@ public static ItemData translateToBedrock(GeyserSession session, ItemStack stack Rarity rarity = Rarity.fromId(components.getOrDefault(DataComponentType.RARITY, 0)); String customName = getCustomName(session, components, bedrockItem, rarity.getColor(), false); if (customName != null) { + PotionContents potionContents = components.get(DataComponentType.POTION_CONTENTS); + // Make custom effect information visible + // Ignore when item have "hide_additional_tooltip" component + if (potionContents != null && components.get(DataComponentType.HIDE_ADDITIONAL_TOOLTIP) == null) { + customName += getPotionEffectInfo(potionContents, session.locale()); + } + nbtBuilder.setCustomName(customName); } @@ -336,7 +344,8 @@ private static String attributeToLore(GeyserSession session, int attribute, Item Effect.INFESTED ); - public static void addPotionEffectLore(PotionContents contents, BedrockItemBuilder builder, String language) { + public static String getPotionEffectInfo(PotionContents contents, String language) { + StringBuilder finalText = new StringBuilder(); List effectInstanceList = contents.getCustomEffects(); for (MobEffectInstance effectInstance : effectInstanceList) { Effect effect = effectInstance.getEffect(); @@ -372,8 +381,35 @@ public static void addPotionEffectLore(PotionContents contents, BedrockItemBuild .color((negativeEffectList.contains(effect)) ? NamedTextColor.RED : NamedTextColor.BLUE) .append(appendTranslatable) .build(); - builder.getOrCreateLore().add(MessageTranslator.convertMessage(component, language)); + finalText.append('\n').append(MessageTranslator.convertMessage(component, language)); } + return finalText.toString(); + } + + public static String getPotionName(PotionContents contents, ItemMapping mapping, String language) { + String customPotionName = contents.getCustomName(); + Potion potion = Potion.getByJavaId(contents.getPotionId()); + + if (customPotionName != null) { + // "custom_name" tag in "potion_contents" component + return MessageTranslator.convertMessage( + Component.translatable(mapping.getJavaItem().translationKey() + ".effect." + customPotionName), + language); + } + if (!contents.getCustomEffects().isEmpty()) { + // Make a name when has custom effects + String potionName; + if (potion != null) { + potionName = potion.toString().toLowerCase(Locale.ROOT); + if (potionName.startsWith("strong_")) potionName = potionName.substring(6); + else if (potionName.startsWith("long_")) potionName = potionName.substring(4); + } + else potionName = "empty"; + return MessageTranslator.convertMessage( + Component.translatable(mapping.getJavaItem().translationKey() + ".effect." + potionName), + language); + } + return null; } private static void addAdvancedTooltips(@Nullable DataComponents components, BedrockItemBuilder builder, Item item, String language) { @@ -502,16 +538,8 @@ public static String getCustomName(GeyserSession session, DataComponents compone } PotionContents potionContents = components.get(DataComponentType.POTION_CONTENTS); if (potionContents != null) { - // "custom_name" tag in "potion_contents" component - String customPotionName = potionContents.getCustomName(); - if (customPotionName != null) { - Component component = Component.text() - .resetStyle() - .color(NamedTextColor.WHITE) - .append(Component.translatable(mapping.getJavaItem().translationKey() + ".effect." + customPotionName)) - .build(); - return MessageTranslator.convertMessage(component, session.locale()); - } + String potionName = getPotionName(potionContents, mapping, session.locale()); + if (potionName != null) return ChatColor.RESET + ChatColor.ESCAPE + translationColor + potionName; } customName = components.get(DataComponentType.ITEM_NAME); if (customName != null && includeDefault) { From eb6ee16b4fe3684e93b62b7a8988678c86c411bf Mon Sep 17 00:00:00 2001 From: BugTeaON Date: Mon, 30 Dec 2024 21:15:53 +0800 Subject: [PATCH 2/7] Make vanilla default components no longer affect the translation of custom name (Fix item_name component not work) --- .../geyser/entity/type/ItemFrameEntity.java | 12 ++++++- .../translator/item/ItemTranslator.java | 31 ++++++++++--------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java index ba3dfb79d9..4df8947e30 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java @@ -118,7 +118,17 @@ public void setItemInFrame(EntityMetadata entityMetadata) { NbtMapBuilder builder = NbtMap.builder(); builder.putByte("Count", (byte) itemData.getCount()); NbtMap itemDataTag = itemData.getTag(); - if (itemData.getTag() != null) { + if (itemDataTag != null) { + // Remove custom name that Geyser sets for items due to translating non-"custom_name" components + String customName = ItemTranslator.getCustomName(session, heldItem.getDataComponents(), + session.getItemMappings().getMapping(heldItem), 'f', false); + if (customName == null) { + // No custom name found, must modify tag if custom name exists + NbtMapBuilder copy = itemDataTag.toBuilder(); + copy.remove("display"); // Also removes lore, but, should not matter + itemDataTag = copy.build(); + } + builder.put("tag", itemDataTag); } builder.putShort("Damage", (short) itemData.getDamage()); diff --git a/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java index c870698d8e..611848510a 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java @@ -71,6 +71,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.item.component.MobEffectDetails; import org.geysermc.mcprotocollib.protocol.data.game.item.component.MobEffectInstance; import org.geysermc.mcprotocollib.protocol.data.game.item.component.PotionContents; +import org.geysermc.mcprotocollib.protocol.data.game.item.component.WrittenBookContent; import java.text.DecimalFormat; import java.util.ArrayList; @@ -164,17 +165,17 @@ public static ItemData translateToBedrock(GeyserSession session, ItemStack stack .build(); } - public static ItemData.@NonNull Builder translateToBedrock(GeyserSession session, Item javaItem, ItemMapping bedrockItem, int count, @Nullable DataComponents components) { + public static ItemData.@NonNull Builder translateToBedrock(GeyserSession session, Item javaItem, ItemMapping bedrockItem, int count, @Nullable DataComponents customComponents) { BedrockItemBuilder nbtBuilder = new BedrockItemBuilder(); // Populates default components that aren't sent over the network - components = javaItem.gatherComponents(components); + DataComponents components = javaItem.gatherComponents(customComponents); // Translate item-specific components javaItem.translateComponentsToBedrock(session, components, nbtBuilder); Rarity rarity = Rarity.fromId(components.getOrDefault(DataComponentType.RARITY, 0)); - String customName = getCustomName(session, components, bedrockItem, rarity.getColor(), false); + String customName = getCustomName(session, customComponents, bedrockItem, rarity.getColor(), true); if (customName != null) { PotionContents potionContents = components.get(DataComponentType.POTION_CONTENTS); // Make custom effect information visible @@ -529,23 +530,25 @@ public static ItemDefinition getBedrockItemDefinition(GeyserSession session, @No * @param translationColor if this item is not available on Java, the color that the new name should be. * Normally, this should just be white, but for shulker boxes this should be gray. */ - public static String getCustomName(GeyserSession session, DataComponents components, ItemMapping mapping, char translationColor, boolean includeDefault) { + public static String getCustomName(GeyserSession session, DataComponents components, ItemMapping mapping, char translationColor, boolean includeNonCustomName) { if (components != null) { // ItemStack#getHoverName as of 1.20.5 Component customName = components.get(DataComponentType.CUSTOM_NAME); if (customName != null) { return MessageTranslator.convertMessage(customName, session.locale()); } - PotionContents potionContents = components.get(DataComponentType.POTION_CONTENTS); - if (potionContents != null) { - String potionName = getPotionName(potionContents, mapping, session.locale()); - if (potionName != null) return ChatColor.RESET + ChatColor.ESCAPE + translationColor + potionName; - } - customName = components.get(DataComponentType.ITEM_NAME); - if (customName != null && includeDefault) { - // Get the translated name and prefix it with a reset char to prevent italics - matches Java Edition - // behavior as of 1.21 - return ChatColor.RESET + ChatColor.ESCAPE + translationColor + MessageTranslator.convertMessage(customName, session.locale()); + if (includeNonCustomName) { + PotionContents potionContents = components.get(DataComponentType.POTION_CONTENTS); + if (potionContents != null) { + String potionName = getPotionName(potionContents, mapping, session.locale()); + if (potionName != null) return ChatColor.RESET + ChatColor.ESCAPE + translationColor + potionName; + } + customName = components.get(DataComponentType.ITEM_NAME); + if (customName != null) { + // Get the translated name and prefix it with a reset char to prevent italics - matches Java Edition + // behavior as of 1.21 + return ChatColor.RESET + ChatColor.ESCAPE + translationColor + MessageTranslator.convertMessage(customName, session.locale()); + } } } From 38d7a458fd96e49f11646ed79edb909c37b60d2d Mon Sep 17 00:00:00 2001 From: BugTeaON Date: Mon, 30 Dec 2024 21:21:08 +0800 Subject: [PATCH 3/7] Fix book title display in tooltips of shulker box --- .../geysermc/geyser/entity/type/ItemFrameEntity.java | 2 +- .../geysermc/geyser/item/type/ShulkerBoxItem.java | 2 +- .../geyser/translator/item/ItemTranslator.java | 12 +++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java index 4df8947e30..afe0dcdc68 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java @@ -121,7 +121,7 @@ public void setItemInFrame(EntityMetadata entityMetadata) { if (itemDataTag != null) { // Remove custom name that Geyser sets for items due to translating non-"custom_name" components String customName = ItemTranslator.getCustomName(session, heldItem.getDataComponents(), - session.getItemMappings().getMapping(heldItem), 'f', false); + session.getItemMappings().getMapping(heldItem), 'f', true, false); if (customName == null) { // No custom name found, must modify tag if custom name exists NbtMapBuilder copy = itemDataTag.toBuilder(); diff --git a/core/src/main/java/org/geysermc/geyser/item/type/ShulkerBoxItem.java b/core/src/main/java/org/geysermc/geyser/item/type/ShulkerBoxItem.java index d8d2c347da..f79560a047 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/ShulkerBoxItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/ShulkerBoxItem.java @@ -98,7 +98,7 @@ public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNul // Only the display name is what we have interest in, so just translate that if relevant if (boxComponents != null) { - String customName = ItemTranslator.getCustomName(session, boxComponents, boxMapping, '7', true); + String customName = ItemTranslator.getCustomName(session, boxComponents, boxMapping, '7', false, true); if (customName != null) { boxItemNbt.putCompound("tag", NbtMap.builder() .putCompound("display", NbtMap.builder() diff --git a/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java index 611848510a..058cc9b04a 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java @@ -175,7 +175,7 @@ public static ItemData translateToBedrock(GeyserSession session, ItemStack stack javaItem.translateComponentsToBedrock(session, components, nbtBuilder); Rarity rarity = Rarity.fromId(components.getOrDefault(DataComponentType.RARITY, 0)); - String customName = getCustomName(session, customComponents, bedrockItem, rarity.getColor(), true); + String customName = getCustomName(session, customComponents, bedrockItem, rarity.getColor(), false, false); if (customName != null) { PotionContents potionContents = components.get(DataComponentType.POTION_CONTENTS); // Make custom effect information visible @@ -530,19 +530,25 @@ public static ItemDefinition getBedrockItemDefinition(GeyserSession session, @No * @param translationColor if this item is not available on Java, the color that the new name should be. * Normally, this should just be white, but for shulker boxes this should be gray. */ - public static String getCustomName(GeyserSession session, DataComponents components, ItemMapping mapping, char translationColor, boolean includeNonCustomName) { + public static String getCustomName(GeyserSession session, DataComponents components, ItemMapping mapping, char translationColor, boolean customNameOnly, boolean includeAll) { if (components != null) { // ItemStack#getHoverName as of 1.20.5 Component customName = components.get(DataComponentType.CUSTOM_NAME); if (customName != null) { return MessageTranslator.convertMessage(customName, session.locale()); } - if (includeNonCustomName) { + if (!customNameOnly) { PotionContents potionContents = components.get(DataComponentType.POTION_CONTENTS); if (potionContents != null) { String potionName = getPotionName(potionContents, mapping, session.locale()); if (potionName != null) return ChatColor.RESET + ChatColor.ESCAPE + translationColor + potionName; } + if (includeAll) { + WrittenBookContent bookContent = components.get(DataComponentType.WRITTEN_BOOK_CONTENT); + if (bookContent != null) { + return ChatColor.RESET + ChatColor.ESCAPE + translationColor + bookContent.getTitle().getRaw(); + } + } customName = components.get(DataComponentType.ITEM_NAME); if (customName != null) { // Get the translated name and prefix it with a reset char to prevent italics - matches Java Edition From d4d202ffbd53292bec3e5258e4f8783c89727f49 Mon Sep 17 00:00:00 2001 From: BugTeaON Date: Mon, 30 Dec 2024 21:23:39 +0800 Subject: [PATCH 4/7] Fix colored item name display in tooltips of shulker box --- .../main/java/org/geysermc/geyser/item/type/ShulkerBoxItem.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/main/java/org/geysermc/geyser/item/type/ShulkerBoxItem.java b/core/src/main/java/org/geysermc/geyser/item/type/ShulkerBoxItem.java index f79560a047..507174a55f 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/ShulkerBoxItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/ShulkerBoxItem.java @@ -35,6 +35,7 @@ import org.geysermc.geyser.level.block.type.Block; import org.geysermc.geyser.registry.type.ItemMapping; import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.text.ChatColor; import org.geysermc.geyser.translator.item.BedrockItemBuilder; import org.geysermc.geyser.translator.item.CustomItemTranslator; import org.geysermc.geyser.translator.item.ItemTranslator; @@ -100,6 +101,7 @@ public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNul if (boxComponents != null) { String customName = ItemTranslator.getCustomName(session, boxComponents, boxMapping, '7', false, true); if (customName != null) { + if (customName.contains("" + ChatColor.ESCAPE)) customName += ChatColor.RESET + ChatColor.GRAY; boxItemNbt.putCompound("tag", NbtMap.builder() .putCompound("display", NbtMap.builder() .putString("Name", customName) From 84865f56d9322af6ffdf3e2e4ef66ac1ba96b62b Mon Sep 17 00:00:00 2001 From: BugTeaON Date: Mon, 30 Dec 2024 23:01:56 +0800 Subject: [PATCH 5/7] Add some code comments --- .../main/java/org/geysermc/geyser/item/type/ShulkerBoxItem.java | 1 + .../org/geysermc/geyser/translator/item/ItemTranslator.java | 2 ++ 2 files changed, 3 insertions(+) diff --git a/core/src/main/java/org/geysermc/geyser/item/type/ShulkerBoxItem.java b/core/src/main/java/org/geysermc/geyser/item/type/ShulkerBoxItem.java index 507174a55f..b470ef0713 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/ShulkerBoxItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/ShulkerBoxItem.java @@ -101,6 +101,7 @@ public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNul if (boxComponents != null) { String customName = ItemTranslator.getCustomName(session, boxComponents, boxMapping, '7', false, true); if (customName != null) { + // Fix count display (e.g., x16) with incorrect color due to some items with colored names if (customName.contains("" + ChatColor.ESCAPE)) customName += ChatColor.RESET + ChatColor.GRAY; boxItemNbt.putCompound("tag", NbtMap.builder() .putCompound("display", NbtMap.builder() diff --git a/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java index 058cc9b04a..9c66fcabac 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java @@ -382,6 +382,7 @@ public static String getPotionEffectInfo(PotionContents contents, String languag .color((negativeEffectList.contains(effect)) ? NamedTextColor.RED : NamedTextColor.BLUE) .append(appendTranslatable) .build(); + // Bedrock supports wrap lines with '\n' in a single string in custom name finalText.append('\n').append(MessageTranslator.convertMessage(component, language)); } return finalText.toString(); @@ -544,6 +545,7 @@ public static String getCustomName(GeyserSession session, DataComponents compone if (potionName != null) return ChatColor.RESET + ChatColor.ESCAPE + translationColor + potionName; } if (includeAll) { + // Fix book title display in tooltips of shulker box WrittenBookContent bookContent = components.get(DataComponentType.WRITTEN_BOOK_CONTENT); if (bookContent != null) { return ChatColor.RESET + ChatColor.ESCAPE + translationColor + bookContent.getTitle().getRaw(); From 62bb4bc1688f08453cb178bb4a5f204a0aad37ac Mon Sep 17 00:00:00 2001 From: BugTeaON Date: Tue, 31 Dec 2024 00:59:49 +0800 Subject: [PATCH 6/7] Block vanilla potion name translation when has hide_additional_tooltip component --- .../org/geysermc/geyser/translator/item/ItemTranslator.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java index 9c66fcabac..ec24472636 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java @@ -388,7 +388,7 @@ public static String getPotionEffectInfo(PotionContents contents, String languag return finalText.toString(); } - public static String getPotionName(PotionContents contents, ItemMapping mapping, String language) { + public static String getPotionName(PotionContents contents, ItemMapping mapping, boolean hideAdditionalTooltip, String language) { String customPotionName = contents.getCustomName(); Potion potion = Potion.getByJavaId(contents.getPotionId()); @@ -398,7 +398,7 @@ public static String getPotionName(PotionContents contents, ItemMapping mapping, Component.translatable(mapping.getJavaItem().translationKey() + ".effect." + customPotionName), language); } - if (!contents.getCustomEffects().isEmpty()) { + if (!hideAdditionalTooltip && !contents.getCustomEffects().isEmpty()) { // Make a name when has custom effects String potionName; if (potion != null) { @@ -541,7 +541,7 @@ public static String getCustomName(GeyserSession session, DataComponents compone if (!customNameOnly) { PotionContents potionContents = components.get(DataComponentType.POTION_CONTENTS); if (potionContents != null) { - String potionName = getPotionName(potionContents, mapping, session.locale()); + String potionName = getPotionName(potionContents, mapping, components.get(DataComponentType.HIDE_ADDITIONAL_TOOLTIP) != null, session.locale()); if (potionName != null) return ChatColor.RESET + ChatColor.ESCAPE + translationColor + potionName; } if (includeAll) { From 81c172840b938fcce94bbed35e57abaecaced699 Mon Sep 17 00:00:00 2001 From: BugTeaON Date: Tue, 31 Dec 2024 11:41:51 +0800 Subject: [PATCH 7/7] Add some brackets --- .../geysermc/geyser/item/type/ShulkerBoxItem.java | 4 +++- .../geyser/translator/item/ItemTranslator.java | 14 ++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/item/type/ShulkerBoxItem.java b/core/src/main/java/org/geysermc/geyser/item/type/ShulkerBoxItem.java index b470ef0713..5d14f748ce 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/ShulkerBoxItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/ShulkerBoxItem.java @@ -102,7 +102,9 @@ public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNul String customName = ItemTranslator.getCustomName(session, boxComponents, boxMapping, '7', false, true); if (customName != null) { // Fix count display (e.g., x16) with incorrect color due to some items with colored names - if (customName.contains("" + ChatColor.ESCAPE)) customName += ChatColor.RESET + ChatColor.GRAY; + if (customName.contains("" + ChatColor.ESCAPE)) { + customName += ChatColor.RESET + ChatColor.GRAY; + } boxItemNbt.putCompound("tag", NbtMap.builder() .putCompound("display", NbtMap.builder() .putString("Name", customName) diff --git a/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java index ec24472636..3f9bf74469 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java @@ -403,10 +403,14 @@ public static String getPotionName(PotionContents contents, ItemMapping mapping, String potionName; if (potion != null) { potionName = potion.toString().toLowerCase(Locale.ROOT); - if (potionName.startsWith("strong_")) potionName = potionName.substring(6); - else if (potionName.startsWith("long_")) potionName = potionName.substring(4); + if (potionName.startsWith("strong_")) { + potionName = potionName.substring(6); + } else if (potionName.startsWith("long_")) { + potionName = potionName.substring(4); + } + } else { + potionName = "empty"; } - else potionName = "empty"; return MessageTranslator.convertMessage( Component.translatable(mapping.getJavaItem().translationKey() + ".effect." + potionName), language); @@ -542,7 +546,9 @@ public static String getCustomName(GeyserSession session, DataComponents compone PotionContents potionContents = components.get(DataComponentType.POTION_CONTENTS); if (potionContents != null) { String potionName = getPotionName(potionContents, mapping, components.get(DataComponentType.HIDE_ADDITIONAL_TOOLTIP) != null, session.locale()); - if (potionName != null) return ChatColor.RESET + ChatColor.ESCAPE + translationColor + potionName; + if (potionName != null) { + return ChatColor.RESET + ChatColor.ESCAPE + translationColor + potionName; + } } if (includeAll) { // Fix book title display in tooltips of shulker box