Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-26 08:10:11 +01:00
Fix: item frames showing names for items without a custom name (fixes https://github.com/GeyserMC/Geyser/issues/5194)
Dieser Commit ist enthalten in:
Ursprung
7b5c1bb370
Commit
030b935d8a
@ -113,14 +113,23 @@ public class ItemFrameEntity extends Entity {
|
|||||||
if (entityMetadata.getValue() != null) {
|
if (entityMetadata.getValue() != null) {
|
||||||
this.heldItem = entityMetadata.getValue();
|
this.heldItem = entityMetadata.getValue();
|
||||||
ItemData itemData = ItemTranslator.translateToBedrock(session, heldItem);
|
ItemData itemData = ItemTranslator.translateToBedrock(session, heldItem);
|
||||||
|
|
||||||
String customIdentifier = session.getItemMappings().getCustomIdMappings().get(itemData.getDefinition().getRuntimeId());
|
String customIdentifier = session.getItemMappings().getCustomIdMappings().get(itemData.getDefinition().getRuntimeId());
|
||||||
|
|
||||||
NbtMapBuilder builder = NbtMap.builder();
|
NbtMapBuilder builder = NbtMap.builder();
|
||||||
|
|
||||||
builder.putByte("Count", (byte) itemData.getCount());
|
builder.putByte("Count", (byte) itemData.getCount());
|
||||||
if (itemData.getTag() != null) {
|
NbtMap itemDataTag = itemData.getTag();
|
||||||
builder.put("tag", itemData.getTag());
|
if (itemDataTag != null) {
|
||||||
|
// Remove custom name that Geyser sets for items due to translating default 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());
|
builder.putShort("Damage", (short) itemData.getDamage());
|
||||||
builder.putString("Name", customIdentifier != null ? customIdentifier : session.getItemMappings().getMapping(entityMetadata.getValue()).getBedrockIdentifier());
|
builder.putString("Name", customIdentifier != null ? customIdentifier : session.getItemMappings().getMapping(entityMetadata.getValue()).getBedrockIdentifier());
|
||||||
|
@ -98,7 +98,7 @@ public class ShulkerBoxItem extends BlockItem {
|
|||||||
|
|
||||||
// Only the display name is what we have interest in, so just translate that if relevant
|
// Only the display name is what we have interest in, so just translate that if relevant
|
||||||
if (boxComponents != null) {
|
if (boxComponents != null) {
|
||||||
String customName = ItemTranslator.getCustomName(session, boxComponents, boxMapping, '7');
|
String customName = ItemTranslator.getCustomName(session, boxComponents, boxMapping, '7', true);
|
||||||
if (customName != null) {
|
if (customName != null) {
|
||||||
boxItemNbt.putCompound("tag", NbtMap.builder()
|
boxItemNbt.putCompound("tag", NbtMap.builder()
|
||||||
.putCompound("display", NbtMap.builder()
|
.putCompound("display", NbtMap.builder()
|
||||||
|
@ -173,7 +173,7 @@ public final class ItemTranslator {
|
|||||||
javaItem.translateComponentsToBedrock(session, components, nbtBuilder);
|
javaItem.translateComponentsToBedrock(session, components, nbtBuilder);
|
||||||
|
|
||||||
Rarity rarity = Rarity.fromId(components.getOrDefault(DataComponentType.RARITY, 0));
|
Rarity rarity = Rarity.fromId(components.getOrDefault(DataComponentType.RARITY, 0));
|
||||||
String customName = getCustomName(session, components, bedrockItem, rarity.getColor());
|
String customName = getCustomName(session, components, bedrockItem, rarity.getColor(), true);
|
||||||
if (customName != null) {
|
if (customName != null) {
|
||||||
nbtBuilder.setCustomName(customName);
|
nbtBuilder.setCustomName(customName);
|
||||||
}
|
}
|
||||||
@ -493,7 +493,7 @@ public final class ItemTranslator {
|
|||||||
* @param translationColor if this item is not available on Java, the color that the new name should be.
|
* @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.
|
* 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) {
|
public static String getCustomName(GeyserSession session, DataComponents components, ItemMapping mapping, char translationColor, boolean includeDefault) {
|
||||||
if (components != null) {
|
if (components != null) {
|
||||||
// ItemStack#getHoverName as of 1.20.5
|
// ItemStack#getHoverName as of 1.20.5
|
||||||
Component customName = components.get(DataComponentType.CUSTOM_NAME);
|
Component customName = components.get(DataComponentType.CUSTOM_NAME);
|
||||||
@ -514,7 +514,7 @@ public final class ItemTranslator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
customName = components.get(DataComponentType.ITEM_NAME);
|
customName = components.get(DataComponentType.ITEM_NAME);
|
||||||
if (customName != null) {
|
if (customName != null && includeDefault) {
|
||||||
// Get the translated name and prefix it with a reset char to prevent italics - matches Java Edition
|
// Get the translated name and prefix it with a reset char to prevent italics - matches Java Edition
|
||||||
// behavior as of 1.21
|
// behavior as of 1.21
|
||||||
return ChatColor.RESET + ChatColor.ESCAPE + translationColor + MessageTranslator.convertMessage(customName, session.locale());
|
return ChatColor.RESET + ChatColor.ESCAPE + translationColor + MessageTranslator.convertMessage(customName, session.locale());
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren