3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 16:12:46 +01:00

Partially implement handling of "hide_tooltip" and fix attribute modifiers in "Armor" category not showing (#4731)

* Skip lore creation if hide tooltips exists

* Fix not showing attributes for "Armor" category

* Minor refactor

---------

Co-authored-by: chris <github@onechris.mozmail.com>
Dieser Commit ist enthalten in:
YHDiamond 2024-06-16 15:01:21 -04:00 committet von GitHub
Ursprung d9f9fcf39a
Commit 6cda7c2202
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
2 geänderte Dateien mit 17 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -125,7 +125,7 @@ public class Item {
*/ */
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) { public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) {
List<Component> loreComponents = components.get(DataComponentType.LORE); List<Component> loreComponents = components.get(DataComponentType.LORE);
if (loreComponents != null) { if (loreComponents != null && components.get(DataComponentType.HIDE_TOOLTIP) == null) {
List<String> lore = builder.getOrCreateLore(); List<String> lore = builder.getOrCreateLore();
for (Component loreComponent : loreComponents) { for (Component loreComponent : loreComponents) {
lore.add(MessageTranslator.convertMessage(loreComponent, session.locale())); lore.add(MessageTranslator.convertMessage(loreComponent, session.locale()));

Datei anzeigen

@ -65,6 +65,12 @@ public final class ItemTranslator {
* The order of these slots is their display order on Java Edition clients * The order of these slots is their display order on Java Edition clients
*/ */
private static final EnumMap<ItemAttributeModifiers.EquipmentSlotGroup, String> SLOT_NAMES; private static final EnumMap<ItemAttributeModifiers.EquipmentSlotGroup, String> SLOT_NAMES;
private static final ItemAttributeModifiers.EquipmentSlotGroup[] ARMOR_SLOT_NAMES = new ItemAttributeModifiers.EquipmentSlotGroup[] {
ItemAttributeModifiers.EquipmentSlotGroup.HEAD,
ItemAttributeModifiers.EquipmentSlotGroup.CHEST,
ItemAttributeModifiers.EquipmentSlotGroup.LEGS,
ItemAttributeModifiers.EquipmentSlotGroup.FEET
};
private static final DecimalFormat ATTRIBUTE_FORMAT = new DecimalFormat("0.#####"); private static final DecimalFormat ATTRIBUTE_FORMAT = new DecimalFormat("0.#####");
static { static {
@ -132,8 +138,10 @@ public final class ItemTranslator {
private static ItemData.@NonNull Builder translateToBedrock(GeyserSession session, Item javaItem, ItemMapping bedrockItem, int count, @Nullable DataComponents components) { private static ItemData.@NonNull Builder translateToBedrock(GeyserSession session, Item javaItem, ItemMapping bedrockItem, int count, @Nullable DataComponents components) {
BedrockItemBuilder nbtBuilder = new BedrockItemBuilder(); BedrockItemBuilder nbtBuilder = new BedrockItemBuilder();
boolean hideTooltips = false;
if (components != null) { if (components != null) {
javaItem.translateComponentsToBedrock(session, components, nbtBuilder); javaItem.translateComponentsToBedrock(session, components, nbtBuilder);
if (components.get(DataComponentType.HIDE_TOOLTIP) != null) hideTooltips = true;
} }
String customName = getCustomName(session, components, bedrockItem); String customName = getCustomName(session, components, bedrockItem);
@ -143,13 +151,13 @@ public final class ItemTranslator {
if (components != null) { if (components != null) {
ItemAttributeModifiers attributeModifiers = components.get(DataComponentType.ATTRIBUTE_MODIFIERS); ItemAttributeModifiers attributeModifiers = components.get(DataComponentType.ATTRIBUTE_MODIFIERS);
if (attributeModifiers != null && attributeModifiers.isShowInTooltip()) { if (attributeModifiers != null && attributeModifiers.isShowInTooltip() && !hideTooltips) {
// only add if attribute modifiers do not indicate to hide them // only add if attribute modifiers do not indicate to hide them
addAttributeLore(attributeModifiers, nbtBuilder, session.locale()); addAttributeLore(attributeModifiers, nbtBuilder, session.locale());
} }
} }
if (session.isAdvancedTooltips()) { if (session.isAdvancedTooltips() && !hideTooltips) {
addAdvancedTooltips(components, nbtBuilder, javaItem, session.locale()); addAdvancedTooltips(components, nbtBuilder, javaItem, session.locale());
} }
@ -207,7 +215,12 @@ public final class ItemTranslator {
} }
ItemAttributeModifiers.EquipmentSlotGroup slotGroup = entry.getSlot(); ItemAttributeModifiers.EquipmentSlotGroup slotGroup = entry.getSlot();
if (slotGroup == ItemAttributeModifiers.EquipmentSlotGroup.ANY) { if (slotGroup == ItemAttributeModifiers.EquipmentSlotGroup.ARMOR) {
// modifier applies to all armor slots
for (ItemAttributeModifiers.EquipmentSlotGroup slot : ARMOR_SLOT_NAMES) {
slotsToModifiers.computeIfAbsent(slot, s -> new ArrayList<>()).add(loreEntry);
}
} else if (slotGroup == ItemAttributeModifiers.EquipmentSlotGroup.ANY) {
// modifier applies to all slots implicitly // modifier applies to all slots implicitly
for (var slot : SLOT_NAMES.keySet()) { for (var slot : SLOT_NAMES.keySet()) {
slotsToModifiers.computeIfAbsent(slot, s -> new ArrayList<>()).add(loreEntry); slotsToModifiers.computeIfAbsent(slot, s -> new ArrayList<>()).add(loreEntry);